X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=macc.hs;fp=macc.hs;h=f1f6d50a98f6e0b6305e9fb0227c28bc741af513;hb=d0420235340ee715db69a023bf0f6ad75d573735;hp=0000000000000000000000000000000000000000;hpb=dfa8e8c67fe722269e1b61016bffa4c9ad5bc0b6;p=matthijs%2Fmaster-project%2Ffinal-presentation.git diff --git a/macc.hs b/macc.hs new file mode 100644 index 0000000..f1f6d50 --- /dev/null +++ b/macc.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE TemplateHaskell, TypeOperators, RecordWildCards, ScopedTypeVariables, TypeFamilies #-} +module MultiplyAccumulate where + +import CLasH.HardwareTypes +import CLasH.Translator.Annotations +type Word = SizedInt D8 + +initacc :: Word +initacc = 0 + +{-# ANN macc (InitState 'initacc) #-} +{-# ANN macc TopEntity #-} +macc :: (Word,Word) -> State Word -> (State Word, Word) +macc (x, y) (State acc) = (State u, u) + where + u = acc + x * y + +{-# ANN program TestInput #-} +program :: [(Word,Word)] +program = + [ (4, 2) -- 4 * 2 + 0 = 8 + , (1, 3) -- 1 * 3 + 8 = 11 + , (2, 2) -- 2 * 2 + 11 = 15 + ] + +run _ _ [] = [] +run func state (i:input) = o:out + where + (state', o) = func i state + out = run func state' input