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 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 makes 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]{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
145 that case, we would have described the architecture show in \in{example}[ex:RecursiveSumAlt]
147 \startuseMPgraphic{RecursiveSumAlt}
148 save reg, inp, a, out;
149 newReg.reg("") "dx(4mm)", "dy(6mm)", "reflect(true)";
150 newCircle.inp(btex $input$ etex) "framed(false)";
151 newCircle.a(btex + etex);
152 newCircle.out(btex $output$ etex) "framed(false)";
154 % Put inp, a and out in one horizontal line, with reg above a
155 reg.c-a.c=(0cm, 2cm);
156 a.c-inp.c=(3cm, 0cm);
157 out.c-a.c=(3cm, 0cm);
160 % Draw objects and lines
168 nccurve(a)(reg) "posA(e)", "angleA(0)", "angleB(180)", "posB(d)";
170 nccurve(reg)(a) "posA(out)", "angleA(180)", "angleB(-30)";
174 \placeexample[here][ex:RecursiveSumAlt]{An alternative interpretation of the description in \in{example}[ex:RecursiveSum]}
175 {\boxedgraphic{RecursiveSumAlt}}
177 The distinction in possible interpretations we see here, is an important
178 distinction in this research. In the first figure, the recursion in the code
179 is taken as recursion in space and each recursion step results in a
180 different piece of hardware, all of which are active simultaneously. In the
181 second figure, the recursion in the code is taken as recursion in time and
182 each recursion step is executed sequentially, \emph{on the same piece of
185 In this research we explore how to apply these two interpretations to
186 hardware descriptions. Additionally, we explore how other functional
187 programming concepts can be applied to hardware descriptions to give use an
188 efficient way to describe hardware.
190 This leads us to the following research question:
192 % Slightly bigger font, some extra spacing.
193 \setupquotation[style=tfb,spacebefore=5mm]
195 How can we describe the structural properties of a hardware design, using
196 a functional language?
198 \setupquotation[style=normal,spacebefore=]
200 We can further split this into subquestions from a hardware perspective:
202 \item How can we describe a stateful design?
203 \item How can we describe (hierarchical) structure in a design?
206 And subquestions from a functional perspective:
208 \item How to interpret recursion in descriptions?
209 \item How to interpret polymorphism?
210 \item How to interpret higher order descriptions?
213 In addition to looking at designing a hardware description language, we
214 will also implement a prototype to test ideas. This prototype will
215 translate hardware descriptions written in the Haskell functional language
216 to simple (netlist-like) hardware descriptions in the \VHDL language. The
217 reasons for choosing these languages are detailed in section
218 \in{}[sec:prototype:input] and \in{}[sec:prototype:output] respectively.
221 \startframedtext[width=8cm,background=box,frame=no]
222 \startalignment[center]
223 {\tfa The name Cλash}
226 The name Cλash more-or-less expands to CAES language for hardware
227 descriptions, where CAES refers to the research chair where this
228 project was undertaken (Computer Architectures for Embedded
229 Systems). The lambda in the name is of course a reference to the
230 lambda abstraction, which is an essential element of most functional
231 languages (and is also prominent in the Haskell logo).
235 The result of this research will thus be a prototype compiler and a language
236 that it can compile, to which we will refer to as the Cλash system and Cλash
237 language for short, or simply Cλash.
239 % Use \subject to hide this section from the toc
241 In the first chapter, we will sketch the context for this research.
242 The current state and history of hardware description languages will be
243 briefly discussed, as well as the state and history of functional
244 programming. Since we're not the first to have merged these approaches,
245 a number of other functional hardware description languages are briefly
248 Chapter two describes the exploratory part of this research: How can we
249 describe hardware using a functional language and how can we use functional
250 concepts for hardware descriptions?
252 Chapter three talks about the prototype that was created and which has guided
253 most of the research. There is some attention for the language chosen for our
254 hardware descriptions, Haskell. The possibilities and limits of this prototype
255 are further explored.
257 During the creation of the prototype, it became apparent that some structured
258 way of doing program transformations was required. Doing ad-hoc interpretation
259 of the hardware description proved non-scalable. These transformations and
260 their application are the subject of the fourth chapter.
262 The next chapter sketches ideas for further research, which are many. Some of
263 them have seen some initial exploration and could provide a basis for future
266 Finally, we present our conclusions.
268 % vim: set sw=2 sts=2 expandtab: