lib: Add __fls() (Find Last Set)
Implement __fls() as an alias for log2(), and remove the duplicate definitions in commonlib/storage/sdhci.c. Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com> Change-Id: Ib458abfec7e03b2979569a8440a6e69b0285ac32 Reviewed-on: https://review.coreboot.org/c/coreboot/+/59738 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
committed by
Hung-Te Lin
parent
5588f34a35
commit
8bb59ca2fa
@ -457,6 +457,8 @@ static inline int clz(u32 x)
|
||||
static inline int log2(u32 x) { return (int)sizeof(x) * 8 - clz(x) - 1; }
|
||||
/* Find First Set: __ffs(0xf) == 0, __ffs(0) == -1, __ffs(1 << 31) == 31 */
|
||||
static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); }
|
||||
/* Find Last Set: __fls(1) == 0, __fls(5) == 2, __fls(1 << 31) == 31 */
|
||||
static inline int __fls(u32 x) { return log2(x); }
|
||||
|
||||
static inline int popcnt64(u64 x) { return __builtin_popcountll(x); }
|
||||
static inline int clz64(u64 x)
|
||||
@ -466,6 +468,7 @@ static inline int clz64(u64 x)
|
||||
|
||||
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)); }
|
||||
static inline int __fls64(u64 x) { return log2_64(x); }
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user