Skip to content

Add support for exact division#1256

Open
andrewwhitehead wants to merge 4 commits intoRustCrypto:masterfrom
andrewwhitehead:feat/div-exact
Open

Add support for exact division#1256
andrewwhitehead wants to merge 4 commits intoRustCrypto:masterfrom
andrewwhitehead:feat/div-exact

Conversation

@andrewwhitehead
Copy link
Copy Markdown
Contributor

@andrewwhitehead andrewwhitehead commented Apr 27, 2026

This adds div_exact and div_exact_vartime methods for Uint, BoxedUint, and Limb. There is currently no trait support.

For cases where it applies, exact division can be much faster than div/rem. In my tests this is about 40% faster for a 4096-bit BoxedUint.

The algorithm is similar to DivideByWord in Modern Computer Arithmetic but I don't have a reference for the adjustments to support a multi-word divisor.

Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 99.34211% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.91%. Comparing base (aa41fdb) to head (eecaff2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/uint/ref_type/div.rs 98.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1256      +/-   ##
==========================================
+ Coverage   90.84%   90.91%   +0.07%     
==========================================
  Files         186      186              
  Lines       21673    21823     +150     
==========================================
+ Hits        19688    19841     +153     
+ Misses       1985     1982       -3     

☔ 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>
@andrewwhitehead
Copy link
Copy Markdown
Contributor Author

andrewwhitehead commented Apr 27, 2026

Oops, I need to add a 32-bit version of the limb inversion. I have a fix but it depends on #1257 which is a separate issue.

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