computer arithmetic : adder · computer arithmetic : adder ... – ripple carry adder, manchester...
TRANSCRIPT
CS222CS222: Computer Arithmetic : AdderComputer Arithmetic : Adder
Continued..& Multiplier
Dr. A. Sahu
Dept of Comp. Sc. & Engg.Dept of Comp. Sc. & Engg.
Indian Institute of Technology Guwahati
1
Outline• Adder Universal Use (N bit addition)
– Ripple Carry Adder, Full Adder, Adder/Substrator,Ripple Carry Adder, Full Adder, Adder/Substrator, – Algorithmic Adder Scheme
• Reducing Adder DelayReducing Adder Delay – Ripple Carry Adder, Manchester Adder– Carry Skip Adder, Carry Select Adder– Carry Look Ahead Adder– Carry Save Adder (Multiple Operand Adder)
• Multiplication Algorithms– Shift and Add, Sequential Algorithms– Array Multiplier with RCA/CSA
2
Adder Universal UseAdder Universal Use• Adder : A = B + C
• Substractor: A = B + (‐C), 2’s complement
• Compare : C = A> B ? 1 : 0 (A‐B>0) : 1 : 0p ( )– Special case of compare with 0
• MultiplyMultiply
• Divide
d• Mod
• Floating point: Add/sub/mul…
3
NN‐‐Bit RippleBit Ripple‐‐Carry Adder: Series of FA CellsCarry Adder: Series of FA Cellspppp yy• To add two n‐bit numbers
A0 B0A1 B1A2 B2A 1B 1
C0FA
A0 B0
FA
A1 B1
FA
A2 B2
FA
An-1Bn-1
Cn. . .
0FA
S0
FA
S1
FA
S2
FA
Sn-1
n
• Adder delay = Tc * n• Tc = (C to C delay) of a FA
A B• Tc = (Cin to Cout delay) of a FA
FA CinCout
4Sum
Mathematically: Ci & SiMathematically: Ci & Si• C =FunC ( x x y y c )• Ci =FunC ( xi‐1, .., x0, yi‐1, .., y0, cin)
• Si =FunS (xi, yi, ci) i i i i
= ( xi + yi + ci) mod 2;
5
Ripple Carry Adder Analysisi 9 8 7 6 5 4 3 2 1 0xi 1 0 1 0 1 1 1 1 0 0 Cin=0
yi 0 0 0 1 0 1 0 0 1 0P K P P P G P P P KP K P P P G P P P K
Ci+1 0 0 1 1 1 1 0 0 0 0
Case Xi Yi Xi+Yi Ci+1 Comment
Kill (Ki=1) 0 0 0 0 Kill/Stop Cin/Cout=0
PropagatePi=1
0 1 1 Ci Propagate CinCout=Cin1 0 1 Ci
6
Generate 1 1 2 1 (Gi=1), Generate Cout, Cout=1
Propagate, Generate & KillPropagate, Generate & Kill• Case 1 (Kill): ki = xi’yi’ = (xi+yi)’i i i i i
• Case 2 (Propagate): pi = xi XOR yiC 3 (G t ) +• Case 3 (Generate): gi = xi + yi
Then
ci+1 = gi + pici = xiyi + (xi XOR yi) ciAlt ti ( i l ) iAlternative (simpler) expression:
ci+1 = gi + aicii+1 gi i i
Since ai = ki’, we call it "alive" 7
Reducing Adder DelayReducing Adder Delay• Ripple Carry Adder: N(tc)+max(tc,ts)• Reducing Carry Delay tc: Manchester Switch• Changing linear factor to smallerg g
– N/k or logN– Carry Look Ahead, Carry Skip, Carry Select, Conditional Sum Adder
• Including a competition signal: addition always may not be the worst case.
• Changing number representation: Carry Saved Adder
8
Switched Carry Ripple (M h ) Add(Manchester) Adder
• Idea: Fast circuit to propagating carry chain
xi+yi Gi Pi Ki Ci+1i yi i i i i+1
0 0 0 1 0
1 0 1 0 Ci
2 1 0 0 1
9
Chain Control Switch ModuleChain Control Switch Module
xi yi
Carry ControlGKP
i yi
giki
1 0 pi
10
CiCi+1
Manchester Adder (MRCA)Manchester Adder (MRCA)
• Delay: t +(n‐1)*tDelay: tsw+(n 1) tp• Here tp < tc, so total delay is less
CC
X0Y0
CC
X1Y1
CC
XiYi
CC
Xn‐1Yn‐1
CC
Cin
CCCCCC
S
Cin
SSS11
S0S1SiSn‐1
Carry Skip AdderCarry Skip Adder• Smaller modification to Ripple Carry Adder
• Reduce worst case delay by reducing the number of FA cell through carry has to Propagate
• Divide n bits in to (n/m) groups of m bits
• If sum of group is 2m‐1 then carry is propagatedIf sum of group is 2 1 then carry is propagated
• Carry is propagated when it propagated by all the bits of the groupsbits of the groups
Pj= pj0 pj1pj2 ..pjm‐‐1
• Cin,j+1 = Cout, j . P’j + Cin,j+Pj12
Carry Skip ExampleCarry Skip Example
P=0 P=1 P=1 P=0 P=1 P=0
1 1 1 0 0 1 1 0 0 1 0 1 1 0 1 1 1 00 1 0 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0
Ci
P
13CjCj+1
P
CSK ModuleC C• If Pj=1: simply skip the group j, Cin,j+1=Cin,jmm
yjxj
M‐bit RCACM0C
Pjmm
Group JCin
CoutMUX
0
1
Cin,j+1
mmModule n‐1
m
sjModule i
mmModule 1
mmModule 0
CSK Module
mm
CSK
mm
CSK Module
mm
CSK Module
mm
14
Module
m
Module
m
Module
m
Module
m
Carry Skip PathCarry Skip Path
skipped
15
Carry Select AdderCarry Select AdderFor a group Sum & Carry is already
FA FA FA FA
FA FA FA FA
Carry is already calculated
Si l l b d FA FA FA FASimply select based on carry
16
Carry Look Ahead Adder (CLA)Carry Look Ahead Adder (CLA)• Basic Idea: Compute Several Carries Simultaneously and use itSimultaneously and use it
• As Ripple Carry or MultiLevel CLAA3 B3 A2 B2 A1 B1 A0 B0A3 B3 A2 B2 A1 B1 A0 B0
FA FA FA FA
P3 G3 C3 P2 G2 C2 P1 G1 C1 P0 G0
S3 S2 S1 S0
17
P3 G3 C3 P2 G2 C2 P1 G1 C1 P0 G04 Bit Carry Look Ahead Generator
C4
CLGCLGiii1iiii BAGwhereCPGC ⋅=⋅+=
0121-ii1iii
iii1iiii
CPP ... PP+ ... GPG= BAGwhereCPGC
⋅⋅⋅+⋅++
−
−
4)inputsof(#forAvailableiii PCS
≤⊕=
4)inputsof(#for Available ≤
18
CLG (Carry Lookahead Generator)CLG (Carry Lookahead Generator)C0
P1G1P2
C1
CG2
P3
C2
C3
G3
P4C4
6.19G4
RCA with CLA unitsRCA with CLA units• As Carry are generated with CLG it takes less timetime
mmModule n‐1
mmModule i
mmModule 1
mmModule 0
CLAModule
CLAModule
CLAModule
CLAModule
m m m m
20
2 Levels of look ahead
a0 3
c0 P0c0
G
c4
0..3b0..3
s0..3 G0
P4i li a4..7b4..7
s4..7 CL
P4G4
no rippling of carry
a8..11b s8 11
c8 Aunit
P8G8b8..11
s8..11
a
c12
8
P12a12..15b12..15
s12..15c16
G12
Group propagate & generateGroup propagate & generate
c1 = p0 c0 + g0c1 p0 c0 + g0c2 = p1 c1 + g1 = p1p0c0+p1g0+g1c = p c + g = p p p c +p p g +p g +gc3 = p2 c2 + g2 = p2p1p0c0+p2p1g0+p2g1+g2c4 = p3 c3 + g3 =
p p p p c +p p p g +p p g +p g +gp3p2p1p0c0+p3p2p1g0+p3p2g1+p3g2+g3P0 = p3p2p1p0G p p p g +p p g +p g +gG0 = p3p2p1g0+p3p2g1+p3g2+g3c4 = P0 c0 + G0
Group propagate & generateGroup propagate & generate
Pi = pi+3 pi+2 pi+1 piPi pi+3 pi+2 pi+1 piGi = pi+3 pi+2 pi+1 gi + pi+3 pi+2 gi+1 + pi+3 gi+2 + gi+3c = P c + Gc4 = P0 c0 + G0
c8 = P4 P0 c0 + P4 G0 + G4
c = P P P c + P P G + P G + Gc12 = P8 P4 P0 c0 + P8 P4 G0 + P8 G4 + G8
c16 = P12 P8 P4 P0 c0 + P12 P8 P4 G0 + P12 P8 G4 + P12 G8 + G12
Summery: Two operand AdditionsSummery: Two operand Additions
• Speeding up additionp g p–Ripple carry adder (carry propagate): O(n)C l k h d O(l )–Carry look ahead: O(log n)
• What about Multi‐Operand AdderWhat about Multi Operand Adder–A=N0+N1+N2+…..+Nn
• Where we require: possibly in multiply or advance computing placesor advance computing places
24
Adding multiple operandsAdding multiple operandsb0a0b1a1b2a2b3a3
+ + + +E FBA
Traditional adderTraditional
e0e1e2e3
++++
Traditional adder
Traditional adder
Adder
Traditional
f0f1f2f3
++++ Traditional adder
Traditional adder
Adder
Traditional
+ + + ++S
Traditional adderAdder
s5 s0s1s2s3s4
Carry save additionCarry save addition
f0e0b0f1e1b1f2e2b2f3e3b3 E FBAf0e0b0f1e1b1f2e2b2f3e3b3
Carry saveadder
E FBA
+ + + + Carry Save Adder
a0a1a2a3
y
Carrysave adder
+ + + + Adder
Carry Save
c'3 s'3s'4 c'2 s'2 c'1 s'1 c'0 s'0
Carrysave adder
C' S'+ + + + Adder
TraditionalTraditional adder
++ ++ ++ ++Traditional Adder
s4 s3 s2 s1 s0s5
S
Multiplication: paper ‐ pencil methodMultiplication: paper pencil method
A 0 1 1B 1 0 1B 1 0 1
0 1 1 0 0 0 0 00 0 0 x
0 1 1 x x0 0 0 1 10 0 0 1 10 1 1 x x
AxB 0 1 1 1 10 0 0 1 10 1 1 1 1
Multiply: Shift & Add
• Decimal number : 15x20=300, 10x20+5x20 =300
• Binary number: 1111 X 10100• Binary number: 1111 X 10100– 1000X10100 + 100X10100 + 10X10100 + 1X10100
Sft3(10100) + ft2(10100) + ft1(10100)+ ft0(10100)– Sft3(10100) + sft2(10100) + sft1(10100)+sft0(10100)
– 1111X10000 + 1111X100
Sf 5(1111) f 2(1111)– Sft5(1111)+sft2(1111)
• Multiplication of N bit number, N shift, N Add, if bit is zero don’t add
• Special addition
28
Shift add multiplierA
shift 0
B0
0
hift 1
B1
+
shft 2
1
B
+i
1n
i 2BABA ×⋅=× ∑−
shi
t 3
B2+
0i∑=
shift B3
+
A x B
Shift add multiplier (sequential)Shift add multiplier (sequential)
i1n
2BABA ×⋅=× ∑−
step1: i=0; s=0 step1: i=0; s=00i
i 2BABA ×⋅=× ∑=
step1: i=0; s=0p ;
do {
step2:
p ;
do {
step2:
p ;
do {
step2:step2:
s += A⋅Bi x 2i
i ++
step2:
if (Bi) s += A
A = 2xA
step2:
if (B0) s += A
A = 2xAi ++
} while (i < n)
A 2xA
i ++
} while (i < n)
A = 2xA
B = B/2; i ++
} while (i < n)} while (i < n) } while (i < n)
Sequential shift add multiplier 1Sequential shift add multiplier 1
step1: i=0; s=0
do {A
2{
step2:
if (B ) s + A+
2n2n
Bif (B0) s += A
A = 2xAcontrol
B0
B = B/2; i ++
} while (i < n)
controls2n } ( )
Sequential shift add multiplier 2Sequential shift add multiplier 2
step1: i=0; s=0step1: i=0; s=0
do {
2
AA
n step2:
if (B0)sH += A+ BB
nn
step3: s = s/2
B = B/2; i ++t lt l
B0
B = B/2; i ++
} while (i < n)s controlcontrol
n
Sequential shift add multiplier 3Sequential shift add multiplier 3
A step1: i=0; s=0|B
do {
Ann
step2:
if (s ) s += A+
if (s0) sH += A
step3:
/s controlcontrol
s = s/2; i ++
} while (i < n)
s controlcontroln
Simple Speeding up11
02
−
×⋅=× ∑ in
iiBABA
11
11
00
0
2...2.2. −−
=
×++×+×= nn
i
BABABA• N Addition can be done in parallel in Log(N) steps using N Adder
110 n
steps using N Adder
A.B0.20 A.B1.21 A.B2.22 A.B3.23
++ ++34
++
Shift add multiplierA
shift 0
B0
0
hift 1
B1
+
shft 2
1
B
+i
1n
i 2BABA ×⋅=× ∑−
shi
t 3
B2+
0i∑=
shift B3
+
A x B
Array mult with carry propagateArray mult with carry propagatep00p01p02p03 p10p11p12p13 0
pij = ai . bj
0+ + ++p20p21p22p23
+ + ++
p30p31p32p33
0+ + ++
0++ ++ ++++s6 s5 s4 s3 s2s7 s1 s0
Array multiplier with carry saveArray multiplier with carry save
p00p01p02p03p10p11p12p13 p20p21p22p23
00
p00p01p02p030
pij = ai . bj
+ + ++p30p31p32p33 0
+ + ++
+ + ++
0++ ++ ++++s6 s5 s4 s3 s2s7 s1 s0
SummarySummary
• Speeding up addition• Speeding up addition–Ripple carry adder (carry propagate): O(n)
–Carry look ahead: O(log n)
• Speeding up array multiplierp g p y p–Using carry propagate adders: ~ 3 n d
Using carr sa e adders ~ 2 n d–Using carry save adders: ~ 2 n d
(here d = delay of 1 bit adder)
39