大久保弘崇
ex8.7
最終更新:
hirotakaohkubo
-
view
ex8.24
2入力セレクタを4段並べることで16入力セレクタを構成する。
lut4 :: [Bit] -> (Bit,Bit,Bit,Bit) -> Bit
lut4 cfgs = \ (a,b,c,d) ->
(hl ->- ch d ->- hl ->- ch c ->- hl ->- ch b ->- hl ->- ch a ->- unwrap) cfgs where
hl = halveList
ch sw (xs,ys) = zipWith (\ x y -> or2 (and2 (inv sw, x), and2 (sw, y))) xs ys
unwrap [x] = x
[a,b,c,d] と cfgs を上、左からの入力とするrowを構成する方がよりコンパクトにできる。
lut4 cfgs = \ (a,b,c,d) -> (row ch ->- unwrap) (cfgs, [d,c,b,a]) where
ch = (halveList-|-id) ->- sel2 ->- tag
sel2 ((xs,ys),sw) = zipWith (\ x y -> or2 (and2 (inv sw, x), and2 (sw, y))) xs ys
tag x = (undefined, x)
unwrap (_,[x]) = x
コードクローンは排除できたが、つじつま合わせで見た目は汚れた。
ex8.25
lut4を2回使って3入力のANDゲートと4入力のANDゲートを作って接続するのが素直な方法。
より無精にするには、4入力のANDゲートを2つ使えばよい。
より無精にするには、4入力のANDゲートを2つ使えばよい。
lutand6 (a,b,c,d,e,f) = ((and4-|-id) ->- align ->- and4) ((a,b,c,d),(e,f)) where
and4 = lut4 [low,low,low,low,low,low,low,low,low,low,low,low,low,low,low,high]
align (x,(e,f)) = (x,e,f,high)