Skip to content

Commit 2adde22

Browse files
TDeckinggitbot
authored and
gitbot
committed
Use widening_mul
1 parent 6dd1c87 commit 2adde22

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
@@ -733,28 +733,9 @@ fn udiv_1e19(n: u128) -> (u128, u64) {
733733
let quot = if n < 1 << 83 {
734734
((n >> 19) as u64 / (DIV >> 19)) as u128
735735
} else {
736-
u128_mulhi(n, FACTOR) >> 62
736+
n.widening_mul(FACTOR).1 >> 62
737737
};
738738

739739
let rem = (n - quot * DIV as u128) as u64;
740740
(quot, rem)
741741
}
742-
743-
/// Multiply unsigned 128 bit integers, return upper 128 bits of the result
744-
#[inline]
745-
fn u128_mulhi(x: u128, y: u128) -> u128 {
746-
let x_lo = x as u64;
747-
let x_hi = (x >> 64) as u64;
748-
let y_lo = y as u64;
749-
let y_hi = (y >> 64) as u64;
750-
751-
// handle possibility of overflow
752-
let carry = (x_lo as u128 * y_lo as u128) >> 64;
753-
let m = x_lo as u128 * y_hi as u128 + carry;
754-
let high1 = m >> 64;
755-
756-
let m_lo = m as u64;
757-
let high2 = (x_hi as u128 * y_lo as u128 + m_lo as u128) >> 64;
758-
759-
x_hi as u128 * y_hi as u128 + high1 + high2
760-
}

0 commit comments

Comments
 (0)