4 {-# LANGUAGE TemplateHaskell #-}
7 import qualified Prelude as P
11 \section{Multiply-Accumulate}
12 \subsection{Pure description}
15 \frametitle{Multiply-Accumulate}
16 Purely Functional Description:
17 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
22 macc (x,y) acc = (u, u)
28 \item Purely functional design (that Jan showed you earlier).
29 \item \emph{acc} is the current state. \emph{u} is the updated state and output.
33 \subsection{Extra's to make it compile}
36 \frametitle{Extra's to make it compile}
38 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
40 {-"{\color<3>[rgb]{1,0,0}"-}import CLasH.HardwareTypes{-"}"-}
41 {-"{\color<4>[rgb]{1,0,0}"-}import CLasH.Translator.Annotations{-"}"-}
42 {-"{\color<3>[rgb]{1,0,0}"-}type Word = SizedInt D8{-"}"-}
44 initacc :: {-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-}
45 {-"{\color<5>[rgb]{1,0,0}"-}initacc = 0{-"}"-}
47 ANN(macc (InitState {-"\ "-} `initacc))
49 macc :: ({-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-},{-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-}) -> {-"{\color<2>[rgb]{1,0,0}"-}State{-"}"-} {-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-} -> ({-"{\color<2>[rgb]{1,0,0}"-}State{-"}"-} {-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-}, {-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-})
50 macc (x, y) ({-"{\color<2>[rgb]{1,0,0}"-}State{-"}"-} acc) = ({-"{\color<2>[rgb]{1,0,0}"-}State{-"}"-} u, u)
56 \item Stuff you need to add to make it compile in \clash{}.
57 \item State wrapper, tells the compiler which argument is the state
58 \item Type declarations. Top-level entity needs to be mono-morphic (and first-order).
59 \item Annotation pragma's. The TopEntity pragma tells the compiler which entity is the top entity.
60 \item The InitState pragma points to the initial state.
66 \centerline{\includegraphics[width=\paperwidth,trim=9mm 4cm 14mm 4cm, clip=true]{macc.png}}
70 \item We see the register and multiplier on the left
71 \item The adder on the right
74 \subsection{Test input}
77 \frametitle{Test input}
78 Test program for the Multiply-Accumulate circuit:
79 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
81 ANN(program TestInput)
82 program :: [(Word,Word)]
84 [ (4, 2) -- 4 * 2 + 0 = 8
85 , (1, 3) -- 1 * 3 + 8 = 11
86 , (2, 2) -- 2 * 2 + 11 = 15
91 \item VHDL Testbench is automatically generated due to the \emph{TestInput} annotation pragma.
95 \item We can also generate VHDL Testbench
101 run func state (i:input) = o:out
103 (state', o) = func i state
104 out = run func state' input
109 let istate = (State initacc)
110 let output = run macc istate input
111 mapM_ (\x -> putStr $ ((show x) P.++ "\n")) output