| 1 | // https://doc.rust-lang.org/std/primitive.u16.html#method.leading_zeros |
| 2 | |
| 3 | #[cfg(not(any(all( |
| 4 | target_arch = "spirv", |
| 5 | not(all( |
| 6 | target_feature = "IntegerFunctions2INTEL", |
| 7 | target_feature = "SPV_INTEL_shader_integer_functions2" |
| 8 | )) |
| 9 | ))))] |
| 10 | #[inline] |
| 11 | pub(craterust-analyzer cargo half 2.7.1 crate/) const fn leading_zeros_u16rust-analyzer cargo half 2.7.1 leading_zeros/leading_zeros_u16().(x: u16) -> u32 { |
| 12 | x.leading_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]leading_zeros().() |
| 13 | } |
| 14 | |
| 15 | #[cfg(all( |
| 16 | target_arch = "spirv", |
| 17 | not(all( |
| 18 | target_feature = "IntegerFunctions2INTEL", |
| 19 | target_feature = "SPV_INTEL_shader_integer_functions2" |
| 20 | )) |
| 21 | ))] |
| 22 | #[inline] |
| 23 | pub(craterust-analyzer cargo half 2.7.1 crate/) const fn leading_zeros_u16(x: u16) -> u32 { |
| 24 | leading_zeros_u16_fallbackrust-analyzer cargo half 2.7.1 leading_zeros/leading_zeros_u16_fallback().(x) |
| 25 | } |
| 26 | |
| 27 | #[cfg(any( |
| 28 | test, |
| 29 | all( |
| 30 | target_arch = "spirv", |
| 31 | not(all( |
| 32 | target_feature = "IntegerFunctions2INTEL", |
| 33 | target_feature = "SPV_INTEL_shader_integer_functions2" |
| 34 | )) |
| 35 | ) |
| 36 | ))] |
| 37 | #[inline] |
| 38 | const fn leading_zeros_u16_fallbackrust-analyzer cargo half 2.7.1 leading_zeros/leading_zeros_u16_fallback().(mut x: u16) -> u32 { |
| 39 | use crunchyrust-analyzer cargo crunchy 0.2.3 crate/::unrollrust-analyzer cargo crunchy 0.2.3 unroll!; |
| 40 | let mut c = 0; |
| 41 | let msb = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().15; |
| 42 | unrollrust-analyzer cargo crunchy 0.2.3 unroll!! { for irust-analyzer cargo half 2.7.1 leading_zeros/i. in 0 .. 16 { |
| 43 | if x &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). msb == 0 { |
| 44 | c += 1; |
| 45 | } else { |
| 46 | return c; |
| 47 | } |
| 48 | #[allow(unused_assignments)] |
| 49 | if irust-analyzer cargo half 2.7.1 leading_zeros/i. <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). 15 { |
| 50 | x <<= 1; |
| 51 | } |
| 52 | }} |
| 53 | c |
| 54 | } |
| 55 | |
| 56 | #[cfg(test)] |
| 57 | mod testrust-analyzer cargo half 2.7.1 leading_zeros/test/ { |
| 58 | |
| 59 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 60 | fn leading_zeros_u16_fallbackrust-analyzer cargo half 2.7.1 leading_zeros/test/leading_zeros_u16_fallback().() { |
| 61 | for x in [44, 97, 304, 1179, 23571] { |
| 62 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(superrust-analyzer cargo half 2.7.1 leading_zeros/::leading_zeros_u16_fallbackrust-analyzer cargo half 2.7.1 leading_zeros/leading_zeros_u16_fallback().(x), x.leading_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]leading_zeros().()); |
| 63 | } |
| 64 | } |
| 65 | } |