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, NonRestoring and Signed Division.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Basic Dividers
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, NonRestoring and Signed Division
z Dividend z2k1z2k2 . . . z2 z1 z0
d Divisor dk1dk2 . . . d1 d0
q Quotient qk1qk2 . . . q1 q0
s Remainder sk1sk2 . . . s1 s0
(s = z  dq)
z = d q + s
 s  <  d 
sign(s) = sign(z)
z > 0
0 s <  d 
z < 0
  d  < s 0
Unsigned Integer Division Overflow
Condition for no overflow (i.e. q fits in k bits):
z = q d + s < (2k1) d + d = d 2k
z = zH 2k + zL < d 2k
zH < d
Basic Equations
s(0) = z
s(j) = 2 s(j1)  qkj (2k d) for j=1..k
s(k) = 2k s
Justification
s(1) = 2 z  qk1 (2k d)
s(2) = 2(2 z  qk1 (2k d))  qk2 (2k d)
s(3) = 2(2(2 z  qk1 (2k d))  qk2 (2k d))  qk3 (2k d)
. . . . . .
s(k) = 2(. . . 2(2(2 z  qk1 (2k d))  qk2 (2k d))  qk3 (2k d) . . .
 q0 (2k d) =
= 2k z  (2k d) (qk1 2k1 + qk2 2k2 + qk3 2k3 + … + q020) =
= 2k z  (2k d) q = 2k (z  d q) = 2k s
zfrac Dividend .z1z2 . . . z(2k1)z2k
dfrac Divisor .d1d2 . . . d(k1) dk
qfrac Quotient .q1q2 . . . q(k1) qk
sfrac Remainder .000…0s(k+1) . . . s(2k1) s2k
k bits
Integer vs. Fractional Division
For Integers:
z = q d + s
22k
z 22k = (q 2k) (d 2k) + s (22k)
For Fractions:
zfrac = qfrac dfrac + sfrac
where
zfrac = z 22k
dfrac = d 2k
qfrac = q 2k
sfrac = s 22k
Sequential Fractional Division
Basic Equations
s(0) = zfrac
s(j) = 2 s(j1)  qj dfrac for j=1..k
2k · sfrac = s(k)
sfrac = 2k · s(k)
Sequential Fractional Division
Justification
s(1) = 2 zfrac  q1 dfrac
s(2) = 2(2 zfrac  q1 dfrac)  q2 dfrac
s(3) = 2(2(2 zfrac  q1 dfrac)  q2 dfrac)  q3 dfrac
. . . . . .
s(k) = 2(. . . 2(2(2 zfrac  q1 dfrac)  q2 dfrac)  q3 dfrac . . .
 qk dfrac =
= 2k zfrac  dfrac (q1 2k1 + q2 2k2 + q3 2k3 + … + qk20) =
= 2k zfrac  dfrac 2k (q1 21 + q2 22 + q3 23 + … + qk2k) =
= 2k zfrac  (2k dfrac) qfrac = 2k (zfrac  dfrac qfrac) = 2k sfrac
Restoring Unsigned Integer Division
s(0) = z
for j = 1 to k
if 2 s(j1)  2k d > 0
qkj = 1
s(j) = 2 s(j1)  2k d
else
qkj = 0
s(j) = 2 s(j1)
NonRestoring Unsigned Integer Division
s(1) = 2 z  2k d
for j = 2 to k
if s(j1) 0
qk(j1) = 1
s(j) = 2 s(j1)  2k d
else
qk(j1) = 0
s(j) = 2 s(j1) + 2k d
end for
if s(k) 0
q0 = 1
else
q0 = 0
Correction step
NonRestoring Unsigned Integer Division
Correction step
s = 2k · s(k)
z = q d + s
z, q, d ≥ 0 s<0
z = (q1) d + (s+d)
z = q’ d + s’
NonRestoring Unsigned Integer Division
Justification
s(j1) ≥ 0
2 s(j1)  2k d < 0
2 (2 s(j1) ) 2k d ≥ 0
Restoring division
NonRestoring division
s(j) = 2 s(j1)
s(j+1) = 2 s(j)  2k d =
= 4 s(j1)  2k d
s(j) = 2 s(j1)  2k d
s(j+1) = 2 s(j) + 2k d =
= 2 (2 s(j1)  2k d)+ 2k d =
= 4 s(j1)  2k d
z
d
 z 
 d 
sign(z)
sign(d)
Unsigned
division
sign(s) = sign(z)
sign(z) = sign(d)
+
 q 
 s 
sign(q) =

sign(z) sign(d)
q
s
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
NonRestoring Signed Integer Division
s(0) = z
for j = 1 to k
if sign(s(j1)) == sign(d)
qkj = 1
s(j) = 2 s(j1)  2k d = 2 s(j1)  qkj (2k d)
else
qkj = 1
s(j) = 2 s(j1) + 2k d = 2 s(j1)  qkj (2k d)
q = BSD_2’s_comp_conversion(q)
Correction_step
NonRestoring Signed Integer Division
Correction step
s = 2k · s(k)
z = q d + s
sign(s) = sign(z)
z = (q1) d + (s+d)
z = q’ d + s’
z = (q+1) d + (sd)
z = q” d + s”
z 0 0 1 0 0 0 0 1
24d 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
q1 11 1 ========================
Fig. 13.9 Example of nonrestoring signed division.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
BSD 2’s Complement Conversion
q = (qk1 qk2 . . . q1 q0)BSD =
= (pk1 pk2 . . . p1 p0 1)2’s complement
where
Example:
qBSD
1 1 1 1
qi
pi
p
1
0
1 0 1 1
1
1
q2’scomp
0 0 1 1 1 = 0 1 1 1
no overflow if pk2 = pk1 (qk1 qk2)
Fast Dividers
Array
Dividers
Dividers
by Convergence
Sequential
Radix2
Highradix
Dividers
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
Fig. 14.15 Block diagram of radixr divider with partial remainder in storedcarry form.
October 1994
Thomas Nicely, Lynchburg Collage, Virginia
finds an error in his computer calculations, and traces
it back to the Pentium processor
November 7, 1994
First press announcement, Electronic Engineering Times
Late 1994
Tim Coe, Vitesse Semiconductor
presents an example with the worstcase error
c = 4 195 835/3 145 727
Pentium = 1.333 739 06...
Correct result = 1.333 820 44...
Intel admits “subtle flaw”
November 30, 1994
Intel’s white paper about the bug and its possible consequences
Intel  average spreadsheet user affected once in 27,000 years
IBM  average spreadsheet user affected once every 24 days
Replacements based on customer needs
December 20, 1994
Announcement of noquestionasked replacements
Error traced back to the lookup table used by
the radix4 SRT division algorithm
2048 cells, 1066 nonzero values {2, 1, 1, 2}
5 nonzero values not downloaded correctly
to the lookup table due to an error in the C script
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 radix2 multiply/divide unit.
u =
= 1.000 677 131
v = 21/1024 = 1.000 677 131
10 times
y = (((v2)2)…)2 = 1.999 999 983
x = (((u2)2)…)2 = 1.999 999 963
10 times
10 times
x’ = u1024 = 1.999 999 973
y’ = v1024 = 1.999 999 994
Hidden digits in the internal representation of numbers
Different algorithms give slightly different results
Very good accuracy
Computer Arithmetic
ECE 645
ECE 646
Cryptography and
Computer Network Security
(Fall 2011)
ECE 746
Advanced Applied
Cryptography
(Spring 2012 or 2013)
ECE 899
Cryptographic Engineering
(Spring 2012)
Network Security
Advanced Applied
Cryptography
Operations in the Galois Fields GF(2n)
Modular integer arithmetic