Commit 0cb3b855 authored by Seth Howell's avatar Seth Howell Committed by Darek Stojaczyk
Browse files

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: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448493


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent 640547c5
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -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.
 */