A FIR filter multiplies fixed constants ($h$) with the current
and a few previous input samples ($x$). Each of these multiplications
- are summed, to produce the result at time $t$. The equation of the FIR
+ are summed, to produce the result at time $t$. The equation of a FIR
filter is indeed equivalent to the equation of the dot-product, which is
shown below:
combination with the existing code and language features, such as all the
choice constructs, as state values are just normal values.
- Returning to the example of the FIR filter, we will slightly change the
- equation belong to it, so as to make the translation to code more obvious.
- What we will do is change the definition of the vector of input samples.
- So, instead of having the input sample received at time
- $t$ stored in $x_t$, $x_0$ now always stores the current sample, and $x_i$
- stores the $ith$ previous sample. This changes the equation to the
- following (Note that this is completely equivalent to the original
- equation, just with a different definition of $x$ that will better suit
- the the transformation to code):
-
- \begin{equation}
- y_t = \sum\nolimits_{i = 0}^{n - 1} {x_i \cdot h_i }
- \end{equation}
-
- Consider that the vector \hs{hs} contains the FIR coefficients and the
- vector \hs{xs} contains the current input sample in front and older
- samples behind. The function that does this shifting of the input samples
- is shown below:
+ We can simulate stateful descriptions using the recursive \hs{run}
+ function:
\begin{code}
- x >> xs = x +> tail xs
- \end{code}
-
- Where the \hs{tail} functions returns all but the first element of a
- vector, and the concatenate operator ($\succ$) adds the new element to the
- left of a vector. The complete definition of the FIR filter then becomes:
-
- \begin{code}
- fir (State (xs,hs)) x = (State (x >> xs,hs), xs *+* hs)
+ run f s (i:inps) = o : (run f s' inps)
+ where
+ (s', o) = f s i
\end{code}
- The resulting netlist of a 4-taps FIR filter based on the above definition
- is depicted in \Cref{img:4tapfir}.
-
- \begin{figure}
- \centerline{\includegraphics{4tapfir}}
- \caption{4-taps FIR Filter}
- \label{img:4tapfir}
- \end{figure}
+ The \hs{run} function maps a list of inputs over the function that a
+ developer wants to simulate, passing the state to each new iteration. Each
+ value in the input list corresponds to exactly one cycle of the (implicit)
+ clock. The result of the simulation is a list of outputs for every clock
+ cycle. As both the \hs{run} function and the hardware description are
+ plain hardware, the complete simulation can be compiled by an optimizing
+ Haskell compiler.
\section{\CLaSH\ prototype}
foo\par bar
+\section{Use cases}
+Returning to the example of the FIR filter, we will slightly change the
+equation belong to it, so as to make the translation to code more obvious.
+What we will do is change the definition of the vector of input samples.
+So, instead of having the input sample received at time
+$t$ stored in $x_t$, $x_0$ now always stores the current sample, and $x_i$
+stores the $ith$ previous sample. This changes the equation to the
+following (Note that this is completely equivalent to the original
+equation, just with a different definition of $x$ that will better suit
+the the transformation to code):
+
+\begin{equation}
+y_t = \sum\nolimits_{i = 0}^{n - 1} {x_i \cdot h_i }
+\end{equation}
+
+Consider that the vector \hs{hs} contains the FIR coefficients and the
+vector \hs{xs} contains the current input sample in front and older
+samples behind. The function that does this shifting of the input samples
+is shown below:
+
+\begin{code}
+x >> xs = x +> tail xs
+\end{code}
+
+Where the \hs{tail} function returns all but the first element of a
+vector, and the concatenate operator ($\succ$) adds a new element to the
+left of a vector. The complete definition of the FIR filter then becomes:
+
+\begin{code}
+fir (State (xs,hs)) x = (State (x >> xs,hs), xs *+* hs)
+\end{code}
+
+The resulting netlist of a 4-taps FIR filter based on the above definition
+is depicted in \Cref{img:4tapfir}.
+
+\begin{figure}
+\centerline{\includegraphics{4tapfir}}
+\caption{4-taps FIR Filter}
+\label{img:4tapfir}
+\end{figure}
+
\section{Related work}
Many functional hardware description languages have been developed over the
years. Early work includes such languages as $\mu$\acro{FP}~\cite{muFP}, an