diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 4eea814c..05da355f 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -150,6 +150,17 @@ inline size_t BitCount(Integral value) { return std::bitset()>(value).count(); } +template +constexpr size_t CountLeadingZeros(T value) { + auto x = static_cast>(value); + size_t result = BitSize(); + while (x != 0) { + x >>= 1; + result--; + } + return result; +} + template constexpr int HighestSetBit(T value) { auto x = static_cast>(value);