MCPcopy Create free account
hub / github.com/RustCrypto/utils / overflowing_add_u128

Function overflowing_add_u128

ctutils/src/primitives.rs:297–308  ·  view source on GitHub ↗
(lhs: u128, rhs: u128)

Source from the content-addressed store, hash-verified

295#[inline]
296#[must_use]
297pub const fn overflowing_add_u128(lhs: u128, rhs: u128) -> (u128, Choice) {
298 #[cfg(target_arch = "riscv32")]
299 {
300 overflowing_add_u128_halves(lhs, rhs)
301 }
302 #[cfg(not(target_arch = "riscv32"))]
303 {
304 let sum = lhs.wrapping_add(rhs);
305 let carry = ((lhs & rhs) | ((lhs | rhs) & !sum)) >> (u128::BITS - 1);
306 (sum, Choice::from_u128_lsb(carry))
307 }
308}
309
310// RV32 can branch even in `u128::wrapping_add`, before computing the final carry.
311// Keep this workaround local to that target, preserving native addition elsewhere.

Callers

nothing calls this directly

Calls 2

from_u128_lsbFunction · 0.85

Tested by

no test coverage detected