1 / 40

Exponentiation and Division

Lecture 9. Exponentiation and Division. Modular Multiplication. Special Cases. k bits. a. a. a x. = p = p H 2 k + p L. x. x. p L. p H. p. a x mod 2 k = p L. a x mod 2 k -1 = p L + p H + carry. a x mod 2 k +1 = p L - p H - borrow. Modular Multiplication.

Télécharger la présentation

Exponentiation and Division

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 9 Exponentiation and Division

  2. Modular Multiplication Special Cases k bits a a a x = p = pH 2k + pL x x pL pH p a x mod 2k = pL a x mod 2k-1 = pL + pH + carry a x mod 2k+1 = pL - pH - borrow

  3. Modular Multiplication Special Case (1) a x mod 2k-1 = (pH 2k + pL) mod (2k-1) = = (pH (2k mod 2k-1) + pL) mod (2k-1) = = pH + pL mod (2k-1) = = pH + pL if pH + pL < 2k - 1 pH + pL -(2k-1)if pH + pL 2k - 1 pL + pH + carry = carry = carry from addition pL + pH

  4. Fig. 12.15 Design of a 4 ´ 4 modulo-15 multiplier.

  5. Fig. 12.16 One way to design of a 4 ´ 4 modulo-13 multiplier.

  6. Exponentiation: Y = XE mod N Right-to-left binary exponentiation Left-to-right binary exponentiation E = (eL-1, eL-2, …, e1, e0)2 Y = 1; S = X; for i=0 to L-1 { if (ei == 1) Y = Y  S mod N; S = S2 mod N; } Y = 1; for i=L-1 downto 0 { Y = Y2 mod N; if (ei == 1) Y = Y  X mod N; }

  7. Exponentiation Example: Y = 712 mod 11 Right-to-left binary exponentiation Left-to-right binary exponentiation 12 = (1 1 0 0)2 i3 2 1 0 ei 1 1 0 0 Y 1 7 2 4 5 i 0 1 2 3 ei 0 0 1 1 Sbefore 7 5 3 9 Yafter 1 1 1 3 5 Safter 7 5 3 9 4 Sbefore - S before round i is computed Safter - S after round i is computed

  8. Right-to-Left Binary Exponentiation in Hardware X 1 enable S Y E SQR MUL output

  9. Left-to-Right Binary Exponentiation in Hardware 1 Y X Control Logic E MUL output

  10. 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)

  11. Basic Equations of Division z = d q + s | s | < | d | sign(s) = sign(z) z > 0 0  s < | d | z < 0 - | d | < s  0

  12. Unsigned Integer Division Overflow Condition for no overflow: z = q d + s < (2k-1) d + d = d 2k z = zH 2k + zL < d 2k zH < d

  13. Sequential Integer Division Basic Equations s(0) = z s(j) = 2 s(j-1) - qk-j (2k d) s(k) = 2k s

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

  15. Sequential Integer Division Justification 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

  16. 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-2k k bits

  17. Integer vs. Fractional Division For Integers: z = q d + s  2-2k z 2-2k = (q 2-k) (d 2-k) + s (2-2k) For Fractions: zfrac = qfrac dfrac + sfrac where zfrac = z 2-2k dfrac = d 2-k qfrac = q 2-k sfrac = s 2-2k

  18. Unsigned Fractional Division Overflow Condition for no overflow: zfrac < dfrac

  19. Sequential Fractional Division Basic Equations sfrac(0) = zfrac s(j) = 2 s(j-1) - q-j dfrac s(k)frac= 2k sfrac

  20. 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 = = 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

  21. 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) - qk-j (2k d) else qk-j = 0 s(j) = 2 s(j-1)

  22. Fig. 13.5 Shift/subtract sequential restoring divider.

  23. Fig. 13.6 Example of restoring unsigned division.

  24. Restoring Signed Integer Division 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

  25. Non-Restoring Unsigned Integer Division s(0) = z qk = 1 for j = 1 to k if qk-(j-1) = 1 s(j) = 2 s(j-1) - 2k d else s(j) = 2 s(j-1) + 2k d if s(j) > 0 qk-j = 1 else qk-j = 0 if s(k) < 0 s(k) = s(k) + 2k d

  26. Non-Restoring Unsigned Integer Division Justification Restoring division Non-Restoring division 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

  27. Fig. 13.7 Example of nonrestoring unsigned division.

  28. Fig. 13.8 Partial remainder variations for restoring andnonrestoring division.

  29. Fig. 13.10 Shift-subtract sequential nonrestoring divider.

  30. 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) - 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) Correction_step q = BSD_2’s_comp_conversion(q);

  31. Fig. 13.9 Example of nonrestoring signed division.

  32. 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”

  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 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 pk-2 = pk-1 (qk-1 qk-2)

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

  35. 1 2 Using Carry-Save Adders with the Dividers sum = u = u1u0.u-1u-2u-3u-4….u-k carry = v = v1v0.v-1v-2v-3v-4….v-k t = u1u0.u-1u-2 + v1v0.v-1v-2 u + v - t = 00.00u-3u-4….u-k + 00.00v-3v-4….v-k < 0 

  36. 1 1 1 1 1 2 2 2 2 2 Using Carry-Save Adders with the Dividers - 0 t - t < -  t < 0 t  0 -  u+v < u+v  0 u+v < 0 q-j = -1 q-j = 0 q-j = 1

  37. Classification of Dividers Array Dividers Dividers by Convergence Sequential Radix-2 High-radix • Restoring • Non-restoring • regular • SRT • using carry save adders • SRT using carry save adders

  38. Fig. 15.7 Restoring array divider composed of controlledsubtractor cells.

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

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

More Related