From a8f72535b76928e7374968ae7ae0407d4f82c5c5 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Mon, 14 Dec 2009 10:58:41 +0100 Subject: [PATCH] Fill in sheets about state. --- matthijs/introduction.lhs | 88 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/matthijs/introduction.lhs b/matthijs/introduction.lhs index 433ffcd..369ab79 100644 --- a/matthijs/introduction.lhs +++ b/matthijs/introduction.lhs @@ -112,12 +112,96 @@ \frame { - TODO: Impure (stateful) example. + \frametitle{Multiply-accumulate} + \begin{columns} + \begin{column}{5cm} + \begin{block}{} + \begin{tabular}{lll} + Input A & Input B & Output \\ + \hline + 1 & 1 & 0 \\ + 1 & 2 & 1 \\ + 1 & 1 & 3 \\ + 2 & 2 & 4 \\ + \end{tabular} + \end{block} + \end{column} + \begin{column}{5cm} + \begin{figure} + TODO: Image of MAC with internal register + \end{figure} + \end{column} + \end{columns} +} + +\note[itemize] +{ + \item Next sheet: MAC circuit and I/O values + \item MAC is common circuit + \item Multiplies pairs, one pair at a time + \item Stores sum so far + \item Not pure! + \item Depends on inputs \emph{and} current register value + \item Solution: Put register value (state) in argument } +\frame +{ + \frametitle{Multiply-accumulate} + \begin{columns} + \begin{column}{5cm} + \begin{block}{} + \vspace{-0.5cm} +\begin{verbatim} +mac (a, b) (State s) = let + sum = s + (a * b) +in (State sum, sum) +\end{verbatim} + \end{block} + \end{column} + \begin{column}{5cm} + \begin{figure} + TODO: Image of MAC with external register + \end{figure} + \end{column} + \end{columns} +} + +\note[itemize] +{ + \item Next sheet: MAC implementation + \item Current state as argument (annotated) + \item Two parts in the result: New state and output + \item Register is placed ``outside'' + \item We want it inside! + \item Annotation allows compiler to put it inside +} + +\begin{frame}[fragile] + \frametitle{Simulating} + + \begin{block}{Recursive run function} + run f (i:is) s = let + (o, s') = f i s + in o : (run f is s') + \end{block} + + \begin{block}{Remember \texttt{mac}} +\vspace{-0.5cm} +\begin{verbatim} +mac (a, b) (State s) = let + sum = s + (a * b) +in (State sum, sum) +\end{verbatim} + \end{block} +\end{frame} + \note[itemize] { - \item TODO + \item Next sheet: run function + \item Used for simulation only + \item Recursion ``stores'' state + \item Each recursion step, \texttt{f} is evaluated once. } \subsection{\clash} -- 2.30.2