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:
parent
98397d9ef7
commit
b5176ded58
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user