From: Igor Fedotov Date: Mon, 29 Jan 2024 16:21:51 +0000 (+0300) Subject: include/intarith: introduce p2aligned() X-Git-Tag: v19.2.3~223^2~6 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=96730b417e57376224c61d67bdb5e307a13bb688;p=ceph.git include/intarith: introduce p2aligned() Signed-off-by: Igor Fedotov --- diff --git a/src/include/intarith.h b/src/include/intarith.h index 92f827d88e580..42bafcf88b4a4 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -57,6 +57,18 @@ constexpr inline T p2align(T x, T align) { return x & -align; } +/* + * return whether x is aligned with (align) + * eg, p2aligned(1200, 1024) ==> false + * eg, p2aligned(1024, 1024) ==> true + * eg, p2aligned(0x1234, 0x100) ==> false + * eg, p2aligned(0x5600, 0x100) ==> true + */ +template +constexpr inline bool p2aligned(T x, T align) { + return p2align(x, align) == x; +} + /* * return x % (mod) align * eg, p2phase(0x1234, 0x100) == 0x34 (x-0x12*align)