diff options
author | Jianjun Wang <jianjun.wang@mediatek.com> | 2021-11-30 10:51:53 +0800 |
---|---|---|
committer | Hung-Te Lin <hungte@chromium.org> | 2021-12-13 02:57:07 +0000 |
commit | 8bb59ca2faee83ba50850900c8b4edf9331ae931 (patch) | |
tree | fab7bde1be5ff24af106a41c8f47b7d4fac75762 /src/include | |
parent | 5588f34a35209f34d9061e6a83856289450d8131 (diff) |
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>
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/lib.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/include/lib.h b/src/include/lib.h index b3cedb571c..863888e16b 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -53,6 +53,8 @@ static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; } static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; } /* Find First Set: __ffs(1) == 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); } /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2_ceil(5) == 3 */ static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x - 1) + 1; } @@ -61,5 +63,6 @@ static inline int popcnt64(u64 x) { return __builtin_popcountll(x); } 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)); } +static inline int __fls64(u64 x) { return log2_64(x); } #endif /* __LIB_H__ */ |