From 7a23528650bc3add8566e64015dd1f5431156d54 Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 11 May 2026 01:24:24 -0300 Subject: [PATCH] util: log2_ceil --- kernel-src/include/util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel-src/include/util.h b/kernel-src/include/util.h index acc4485b..5cd7ed42 100644 --- a/kernel-src/include/util.h +++ b/kernel-src/include/util.h @@ -23,6 +23,13 @@ static inline unsigned long log2(unsigned long x) { return sizeof(unsigned long) * 8 - __builtin_clzll(x) - 1; } +static inline unsigned long ceil_log2(unsigned long x) { + if (x <= 1) + return 0; + + return log2(x - 1) + 1; +} + #define min(x, y) (x > y ? y : x) #define max(x, y) (x < y ? y : x)