Programming Examples: Bluespec-5
Programming Examples: Bluespec-5
Programming Examples: Bluespec-5
Bluespec-5
Programming Examples
Arvind
Laboratory for Computer Science
M.I.T.
Lecture 21
http://www.csg.lcs.mit.edu/6.827
L21-2
Arvind
Quiz
• Determine if a n-bit number contains
exactly one “1”.
http://www.csg.lcs.mit.edu/6.827
L21-3
Arvind
Outline
• Lennart’s problem √
• Instruction Encoding ⇐
– Pack and Unpack
http://www.csg.lcs.mit.edu/6.827
L21-4
Arvind
0 0 a3
0 1 b5
1 1 p31
http://www.csg.lcs.mit.edu/6.827
L21-5
Arvind
t” ! 0 0 a3
bi ing
2 0 1 b5
“3 cod
en 1 p31
http://www.csg.lcs.mit.edu/6.82
L21-6
Arvind
6 5 5 5 5 6
Reg-Reg Op Rs1 Rs2 Rd Const Opx
Jump/Call Op Const
http://www.csg.lcs.mit.edu/6.827
L21-7
Arvind
L21-8
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-9
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-10
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-11
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-12
Arvind
pack (Nop) = 0
http://www.csg.lcs.mit.edu/6.827
L21-13
Arvind
...
http://www.csg.lcs.mit.edu/6.827
L21-14
Arvind
Decoding Functions
isImmInstr :: Bit (SizeOf Instruction) -> Bool
isImmInstr bs = not (isSpecialInstr bs || isREGIMMInstr bs
|| isJumpInstr bs )
http://www.csg.lcs.mit.edu/6.827
L21-15
Arvind
Outline
• Lennart’s problem √
• Instruction Encoding √
– Pack and Unpack
http://www.csg.lcs.mit.edu/6.827
L21-16
Arvind
Wallace addition
Add several m-bit numbers
am-1 a2 a1 a0
bm-1 b2 b1 b0
cm-1 c2 c1 c0
L21-17
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-18
Arvind
at 2n-1 N at 22 at 21 at 20
One full wallace step
ceiling(N/3)
Nil
(discard)
2ceiling(N/3)
at 2n-1 at 23 at 22 at 21 at 20
http://www.csg.lcs.mit.edu/6.827
L21-19
Arvind
at 2n-1 at 22 at 21 at 20
wallaceStep
wallaceStep
L21-20
Arvind
http://www.csg.lcs.mit.edu/6.827
10
L21-21
Arvind
http://www.csg.lcs.mit.edu/6.827
L21-22
Combine:
Arvind
http://www.csg.lcs.mit.edu/6.827
11
L21-23
Arvind
Wallace algorithm
while p f x = if p x then (while p f (f x))
else x
isLengthGT2 x = (length x) > 2
isAnyLengthGT2 xs = foldr (or) False (map isLengthGT2 xs)
http://www.csg.lcs.mit.edu/6.827
L21-24
Arvind
12
L21-25
Arvind
Pipelined Wallace
while :: (t->Bool) -> (t->t) -> t -> t
while p f x = if p x then (while p f (f x)) else x
http://www.csg.lcs.mit.edu/6.827
L21-26
Arvind
Alternatives
• Write a less parameterized solution.
– Given a k we can figure out how many wallace
iterations are needed and do all the unfolding
manually
• Keep the register size the same after
every iteration
– need to pack the bits in some suitable order
– extra hardware and may be messy coding
– different termination condition
• Fix the language!
– discussions underway
http://www.csg.lcs.mit.edu/6.827
13
L21-27
Arvind
Manual unrolling
http://www.csg.lcs.mit.edu/6.827
L21-28
Arvind
http://www.csg.lcs.mit.edu/6.827
14