Add the atbegshi package, which is not available on Debian.
[matthijs/master-project/final-presentation.git] / macc.lhs
1 %include talk.fmt
2 %if style == newcode
3 \begin{code}
4 {-# LANGUAGE TemplateHaskell #-}
5 module Main where
6
7 import qualified Prelude as P
8 \end{code}
9 %endif
10
11 \section{Multiply-Accumulate}
12 \subsection{Pure description}
13 \frame
14 {
15 \frametitle{Multiply-Accumulate}
16 Purely Functional Description:
17 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
18 %if style == newcode
19
20 %else
21 \begin{code}
22 macc (x,y) acc = (u, u)
23   where
24     u = acc + x * y
25 \end{code}
26 \end{beamercolorbox}
27 }\note[itemize]{
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. 
30 }
31 %endif
32
33 \subsection{Extra's to make it compile}
34 \frame
35 {
36 \frametitle{Extra's to make it compile}
37 {\clash} Description:
38 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
39 \begin{code}
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{-"}"-}
43
44 initacc :: {-"{\color<3>[rgb]{1,0,0}"-}Word{-"}"-}
45 {-"{\color<5>[rgb]{1,0,0}"-}initacc = 0{-"}"-}
46
47 ANN(macc (InitState {-"\ "-} `initacc))
48 ANN(macc TopEntity)
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)
51   where
52     u = acc + x * y
53 \end{code}
54 \end{beamercolorbox}
55 }\note[itemize]{
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. 
61 }
62
63 \begin{frame}[plain]
64    \vspace{-0.8em}
65    \begin{figure} 
66       \centerline{\includegraphics[width=\paperwidth,trim=9mm 4cm 14mm 4cm, clip=true]{macc.png}}
67     \end{figure}
68 \end{frame}
69 \note[itemize]{
70 \item We see the register and multiplier on the left
71 \item The adder on the right
72 }
73
74 \subsection{Test input}
75 \frame
76 {
77 \frametitle{Test input}
78 Test program for the Multiply-Accumulate circuit:
79 \begin{beamercolorbox}[sep=-2.5ex,rounded=true,shadow=true,vmode]{codebox}
80 \begin{code}
81 ANN(program TestInput)
82 program :: [(Word,Word)]
83 program =
84   [ (4, 2)  -- 4 * 2 + 0    =   8
85   , (1, 3)  -- 1 * 3 + 8    =   11
86   , (2, 2)  -- 2 * 2 + 11   =   15
87   ]
88 \end{code}
89 \end{beamercolorbox}
90 \begin{itemize}
91   \item VHDL Testbench is automatically generated due to the \emph{TestInput} annotation pragma.
92 \end{itemize}
93
94 }\note[itemize]{
95 \item We can also generate VHDL Testbench
96 }
97
98 %if style == newcode
99 \begin{code}
100 run _     _    []        = []
101 run func state (i:input) = o:out
102   where
103     (state', o) = func i state
104     out         = run func state' input
105     
106 main :: IO ()
107 main = do
108   let input = program
109   let istate = (State initacc)
110   let output = run macc istate input
111   mapM_ (\x -> putStr $ ((show x) P.++ "\n")) output
112   return ()
113 \end{code}
114 %endif