Skip to content

mul.rs: use wrapping_mul to avoid infinite recursion #132

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
Jan 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/int/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ macro_rules! mul {
pub extern "C" fn $intrinsic(a: $ty, b: $ty) -> $ty {
let half_bits = <$ty>::bits() / 4;
let lower_mask = !0 >> half_bits;
let mut low = (a.low() & lower_mask) * (b.low() & lower_mask);
let mut low = (a.low() & lower_mask).wrapping_mul(b.low() & lower_mask);
let mut t = low >> half_bits;
low &= lower_mask;
t += (a.low() >> half_bits) * (b.low() & lower_mask);
t += (a.low() >> half_bits).wrapping_mul(b.low() & lower_mask);
low += (t & lower_mask) << half_bits;
let mut high = t >> half_bits;
t = low >> half_bits;
low &= lower_mask;
t += (b.low() >> half_bits) * (a.low() & lower_mask);
t += (b.low() >> half_bits).wrapping_mul(a.low() & lower_mask);
low += (t & lower_mask) << half_bits;
high += t >> half_bits;
high += (a.low() >> half_bits) * (b.low() >> half_bits);
high += (a.low() >> half_bits).wrapping_mul(b.low() >> half_bits);
high = high.wrapping_add(a.high().wrapping_mul(b.low()).wrapping_add(a.low().wrapping_mul(b.high())));
<$ty>::from_parts(low, high)
}
Expand Down