aboutsummaryrefslogtreecommitdiff
path: root/base/include/berberis/base/bit_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/include/berberis/base/bit_util.h')
-rw-r--r--base/include/berberis/base/bit_util.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/base/include/berberis/base/bit_util.h b/base/include/berberis/base/bit_util.h
index e3610dde..4fb08470 100644
--- a/base/include/berberis/base/bit_util.h
+++ b/base/include/berberis/base/bit_util.h
@@ -70,8 +70,9 @@ constexpr bool IsAligned(T* p, size_t align) {
template <typename T>
constexpr T BitUtilLog2(T x) {
static_assert(std::is_integral_v<T>, "Log2: T must be integral");
- DCHECK(IsPowerOf2(x));
- return x == 1 ? 0 : BitUtilLog2(x >> 1) + 1;
+ CHECK(IsPowerOf2(x));
+ // TODO(b/260725458): Use std::countr_zero after C++20 becomes available
+ return __builtin_ctz(x);
}
// Verify that argument value fits into a target.