chapter 14: arithmetic modules - wiley.com · describe the designs of arithmetic-logic unit (alu)...

42
Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-1 Chapter 14: Arithmetic Modules Department of Electronic Engineering National Taiwan University of Science and Technology Prof. Ming-Bo Lin

Upload: tranngoc

Post on 29-Mar-2019

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-1

Chapter 14: Arithmetic Modules

Department of Electronic Engineering

National Taiwan University of Science and Technology

Prof. Ming-Bo Lin

Page 2: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-2

Syllabus

ObjectivesAddition and subtractionMultiplicationDivisionArithmetic and logic unit

Page 3: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-3

Objectives

After completing this chapter, you will be able to:Describe both addition and subtraction modulesUnderstand the principles of carry-look-ahead (CLA) adderUnderstand the essential ideas of parallel-prefix addersDescribe the basic operations of multiplicationDescribe the basic operations of divisionDescribe the designs of arithmetic-logic unit (ALU)

Page 4: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-4

Syllabus

ObjectivesAddition and subtraction

Carry-look-ahead (CLA) addersParallel-prefix adders

MultiplicationDivisionArithmetic and logic unit

Page 5: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-5

Bottleneck of Ripple-Carry Adder

Bottleneck of n-bit ripple-carry adderThe generation of carries

Ways of carry generation carry-look-ahead (CLA) adder parallel-prefix adders:

• Kogge-Stone adder• Brent-Kung adder

others

Page 6: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-6

A CLA adder

Definition carry generate (gi): gi = xi · yi

carry propagate (pi): pi = xi ⊕ yi

iii cps ⊕=

iiii cpgc ⋅+=+1

0001 cpgc +=

001011

000111112 )(gppgpg

cpgpgcpgc++=

++=+=

Page 7: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-7

A Carry-Lookahead Generator

Page 8: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-8

A CLA Adder

Page 9: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-9

A CLA Adder

// a 4-bit CLA adder using assign statementsmodule cla_adder_4bits(x, y, cin, sum, cout);// inputs and outputsinput [3:0] x, y;input cin;output [3:0] sum;output cout;

// internal wireswire p0,g0, p1,g1, p2,g2, p3,g3;wire c4, c3, c2, c1;

// compute the p for each stageassign p0 = x[0] ^ y[0], p1 = x[1] ^ y[1],

p2 = x[2] ^ y[2], p3 = x[3] ^ y[3];

Page 10: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-10

A CLA Adder

// compute the g for each stageassign g0 = x[0] & y[0], g1 = x[1] & y[1],

g2 = x[2] & y[2], g3 = x[3] & y[3];// compute the carry for each stageassign c1 = g0 | (p0 & cin),

c2 = g1 | (p1 & g0) | (p1 & p0 & cin),c3 = g2 | (p2 & g1) | (p2 & p1 & g0) | (p2 & p1 & p0 & cin),c4 = g3 | (p3 & g2) | (p3 & p2 & g1) | (p3 & p2 & p1 & g0) |

(p3 & p2 & p1 & p0 & cin);// compute Sumassign sum[0] = p0 ^ cin, sum[1] = p1 ^ c1,

sum[2] = p2 ^ c2, sum[3] = p3 ^ c3;// assign carry outputassign cout = c4;endmodule

Page 11: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-11

A CLA Adder --- Using generate statements

// an n-bit CLA adder using generate loopsmodule cla_adder_generate(x, y, cin, sum, cout);// inputs and outputsparameter N = 4; //define the default sizeinput [N-1:0] x, y;input cin;output [N-1:0] sum;output cout;

// internal wireswire [N-1:0] p, g;wire [N:0] c;// assign input carryassign c[0] = cin;

n 4 8 16 32

f (MHz) 104.3 78.9 53.0 32.0LUTs 8 16 32 64

Virtex 2 XC2V250 FG456 -6

Page 12: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-12

A CLA Adder --- Using generate statementsgenvar i;generate for (i = 0; i <N; i = i + 1) begin: pq_cla

assign p[i] = x[i] ^ y[i];assign g[i] = x[i] & y[i];

end endgenerate // compute generate and propagation

generate for (i = 1; i < N+1; i = i + 1) begin: carry_claassign c[i] = g[i-1] | (p[i-1] & c[i-1]);

end endgenerate // compute carry for each stage

generate for (i = 0; i < N; i = i + 1) begin: sum_claassign sum[i] = p[i] ^ c[i];

end endgenerate // compute sum

assign cout = c[n]; // assign final carry…

Page 13: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-13

Syllabus

ObjectivesAddition and subtraction

Carry-look-ahead (CLA) adderParallel-prefix adders

MultiplicationDivisionArithmetic and logic unit

Page 14: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-14

Parallel-Prefix AddersThe prefix sums

s[i,0] = xi xi-1 … x1 x0

where 0 ≤ i < n

From bits k to i

where 0 ≤ i < n, k ≤ j < i, 0 ≤ k < n

[ , ] [ , 1] [ , 1] [ , ]

[ , ] , 1] [ , ]

i k i j i j j k

i k i j j k

g g p gp p p

+ +

+

= + ⋅

= ⋅

iiii

iiii

yxp

yxg

⊕=

⋅=

],[

],[

Page 15: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-15

Parallel-Prefix Adders

The carry of ith-bit adder can be written as

Define group g[i,j] and p[i,j] as a group and denoted as w[i,j] = (g[i,j], p[i,j])

111 −−− ⋅+= iiii cpgc

[ ,0] [ , 1] [ , 1] [ ,0]i i j i j jg g p g+ += + ⋅

Page 16: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-16

Parallel-Prefix Adders

The operator in w[i,k] = w[i,j+1] w[j,k] is a binary associative operator.

1 1 1i i i ic g p c− − −= + ⋅

[ ,0] [ , 1] [ , 1] [ ,0]i i j i j jg g p g+ += + ⋅

Page 17: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-17

Kogge-Stone Adder

Page 18: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-18

Brent-Kung Adder

Page 19: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-19

Parallel-Prefix Adders

An n-input Kogge-Stone parallel-prefix networka propagation delay of log2n levelsa cost of nlog2n - n + 1 cells

An n-input Brent-Kung parallel-prefix networka propagation delay of 2log2n - 2 levels and a cost of 2n - 2 - log2n cells

Page 20: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-20

Syllabus

ObjectivesAddition and subtractionMultiplication

Shift-and-add multiplicationBasic array multipliersA signed array multiplier

DivisionArithmetic and logic unit

Page 21: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-21

Shift-and-Add Multiplication

Page 22: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-22

Shift-and-Add Multiplication

A sequential implementation

Page 23: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-23

Syllabus

ObjectivesAddition and subtractionMultiplication

Shift-and-add multiplicationBasic array multipliersA signed array multiplier

DivisionArithmetic and logic unit

Page 24: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-24

A Basic Array Multiplier

An iterative logic structure

( ) ( )∑∑∑∑∑−+

=

=

+−

=

=

=⋅=⋅⋅⋅⋅⋅=×=

1

0

1

0

1

0

1

0

1

02222

nm

k

kk

n

j

jiji

m

i

n

j

jj

m

i

ii PyxyxYXP

Page 25: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-25

A Basic Unsigned Array Multiplier

Page 26: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-26

An Unsigned CSA Array Multiplier

Page 27: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-27

Syllabus

ObjectivesAddition and subtractionMultiplication

Shift-and-add multiplicationBasic array multipliersA signed array multiplier

DivisionArithmetic and logic unit

Page 28: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-28

A Signed Array Multiplier

Let X and Y be two two’s complement number im

ii

mm xxX 22

2

0

11 ∑+−=

=

−−

jn

jj

nn yyY 22

2

0

11 ∑+−=

=

−−

∑ ∑+−+∑ ∑=

∑+−

∑+−=

=

=

=

−+−

−+−

−+−−

+−

=

=

=

−−

=

−−

2

0

2

0

11

11

211

2

0

2

0

2

0

11

2

0

11

2222

2222

m

i

n

j

mjjm

nini

nmnm

jij

m

i

n

ji

n

j

jj

nn

m

i

ii

mm

yxyxyxyx

yyxx

XYP

Page 29: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-29

A Signed Array Multiplier

Page 30: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-30

A Signed Array Multiplier

Page 31: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-31

Syllabus

ObjectivesAddition and subtractionMultiplicationDivision

Nonrestoring division algorithmImplementations

Arithmetic and logic unit

Page 32: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-32

An Unsigned Non-restoring Division Algorithm

Page 33: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-33

An Unsigned Non-restoring Division Algorithm

Page 34: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-34

An Unsigned Nonrestoring Division Example

Page 35: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-35

Syllabus

ObjectivesAddition and subtractionMultiplicationDivision

Nonrestoring division algorithmImplementations

Arithmetic and logic unit

Page 36: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-36

A Sequential Unsigned Non-restoring Division

A sequential implementation

Page 37: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-37

An Unsigned Array Non-restoring Divider

Page 38: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-38

Syllabus

ObjectivesAddition and subtractionMultiplicationDivisionArithmetic and logic unit

Basic functionsImplementations

Page 39: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-39

Arithmetic-Logic Units

Arithmetic unitadditionsubtractionmultiplicationdivision

Logical unitANDORNOT

Page 40: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-40

Shift Operations

Logical shiftLogical left shiftLogical right shift

Arithmetic shiftArithmetic left shiftArithmetic right shift

Page 41: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-41

Syllabus

ObjectivesAddition and subtractionMultiplicationDivisionArithmetic and logic unit

Basic functionsImplementations

Page 42: Chapter 14: Arithmetic Modules - wiley.com · Describe the designs of arithmetic-logic unit (ALU) Chapter 14: Arithmetic Modules Digital System Designs and Practices Using Verilog

Chapter 14: Arithmetic Modules

Digital System Designs and Practices Using Verilog HDL and FPGAs @ 2008-2010, John Wiley 14-42

Arithmetic-Logic Units