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 <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448493
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
Seth Howell 2019-03-19 16:14:26 -07:00 committed by Darek Stojaczyk
parent 640547c5c1
commit 0cb3b8550a

View File

@ -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.
*/