We now support Annotations to indicate top-level entity and initial state
[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 import CLasH.Translator.Annotations
11
12 constant :: e -> Op D4 e
13 constant e a b =
14   (e +> (e +> (e +> (singleton e))))
15
16 invop :: Op n Bit
17 invop a b = map hwnot a
18
19 andop :: Op n Bit
20 andop a b = zipWith hwand a b
21
22 -- Is any bit set?
23 --anyset :: (PositiveT n) => Op n Bit
24 anyset :: (Bit -> Bit -> Bit) -> Op D4 Bit
25 --anyset a b = copy undefined (a' `hwor` b')
26 anyset f a b = constant (a' `hwor` b') a b
27   where 
28     a' = foldl f Low a
29     b' = foldl f Low b
30
31 xhwor = hwor
32
33 type Op n e = (TFVec n e -> TFVec n e -> TFVec n e)
34 type Opcode = Bit
35
36 {-# ANN actual_alu InitState #-}
37 initstate = High
38
39 alu :: Op n e -> Op n e -> Opcode -> TFVec n e -> TFVec n e -> TFVec n e
40 alu op1 op2 opc a b =
41   case opc of
42     Low -> op1 a b
43     High -> op2 a b
44
45 {-# ANN actual_alu TopEntity #-}
46 actual_alu :: Opcode -> TFVec D4 Bit -> TFVec D4 Bit -> TFVec D4 Bit
47 --actual_alu = alu (constant Low) andop
48 actual_alu = alu (anyset xhwor)  andop