From: Matthijs Kooijman Date: Fri, 2 Oct 2009 11:31:24 +0000 (+0200) Subject: Add two new simple normal form examples. X-Git-Tag: final-thesis~228 X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Freport.git;a=commitdiff_plain;h=eca9391c2835722ba61218e5a0c13d25872f0a03 Add two new simple normal form examples. --- diff --git a/Chapters/Normalization.tex b/Chapters/Normalization.tex index 6853d88..4b3a08c 100644 --- a/Chapters/Normalization.tex +++ b/Chapters/Normalization.tex @@ -64,7 +64,104 @@ be an input port, every bound value will become a concurrent statement (such as a component instantiation or conditional signal assignment) and the result variable will become the output port. -An example of a program in canonical form would be: +\startbuffer[MulSum] +alu :: Bit -> Word -> Word -> Word +alu = λa.λb.λc. + let + mul = (*) a b + sum = (+) mul c + in + sum +\stopbuffer + +\startuseMPgraphic{MulSum} + save a, b, c, mul, add, sum; + + % I/O ports + newCircle.a(btex $a$ etex) "framed(false)"; + newCircle.b(btex $b$ etex) "framed(false)"; + newCircle.c(btex $c$ etex) "framed(false)"; + newCircle.sum(btex $res$ etex) "framed(false)"; + + % Components + newCircle.mul(btex - etex); + newCircle.add(btex + etex); + + a.c - b.c = (0cm, 2cm); + b.c - c.c = (0cm, 2cm); + add.c = c.c + (2cm, 0cm); + mul.c = midpoint(a.c, b.c) + (2cm, 0cm); + sum.c = add.c + (2cm, 0cm); + c.c = origin; + + % Draw objects and lines + drawObj(a, b, c, mul, add, sum); + + ncarc(a)(mul) "arcangle(15)"; + ncarc(b)(mul) "arcangle(-15)"; + ncline(c)(add); + ncline(mul)(add); + ncline(add)(sum); +\stopuseMPgraphic + +\placeexample[ex:MulSum]{\small{ALU} described in normal form} + \startcombination[2*1] + {\typebufferlam{MulSum}}{Description in normal form} + {\boxedgraphic{MulSum}}{Described architecture} + \stopcombination + +\startbuffer[AddSubAlu] +alu :: Bit -> Word -> Word -> Word +alu = λopcode.λa.λb. + let + res1 = (+) a b + res2 = (-) a b + res = case op of + Low -> res1 + High -> res2 + in + res +\stopbuffer + +\startuseMPgraphic{AddSubAlu} + save opcode, a, b, add, sub, mux, res; + + % I/O ports + newCircle.opcode(btex $opcode$ etex) "framed(false)"; + newCircle.a(btex $a$ etex) "framed(false)"; + newCircle.b(btex $b$ etex) "framed(false)"; + newCircle.res(btex $res$ etex) "framed(false)"; + % Components + newCircle.add(btex + etex); + newCircle.sub(btex - etex); + newMux.mux; + + opcode.c - a.c = (0cm, 2cm); + add.c - a.c = (4cm, 0cm); + sub.c - b.c = (4cm, 0cm); + a.c - b.c = (0cm, 3cm); + mux.c = midpoint(add.c, sub.c) + (1.5cm, 0cm); + res.c - mux.c = (1.5cm, 0cm); + b.c = origin; + + % Draw objects and lines + drawObj(opcode, a, b, res, add, sub, mux); + + ncline(a)(add) "posA(e)"; + ncline(b)(sub) "posA(e)"; + nccurve(a)(sub) "posA(e)", "angleA(0)"; + nccurve(b)(add) "posA(e)", "angleA(0)"; + nccurve(add)(mux) "posB(inpa)", "angleB(0)"; + nccurve(sub)(mux) "posB(inpb)", "angleB(0)"; + nccurve(opcode)(mux) "posB(n)", "angleA(0)", "angleB(-90)"; + ncline(mux)(res) "posA(out)"; +\stopuseMPgraphic + +\placeexample[ex:AddSubAlu]{\small{ALU} described in normal form} + \startcombination[2*1] + {\typebufferlam{AddSubAlu}}{Description in normal form} + {\boxedgraphic{AddSubAlu}}{Described architecture} + \stopcombination \startlambda -- All arguments are an inital lambda