Add automated testbench generation according to supplied test input
[matthijs/master-project/cλash.git] / HighOrdAlu.hs
1 {-# LANGUAGE TemplateHaskell #-}
2
3 module HighOrdAlu where
4
5 import Prelude hiding (
6   null, length, head, tail, last, init, take, drop, (++), map, foldl, foldr,
7   zipWith, zip, unzip, concat, reverse, iterate )
8 import Bits
9 import Types
10 import Data.Param.TFVec
11 import Data.RangedWord
12 import CLasH.Translator.Annotations
13
14 constant :: e -> Op D4 e
15 constant e a b =
16   (e +> (e +> (e +> (singleton e))))
17
18 invop :: Op n Bit
19 invop a b = map hwnot a
20
21 andop :: Op n Bit
22 andop a b = zipWith hwand a b
23
24 -- Is any bit set?
25 --anyset :: (PositiveT n) => Op n Bit
26 anyset :: (Bit -> Bit -> Bit) -> Op D4 Bit
27 --anyset a b = copy undefined (a' `hwor` b')
28 anyset f a b = constant (a' `hwor` b') a b
29   where 
30     a' = foldl f Low a
31     b' = foldl f Low b
32
33 xhwor = hwor
34
35 type Op n e = (TFVec n e -> TFVec n e -> TFVec n e)
36 type Opcode = Bit
37
38 {-# ANN sim_input TestInput#-}
39 sim_input = [ (High,$(vectorTH [High,Low,Low,Low]),$(vectorTH [High,Low,Low,Low]))
40             , (High,$(vectorTH [High,High,High,High]),$(vectorTH [High,High,High,High]))
41             , (Low,$(vectorTH [High,Low,Low,High]),$(vectorTH [High,Low,High,Low]))]
42
43 {-# ANN actual_alu InitState #-}
44 initstate = High
45
46 alu :: Op n e -> Op n e -> Opcode -> TFVec n e -> TFVec n e -> TFVec n e
47 alu op1 op2 opc a b =
48   case opc of
49     Low -> op1 a b
50     High -> op2 a b
51
52 {-# ANN actual_alu TopEntity #-}
53 actual_alu :: (Opcode, TFVec D4 Bit, TFVec D4 Bit) -> TFVec D4 Bit
54 --actual_alu = alu (constant Low) andop
55 actual_alu (opc, a, b) = alu (anyset xhwor) (andop) opc a b