Skip to content

Commit ee0aacf

Browse files
authored
mul.rs: use wrapping_mul not plain
rustc in debug mode with a plain multiplication will call @llvm.umul.with.overflow.* which may call the builtin resulting in infinite recursion.
1 parent 0fd5e75 commit ee0aacf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/int/mul.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ macro_rules! mul {
99
pub extern "C" fn $intrinsic(a: $ty, b: $ty) -> $ty {
1010
let half_bits = <$ty>::bits() / 4;
1111
let lower_mask = !0 >> half_bits;
12-
let mut low = (a.low() & lower_mask) * (b.low() & lower_mask);
12+
let mut low = (a.low() & lower_mask).wrapping_mul(b.low() & lower_mask);
1313
let mut t = low >> half_bits;
1414
low &= lower_mask;
15-
t += (a.low() >> half_bits) * (b.low() & lower_mask);
15+
t += (a.low() >> half_bits).wrapping_mul(b.low() & lower_mask);
1616
low += (t & lower_mask) << half_bits;
1717
let mut high = t >> half_bits;
1818
t = low >> half_bits;
1919
low &= lower_mask;
20-
t += (b.low() >> half_bits) * (a.low() & lower_mask);
20+
t += (b.low() >> half_bits).wrapping_mul(a.low() & lower_mask);
2121
low += (t & lower_mask) << half_bits;
2222
high += t >> half_bits;
23-
high += (a.low() >> half_bits) * (b.low() >> half_bits);
23+
high += (a.low() >> half_bits).wrapping_mul(b.low() >> half_bits);
2424
high = high.wrapping_add(a.high().wrapping_mul(b.low()).wrapping_add(a.low().wrapping_mul(b.high())));
2525
<$ty>::from_parts(low, high)
2626
}

0 commit comments

Comments
 (0)