summaryrefslogtreecommitdiffstats
path: root/src/include/lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/lib.h')
-rw-r--r--src/include/lib.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/include/lib.h b/src/include/lib.h
index 8e8bab55c19c..b3cedb571c78 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -54,8 +54,8 @@ static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; }
/* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */
static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); }
-/* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */
-static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); }
+/* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2_ceil(5) == 3 */
+static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x - 1) + 1; }
static inline int popcnt64(u64 x) { return __builtin_popcountll(x); }
static inline int clz64(u64 x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; }