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

Function leading_zeros_u32_soft

ctutils/src/primitives.rs:271–283  ·  view source on GitHub ↗
(mut value: u32)

Source from the content-addressed store, hash-verified

269#[inline]
270#[allow(clippy::arithmetic_side_effects, reason = "shift is between 1 and 16")]
271const fn leading_zeros_u32_soft(mut value: u32) -> u32 {
272 let mut count = 0u32;
273 let mut shift = 16;
274 while shift != 0 {
275 let mask = Choice::from_u32_nz(value >> (u32::BITS - shift))
276 .not()
277 .to_u32_mask();
278 value ^= mask & (value ^ (value << shift));
279 count = count.wrapping_add(mask & shift);
280 shift >>= 1;
281 }
282 count.wrapping_add(Choice::from_u32_nz(value).not().to_u32_mask() & 1)
283}
284
285/// Add two integers, returning the wrapping sum and [`Choice::TRUE`] on overflow.
286#[inline]

Callers 2

leading_zeros_u32Function · 0.85
trailing_zeros_u32Function · 0.85

Calls 3

from_u32_nzFunction · 0.85
to_u32_maskMethod · 0.80
notMethod · 0.80

Tested by

no test coverage detected