1 {-# LANGUAGE TemplateHaskell, ScopedTypeVariables, NoImplicitPrelude #-}
3 module HighOrdAlu where
5 import qualified Prelude as P
6 import CLasH.HardwareTypes
7 import CLasH.Translator.Annotations
9 constant :: NaturalT n => e -> Op n e
10 constant e a b = copy e
13 invop a b = map hwnot a
15 andop :: (e -> e -> e) -> Op n e
16 andop f a b = zipWith f a b
19 --anyset :: (PositiveT n) => Op n Bit
20 anyset :: NaturalT n => (e -> e -> e) -> e -> Op n e
21 --anyset a b = copy undefined (a' `hwor` b')
22 anyset f s a b = constant (f a' b') a b
29 type Op n e = (Vector n e -> Vector n e -> Vector n e)
32 {-# ANN sim_input TestInput#-}
33 sim_input :: [(Opcode, Vector D4 (SizedInt D8), Vector D4 (SizedInt D8))]
34 sim_input = [ (High, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8])))
35 , (High, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8])))
36 , (Low, $(vectorTH ([4,3,2,1]::[SizedInt D8])), $(vectorTH ([1,2,3,4]::[SizedInt D8]))) ]
38 {-# ANN actual_alu InitState #-}
41 alu :: Op n e -> Op n e -> Opcode -> Vector n e -> Vector n e -> Vector n e
47 {-# ANN actual_alu TopEntity #-}
48 actual_alu :: (Opcode, Vector D4 (SizedInt D8), Vector D4 (SizedInt D8)) -> Vector D4 (SizedInt D8)
49 --actual_alu = alu (constant Low) andop
50 actual_alu (opc, a, b) = alu (anyset (+) (0 :: SizedInt D8)) (andop (-)) opc a b
52 runalu = P.map actual_alu sim_input