From cf858a87fc36197c447d20d0cf1e636c449e6527 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 16 Jul 2023 21:43:22 -0300 Subject: [PATCH] util: ilog2 --- kernel-src/include/util.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel-src/include/util.h b/kernel-src/include/util.h index 287bfea0..1bace0df 100644 --- a/kernel-src/include/util.h +++ b/kernel-src/include/util.h @@ -8,4 +8,8 @@ static inline long abs(long x) { return x < 0 ? -x : x; } +static inline long ilog2(long x) { + return sizeof(long) * 8 - __builtin_clz(x) - 1; +} + #endif