2019-01-03 09:50:11 +08:00
|
|
|
extern crate compiler_builtins;
|
|
|
|
|
|
|
|
use compiler_builtins::int::__clzsi2;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn __clzsi2_test() {
|
2019-05-15 05:33:08 +08:00
|
|
|
let mut i: usize = core::usize::MAX;
|
|
|
|
// Check all values above 0
|
|
|
|
while i > 0 {
|
|
|
|
assert_eq!(__clzsi2(i) as u32, i.leading_zeros());
|
|
|
|
i >>= 1;
|
|
|
|
}
|
|
|
|
// check 0 also
|
|
|
|
i = 0;
|
2019-01-03 09:50:11 +08:00
|
|
|
assert_eq!(__clzsi2(i) as u32, i.leading_zeros());
|
2019-05-15 05:33:08 +08:00
|
|
|
// double check for bit patterns that aren't just solid 1s
|
|
|
|
i = 1;
|
|
|
|
for _ in 0..63 {
|
|
|
|
assert_eq!(__clzsi2(i) as u32, i.leading_zeros());
|
|
|
|
i <<= 2;
|
|
|
|
i += 1;
|
|
|
|
}
|
2019-01-03 09:50:11 +08:00
|
|
|
}
|