From 0cb3b8550a2fb38ee0b10c8223520b1453538469 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Tue, 19 Mar 2019 16:14:26 -0700 Subject: [PATCH] util: add power of 2 alignment for uint64_t variables. We need this for making sure we get proper allocations for our spdk mempools. Change-Id: I850c29768ef0551c5d1a2aa0c78dbd323535aa78 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448493 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Darek Stojaczyk --- include/spdk/util.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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. */