Skip to content

Update multiword division to better match GMP paper#1244

Open
andrewwhitehead wants to merge 3 commits intoRustCrypto:masterfrom
andrewwhitehead:feat/gmp-div3by2
Open

Update multiword division to better match GMP paper#1244
andrewwhitehead wants to merge 3 commits intoRustCrypto:masterfrom
andrewwhitehead:feat/gmp-div3by2

Conversation

@andrewwhitehead
Copy link
Copy Markdown
Contributor

This updates multiword division to align more with the primary source, "Improved Division by Invariant Integers" by Niels Möller and Torbjorn Granlund. An adjusted reciprocal is used in div3by2 and performance is improved by not relying on div2by1 in this method.

Sample benchmarks
wrapping ops/div/rem, U256/U128
                        time:   [58.734 ns 58.761 ns 58.791 ns]
                        change: [−16.101% −16.029% −15.957%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/div/rem, U256/U128 (in U256)
                        time:   [66.011 ns 66.237 ns 66.500 ns]
                        change: [−15.849% −15.668% −15.450%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/div/rem, U256/U128 (in U512)
                        time:   [69.467 ns 69.592 ns 69.767 ns]
                        change: [−15.059% −14.951% −14.830%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/div/rem_vartime, U256/U128, full size
                        time:   [50.480 ns 50.581 ns 50.730 ns]
                        change: [−21.055% −20.054% −19.285%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/div/rem, U256/Limb, full size
                        time:   [66.068 ns 66.137 ns 66.229 ns]
                        change: [−15.791% −15.482% −15.235%] (p = 0.00 < 0.05)
                        Performance has improved.

wrapping ops/mul_mod, U256
                        time:   [104.11 ns 104.23 ns 104.44 ns]
                        change: [−27.015% −26.924% −26.835%] (p = 0.00 < 0.05)
                        Performance has improved.
wrapping ops/mul_mod_vartime, U256
                        time:   [81.175 ns 81.268 ns 81.396 ns]
                        change: [−31.462% −31.182% −30.941%] (p = 0.00 < 0.05)
                        Performance has improved.

sqrt/floor_sqrt, U256   time:   [674.50 ns 675.67 ns 677.24 ns]
                        change: [−12.397% −12.140% −11.855%] (p = 0.00 < 0.05)
                        Performance has improved.
sqrt/floor_sqrt, U512   time:   [1.3456 µs 1.3469 µs 1.3484 µs]
                        change: [−20.870% −20.404% −20.060%] (p = 0.00 < 0.05)
                        Performance has improved.
sqrt/floor_sqrt_vartime, U256
                        time:   [385.17 ns 387.96 ns 392.49 ns]
                        change: [−15.005% −14.562% −13.995%] (p = 0.00 < 0.05)
                        Performance has improved.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.89%. Comparing base (4908ded) to head (1d6031f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1244      +/-   ##
==========================================
+ Coverage   90.87%   90.89%   +0.02%     
==========================================
  Files         186      186              
  Lines       21594    21646      +52     
==========================================
+ Hits        19623    19675      +52     
  Misses       1971     1971              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant