Skip to content

Handle remainder as a wide word in div3by2 #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

andrewwhitehead
Copy link
Contributor

In regards comments on #646, this handles potential overflow in the remainder value.

@tarcieri tarcieri merged commit f5094eb into RustCrypto:master Aug 15, 2024
18 checks passed
// If r < b and q*y[-2] > r*x[-1], then set q = q - 1 and r = r + v1
let done = ConstChoice::from_word_nonzero((rem >> Word::BITS) as Word)
.or(ConstChoice::from_wide_word_le(qy, rx));
quo = done.select_word(quo.saturating_sub(1), quo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have wrapping_sub here, I'm not sure if saturating_sub is constant-time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spot checking it in Godbolt saturating_sub uses cmovae on x86 and csel on aarch64, which (for now, until the optimizer decides differently) seem pretty ideal

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.

3 participants