Basic Dividers

54
1 Basic Dividers Lecture 10

description

Lecture 10. Basic Dividers. Required Reading. Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design. Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers 13.4, Non-Restoring and Signed Division. - PowerPoint PPT Presentation

Transcript of Basic Dividers

Page 1: Basic Dividers

1

Basic Dividers

Lecture 10

Page 2: Basic Dividers

Required Reading

Chapter 13, Basic Division Schemes13.1, Shift/Subtract Division Algorithms13.3, Restoring Hardware Dividers13.4, Non-Restoring and Signed Division

Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design

Page 3: Basic Dividers

Notation and

Basic Equations

Page 4: Basic Dividers

4

Notation

z Dividend z2k-1z2k-2 . . . z2 z1 z0

d Divisor dk-1dk-2 . . . d1 d0

q Quotient qk-1qk-2 . . . q1 q0

s Remainder sk-1sk-2 . . . s1 s0

(s = z - dq)

Page 5: Basic Dividers

5

Basic Equations of Division

z = d q + s

sign(s) = sign(z)

| s | < | d |

z > 00 s < | d |

z < 0- | d | < s 0

Page 6: Basic Dividers

6

Unsigned Integer Division Overflow

z = zH 2k + zL < d 2k

Condition for no overflow (i.e. q fits in k bits):

z = q d + s < (2k-1) d + d = d 2k

zH < d

• Must check overflow because obviously the quotient q can also be 2k bits. • For example, if the divisor d is 1, then the quotient q is the

dividend z, which is 2k bits

Page 7: Basic Dividers

7

Sequential Integer DivisionBasic Equations

s(0) = z

s(j) = 2 s(j-1) - qk-j (2k d) for j=1..k

s(k) = 2k s

Page 8: Basic Dividers

8

Sequential Integer DivisionJustification

s(1) = 2 z - qk-1 (2k d)s(2) = 2(2 z - qk-1 (2k d)) - qk-2 (2k d)s(3) = 2(2(2 z - qk-1 (2k d)) - qk-2 (2k d)) - qk-3 (2k d)

. . . . . .

s(k) = 2(. . . 2(2(2 z - qk-1 (2k d)) - qk-2 (2k d)) - qk-3 (2k d) . . . - q0 (2k d) = = 2k z - (2k d) (qk-1 2k-1 + qk-2 2k-2 + qk-3 2k-3 + … + q020) = = 2k z - (2k d) q = 2k (z - d q) = 2k s

Page 9: Basic Dividers

9

Fig. 13.2 Examples of sequential division with integer and fractional operands.

Page 10: Basic Dividers

Fractional Division

Page 11: Basic Dividers

11

Unsigned Fractional Division

zfrac Dividend .z-1z-2 . . . z-(2k-1)z-2k

dfrac Divisor .d-1d-2 . . . d-(k-1) d-k

qfrac Quotient .q-1q-2 . . . q-(k-1) q-k

sfrac Remainder .000…0s-(k+1) . . . s-(2k-1) s-2kk bits

Page 12: Basic Dividers

12

Integer vs. Fractional Division

For Integers:

z = q d + s 2-2k

z 2-2k = (q 2-k) (d 2-k) + s (2-2k)

zfrac = qfrac dfrac + sfrac

For Fractions:

wherezfrac = z 2-2k

dfrac = d 2-k

qfrac = q 2-k

sfrac = s 2-2k

Page 13: Basic Dividers

13

Unsigned Fractional Division Overflow

Condition for no overflow:

zfrac < dfrac

Page 14: Basic Dividers

14

Sequential Fractional DivisionBasic Equations

s(0) = zfrac

s(j) = 2 s(j-1) - q-j dfrac for j=1..k

2k · sfrac = s(k)

sfrac = 2-k · s(k)

Page 15: Basic Dividers

15

Sequential Fractional DivisionJustification

s(1) = 2 zfrac - q-1 dfrac

s(2) = 2(2 zfrac - q-1 dfrac) - q-2 dfrac

s(3) = 2(2(2 zfrac - q-1 dfrac) - q-2 dfrac) - q-3 dfrac

. . . . . .

s(k) = 2(. . . 2(2(2 zfrac - q-1 dfrac) - q-2 dfrac) - q-3 dfrac . . . - q-k dfrac = = 2k zfrac - dfrac (q-1 2k-1 + q-2 2k-2 + q-3 2k-3 + … + q-k20) = = 2k zfrac - dfrac 2k (q-1 2-1 + q-2 2-2 + q-3 2-3 + … + q-k2-k) = = 2k zfrac - (2k dfrac) qfrac = 2k (zfrac - dfrac qfrac) = 2k sfrac

Page 16: Basic Dividers

Restoring Unsigned Integer Division

Page 17: Basic Dividers

17

Restoring Unsigned Integer Division

s(0) = z

for j = 1 to k

if 2 s(j-1) - 2k d > 0 qk-j = 1 s(j) = 2 s(j-1) - 2k d else qk-j = 0 s(j) = 2 s(j-1)

Page 18: Basic Dividers

18

Fig. 13.6 Example of restoring unsigned division.

Page 19: Basic Dividers

19

Fig. 13.5 Shift/subtract sequential restoring divider.

Page 20: Basic Dividers

Non-Restoring Unsigned Integer Division

Page 21: Basic Dividers

Non-Restoring Unsigned Integer Division

s(1) = 2 z - 2k dfor j = 2 to k if s(j-1) 0 qk-(j-1) = 1 s(j) = 2 s(j-1) - 2k d else qk-(j-1) = 0 s(j) = 2 s(j-1) + 2k dend forif s(k) 0 q0 = 1else q0 = 0 Correction step

Page 22: Basic Dividers

22

Non-Restoring Unsigned Integer Division

Correction step

z = q d + s

z = (q-1) d + (s+d)z = q’ d + s’

z, q, d ≥ 0 s<0

s = 2-k · s(k)

Page 23: Basic Dividers

23

Fig. 13.7 Example of nonrestoring unsigned division.

Page 24: Basic Dividers

24

Fig. 13.8 Partial remainder variations for restoring andnonrestoring division.

Page 25: Basic Dividers

25

s(j) = 2 s(j-1)

s(j+1) = 2 s(j) - 2k d = = 4 s(j-1) - 2k d

s(j) = 2 s(j-1) - 2k d

s(j+1) = 2 s(j) + 2k d = = 2 (2 s(j-1) - 2k d) + 2k d = = 4 s(j-1) - 2k d

Restoring division Non-Restoring division

Non-Restoring Unsigned Integer Division

Justification

s(j-1) ≥ 0 2 s(j-1) - 2k d < 0 2 (2 s(j-1) ) - 2k d ≥ 0

Page 26: Basic Dividers

Signed Integer Division

Page 27: Basic Dividers

27

Signed Integer Division

z d

| z | | d | sign(z) sign(d)

| q | | s |

sign(s) = sign(z)

sign(q) =+

-

Unsigneddivision

sign(z) = sign(d)

sign(z) sign(d)

q s

Page 28: Basic Dividers

28

Examples of division with signed operands

z = 5 d = 3 q = 1 s = 2

z = 5 d = –3 q = –1 s = 2

z = –5 d = 3 q = –1 s = –2

z = –5 d = –3 q = 1 s = –2

Magnitudes of q and s are unaffected by input signsSigns of q and s are derivable from signs of z and d

Examples of Signed Integer Division

Page 29: Basic Dividers

Non-RestoringSigned Integer Division

Page 30: Basic Dividers

30

Non-Restoring Signed Integer Division

s(0) = zfor j = 1 to k if sign(s(j-1)) == sign(d) qk-j = 1 s(j) = 2 s(j-1) - 2k d = 2 s(j-1) - qk-j (2k d) else qk-j = -1 s(j) = 2 s(j-1) + 2k d = 2 s(j-1) - qk-j (2k d) q = BSD_2’s_comp_conversion(q)Correction_step

Page 31: Basic Dividers

31

Non-Restoring Signed Integer Division

Correction step

z = q d + s

z = (q-1) d + (s+d)z = q’ d + s’

z = (q+1) d + (s-d)z = q” d + s”

s = 2-k · s(k)

sign(s) = sign(z)

Page 32: Basic Dividers

32

Fig. 13.9 Example of nonrestoring signed division.========================z 0 0 1 0 0 0 0 124d 1 1 0 0 1 –24d 0 0 1 1 1 ========================s(0) 0 0 0 1 0 0 0 0 1 2s(0) 0 0 1 0 0 0 0 1 sign(s(0)) sign(d),+24d 1 1 0 0 1 so set q3 = 1 and add––––––––––––––––––––––––s(1) 1 1 1 0 1 0 0 1 2s(1) 1 1 0 1 0 0 1 sign(s(1)) = sign(d), +(–24d) 0 0 1 1 1 so set q2 = 1 and subtract––––––––––––––––––––––––s(2) 0 0 0 0 1 0 1 2s(2) 0 0 0 1 0 1 sign(s(2)) sign(d),+24d 1 1 0 0 1 so set q1 = 1 and add––––––––––––––––––––––––s(3) 1 1 0 1 1 1 2s(3) 1 0 1 1 1 sign(s(3)) = sign(d), +(–24d) 0 0 1 1 1 so set q0 = 1 and subtract––––––––––––––––––––––––s(4) 1 1 1 1 0 sign(s(4)) sign(z),+(–24d) 0 0 1 1 1 so perform corrective subtraction––––––––––––––––––––––––s(4) 0 0 1 0 1 s 0 1 0 1 q

1 11 1 ========================

p = 0 1 0 1 Shift, compl MSB 1 1 0 1 1 Add 1 to correct 1 1 0 0 Check: 33/(7) = 4

Page 33: Basic Dividers

33

BSD 2’s Complement Conversion

q = (qk-1 qk-2 . . . q1 q0)BSD =

= (pk-1 pk-2 . . . p1 p0 1)2’s complement

where

piqi

-1 011

Example:

1 -1 1 1qBSD

p

q2’scomp

1 0 1 1

0 0 1 1 1 = 0 1 1 1

no overflow if pk-2 = pk-1 (qk-1 qk-2)

Page 34: Basic Dividers

Fast Review ofFast Dividers

Page 35: Basic Dividers

35

Classification of Dividers

Sequential

Radix-2 High-radix

RestoringNon-restoring

• regular• SRT• regular using carry save adders• SRT using carry save adders

ArrayDividers

Dividersby Convergence

Page 36: Basic Dividers

36

ArrayDividers

Page 37: Basic Dividers

37

Fig. 15.7 Restoring array divider composed of controlledsubtractor cells.

Page 38: Basic Dividers

38

Fig. 15.8 Nonrestoring array divider built of controlledadd/subtract cells.

Page 39: Basic Dividers

39

SequentialDividers

with Carry-Save Adders

Page 40: Basic Dividers

40

Fig. 14.8 Block diagram of a radix-2 divider with partialremainder in stored-carry form.

Page 41: Basic Dividers

41

Carry v

CSA tree

Adder

Divisor d

k k

Select q –j

Shift left

2s Sum u

Multiple generation /

selection

Carry Sum

q –j

. . . q –j | | d or its complement

Fig. 14.15 Block diagram of radix-r divider with partial remainder in stored-carry form.

Process to derive the details:

Radix r

Digit set [–, ] for q–j

Number of bits of p (v and u) and d to be inspected

Quotient digit selection unit (table or logic)

Multiple generation/selection scheme

Conversion of redundant q to 2’s complement

Radix r Divider

Page 42: Basic Dividers

42

Pentium bug (1)October 1994

Thomas Nicely, Lynchburg Collage, Virginiafinds an error in his computer calculations, and tracesit back to the Pentium processor

Tim Coe, Vitesse Semiconductorpresents an example with the worst-case error

c = 4 195 835/3 145 727

Pentium = 1.333 739 06...Correct result = 1.333 820 44...

November 7, 1994

Late 1994

First press announcement, Electronic Engineering Times

Page 43: Basic Dividers

43

Pentium bug (2)

Intel admits “subtle flaw”

Intel’s white paper about the bug and its possible consequences

Intel - average spreadsheet user affected once in 27,000 yearsIBM - average spreadsheet user affected once every 24 days

Replacements based on customer needs

Announcement of no-question-asked replacements

November 30, 1994

December 20, 1994

Page 44: Basic Dividers

44

Pentium bug (3)

Error traced back to the look-up table used bythe radix-4 SRT division algorithm

2048 cells, 1066 non-zero values {-2, -1, 1, 2}

5 non-zero values not downloaded correctly to the lookup table due to an error in the C script

Page 45: Basic Dividers

45

Page 46: Basic Dividers

46

Multiply/DivideUnit

Page 47: Basic Dividers

47

The control unit proceeds through necessary steps for multiplication or division (including using the appropriate shift direction)

Fig. 15.9 Sequential radix-2 multiply/divide unit.

Multiplier x or quotient q

Mux

Adder out c

0 1

Partial product p or partial remainder s

Multiplicand a or divisor d

Shift control

Shift

Enable

in c

q k–j

MSB of 2s (j–1)

k

k

k

j x

MSB of p (j+1)

Divisor sign

Multiply/ divide control

Select

Mul Div

The slight speed penalty owing to a more complex control unit is insignificant

Multiply-Divide Unit

Page 48: Basic Dividers

Learn to deal with approximations

• In digital arithmetic one has to come to grips with approximation and questions like:– When is approximation good enough

– What margin of error is acceptable

• Be aware of the applications you are designing the arithmetic circuit or program for

• Analyze the implications of your approximation

Page 49: Basic Dividers

Calculators

2.....u =

10 times

v = 21/1024 = 1.000 677 131= 1.000 677 131

x = (((u2)2)…)2 = 1.999 999 963

10 times

x’ = u1024 = 1.999 999 973

y = (((v2)2)…)2 = 1.999 999 983

10 times

y’ = v1024 = 1.999 999 994

Hidden digits in the internal representation of numbersDifferent algorithms give slightly different results

Very good accuracy

Page 50: Basic Dividers

DIGITAL SYSTEMS DESIGN

Concentration advisors: Kris Gaj

• ECE 545 Digital System Design with VHDL (Fall semesters)– K. Gaj, project, FPGA design with VHDL, Aldec/Synplicity/Xilinx/Altera

2. ECE 645 Computer Arithmetic (Spring semesters)– K. Gaj, project, FPGA design with VHDL or Verilog,

Aldec/Synplicity/Xilinx/Altera

3. ECE 586 Digital Integrated Circuits (Spring semesters) – D. Ioannou

4. ECE 681 VLSI Design for ASICs (Fall semesters)– N. Klimavicz, project/lab, front-end and back-end ASIC design with Synopsys tools

5. ECE 682 VLSI Test Concepts (Spring semesters)– T. Storey, homework

Page 51: Basic Dividers

Follow-up courses

Computer ArithmeticECE 645

ECE 746Advanced Applied

Cryptography(Spring 2012 or 2013)

ECE 646Cryptography and

Computer Network Security(Fall 2011)

ECE 899Cryptographic Engineering

(Spring 2012)

Page 52: Basic Dividers

Cryptography and Computer Network Security

Advanced Applied Cryptography

• AES• Stream ciphers• Elliptic curve cryptosystems• Random number generators• Smart cards• Attacks against implementations (timing, power, fault analysis)• Efficient and secure implementations of cryptography• Security in various kinds of networks (IPSec, wireless)• Zero-knowledge identification schemes

• Historical ciphers• Classical encryption (DES, Triple DES, RC5, IDEA)• Public key encryption (RSA)• Hash functions and MACs • Digital signatures• Public key certificates• PGP• Secure Internet Protocols• Cryptographic standards

Modular integer arithmetic Operations in the Galois Fields GF(2n)

Page 53: Basic Dividers
Page 54: Basic Dividers

Selected Topics

True Random Number Generators Fast Finite Field Multiplication Elliptic and Hyperelliptic Curve Cryptography Instruction Set Extensions for Cryptographic Applications FPGA and ASIC Implementations of AES Secure and Efficient Implementation of Symmetric Encryption Block Cipher Modes of Operation in Hardware Basics of Side-Channel Analysis Improved Techniques for Side-Channel Analysis Electromagnetic Attacks and Countermeasures Microarchitectural Attacks and Countermeasures (cache attacks)