faster multiprecision integer division
play

Faster multiprecision integer division William Hart June 22, 2015 - PowerPoint PPT Presentation

Outline Multiprecision integer division Faster multiprecision integer division William Hart June 22, 2015 William Hart Faster multiprecision integer division Outline Multiprecision integer division Multiprecision integer division William


  1. Outline Multiprecision integer division Faster multiprecision integer division William Hart June 22, 2015 William Hart Faster multiprecision integer division

  2. Outline Multiprecision integer division Multiprecision integer division William Hart Faster multiprecision integer division

  3. Outline Multiprecision integer division Multiprecision integer division • Given: • A = < a m − 1 , a m − 2 , a m − 3 , . . . , a 1 , a 0 > • D = < d n − 1 , . . . , d 1 , d 0 > William Hart Faster multiprecision integer division

  4. Outline Multiprecision integer division Multiprecision integer division • Given: • A = < a m − 1 , a m − 2 , a m − 3 , . . . , a 1 , a 0 > • D = < d n − 1 , . . . , d 1 , d 0 > • Compute: • Approximate quotient Q ⋆ William Hart Faster multiprecision integer division

  5. Outline Multiprecision integer division Multiprecision integer division • Given: • A = < a m − 1 , a m − 2 , a m − 3 , . . . , a 1 , a 0 > • D = < d n − 1 , . . . , d 1 , d 0 > • Compute: • Approximate quotient Q ⋆ • Exact quotient Q William Hart Faster multiprecision integer division

  6. Outline Multiprecision integer division Multiprecision integer division • Given: • A = < a m − 1 , a m − 2 , a m − 3 , . . . , a 1 , a 0 > • D = < d n − 1 , . . . , d 1 , d 0 > • Compute: • Approximate quotient Q ⋆ • Exact quotient Q • Quotient Q and remainder R William Hart Faster multiprecision integer division

  7. Outline Multiprecision integer division Machine primitive • Machine does 2 × 1 division William Hart Faster multiprecision integer division

  8. Outline Multiprecision integer division Machine primitive • Machine does 2 × 1 division • < u 1 , u 0 > by < v 0 > , quotient and remainder both 1 limb William Hart Faster multiprecision integer division

  9. Outline Multiprecision integer division Machine primitive • Machine does 2 × 1 division • < u 1 , u 0 > by < v 0 > , quotient and remainder both 1 limb • Require v 0 normalised William Hart Faster multiprecision integer division

  10. Outline Multiprecision integer division Machine primitive • Machine does 2 × 1 division • < u 1 , u 0 > by < v 0 > , quotient and remainder both 1 limb • Require v 0 normalised • If B = 2 32 or 2 64 then B < v 0 ≤ B / 2 William Hart Faster multiprecision integer division

  11. Outline Multiprecision integer division Machine primitive • Machine does 2 × 1 division • < u 1 , u 0 > by < v 0 > , quotient and remainder both 1 limb • Require v 0 normalised • If B = 2 32 or 2 64 then B < v 0 ≤ B / 2 • Also require u 1 < v 0 William Hart Faster multiprecision integer division

  12. Outline Multiprecision integer division Schoolbook algorithm • Shift A and D left so that D is normalised William Hart Faster multiprecision integer division

  13. Outline Multiprecision integer division Schoolbook algorithm • Shift A and D left so that D is normalised • Ensure top n limbs of A are less than D William Hart Faster multiprecision integer division

  14. Outline Multiprecision integer division Schoolbook algorithm • Shift A and D left so that D is normalised • Ensure top n limbs of A are less than D • i ← m − n + 1 • while i ≥ 0 • q i ← quotient of < a n + i , a n + i − 1 > by < d n − 1 > • A ← A − q i DB i • i ← i − 1 William Hart Faster multiprecision integer division

  15. Outline Multiprecision integer division Schoolbook algorithm • Shift A and D left so that D is normalised • Ensure top n limbs of A are less than D • i ← m − n + 1 • while i ≥ 0 • q i ← quotient of < a n + i , a n + i − 1 > by < d n − 1 > • A ← A − q i DB i • i ← i − 1 • Shift remainder right William Hart Faster multiprecision integer division

  16. Outline Multiprecision integer division Problems • May have < a n + i , a n + i − 1 > ≥ d n − 1 B William Hart Faster multiprecision integer division

  17. Outline Multiprecision integer division Problems • May have < a n + i , a n + i − 1 > ≥ d n − 1 B • q i D may be too large William Hart Faster multiprecision integer division

  18. Outline Multiprecision integer division Problems • May have < a n + i , a n + i − 1 > ≥ d n − 1 B • q i D may be too large • Need tests and adjustments for both cases William Hart Faster multiprecision integer division

  19. Outline Multiprecision integer division Standard improvement No. 1 • Multiply by precomputed inverse ν of d n − 1 instead of division William Hart Faster multiprecision integer division

  20. Outline Multiprecision integer division Standard improvement No. 1 • Multiply by precomputed inverse ν of d n − 1 instead of division • 1986 Barret used B 2 n / d William Hart Faster multiprecision integer division

  21. Outline Multiprecision integer division Standard improvement No. 1 • Multiply by precomputed inverse ν of d n − 1 instead of division • 1986 Barret used B 2 n / d • 1986 Beame, Cook, Hoover suggested using an under approximation of the inverse William Hart Faster multiprecision integer division

  22. Outline Multiprecision integer division Standard improvement No. 1 • Multiply by precomputed inverse ν of d n − 1 instead of division • 1986 Barret used B 2 n / d • 1986 Beame, Cook, Hoover suggested using an under approximation of the inverse • 1951 Wallace, diode transistor circuits William Hart Faster multiprecision integer division

  23. Outline Multiprecision integer division Standard improvement No. 1 • Multiply by precomputed inverse ν of d n − 1 instead of division • 1986 Barret used B 2 n / d • 1986 Beame, Cook, Hoover suggested using an under approximation of the inverse • 1951 Wallace, diode transistor circuits • 2000 BC, Babylonian “Clay tablet” PC’s William Hart Faster multiprecision integer division

  24. Outline Multiprecision integer division Precomputed inverses • 1994, Granlund, Montgomery suggested ν = ⌊ ( B 2 − 1 ) / d n − 1 ⌋ − B William Hart Faster multiprecision integer division

  25. Outline Multiprecision integer division Precomputed inverses • 1994, Granlund, Montgomery suggested ν = ⌊ ( B 2 − 1 ) / d n − 1 ⌋ − B • One mulhigh, one mul William Hart Faster multiprecision integer division

  26. Outline Multiprecision integer division Precomputed inverses • 1994, Granlund, Montgomery suggested ν = ⌊ ( B 2 − 1 ) / d n − 1 ⌋ − B • One mulhigh, one mul • At most 3 correction steps for 2 × 1 division William Hart Faster multiprecision integer division

  27. Outline Multiprecision integer division Precomputed inverses • 1994, Granlund, Montgomery suggested ν = ⌊ ( B 2 − 1 ) / d n − 1 ⌋ − B • One mulhigh, one mul • At most 3 correction steps for 2 × 1 division Additional problem: • Quotient limb may now be too small or too large!! William Hart Faster multiprecision integer division

  28. Outline Multiprecision integer division M¨ oller-Granlund (2011) • Same precomputed inverse William Hart Faster multiprecision integer division

  29. Outline Multiprecision integer division M¨ oller-Granlund (2011) • Same precomputed inverse • Algorithm improved to one mul, one mullow William Hart Faster multiprecision integer division

  30. Outline Multiprecision integer division M¨ oller-Granlund (2011) • Same precomputed inverse • Algorithm improved to one mul, one mullow • One correction with unpredicted branch William Hart Faster multiprecision integer division

  31. Outline Multiprecision integer division M¨ oller-Granlund (2011) • Same precomputed inverse • Algorithm improved to one mul, one mullow • One correction with unpredicted branch • One very unlikely correction William Hart Faster multiprecision integer division

  32. Outline Multiprecision integer division Improvement No. 2 Problem : multiprecision corrections very expensive William Hart Faster multiprecision integer division

  33. Outline Multiprecision integer division Improvement No. 2 Problem : multiprecision corrections very expensive • Idea : use 3 × 2 divisions to reduce probability of MP-correction William Hart Faster multiprecision integer division

  34. Outline Multiprecision integer division Improvement No. 2 Problem : multiprecision corrections very expensive • Idea : use 3 × 2 divisions to reduce probability of MP-correction • M¨ oller-Granlund give 3 × 2 version of their algorithm William Hart Faster multiprecision integer division

  35. Outline Multiprecision integer division Our precomputed inverse • Use ν = ⌊ B 2 / ( d n − 1 + 1 ) ⌋ − B William Hart Faster multiprecision integer division

  36. Outline Multiprecision integer division Our precomputed inverse • Use ν = ⌊ B 2 / ( d n − 1 + 1 ) ⌋ − B • Because we used d n − 1 + 1, quotient is never too large William Hart Faster multiprecision integer division

  37. Outline Multiprecision integer division Our precomputed inverse • Use ν = ⌊ B 2 / ( d n − 1 + 1 ) ⌋ − B • Because we used d n − 1 + 1, quotient is never too large • Approximate quotient can be done with no corrections William Hart Faster multiprecision integer division

Recommend


More recommend