diff --git a/include/spdk/util.h b/include/spdk/util.h index 78cb155ee..658a9b13d 100644 --- a/include/spdk/util.h +++ b/include/spdk/util.h @@ -70,6 +70,22 @@ spdk_align32pow2(uint32_t x) return 1u << (1 + spdk_u32log2(x - 1)); } +static inline uint64_t +spdk_u64log2(uint64_t x) +{ + if (x == 0) { + /* log(0) is undefined */ + return 0; + } + return 63u - __builtin_clzl(x); +} + +static inline uint64_t +spdk_align64pow2(uint64_t x) +{ + return 1u << (1 + spdk_u64log2(x - 1)); +} + /** * Check if a uint32_t is a power of 2. */