lib and libpayload: add 64-bit versions of clz, __ffs and log2
Add 64-bit versions of clz, __ffs & log2: `__ffs64`, `__clz64`, and `log2_64`. Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Change-Id: Iefc6e6c51f5b20607c88e38660a499a4f77ce0d0 Reviewed-on: https://review.coreboot.org/c/coreboot/+/45938 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
committed by
Angel Pons
parent
7223bfa47e
commit
7ded1afe0a
@@ -56,4 +56,8 @@ 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); }
|
||||
|
||||
static inline int clz64(u64 x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; }
|
||||
static inline int log2_64(u64 x) { return sizeof(x) * 8 - clz64(x) - 1; }
|
||||
static inline int __ffs64(u64 x) { return log2_64(x & (u64)(-(s64)x)); }
|
||||
|
||||
#endif /* __LIB_H__ */
|
||||
|
Reference in New Issue
Block a user