basic adders and counters implementation of adders in fpgas ece 645: lecture 3

62
Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Upload: arlene-beasley

Post on 15-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Basic Adders and Counters

Implementation of Adders in FPGAs

ECE 645: Lecture 3

Page 2: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Required Reading

Chapter 5, Basic Addition and Counting, Sections 5.1-5.5, pp. 75-85.

Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design

Page 3: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Required Reading

Chapter 9, Using Carry and Arithmetic Logic

Spartan-3 Generation FPGA User Guide http://www.xilinx.com/support/documentation/spartan-3_user_guides.htm

Page 4: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Half-adder

x

y

c

sHA

x + y = ( c s )2

2 1

x y c s0011

0101

0001

0110

Page 5: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Half-adderAlternative implementations (1)

s = xy + xy

b)

a)

s = x y

c = xy

c = x + y

Page 6: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

c)c = xy

s = xc + yc = xc yc

Half-adderAlternative implementations (2)

Page 7: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Full-adder

xy

cout

sFA

x + y + cin = ( cout s )2

2 1

x y cout s

00001111

00110011

00010111

01101001

cin

01010101

cin

Page 8: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Full-adderAlternative implementations (1)

a) s = (x y) cin

cout = xy + cin (x y)

s

c

c

Page 9: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Full-adderAlternative implementations (2)

s = x y cin = xycin + xycin + xycin + xycin

cout = xy + xcin + ycinb)

Page 10: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Full-adderAlternative implementations (3)

c)

x y cout s0011

0101

0

1

cin

cin

cin

cin

cin

cin

Page 11: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

x

yA2

A1

XORD

0 1

Cin

Cout

S

p

g

Full-adderAlternative implementations (4)

Implementation used to generate fast carry logic in Xilinx FPGAs

x y cout

0011

0101

y

y

cin

cin

p = x yg = ys= p cin = x y cin

Page 12: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 13: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 14: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 15: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Latency of a k-bit ripple-carry adder

Tripple-add = TFA(x,ycout) + + (k-2) TFA(cincout) + + TFA(cin s)

Latency k TFA

Latency k

Page 16: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 17: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 18: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Overflow for signed numbers (1)

Indication of overflow

Positive+ Positive= Negative

Negative+ Negative= Positive

Formulas

Overflow2’s complement = xk-1 yk-1 sk-1 + xk-1 yk-1 sk-1 =

= ck ck-1

Page 19: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Overflow for signed numbers (2)

xk-1 yk-1 ck-1 ck sk-1 overflow ckck-1

00001111

00110011

01010101

00010111

01101001

01000010

01000010

Page 20: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Implementation of Adders in FPGAs

Page 21: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Technology Low-cost High-performance

120/150 nm Virtex 2, 2 Pro

90 nm Spartan 3 Virtex 4

65 nm Virtex 5

45 nm Spartan 6

40 nm Virtex 6

Xilinx FPGA Devices

Page 22: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Altera FPGA Devices

Technology Low-cost Mid-range High-performanc

e130 nm Cyclone Stratix

90 nm Cyclone II Stratix II

65 nm Cyclone III Arria I Stratix III

40 nm Cyclone IV Arria II Stratix IV

Page 23: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

23ECE 448 – FPGA and ASIC Design with VHDL

Programmableinterconnect

Programmablelogic blocks

The Design Warrior’s Guide to FPGAsDevices, Tools, and Flows. ISBN 0750676043

Copyright © 2004 Mentor Graphics Corp. (www.mentor.com)

General structure of an FPGA

Page 24: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

24ECE 448 – FPGA and ASIC Design with VHDL

Page 25: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

25ECE 448 – FPGA and ASIC Design with VHDL

CLB CLB

CLB CLB

Logic cell

Slice

Logic cell

Logic cell

Slice

Logic cell

Logic cell

Slice

Logic cell

Logic cell

Slice

Logic cell

Configurable logic block (CLB)

The Design Warrior’s Guide to FPGAsDevices, Tools, and Flows. ISBN 0750676043

Copyright © 2004 Mentor Graphics Corp. (www.mentor.com)

Xilinx Spartan 3 FPGAs

Page 26: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

26ECE 448 – FPGA and ASIC Design with VHDL

CLB Structure

Page 27: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

27ECE 448 – FPGA and ASIC Design with VHDL

CLB Slice Structure

• Each slice contains two sets of the following:• Four-input LUT

• Any 4-input logic function,• or 16-bit x 1 sync RAM (SLICEM only)• or 16-bit shift register (SLICEM only)

• Carry & Control• Fast arithmetic logic• Multiplier logic• Multiplexer logic

• Storage element• Latch or flip-flop• Set and reset• True or inverted inputs• Sync. or async. control

Page 28: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

28ECE 448 – FPGA and ASIC Design with VHDL

LUT (Look-Up Table) Functionality

• Look-Up tables are primary elements for logic implementation

• Each LUT can implement any function of 4 inputs

x1 x2 x3 x4

y

x1 x2

y

LUT

x1x2x3x4

y

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y0100010101001100

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y1111111111110000

x1 x2 x3 x4

y

x1 x2 x3 x4

y

x1 x2

y

x1 x2

y

LUT

x1x2x3x4

y

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y0100010101001100

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y0100010101001100

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y1111111111110000

0x1

0x2 x3 x4

0 00 0 0 10 0 1 00 0 1 10 1 0 00 1 0 10 1 1 00 1 1 11 0 0 01 0 0 11 0 1 01 0 1 11 1 0 01 1 0 11 1 1 01 1 1 1

y1111111111110000

Page 29: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

29ECE 448 – FPGA and ASIC Design with VHDL

COUT

D Q

CK

S

REC

D Q

CK

REC

O

G4G3G2G1

Look-UpTable

Carry&

ControlLogic

O

YB

Y

F4F3F2F1

XB

X

Look-UpTable

F5IN

BYSR

S

Carry&

ControlLogic

CINCLKCE SLICE

Carry & Control Logic

Page 30: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

x yCOUT

0011

0101

y

y

CIN

CIN

Propagate = x yGenerate = ySum= Propagate CIN = x y CIN

xy

Carry & Control Logic in Xilinx FPGAs

Page 31: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Carry & Control Logic in Spartan 3 FPGAs

LUT

Hardwired (fast) logic

Page 32: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Simplified View of Spartan-3 FPGA Carry and Arithmetic Logic in One

Logic Cell

Page 33: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Simplified View of Carry Logic in One Spartan 3 Slice

Page 34: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 35: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Critical Path for anAdder Implemented UsingXilinx Spartan 3 FPGAs

Page 36: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Number and Length of Carry Chainsfor Spartan 3 FPGAs

Page 37: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Bottom Operand Input to Carry Out DelayTOPCYF

0.9 ns for Spartan 3

Page 38: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

0.2 ns for Spartan 3

Carry Propagation DelaytBYP

Page 39: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Carry Input to Top Sum Combinational Output DelayTCINY

1.2 ns for Spartan 3

Page 40: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Critical Path Delays and Maximum Clock Frequencies(into account surrounding registers)

Page 41: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Major Differences between Xilinx Families

Number of CLB slicesper CLB

Number of LUTsper CLB slice

Look-Up Tables

Number of adderstages per CLB slice

Spartan 3Virtex 4

Virtex 5, Virtex 6,Spartan 6

4-input 6-input

4

2

2

2

4

4

Page 42: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Altera Cyclone IIILogic Element (LE) – Normal Mode

Page 43: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Altera Cyclone IIILogic Element (LE) – Arithmetic Mode

Page 44: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Altera Stratix III, Stratix IVAdaptive Logic Modules (ALM) – Normal Mode

Page 45: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Altera Stratix III, Stratix IVAdaptive Logic Modules (ALM) – Arithmetic Mode

Page 46: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Bit-Serial & Digit-Serial Adders

Page 47: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 48: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Bit-serialadder

xi yi

si

c0

startci+1

clk

Page 49: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Digit-serialadder

d d

d

xi yi

si

c0

startci+1

clk

Page 50: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Addition of a Constant

Page 51: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Addition of a constant (1)

xk-1 xk-2 . . . x1 x0

yk-1 yk-2 . . . y1 y0

variableconstant+

xk-1 xk-2 . . . xh+1 xh xh-1 . . . x0

yk-1 yk-2 . . . yh+1 1 0 . . . 0

variableconstant+

xh xh-1 . . . x0

sk-1 sk-2 . . . s1 s0

sk-1 sk-2 . . . sh+1

Page 52: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Addition of a constant (2)

. . .HA/MHA

HA/MHA

HA/MHA

HA/MHA

x0xh-1xhxh+1xh+2xk-1 xk-2 . . . . . .

. .

x0xh-1xhsh+1sh+2

sk-1 sk-2 . . . . . .

If yi = 0 Half-adder (HA) yi = 1 Modified half-adder (MHA)

ck

Page 53: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Modified half-adder

x

y

c

sMHA

x + y + 1 = ( c s )2

2 1

x y c s0011

0101

0111

1001

Page 54: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

HA HAHAHA

x1x2xk-1 xk-2 . . .

. .

s1s2sk-1 sk-2 . . .

x0

x0

ck

Incrementer

MHA MHAMHAMHA

x1x2xk-1 xk-2 . . .

. .

s1s2sk-1 sk-2 . . .

x0

x0

ck

Decrementer

Page 55: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 56: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 57: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Asynchronous Adders

Page 58: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Possible solutions to the carry propagate problem

1. Detect the end of propagation rather than wait for the worst-case time

2. Speed-up propagation via • look-ahead• carry skip• carry select, etc

3. Limit carry propagation to within a small number of bits

4. Eliminate carry propagation through the redundant number representation

Page 59: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3
Page 60: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Analysis of carry propagation

Probability of carry generation = (xiyi = 11)4

1

Probability of carry propagation = (xiyi = 01 or 10)2

1

Probability of carry anihilation = (xiyi = 00 or 11)21

j j-1 . . . . . . . i+1 i

1 0 … 1 …0 … 1 11 1 … 0 …1 … 0 1

Probability of carry propagatingfrom position i to position j

=

11 or 00 01 or 10

1

21 ij

21

probability of propagation

probability of anihilation

=ij

21

Page 61: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Expected length of the carry chain that starts at position i (1)

Expected length(i, k) =

ikik

ijk

ij

ij

1

2

1)(

2

11

1

)(

Lengthof the carry chain

Probabilityof the given length

Probabilityof propagationtill the end ofadder

Distancetill the end of adder

Page 62: Basic Adders and Counters Implementation of Adders in FPGAs ECE 645: Lecture 3

Expected length of the carry chain that starts at position i (2)

Expected length(i, k) =

)1(22 ik

For i << k

Expected length of the carry propagation is 2