util: add spdk_u32_is_pow2() function

Change-Id: I438053d85360f1c3ecc2b7661dbd573e0217ac46
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/373672
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-08-09 17:15:37 -07:00 committed by Jim Harris
parent 98397d9ef7
commit b5176ded58

View File

@ -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