Docsity

Arithmetic Circuits - Lecture Notes | COMP 411, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Arithmetic Circuits - Lecture Notes | COMP 411 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

L10 – Arithmetic Circuits

10/4/

Arithmetic Circuits

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

Reading: Study Chapter 3.

L10 – Arithmetic Circuits

10/4/

Review: 2’s Complement

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/

Designing a Full Adder: From Last Time

1) Start with a truth table:2) Write down eqns for the

“1” outputsC

o

= C

i

AB + C

i

AB + C

i

AB + C

i

AB

S = C

i

AB + C

i

AB + C

i

AB + C

i

AB

3) Simplifing a bit

C

o

= C

i

(A + B) + AB

S = C

i

A

B

C

i

A
B
C

o

S

C

o

= C

i

(A

B) + AB

S = C

i

(A

B)

L10 – Arithmetic Circuits

10/4/

For Those Who Prefer Logic Diagrams …

A little tricky, but only5 gates/bit

CI
A B
S
CO

C

o

= C

i

(A

B) + AB

S = C

i

(A

B)

“Sum”

Logic

“Carry”

Logic

L10 – Arithmetic Circuits

10/4/

Condition Codes

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)

V

(overflow): indicates that the answer has

too many bits to be represented correctly bythe result width, e.g., “(

i-

i-

Z

(zero): result is = 0

big NOR gate

N

(negative): result is < 0

S

N-

C

(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/

T

PD

of Ripple-Carry Adder

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

  • t

PD,OR

) +(N-2)*(t

PD,OR

  • t

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

FA

A

B

CO

CI

S

FA

A

B

CO

CI

S

FA
A

n-

B

n-

A

n-

B

n-

A

2

B

2

A

1

B

1

A

0

B

0

S

n-

S

n-

S

2

S

1

S

0

A

B

CO

CI

S

FA

A

B

CO

CI

S

FA
C

CI

A B

S

CO

A,B to CO

L10 – Arithmetic Circuits

10/4/

N-Bit Addition in Constant Time?

So

if we had (N+1)-input gates and didn’t mind a lot of

loading on the P signals

, the propagation delay of adder built

using P/G equation to compute C

IN

of each bit would be:

4 gate delays

Of course, this is impractical when N is “large” (i.e. > 4) butit does lead to some interesting ideas:

faster ripple-carry implementations

hierarchical carry-lookahead adders

L10 – Arithmetic Circuits

10/4/

Carry-Lookahead Adders (CLA)

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:

G

HL

= G

H

+ P

H

G

L

P

HL

= P

H

P

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

GP

G

L

P

L

A

B

CO

C I

G

P

S

FA

A

B

CO

C I

G

P

S

FA

G

H

P

H

G

HL

P

HL

GP

G

L

P

L

L10 – Arithmetic Circuits

10/4/

8-bit CLA (Carry Generation)

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

= G

j-i

+ P

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

C
C
C
C
C
C
C
C
C
C
C
C
C
C
C

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

C
C C
C
C
C
C

Notice that theinputs on theright of each Cblocks are thesame as theinputs on theleft of eachcorrespondingGP block.

L10 – Arithmetic Circuits

10/4/

8-Bit CLA (Complete)

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

t

PD

(log(N))

G

H

P

H

G

HL

P

HL

GP

G

L

P

L

c

j

c

i

c

i

G

L

P

L

C

G

H

P

H

C

j

G

HL

P

HL

C

i

GP/C

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/

Carry-Select Adders

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/

Adder Summary

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

A
B
S

Add/Sub

A
B
S

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/

More Shifting

0

1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

R

7

R

6

R

5

R

4

R

3

R

2

R

1

R

0

X

7

X

6

X

5

X

4

X

3

X

2

X

1

X

0

SHL

0

1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

S

7

S

6

S

5

S

4

S

3

S

2

S

1

S

0

X

7

X

6

X

5

X

4

X

3

X

2

X

1

X

0

SHL

0

1 0

1 0

1 0

1 0

1 0

1 0

1 0

1

S

7

S

6

S

5

S

4

S

3

S

2

S

1

S

0

X

7

X

6

X

5

X

4

X

3

X

2

X

1

X

0

“0”

SHL

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/

Barrel Shifting

0

1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

R

7

R

6

R

5

R

4

R

3

R

2

R

1

R

0

X

7

X

6

X

5

X

4

X

3

X

2

X

1

X

0

SHL

0

1

0

1

0

1

0

1

0

1

0

1

0

1

0

1

S

7

S

6

S

5

S

4

S

3

S

2

S

1

S

0

SHL

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

T

7

T

6

T

5

T

4

T

3

T

2

T

1

T

0

SHL

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

A Y
S

N-bits

N-bits

log

2

(N)

bits