Give all code examples a number and label
[matthijs/master-project/dsd-paper.git] / HigherOrderCPU.hs
index 8833766ebca36789ff9feb1808fe8207c90b5e03..a881001cb756df49c8c61bf005b7531842b397dc 100644 (file)
@@ -24,11 +24,11 @@ type CpuState = State (Vector D4 Word)
 
 {-# ANN cpu TopEntity #-}
 {-# ANN cpu (InitState 'cpuState) #-}
 
 {-# ANN cpu TopEntity #-}
 {-# ANN cpu (InitState 'cpuState) #-}
-cpu :: CpuState -> Word -> Vector D4 (Index D6, Index D6)
+cpu :: CpuState -> Word -> Vector D4 (Index D6, Index D6) -> Opcode
   -> (CpuState, Word)
   -> (CpuState, Word)
-cpu (State fuss) input addrs = (State fuss', out)
+cpu (State fuss) input addrs opc = (State fuss', out)
   where
   where
-    fuss'   = (fu const inputs (addrs!(0 :: Index D3))) +> (
+    fuss'   = (fu (multiop opc) inputs (addrs!(0 :: Index D3))) +> (
               (fu (+)   inputs (addrs!(1 :: Index D3))) +> (
               (fu (-)   inputs (addrs!(2 :: Index D3))) +> (
               (fu (*)   inputs (addrs!(3 :: Index D3))) +> empty)))
               (fu (+)   inputs (addrs!(1 :: Index D3))) +> (
               (fu (-)   inputs (addrs!(2 :: Index D3))) +> (
               (fu (*)   inputs (addrs!(3 :: Index D3))) +> empty)))
@@ -36,4 +36,17 @@ cpu (State fuss) input addrs = (State fuss', out)
     out     = head fuss
 
 cpuState :: Vector D4 Word
     out     = head fuss
 
 cpuState :: Vector D4 Word
-cpuState = copy 0
\ No newline at end of file
+cpuState = copy 0
+
+data Opcode = Shift | Xor | Equal
+
+multiop :: Opcode -> Word -> Word -> Word
+multiop opc a b = case opc of
+  Shift             -> shift a b
+  Xor               -> xor a b 
+  Equal | a == b    -> 1
+        | otherwise -> 0
+
+-- Placeholders, since we don't have these operations
+xor = const
+shift = const