You are on page 1of 18

Topic 4: Arithmetic in ARM

Part 3
Overview of prefix computation

 Given a set of n elements, x1 , x2 , …, xn and a


binary operation o, prefix computation involves
finding all the partial outputs
x1 o x2 o….. o xi for 1≤ i ≤ n

- What is meant by partial output ?


Partial output

 Consider
x1 o x2 o….. o xi

- We want to find xi-1 o xi ,


xi-2 o xi-1 o x i , xi-3 o xi-2 o xi-1 o xi and so on

3
Example

 Suppose we want to find


6o5o4o3o2o1
Let us assume that o represents addition
Then our task is to calculate 2 + 1,
3+2+1, 4+3+2+1, 5+4+3+2+1 and
6+5+4+3+2+1
and report along with 1 (the only element
on the right) as the six outputs
Direct algorithm for summation

 Consider finding 2 + 1, 3+2+1, 4+3+2+1,


5+4+3+2+1 and 6+5+4+3+2+1
 A simple algorithm is to find the sum of 2
and 1 first and store the result (call it as
say X)
 Then add 3 to this result and store it (call
it as say Y)
 Continuing this way, we can complete the
5 process in 5 steps
Can we do it faster ?

 Is there some other way of handling the


prefixes ?

6
Key observations for speedup

 Associativity of the summation (will see


this in more detail in the slides to follow)
 Ability to do some computations in
parallel

7
Prefix sums faster !

Note that this computes all the sums in 3 steps altogether

6 5 4 3 2 1

+ + +

+ +
+ +

B6 B5 B4 B3 B2 B1
How fast in general ?

 We can show that log2 (input size) is


roughly how fast we can compute (where
we take logarithm to the base 2)

 A small constant may also be involved


but the number of steps will, in general,
depend on the depth of the structure

9
Why is this relevant to our multi-bit
addition ?

 We would like to see if the prefix sum idea


can be extended to the calculation of
carries fast and in a regular manner
o can be defined for multi-bit addition

 Consider (gi, pi) and (gj, pj). Then define


(gi, pi) o (gj, pj) = (gi + pi gj, pi pj)
 o can be shown to be associative. That is,
(gi, pi) o [(gj, pj) o (gk, pk)] = [(gi, pi) o (gj, pj)]
o (gk, pk)

EXERCISE: Verify this


Exercise

 Is the o operator commutative ?


Prefix computation for carry calculation

 Recall C1 = g0 + p0 C0
- This can also be written as
C1 = ( g0 , p0 ) o (C0, 0)
Similarly,
C2 = (g1, p1) o ( g0 , p0 ) o (C0, 0)
C3 = (g2, p2) o (g1, p1) o ( g0 , p0 ) o (C0, 0)

This is what we mean by prefix computation for


calculation of successive carries
Prefix Adders

 Various adders based on the prefix


concept have been proposed.
 Popular prefix adders include:
Ladner-Fischer prefix adder
Brent-Kung prefix adder

14
How do the prefix adders vary ?

 Their structure (as defined by what is


known as the prefix graph) is different
 The prefix-style computation allows, for
example, the Ladner-Fischer adder to
have fewer levels than the Brent-Kung
adder
 On the other hand, fewer associative (o)
operations are involved in Brent-Kung
than in Ladner-Fischer especially for large
15
adder-size (16 bits, 32 bits and so on)
8-bit Ladner-Fischer prefix graph

(g7, p7) (g5, p5) (g3, p3) (g1, p1)


(g6, p6) (g4, p4) (g2, p2) (g0, p0)
c0

c8 c7 c6 c5 c4 c3 c2 c1
What to infer from the Ladner-
Fischer graph ?

 (c2, 0) = (g1, p1) o (c1, 0)

 (c3, 0) = (g2, p2) o (c2, 0)


 (c4, 0) = [(g3, p3) o (g2, p2) ] o (c2, 0)

17
More on the Ladner-Fischer graph

 (c5, 0) = (g4, p4) o (c4, 0)


 (c6, 0) = [(g5, p5) o (g4, p4)] o (c4, 0)
 (c7, 0) = {(g6, p6) o [(g5, p5) o (g4, p4)]} o
(c4, 0)
 (c8, 0) = {[(g7, p7) o (g6, p6)] o [(g5, p5) o
(g4, p4)]} o (c4, 0)

18

You might also like