1 2 3 4 5 6 7 8 9 10 11 12 13 14
//! This module implements intrinsics for counting trailing and leading zeros //! for 256-bit integers. use crate::U256; pub fn ctlz(a: &U256) -> u32 { let f = -((*a.high() == 0) as i128) as u128; ((a.high() & !f) | (a.low() & f)).leading_zeros() + ((f as u32) & 128) } pub fn cttz(a: &U256) -> u32 { let f = -((*a.low() == 0) as i128) as u128; ((a.high() & f) | (a.low() & !f)).trailing_zeros() + ((f as u32) & 128) }