1 \chapter[chap:introduction]{Introduction}
2 This thesis describes the result and process of my work during my
3 Master's assignment. In these pages, I will try to introduce the world
4 of hardware descriptions, the world of functional languages and
5 compilers and introduce the hardware description language Cλash that will
6 connect these worlds and puts a step towards making hardware programming
7 on the whole easier, more maintainable and generally more pleasant.
9 % Use \subject to hide this section from the toc
10 \subject{Research goals}
11 This research started out with the notion that a functional program is very
12 easy to interpret as a hardware description. A functional program typically
13 does no assumptions about evaluation order and does not have any side
14 effects. This fits hardware nicely, since the evaluation order for hardware
15 is simply everything in parallel.
17 As a motivating example, consider the simple functional program shown in
18 \in{example}[ex:AndWord]\footnote[notfinalsyntax]{Note that this example is not in the final
19 Cλash syntax}. This is a very natural way to describe a lot of parallel not
20 ports, that perform a bitwise not on a bitvector. The example also shows an
21 image of the architecture described.
24 notword :: [Bit] -> [Bit]
28 \startuseMPgraphic{AndWord}
31 newCircle.inp(btex $\overrightarrow{input}$ etex) "framed(false)";
34 newCircle.a[i](btex not etex);
36 newCircle.out(btex $\overrightarrow{output}$ etex) "framed(false)";
38 % Center the input and output ports vertically, and put them left and right
40 inp.c = (xpart(a1.c) - 2cm, ypart((a[1].c + a[num].c)/2));
41 out.c = (xpart(a1.c) + 2cm, ypart((a[1].c + a[num].c)/2));
43 % Space the operations vertically, with some extra space between the middle
45 a2.c-a1.c=(0cm, 1.5cm);
46 a3.c-a2.c=(0cm, 2.5cm);
47 a4.c-a3.c=(0cm, 1.5cm);
50 % Draw objects and lines
58 % Draw a dotted line between the middle operations
59 ncline(a2)(a3) "linestyle(dashed withdots)", "arrows(-)";
61 \placeexample[here][ex:AndWord]{Simple architecture that inverts a vector of bits.}
62 \startcombination[2*1]
63 {\typebufferlam{AndWord}}{Haskell description of the architecture.}
64 {\boxedgraphic{AndWord}}{The architecture described by the Haskell description.}
67 Slightly more complicated is the incremental summation of
68 values show in \in{example}[ex:RecursiveSum]\note[notfinalsyntax].
70 In this example we see a recursive function \hs{sum'} that recurses over a
71 list and takes an accumulator argument that stores the sum so far. On each
72 step of the recusion, another number from the input vector is added to the
73 accumulator and each intermediate step returns its result.
75 This is a nice description of a series of sequential adders that produce
76 the incremental sums of a vector of numbers. For an input list of length 4,
77 the corresponding architecture is show in the example.
79 \startbuffer[RecursiveSum]
83 sum' :: Int -> [Int] -> [Int]
85 sum' acc (x:xs) = acc' : (sum' acc' xs)
89 \startuseMPgraphic{RecursiveSum}
90 save inp, a, zero, out;
92 newCircle.inp(btex $\overrightarrow{input}$ etex) "framed(false)";
93 newCircle.zero(btex $0$ etex) "framed(false)";
96 newCircle.a[i](btex + etex);
98 newCircle.out(btex $\overrightarrow{output}$ etex) "framed(false)";
100 % Center the input and output ports vertically, and put them left and right
103 % Space the operations vertically, with some extra space between the middle
105 a1.c-inp.c=(2cm, 0cm);
106 a2.c-a1.c=(1.5cm, 0cm);
107 a3.c-a2.c=(1.5cm, 0cm);
108 a4.c-a3.c=(1.5cm, 0cm);
109 out.c-a4.c=(2cm, 0cm);
111 % Put the zero above the input
112 zero.c-inp.c=(0cm, 1cm);
114 nccurve(zero)(a1) "angleA(0)", "angleB(-40)";
115 % Draw objects and lines
120 nccurve(a[i])(out) "posA(e)", "angleB(" & decimal((num - i)*-20) & ")", "angleA(60)";
122 nccurve(inp)(a[i]) "angleA(" & decimal(i*-15) & ")", "angleB(40)";
124 ncline(a[i-1])(a[i]);
135 \placeexample[here][ex:RecursiveSum]{A recursive description that sums values.}
136 \startcombination[2*1]
137 {\typebufferlam{RecursiveSum}}{Haskell description of the architecture.}
138 {\boxedgraphic{RecursiveSum}}{The architecture described by the Haskell description.}
142 Or... is this the description of a single accumulating adder, that will add
143 one element of each input each clock cycle and has a reset value of 0? In
144 that case, we would have described the architecture show in \in{example}[ex:RecursiveSumAlt]
146 \startuseMPgraphic{RecursiveSumAlt}
147 save reg, inp, a, out;
148 newReg.reg("") "dx(4mm)", "dy(6mm)", "reflect(true)";
149 newCircle.inp(btex $input$ etex) "framed(false)";
150 newCircle.a(btex + etex);
151 newCircle.out(btex $output$ etex) "framed(false)";
153 % Put inp, a and out in one horizontal line, with reg above a
154 reg.c-a.c=(0cm, 2cm);
155 a.c-inp.c=(3cm, 0cm);
156 out.c-a.c=(3cm, 0cm);
159 % Draw objects and lines
167 nccurve(a)(reg) "posA(e)", "angleA(0)", "angleB(180)", "posB(d)";
169 nccurve(reg)(a) "posA(out)", "angleA(180)", "angleB(-30)";
173 \placeexample[here][ex:RecursiveSumAlt]{An alternative interpretation of the description in \in{example}[ex:RecursiveSum]}
174 {\boxedgraphic{RecursiveSumAlt}}
176 The distinction in possible interpretations we see here, is an important
177 distinction in this research. In the first figure, the recursion in the code
178 is taken as recursion in space and each recursion step results in a
179 different piece of hardware, all of which are active simultaneously. In the
180 second figure, the recursion in the code is taken as recursion in time and
181 each recursion step is executed sequentially, \emph{on the same piece of
184 In this research we explore how to apply these two interpretations to
185 hardware descriptions. Additionally, we explore how other functional
186 programming concepts can be applied to hardware descriptions to give use an
187 efficient way to describe hardware.
189 This leads us to the following research question:
191 % Slightly bigger font, some extra spacing.
192 \setupquotation[style=tfb,spacebefore=5mm]
194 How can we describe the structural properties of a hardware design, using
195 a functional language?
197 \setupquotation[style=normal,spacebefore=]
199 We can further split this into subquestions from a hardware perspective:
201 \item How can we describe a stateful design?
202 \item How can we describe (hierarchical) structure in a design?
205 And subquestions from a functional perspective:
207 \item How to interpret recursion in descriptions?
208 \item How to interpret polymorphism?
209 \item How to interpret higher order descriptions?
212 In addition to looking at designing a hardware description language, we
213 will also implement a prototype to test drive our ideas. This prototype will
214 translate hardware descriptions written in the Haskell functional language
215 to simple (netlist-like) hardware descriptions in the \VHDL language. The
216 reasons for choosing these languages are detailed in section
217 \in{}[sec:prototype:input] and \in{}[sec:prototype:output] respectively.
220 \startframedtext[width=8cm,background=box,frame=no]
221 \startalignment[center]
222 {\tfa The name Cλash}
225 The name Cλash more-or-less expands to CAES language for hardware
226 descriptions, where CAES refers to the research chair where this
227 project was undertaken (Computer Architectures for Embedded
228 Systems). The lambda in the name is of course a reference to the
229 lambda abstraction, which is an essential element of most functional
230 languages (and is also prominent in the Haskell logo).
234 The result of this research will thus be a prototype compiler and a language
235 that it can compile, to which we will refer to as the Cλash system and Cλash
236 language for short, or simply Cλash.
238 % Use \subject to hide this section from the toc
240 In the first chapter, we will sketch the context for this research.
241 The current state and history of hardware description languages will be
242 briefly discussed, as well as the state and history of functional
243 programming. Since we're not the first to have merged these approaches,
244 a number of other functional hardware description languages are briefly
247 Chapter two describes the exploratory part of this research: How can we
248 describe hardware using a functional language and how can we use functional
249 concepts for hardware descriptions?
251 Chapter three talks about the prototype that was created and which has guided
252 most of the research. There is some attention for the language chosen for our
253 hardware descriptions, Haskell. The possibilities and limits of this prototype
254 are further explored.
256 During the creation of the prototype, it became apparent that some structured
257 way of doing program transformations was required. Doing ad-hoc interpretation
258 of the hardware description proved non-scalable. These transformations and
259 their application are the subject of the fourth chapter.
261 The next chapter sketches ideas for further research, which are many. Some of
262 them have seen some initial exploration and could provide a basis for future
265 Finally, we present our conclusions.
267 % vim: set sw=2 sts=2 expandtab: