-
Notifications
You must be signed in to change notification settings - Fork 246
libm: implement accelerated computation of (x << e) % y
#1012
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
base: master
Are you sure you want to change the base?
Conversation
libm/src/math/support/int_traits.rs
Outdated
+ core::ops::Add<Output = Self> | ||
+ core::ops::Sub<Output = Self> | ||
+ core::ops::Shl<u32, Output = Self> | ||
+ core::ops::Shr<u32, Output = Self> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core::ops
-> ops
since it's already in scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this commit should be able to allow the #[allow(dead_code)]
on NarrowingDiv
use crate::support::int_traits::NarrowingDiv; | ||
use crate::support::{DInt, HInt, Int}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a module-level doc comment with some of the common names used here? E.g. R
, RR
(if that's not R*R
) r
, m
, q
, xq
. I'm unfortunately a bit lost :) (but I don't need to understand it in detail)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you've authored this, add /* SPDX-License-Identifier: MIT OR Apache-2.0 */
as well (or only MIT if it's derived, as appropriate)
} | ||
|
||
#[cfg(test)] | ||
mod test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this spot check another integer size as well? Just using constants
d78b5da
to
c69e44a
Compare
I've now rebased and applied the previous feedback.
To make the module easier to follow, I moved the public interface, |
// The partial remainder is in `[0, 2y)` ... | ||
let r = m.partial_remainder(); | ||
// ... so check and correct, and compensate for the earlier shift. | ||
r.checked_sub(y).unwrap_or(r) >> s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That minor tweak:
Previously the right shift was done first, and then the checked_sub
was with the original y
. Now that's done first with the left-shifted y
, and the shift is last.
Builds on #1011, both were split from #1002
The computation is implemented in
linear_mul_reduction
.