Reword description about vector type notation
[matthijs/master-project/dsd-paper.git] / HigherOrderCPU.hs
1 {-# LANGUAGE TypeOperators, TemplateHaskell, TypeFamilies, ScopedTypeVariables #-}
2
3 module HigherOrderCPU where
4
5 -- hide default prelude functions
6 import qualified Prelude as P
7
8 -- import CλaSH specific types
9 import CLasH.HardwareTypes hiding (min,foldl1,const)
10 import CLasH.Translator.Annotations
11
12 type Word   = SizedInt D16
13 type Index  = RangedWord
14
15 const a b = a
16
17 fu op inputs (addr1, addr2) out =
18   (out', out)
19   where
20     in1  = inputs!addr1
21     in2  = inputs!addr2
22     out' = op in1 in2
23
24 type CpuState = State (Vector D4 Word)
25
26 {-# ANN cpu TopEntity #-}
27 {-# ANN cpu (InitState 'cpuState) #-}
28 cpu :: 
29   Word 
30   -> Vector D4 (Index D6, Index D6)
31   -> CpuState
32   -> (CpuState, Word)
33 cpu input addrs (State fuss) =
34   (State fuss', out)
35   where
36     fures = (fu const inputs (addrs!(0 :: Index D3)) (fuss!(0 :: Index D3))) +> (
37             (fu (+)   inputs (addrs!(1 :: Index D3)) (fuss!(1 :: Index D3))) +> (
38             (fu (-)   inputs (addrs!(2 :: Index D3)) (fuss!(2 :: Index D3))) +> (
39             (fu (*)   inputs (addrs!(3 :: Index D3)) (fuss!(3 :: Index D3))) +> empty)))
40     (fuss', outputs) = unzip fures
41     inputs = 0 +> (1 +> (input +> outputs))
42     out = head outputs
43
44 cpuState :: Vector D4 Word
45 cpuState = copy 0