Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/45938 )
Change subject: lib: add 64-bit versions of clz, __ffs and log2 ......................................................................
lib: add 64-bit versions of clz, __ffs and log2
Tack on `_64` to the end of the 32-bit name.
Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org Change-Id: Iefc6e6c51f5b20607c88e38660a499a4f77ce0d0 --- M src/include/lib.h 1 file changed, 4 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/45938/1
diff --git a/src/include/lib.h b/src/include/lib.h index 46d8b02..4342b9e 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -56,4 +56,8 @@ /* 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); }
+static inline long long clz_64(u64 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; } +static inline int log2_64(u64 x) { return sizeof(x) * 8 - clz_64(x) - 1; } +static inline int __ffs_64(u64 x) { return log2_64(x & (u64)(-(s64)x)); } + #endif /* __LIB_H__ */