Skip to content

Commit e7e091f

Browse files
TDeckinggitbot
authored and
gitbot
committed
Use widening_mul
1 parent 5e3f612 commit e7e091f

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

core/src/fmt/num.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -726,28 +726,9 @@ fn udiv_1e19(n: u128) -> (u128, u64) {
726726
let quot = if n < 1 << 83 {
727727
((n >> 19) as u64 / (DIV >> 19)) as u128
728728
} else {
729-
u128_mulhi(n, FACTOR) >> 62
729+
n.widening_mul(FACTOR).1 >> 62
730730
};
731731

732732
let rem = (n - quot * DIV as u128) as u64;
733733
(quot, rem)
734734
}
735-
736-
/// Multiply unsigned 128 bit integers, return upper 128 bits of the result
737-
#[inline]
738-
fn u128_mulhi(x: u128, y: u128) -> u128 {
739-
let x_lo = x as u64;
740-
let x_hi = (x >> 64) as u64;
741-
let y_lo = y as u64;
742-
let y_hi = (y >> 64) as u64;
743-
744-
// handle possibility of overflow
745-
let carry = (x_lo as u128 * y_lo as u128) >> 64;
746-
let m = x_lo as u128 * y_hi as u128 + carry;
747-
let high1 = m >> 64;
748-
749-
let m_lo = m as u64;
750-
let high2 = (x_hi as u128 * y_lo as u128 + m_lo as u128) >> 64;
751-
752-
x_hi as u128 * y_hi as u128 + high1 + high2
753-
}

0 commit comments

Comments
 (0)