summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--payloads/libpayload/include/libpayload.h8
-rw-r--r--src/include/lib.h4
2 files changed, 12 insertions, 0 deletions
diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h
index 01d71b8e61..475fe0f3fc 100644
--- a/payloads/libpayload/include/libpayload.h
+++ b/payloads/libpayload/include/libpayload.h
@@ -454,6 +454,14 @@ 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)); }
+
+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)); }
/** @} */
/**
diff --git a/src/include/lib.h b/src/include/lib.h
index 46d8b02112..a0003d3e29 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -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__ */