diff options
Diffstat (limited to 'src/common/bit_util.h')
-rw-r--r-- | src/common/bit_util.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 1eea17ba1..14e53c273 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -58,4 +58,23 @@ inline u64 CountLeadingZeroes64(u64 value) { return __builtin_clzll(value); } #endif + +inline u32 CountTrailingZeroes32(u32 value) { + u32 count = 0; + while (((value >> count) & 0xf) == 0 && count < 32) + count += 4; + while (((value >> count) & 1) == 0 && count < 32) + count++; + return count; +} + +inline u64 CountTrailingZeroes64(u64 value) { + u64 count = 0; + while (((value >> count) & 0xf) == 0 && count < 64) + count += 4; + while (((value >> count) & 1) == 0 && count < 64) + count++; + return count; +} + } // namespace Common |