\centerline{\includegraphics{mac.svg}}
\caption{Combinatorial Multiply-Accumulate}
\label{img:mac-comb}
+ \vspace{-1.5em}
\end{figure}
The use of a composite result value is demonstrated in the next example,
\centerline{\includegraphics{mac-nocurry.svg}}
\caption{Combinatorial Multiply-Accumulate (composite output)}
\label{img:mac-comb-composite}
+ \vspace{-1.5em}
\end{figure}
\subsection{Choice}
\centerline{\includegraphics{choice-case.svg}}
\caption{Choice - sumif}
\label{img:choice}
+ \vspace{-1.5em}
\end{figure}
A user-friendly and also very powerful form of choice that is not found in
\centerline{\includegraphics{mac-state.svg}}
\caption{Stateful Multiply-Accumulate}
\label{img:mac-state}
+ \vspace{-1.5em}
\end{figure}
Note that the \hs{macS} function returns bot the new state and the value
\centerline{\includegraphics{compilerpipeline.svg}}
\caption{\CLaSHtiny\ compiler pipeline}
\label{img:compilerpipeline}
+\vspace{-1.5em}
\end{figure}
The output of the \GHC\ front-end consists of the translation of the original Haskell description in \emph{Core}~\cite{Sulzmann2007}, which is a smaller, typed, functional language. This \emph{Core} language is relatively easy to process compared to the larger Haskell language. A description in \emph{Core} can still contain elements which have no direct translation to hardware, such as polymorphic types and function-valued arguments. Such a description needs to be transformed to a \emph{normal form}, which only contains elements that have a direct translation. The second stage of the compiler, the \emph{normalization} phase, exhaustively applies a set of \emph{meaning-preserving} transformations on the \emph{Core} description until this description is in a \emph{normal form}. This set of transformations includes transformations typically found in reduction systems and lambda calculus~\cite{lambdacalculus}, such as $\beta$-reduction and $\eta$-expansion. It also includes self-defined transformations that are responsible for the reduction of higher-order functions to `regular' first-order functions.
\centerline{\includegraphics{4tapfir.svg}}
\caption{4-taps \acrotiny{FIR} Filter}
\label{img:4tapfir}
+\vspace{-1.5em}
\end{figure}
\subsection{Higher-order CPU}
common operations.
The CPU contains a number of data sources, represented by the horizontal
-lines in figure TODO:REF. These data sources offer the previous outputs
+lines in \Cref{img:highordcpu}. These data sources offer the previous outputs
of each function units, along with the single data input the cpu has and
two fixed intialization values.
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
+multiop Shift a b = shift a b
+multiop Xor a b = xor a b
+multiop Equal a b | a == b = 1
+ | otherwise = 0
\end{code}
The cpu function ties everything together. It applies the \hs{fu}
function four times, to create a different function unit each time. The
first application is interesting, because it does not just pass a
function to \hs{fu}, but a partial application of \hs{multiop}. This
-shows how the first funcition unit effectively gets an extra input,
+shows how the first function unit effectively gets an extra input,
compared to the others.
The vector \hs{inputs} is the set of data sources, which is passed to
out = head s'
\end{code}
+\begin{figure}
+\centerline{\includegraphics{highordcpu.svg}}
+\caption{CPU with higher-order Function Units}
+\label{img:highordcpu}
+\vspace{-1.5em}
+\end{figure}
+
Of course, this is still a simple example, but it could form the basis
of an actual design, in which the same techniques can be reused.