

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















L10 – Arithmetic Circuits
10/4/
Didn’t I learn howto do addition inthe second grade?UNC courses aren’twhat they used tobe...
Finally; time to
build some
serious
functional
blocks
We’ll need
a lot of
boxes
L10 – Arithmetic Circuits
10/4/
0
1
2
3
N-
N-
N bits
8-bit 2’s complement example:
7
6
4
2
1
If we use a two’s-complement representation for signed integers, thesame binary addition procedure will work for adding both signed andunsigned numbers.By moving the implicit “binary” point, we can represent fractions too:
3
2
0
“sign bit”
“binary” point
Range: – 2
N-
to 2
N-
L10 – Arithmetic Circuits
10/4/
o
i
i
i
i
i
i
i
i
o
i
i
i
o
o
i
i
L10 – Arithmetic Circuits
10/4/
o
i
i
“Sum”
Logic
“Carry”
Logic
L10 – Arithmetic Circuits
10/4/
Besides the sum, one often wants four other bitsof information from an arithmetic unit:
To compare A and B,
perform A–B and use
condition codes:Signed comparison:
LT
N
⊕⊕⊕⊕
V
LE
Z+(N
⊕⊕⊕⊕
V)
EQ
Z
NE
~Z
GE
~(N
⊕ ⊕
⊕ ⊕
V)
GT
~(Z+(N
⊕⊕⊕⊕
V))
Unsigned comparison:
LTU
C
LEU
C+Z
GEU
~C
GTU
~(C+Z)
To compare A and B,
perform A–B and use
condition codes:Signed comparison:
LT
N
⊕⊕⊕⊕
V
LE
Z+(N
⊕⊕⊕⊕
V)
EQ
Z
NE
~Z
GE
~(N
⊕ ⊕
⊕ ⊕
V)
GT
~(Z+(N
⊕⊕⊕⊕
V))
Unsigned comparison:
LTU
C
LEU
C+Z
GEU
~C
GTU
~(C+Z)
(overflow): indicates that the answer has
too many bits to be represented correctly bythe result width, e.g., “(
i-
i-
(zero): result is = 0
big NOR gate
(negative): result is < 0
S
N-
(carry): indicates that add in the most
significant position produced a carry, e.g.,“1 + (-1)”
from last FA
N
1
i
B
1 i A N 1 i B
1
i
A
V
− − + − − =
1
i
CI
1
i
CO
V
−
⊕
−
=
-or-
L10 – Arithmetic Circuits
10/4/
Worse-case path: carry propagation from LSB to MSB, e.g., whenadding 11…111 to 00…001. t
PD
= (t
PD,XOR
+t
PD,AND
PD,OR
) +(N-2)*(t
PD,OR
PD,AND
) + t
PD,XOR
≈≈≈≈
Θ Θ
Θ Θ
(N)
CI to CO
CI
N-
to S
N-
(N) is read “order N” and tells us that the latency of our adder
grows in proportion to the number of bits in the operands.
A
B
CO
CI
S
A
B
CO
CI
S
A
B
CO
CI
S
n-
n-
n-
n-
2
2
1
1
0
0
n-
n-
2
1
0
A
B
CO
CI
S
A
B
CO
CI
S
CI
A B
S
CO
A,B to CO
L10 – Arithmetic Circuits
10/4/
IN
L10 – Arithmetic Circuits
10/4/
We can build a hierarchical carry chain by generalizing our definition ofthe Carry Generate/Propagate (GP) Logic. We start by dividing ouraddend into two parts, a higher part, H, and a lower part, L. The GPfunction can be expressed as follows:
HL
H
H
L
HL
H
L
Generate a carry out if the high partgenerates one, or if the low part generates oneand the high part propagates it. Propagate acarry if both the high and low parts propagatetheirs.
Hierarchical building block
P/G generation
1
st
level of
lookahead
G
H
P
H
G
HL
P
HL
G
L
P
L
A
B
CO
C I
G
P
S
A
B
CO
C I
G
P
S
G
H
P
H
G
HL
P
HL
G
L
P
L
L10 – Arithmetic Circuits
10/4/
Log
2
(N)
Now, given a the value of the carry-in of the least-significant bit,wecan generate the carries for every adder.
c
j
j-i
j-i
c
i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
c
j
c
i
c
i
G
j-i
P
j-i
G
3-
P
3-
G
1-
P
1-
G
5-
P
5-
G
6
P
6
G
4
P
4
G
2
P
2
G
0
P
0
Notice that theinputs on theright of each Cblocks are thesame as theinputs on theleft of eachcorrespondingGP block.
L10 – Arithmetic Circuits
10/4/
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
B
CO
CI
G
P
S
FA
A
7
B
7
A
6
B
6
A
5
B
5
A
4
B
4
A
3
B
3
A
2
B
2
A
1
B
1
A
0
B
0
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
j
G
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
G
H
P
H
C
jG
L
P
L
C
i
GP/C
G
HL
P
HL
C
i
PD
G
H
P
H
G
HL
P
HL
G
L
P
L
c
j
c
i
c
i
G
L
P
L
G
H
P
H
C
j
G
HL
P
HL
C
i
G
L
P
L
C
I
CI
A B
S
CO
G
P
Notice that we don’t needthe carry-out output ofthe adder any more.
C
0
L10 – Arithmetic Circuits
10/4/
Idea: do two additions, one assuming carry-in is 0, the other assumingcarry-in is 1. Use MUX to select correct answer when correct carry-in isknown.
Left blocks can be bigger – more ripple time time while waiting for select
With one stage: 50% more cost, but twice as fast as ripple-carryWith multiple (variable-size) blocks: t
PD
(sqrt(N))
L10 – Arithmetic Circuits
10/4/
Adding is not only a common, but it is also tends to be one of the most
time-critical of operations. As a result, a wide range of adderarchitectures have been developed that allow a designer to tradeoffcomplexity (in terms of the number of gates) for performance.
Ripple
Carry
Carry
Skip
Carry
Select
Carry
Lookahead
Smaller / Slower
Bigger / Faster
Add
Add/Sub
sub
A this point we’ll define a high-levelfunctional unit for an adder, andspecify the details of theimplementation as necessary.
L10 – Arithmetic Circuits
10/4/
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
“0”
Using the samebasic idea we canbuild left shiftersof arbitrary sizesusing muxes.Each shift amountrequires its ownset of muxes.
Hum, maybe
we could do
something
more clever.
L10 – Arithmetic Circuits
10/4/
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
7
6
5
4
3
2
1
0
7
6
5
4
3
2
1
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
7
6
5
4
3
2
1
0
If we connect our “shift-left-two” shifter to the output ofour “shift-left-one” we canshift by 0, 1, 2, or 3 bits.
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
7
6
5
4
3
2
1
0
And, if we add one more“shift-left-4” shifter we cando any shift up to 7 bits!So, let’s put a box around itand call it a new functionalblock.
Left
Barrel
Shifter
N-bits
N-bits
log
2
(N)
bits