Lecture 10 Basic Dividers Required Reading Behrooz Parhami
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 Chapter 15 Variation in Dividers 15. 6, Combined Multiply/Divide Units
Notation and Basic Equations
Notation z Dividend z 2 k-1 z 2 k-2. . . 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 (s = z - dq) sk-1 sk-2. . . s 1 s 0 4
Basic Equations of Division z=dq +s |s|<|d| sign(s) = sign(z) z>0 0 s<|d| z<0 -|d|<s 0 5
Unsigned Integer Division Overflow • Must check overflow because obviously the quotient q can also be 2 k bits. • For example, if the divisor d is 1, then the quotient q is the dividend z, which is 2 k bits Condition for no overflow (i. e. q fits in k bits): z = q d + s < (2 k-1) d + d = d 2 k z = z. H 2 k + z. L < d 2 k z. H < d 6
Sequential Integer Division Basic Equations s(0) = z s(j) = 2 s(j-1) - qk-j (2 k d) for j=1. . k s(k) = 2 k s 7
Sequential Integer Division Justification s(1) = 2 z - qk-1 (2 k d) s(2) = 2(2 z - qk-1 (2 k d)) - qk-2 (2 k d) s(3) = 2(2(2 z - qk-1 (2 k d)) - qk-2 (2 k d)) - qk-3 (2 k d). . . s(k) = 2(. . . 2(2(2 z - qk-1 (2 k d)) - qk-2 (2 k d)) - qk-3 (2 k d). . . - q 0 (2 k d) = = 2 k z - (2 k d) (qk-1 2 k-1 + qk-2 2 k-2 + qk-3 2 k-3 + … + q 020) = = 2 k z - (2 k d) q = 2 k (z - d q) = 2 k s 8
Fig. 13. 2 Examples of sequential division with integer and fractional operands. 9
Fractional Division
Unsigned Fractional Division zfrac Dividend . z-1 z-2. . . z-(2 k-1)z-2 k dfrac Divisor . d-1 d-2. . . d-(k-1) d-k qfrac Quotient . q-1 q-2. . . q-(k-1) q-k sfrac Remainder . 000… 0 s-(k+1). . . s-(2 k-1) s-2 k k bits 11
Integer vs. Fractional Division For Integers: z=qd+s 2 -2 k z 2 -2 k = (q 2 -k) (d 2 -k) + s (2 -2 k) For Fractions: zfrac = qfrac dfrac + sfrac where zfrac = z 2 -2 k dfrac = d 2 -k qfrac = q 2 -k sfrac = s 2 -2 k 12
Unsigned Fractional Division Overflow Condition for no overflow: zfrac < dfrac 13
Sequential Fractional Division Basic Equations s(0) = zfrac s(j) = 2 s(j-1) - q-j dfrac for j=1. . k 2 k · sfrac = s(k) sfrac = 2 -k · s(k) 14
Sequential Fractional Division Justification 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 = = 2 k zfrac - dfrac (q-1 2 k-1 + q-2 2 k-2 + q-3 2 k-3 + … + q-k 20) = = 2 k zfrac - dfrac 2 k (q-1 2 -1 + q-2 2 -2 + q-3 2 -3 + … + q-k 2 -k) = = 2 k zfrac - (2 k dfrac) qfrac = 2 k (zfrac - dfrac qfrac) = 2 k sfrac 15
Restoring Unsigned Integer Division
Restoring Unsigned Integer Division s(0) = z for j = 1 to k if 2 s(j-1) - 2 k d > 0 qk-j = 1 s(j) = 2 s(j-1) - 2 k d else qk-j = 0 s(j) = 2 s(j-1) end for 17
Fig. 13. 6 Example of restoring unsigned division. 18
Fig. 13. 5 Shift/subtract sequential restoring divider . 19
Non-Restoring Unsigned Integer Division
Non-Restoring Unsigned Integer Division s(0) = z s(1) = 2 s(0) - 2 k d for j = 2 to k if s(j-1) 0 qk-(j-1) = 1 s(j) = 2 s(j-1) - 2 k d else qk-(j-1) = 0 s(j) = 2 s(j-1) + 2 k d end for if s(k) 0 q 0 = 1 else q 0 = 0 Correction step
Non-Restoring Unsigned Integer Division Correction step s = 2 -k · s(k) z=qd+s z, q, d ≥ 0 s<0 z = (q-1) d + (s+d) z = q’ d + s’ 22
Example of nonrestoring unsigned division 23
Partial remainder variations for restoring and nonrestoring division 24
Non-Restoring Unsigned Integer Division Justification s(j-1) ≥ 0 2 s(j-1) - 2 k d < 0 2 (2 s(j-1) ) - 2 k d Restoring division ≥ 0 Non-Restoring division s(j) = 2 s(j-1) - 2 k d s(j+1) = 2 s(j) - 2 k d = = 4 s(j-1) - 2 k d s(j+1) = 2 s(j) + 2 k d = = 2 (2 s(j-1) - 2 k d) + 2 k d = = 4 s(j-1) - 2 k d 25
Convergence of the Partial Quotient to q 1111 Partial quotient 1110 1101 Example 1100 (0 1 1 1 0 1)two / (1 0 1 0)two (117)ten/(10)ten = (11)ten = (1011)two q(2) Nonrestoring 1011 1010 q q(3) 1001 Restoring 1000 q(1) 0111 In restoring division, the partial quotient converges to q from below q(4) q(2) 0110 0101 0100 In nonrestoring division, the partial quotient may overshoot q, but converges to it after some oscillations May 2012 0011 0010 0001 0000 0 q(0) Computer Arithmetic, Division Iteration 1 2 3 4 Slide 26
Signed Integer Division
Signed Integer Division z |z| |d| sign(z) Unsigned division |q| d sign(d) sign(s) = sign(z) + sign(z) = sign(d) sign(q) = - sign(z) sign(d) |s| q s 28
Examples of Signed Integer Division 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 29
Non-Restoring Signed Integer Division
Non-Restoring Signed Integer Division s(0) = z for j = 1 to k if sign(s(j-1)) == sign(d) qk-j = 1 s(j) = 2 s(j-1) - 2 k d = 2 s(j-1) - qk-j (2 k d) else qk-j = -1 s(j) = 2 s(j-1) + 2 k d = 2 s(j-1) - qk-j (2 k d) end for q = BSD_2’s_comp_conversion(q) Correction_step 31
Non-Restoring Signed Integer Division Correction step s = 2 -k · s(k) z=qd+s sign(s) = sign(z) z = (q-1) d + (s+d) z = q’ d + s’ z = (q+1) d + (s-d) z = q” d + s” 32
Example of nonrestoring signed division ============ z 0010 0001 24 d 1 1001 4 – 2 d 0 0111 ============ s(0) 0 0010 0001 2 s(0) 0 0 1 sign(s(0)) sign(d), +24 d 1 1001 so set q 3 = -1 and add –––––––––––– s(1) 1 1101 001 (1) 2 s 1 1010 01 sign(s(1)) = sign(d), +(– 24 d) 0 0111 so set q 2 = 1 and subtract –––––––––––– s(2) 0 0001 01 2 s(2) 0 0010 1 sign(s(2)) sign(d), +24 d 1 1001 so set q 1 = -1 and add –––––––––––– s(3) 1 1011 1 (3) 2 s 1 0111 sign(s(3)) = sign(d), +(– 24 d) 0 0111 so set q 0 = 1 and subtract –––––––––––– s(4) 1 1110 sign(s(4)) sign(z), +(– 24 d) 0 0111 so perform corrective subtraction –––––––––––– s(4) 0 0101 p= 0 1 Shift, compl MSB s 0101 1 1 0 1 1 Add 1 to correct q 1 1 -1 1 0 0 Check: 33/(-7) = -4 ============ 33
BSD 2’s Complement Conversion q = (qk-1 qk-2. . . q 1 q 0)BSD = = (pk-1 pk-2. . . p 1 p 0 1)2’s complement where qi -1 1 pi 0 1 Example: q. BSD p q 2’scomp no overflow if pk-2 = pk-1 1 1 1 011 00111 =0111 (qk-1 qk-2) 34
Nonrestoring Hardware Divider May 2012 Computer Arithmetic, Division Slide 35
Multiply/Divide Unit 36
Multiply-Divide Unit The control unit proceeds through necessary steps for multiplication or division (including using the appropriate shift direction) The slight speed penalty owing to a more complex control unit is insignificant Fig. 15. 9 Sequential radix-2 multiply/divide unit. 37
- Slides: 37