From: Igor Fedotov Date: Mon, 29 Jan 2024 16:21:51 +0000 (+0300) Subject: include/intarith: introduce p2aligned() X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=95bdff7d534d10f54713864312ff01048794e12f;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 92f827d88e58..42bafcf88b4a 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)