Docsity

Division - Computer Arithmetic - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Part IV
Division
Number Representation
Numbers and Arithmetic
Representing Signed Numbers
Redundant Number Systems
Residue Number Systems
Addition / Subtraction
Basic Addition and Counting
Carry-Lookahead Adders
Variations in Fast Adders
Multioperand Addition
Multiplication
Basic Multiplication Schemes
High-Radix Multipliers
Tree and Array Multipliers
Variations in Multipliers
Division
Basic Division Schemes
High-Radix Dividers
Variations in Dividers
Division by Convergence
Real Arithmetic
Floating-Point Reperesentations
Floating-Point Operations
Errors and Error Control
Precise and Certifiable Arithmetic
Function Evaluation
Square-Rooting Methods
The CORDIC Algorithms
Variations in Function Evaluation
Arithmetic by Table Lookup
Implementation Topics
High-Throughput Arithmetic
Low-Power Arithmetic
Fault-Tolerant Arithmetic
Past, Present, and Future
Parts Chapters
I.
II.
III.
IV.
V.
VI.
VII.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
25.
26.
27.
28.
21.
22.
23.
24.
17.
18.
19.
20.
13.
14.
15.
16.
Elementary Operations
28. Reconfigurable Arithmetic
Appendix: Past, Present, and Future
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61

Partial preview of the text

Download Division - Computer Arithmetic - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Part IV

Division

Number Representation

Numbers and ArithmeticRepresenting Signed Numbers Redundant Number SystemsResidue Number Systems

Addition / Subtraction

Basic Addition and CountingCarry-Look ahead Adders Variations in Fast AddersMultioperand Addition

Multiplication

Basic Multiplication SchemesHigh-Radix Multipliers Tree and Array MultipliersVariations in Multipliers

Division

Basic Division SchemesHigh-Radix Dividers Variations in DividersDivision by Convergence

Real Arithmetic

Floating-Point ReperesentationsFloating-Point Operations Errors and Error ControlPrecise and Certifiable Arithmetic

Function Evaluation

Square-Rooting MethodsThe CORDIC Algorithms Variations in Function EvaluationArithmetic by Table Lookup

Implementation Topics

High-Throughput ArithmeticLow-Power Arithmetic Fault-Tolerant ArithmeticPast, Present, and Future

Parts Chapters I.

II.

III.

IV.

V.

VI.

VII.

1.2. 3.4. 5.6. 7.8.

10.9. 11.12.

25.26. 27.28.

21.22. 23.24.

17.18. 19.20.

13.14. Elementary Operations 15.16.

  1. Reconfigurable Arithmetic Appendix: Past, Present, and Future

IV Division

Topics in This Part

Chapter 13 Basic Division Schemes

Chapter 14 High-Radix Dividers

Chapter 15 Variations in Dividers

Chapter 16 Division by Convergence

Review Division schemes and various speedup methods

  • Hardest basic operation (fortunately, also the rarest)
  • Division speedup methods: high-radix, array,...
  • Combined multiplication / division hardware
  • Digit-recurrence vs convergence division schemes

Basic Division Schemes: Topics

Topics in This Chapter

13.1 Shift/Subtract Division Algorithms

13.2 Programmed Division

13.3 Restoring Hardware Dividers

13.4 Nonrestoring and Signed Division

13.5 Division by Constants

13.6 Radix-2 SRT Division

13.1 Shift/Subtract Division Algorithms

Notation for our discussion of division algorithms: z Dividend z 2 k – 1 z 2 k – 2... z 3 z 2 z 1 z 0 d Divisor dk – 1 dk – 2... d 1 d 0 q Quotient qk – 1 qk – 2... q 1 q 0 s Remainder, z – ( dq ) sk – 1 sk – 2... s 1 s 0 Initially, we assume unsigned operands

Fig. 13.1 Division of an 8-bit number by a 4-bit number in dot notation.

Dividend

Subtracted bit-matrix

z

s Remainder

d Divisor q Quotient

  • q (^) 3 d 2 3
  • q (^) 2 d 2 2
  • q (^) 1 d 2 1
  • q (^) 0 d 2 0

Division Recurrence

Division with left shifts

s ( j )^ = 2 s ( j – 1)^ – qk – j (2 k^ d ) with s (0)^ = z and |–shift–| s ( k )^ = 2 ks |––– subtract –––|

(There is no corresponding right-shift algorithm)

Fig. 13.

Dividend Subtracted bit-matrix

z

s Remainder

d Divisor q Quotient

  • q (^) 3 d 2 3
  • q (^) 2 d 2 2
  • q (^) 1 d 2 1
  • q (^) 0 d 2 0

Integer division is characterized by z = dq + s

2 –^2 kz = (2– kd )  ( 2 – kq ) + 2–^2 ks z frac = d frac  q frac + 2– k^ s frac

Divide fractions like integers; adjust the remainder

No-overflow condition for fractions is: z frac < d frac

k bits k bits

2 z

2 k^ d

0

Examples of Basic Division

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

Integer division Fractional division ====================== ===================== z 0 1 1 1 0 1 0 1 z frac. 0 1 1 1 0 1 0 1 24 d 1 0 1 0 d frac. 1 0 1 0 ====================== ===================== s (0)^ 0 1 1 1 0 1 0 1 s (0)^. 0 1 1 1 0 1 0 1 2 s (0)^ 0 1 1 1 0 1 0 1 2 s (0)^ 0. 1 1 1 0 1 0 1

  • q 3 24 d 1 0 1 0 { q 3 = 1} – q – 1 d. 1 0 1 0 { q – 1 =1} ––––––––––––––––––––––– –––––––––––––––––––––– s (1)^ 0 1 0 0 1 0 1 s (1)^. 0 1 0 0 1 0 1 2 s (1)^ 0 1 0 0 1 0 1 2 s (1)^ 0. 1 0 0 1 0 1
  • q 2 24 d 0 0 0 0 { q 2 = 0} – q – 2 d. 0 0 0 0 { q – 2 =0} ––––––––––––––––––––––– –––––––––––––––––––––– s (2)^ 1 0 0 1 0 1 s (2)^. 1 0 0 1 0 1 2 s (2)^ 1 0 0 1 0 1 2 s (2)^ 1. 0 0 1 0 1
  • q 1 24 d 1 0 1 0 { q 1 = 1} – q – 3 d. 1 0 1 0 { q – 3 =1} ––––––––––––––––––––––– –––––––––––––––––––––– s (3)^ 1 0 0 0 1 s (3)^. 1 0 0 0 1 2 s (3)^ 1 0 0 0 1 2 s (3)^ 1. 0 0 0 1
  • q 0 24 d 1 0 1 0 { q 0 = 1} – q – 4 d. 1 0 1 0 { q – 4 =1} ––––––––––––––––––––––– –––––––––––––––––––––– s (4)^ 0 1 1 1 s (4)^. 0 1 1 1 s 0 1 1 1 s frac 0. 0 0 0 0 0 1 1 1 q 1 0 1 1 q frac. 1 0 1 1 ====================== =====================

Decimal

Assembly Language Program for Division

Fig. 13. Programmed division using left shifts.

{Using left shifts, divide unsigned 2k-bit dividend, z_high|z_low, storing the k-bit quotient and remainder. Registers: R0 holds 0 Rc for counter Rd for divisor Rs for z_high & remainder Rq for z_low & quotient} {Load operands into registers Rd, Rs, and Rq} div: load Rd with divisor load Rs with z_high load Rq with z_low {Check for exceptions} branch d_by_0 if Rd = R branch d_ovfl if Rs > Rd {Initialize counter} load k into Rc {Begin division loop} d_loop: shift Rq left 1 {zero to LSB, MSB to carry} rotate Rs left 1 {carry to LSB, MSB to carry} skip if carry = 1 branch no_sub if Rs < Rd sub Rd from Rs incr Rq {set quotient digit to 1} no_sub: decr Rc {decrement counter by 1} branch d_loop if Rc  0 {Store the quotient and remainder} store Rq into quotient store Rs into remainder d_by_0: ... d_ovfl: ... d_done: ...

Rs Rq

Rd 0 0... 0 0 0 0 2 kd

CarryFlag

Shifted PartialRemainder Shifted PartialQuotient

Partial Remainder (2k – j Bits) Partial Quotient(j Bits)

Nextquotient digitinserted here

Divisor d

Fig. 13. Register usage for programmed division.

Time Complexity of Programmed Division

Assume k -bit words

k iterations of the main loop 6-8 instructions per iteration, depending on the quotient bit

Thus, 6 k + 3 to 8 k + 3 machine instructions, ignoring operand loads and result store

k = 32 implies 220+^ instructions on average

This is too slow for many modern applications!

Microprogrammed division would be somewhat better

Example of Restoring Unsigned Division

Fig. 13.6 Example of restoring unsigned division.

======================= z 0 1 1 1 0 1 0 1 24 d 0 1 0 1 0

  • 24 d 1 0 1 1 0 ======================= s (0)^0 0 1 1 1 0 1 0 1 2 s (0)^0 1 1 1 0 1 0 1 +(– 24 d ) 1 0 1 1 0 –––––––––––––––––––––––– s (1)^0 0 1 0 0 1 0 1 Positive, so set q 3 = 1 2 s (1)^0 1 0 0 1 0 1 +(– 24 d ) 1 0 1 1 0 –––––––––––––––––––––––– s (2)^1 1 1 1 1 0 1 Negative, so set q 2 = 0 s (2)=2 s (1)^0 1 0 0 1 0 1 and restore 2 s (2)^1 0 0 1 0 1 +(– 24 d ) 1 0 1 1 0 –––––––––––––––––––––––– s (3)^0 1 0 0 0 1 Positive, so set q 1 = 1 2 s (3)^1 0 0 0 1 +(– 24 d ) 1 0 1 1 0 –––––––––––––––––––––––– s (4)^0 0 1 1 1 Positive, so set q 0 = 1 s 0 1 1 1 q 1 0 1 1 =======================

No overflow, because (0111)two < (1010)two

Indirect Signed Division

In division with signed operands, q and s are defined by

z = dq + s sign( s ) = sign( z ) | s | < | d |

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 signs Signs of q and s are derivable from signs of z and d

Will discuss direct signed division later

(not q = – 2, s = – 1)

Justification for Nonrestoring Division

Why it is acceptable to store an incorrect value in the partial-remainder register?

Shifted partial remainder at start of the cycle is u

Suppose subtraction yields the negative result u – 2 kd

Option 1: Restore the partial remainder to correct value u , shift left, and subtract to get 2 u – 2 kd

Option 2: Keep the incorrect partial remainder u – 2 kd , shift left, and add to get 2( u – 2 kd ) + 2 kd = 2 u – 2 kd

Example of Nonrestoring Unsigned Division

Fig. 13.7 Example of nonrestoring unsigned division.

======================= z 0 1 1 1 0 1 0 1 24 d 0 1 0 1 0

  • 24 d 1 0 1 1 0 ======================= s (0)^0 0 1 1 1 0 1 0 1 2 s (0)^0 1 1 1 0 1 0 1 Positive, +(– 24 d ) 1 0 1 1 0 so subtract –––––––––––––––––––––––– s (1)^0 0 1 0 0 1 0 1 2 s (1)^0 1 0 0 1 0 1 Positive, so set q 3 = 1 +(– 24 d ) 1 0 1 1 0 and subtract –––––––––––––––––––––––– s (2)^1 1 1 1 1 0 1 2 s (2)^1 1 1 1 0 1 Negative, so set q 2 = 0 +2^4 d 0 1 0 1 0 and add –––––––––––––––––––––––– s (3)^0 1 0 0 0 1 2 s (3)^1 0 0 0 1 Positive, so set q 1 = 1 +(– 24 d ) 1 0 1 1 0 and subtract –––––––––––––––––––––––– s (4)^0 0 1 1 1 Positive, so set q 0 = 1 s 0 1 1 1 q 1 0 1 1 =======================

No overflow: (0111)two < (1010)two

Decimal

Convergence of the Partial Quotient to q

In restoring division, the partial quotient converges to q from below

Example

(0 1 1 1 0 1 0 1)two / (1 0 1 0)two

(117)ten/(10)ten = (11)ten = (1011)two

In nonrestoring division, the partial quotient may overshoot q , but converges to it after some oscillations (^0000)

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010

1011

1100

1101

1110

1111 Partial quotient

Iteration 0 1 2 3 4

q

q (1)^ q (2)

q (3)

q (4)

q (2)

Restoring

Nonrestoring

q (0)

Nonrestoring Division with Signed Operands

Restoring division

qk – j = 0 means no subtraction (or subtraction of 0) qk – j = 1 means subtraction of d

Nonrestoring division

We always subtract or add It is as if quotient digits are selected from the set {1, - 1}: 1 corresponds to subtraction - 1 corresponds to addition Our goal is to end up with a remainder that matches the sign of the dividend

This idea of trying to match the sign of s with the sign of z , leads to a direct signed division algorithm

if sign( s ) = sign( d ) then qk – j = 1 else qk – j = - 1

Example: q =... 0 0 0 1...

... 1 - 1 - 1 - 1...