1 {-# LANGUAGE TypeOperators, TemplateHaskell, TypeFamilies, ScopedTypeVariables #-}
3 module HigherOrderCPU where
5 -- hide default prelude functions
6 import qualified Prelude as P
8 -- import CλaSH specific types
9 import CLasH.HardwareTypes hiding (min,foldl1,const)
10 import CLasH.Translator.Annotations
12 type CpuState = State (Vector D4 (Signed D16))
14 fu op inputs (a1, a2) =
15 op (inputs!a1) (inputs!a2)
21 data Opcode = Shift | Xor | Equal
25 multiop Equal = \a b -> if a == b then 1 else 0
27 fu0 c = fu (multiop c)
29 {-# ANN cpu TopEntity #-}
30 {-# ANN cpu (InitState 'cpuState) #-}
32 -> (Signed D16, Opcode, Vector D4 (Index D6, Index D6))
33 -> (CpuState, Signed D16)
34 cpu (State s) (x,opc,addrs) = (State s', out)
36 inputs = x +> (0 +> (1 +> s))
37 s' = (fu0 opc inputs (addrs!(0 :: Index D3))) +> (
38 (fu1 inputs (addrs!(1 :: Index D3))) +> (
39 (fu2 inputs (addrs!(2 :: Index D3))) +> (
40 (fu3 inputs (addrs!(3 :: Index D3))) +> empty)))
44 cpuState :: Vector D4 (Signed D16)
47 type Index = RangedWord
48 type Signed = SizedInt