diff options
| author | Tobias Decking <Tobias.Decking@gmail.com> | 2025-02-01 23:44:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-01 23:44:52 +0100 |
| commit | 4f5116e236843492998acfa42381d14db360f2ab (patch) | |
| tree | 9daa686665374c4ad9181f2c1b4176c9cc041a2d | |
| parent | e08cd3cf05e5bfa3323cc21ea8f81f4a15a2f969 (diff) | |
| download | rust-4f5116e236843492998acfa42381d14db360f2ab.tar.gz rust-4f5116e236843492998acfa42381d14db360f2ab.zip | |
Use `widening_mul`
| -rw-r--r-- | library/core/src/fmt/num.rs | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index 683e45b35f7..fd548018dad 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -726,28 +726,9 @@ fn udiv_1e19(n: u128) -> (u128, u64) { let quot = if n < 1 << 83 { ((n >> 19) as u64 / (DIV >> 19)) as u128 } else { - u128_mulhi(n, FACTOR) >> 62 + n.widening_mul(FACTOR).1 >> 62 }; let rem = (n - quot * DIV as u128) as u64; (quot, rem) } - -/// Multiply unsigned 128 bit integers, return upper 128 bits of the result -#[inline] -fn u128_mulhi(x: u128, y: u128) -> u128 { - let x_lo = x as u64; - let x_hi = (x >> 64) as u64; - let y_lo = y as u64; - let y_hi = (y >> 64) as u64; - - // handle possibility of overflow - let carry = (x_lo as u128 * y_lo as u128) >> 64; - let m = x_lo as u128 * y_hi as u128 + carry; - let high1 = m >> 64; - - let m_lo = m as u64; - let high2 = (x_hi as u128 * y_lo as u128 + m_lo as u128) >> 64; - - x_hi as u128 * y_hi as u128 + high1 + high2 -} |
