util: add spdk_u64_is_pow2()

There already is a spdk_u32_is_pow2() function that handles uint32_t.
Add a spdk_u64_is_pow2() function that handles uint64_t.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Change-Id: Idc96680dbe280d1510aba94a6900eff64ccb4f03
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10179
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Niklas Cassel 2021-11-11 01:03:28 +00:00 committed by Jim Harris
parent 1f9c7a74bc
commit 01f94ea947

View File

@ -110,6 +110,19 @@ spdk_u32_is_pow2(uint32_t x)
return (x & (x - 1)) == 0;
}
/**
* Check if a uint64_t is a power of 2.
*/
static inline bool
spdk_u64_is_pow2(uint64_t x)
{
if (x == 0) {
return false;
}
return (x & (x - 1)) == 0;
}
static inline uint64_t
spdk_divide_round_up(uint64_t num, uint64_t divisor)
{