1 {-# LANGUAGE TemplateHaskell, ScopedTypeVariables #-}
3 module HighOrdAlu where
5 import qualified Prelude as P
6 import Prelude hiding (
7 null, length, head, tail, last, init, take, drop, (++), map, foldl, foldr,
8 zipWith, zip, unzip, concat, reverse, iterate )
11 import Types.Data.Num.Ops
12 import Types.Data.Num.Decimal.Digits
13 import Types.Data.Num.Decimal.Ops
14 import Types.Data.Num.Decimal.Literals
15 import Data.Param.TFVec
16 import Data.RangedWord
18 import CLasH.Translator.Annotations
20 constant :: NaturalT n => e -> Op n e
21 constant e a b = copy e
24 invop a b = map hwnot a
26 andop :: (e -> e -> e) -> Op n e
27 andop f a b = zipWith f a b
30 --anyset :: (PositiveT n) => Op n Bit
31 anyset :: NaturalT n => (e -> e -> e) -> e -> Op n e
32 --anyset a b = copy undefined (a' `hwor` b')
33 anyset f s a b = constant (f a' b') a b
40 type Op n e = (TFVec n e -> TFVec n e -> TFVec n e)
43 {-# ANN sim_input TestInput#-}
44 sim_input :: [(Opcode, TFVec D4 (SizedInt D8), TFVec D4 (SizedInt D8))]
45 sim_input = [ (High, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8])))
46 , (High, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8])))
47 , (Low, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8]))) ]
49 {-# ANN actual_alu InitState #-}
52 alu :: Op n e -> Op n e -> Opcode -> TFVec n e -> TFVec n e -> TFVec n e
58 {-# ANN actual_alu TopEntity #-}
59 actual_alu :: (Opcode, TFVec D4 (SizedInt D8), TFVec D4 (SizedInt D8)) -> TFVec D4 (SizedInt D8)
60 --actual_alu = alu (constant Low) andop
61 actual_alu (opc, a, b) = alu (anyset (+) (0 :: SizedInt D8)) (andop (-)) opc a b
63 runalu = P.map actual_alu sim_input