Commit b5176ded authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

util: add spdk_u32_is_pow2() function



Change-Id: I438053d85360f1c3ecc2b7661dbd573e0217ac46
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/373672


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 98397d9e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -67,6 +67,19 @@ spdk_align32pow2(uint32_t x)
	return 1u << (1 + spdk_u32log2(x - 1));
}

/**
 * Check if a uint32_t is a power of 2.
 */
static inline bool
spdk_u32_is_pow2(uint32_t x)
{
	if (x == 0) {
		return false;
	}

	return (x & (x - 1)) == 0;
}

#ifdef __cplusplus
}
#endif