Merge git://github.com/darchon/clash into cλash
[matthijs/master-project/cλash.git] / HighOrdAlu.hs
1 module HighOrdAlu where
2
3 import Prelude hiding (
4   null, length, head, tail, last, init, take, drop, (++), map, foldl, foldr,
5   zipWith, zip, unzip, concat, reverse, iterate )
6 import Bits
7 import Types
8 import Data.Param.TFVec
9 import Data.RangedWord
10
11 constant :: e -> Op D4 e
12 constant e a b =
13   (e +> (e +> (e +> (singleton e))))
14
15 invop :: Op n Bit
16 invop a b = map hwnot a
17
18 andop :: Op n Bit
19 andop a b = zipWith hwand a b
20
21 -- Is any bit set?
22 --anyset :: (PositiveT n) => Op n Bit
23 anyset :: (Bit -> Bit -> Bit) -> Op D4 Bit
24 --anyset a b = copy undefined (a' `hwor` b')
25 anyset f a b = constant (a' `hwor` b') a b
26   where 
27     a' = foldl f Low a
28     b' = foldl f Low b
29
30 xhwor = hwor
31
32 type Op n e = (TFVec n e -> TFVec n e -> TFVec n e)
33 type Opcode = Bit
34
35 alu :: Op n e -> Op n e -> Opcode -> TFVec n e -> TFVec n e -> TFVec n e
36 alu op1 op2 opc a b =
37   case opc of
38     Low -> op1 a b
39     High -> op2 a b
40
41 actual_alu :: Opcode -> TFVec D4 Bit -> TFVec D4 Bit -> TFVec D4 Bit
42 --actual_alu = alu (constant Low) andop
43 actual_alu = alu (anyset xhwor)  andop