From: Adam Kupczyk Date: Thu, 9 Nov 2023 01:06:38 +0000 (+0000) Subject: include/intarith: add p2remain X-Git-Tag: v20.0.0~1280^2~32 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5ef9d11cb5b85a9e4b3c36634a4ccf5ee2a9cbbb;p=ceph.git include/intarith: add p2remain p2remain gives remaining data in a block. It simialar to p2nphase, but for 0 offset returns full size. Signed-off-by: Adam Kupczyk --- diff --git a/src/include/intarith.h b/src/include/intarith.h index 92f827d88e580..260083edeb630 100644 --- a/src/include/intarith.h +++ b/src/include/intarith.h @@ -78,6 +78,17 @@ constexpr inline T p2nphase(T x, T align) { return -x & (align - 1); } +/* + * return how much space is left in this block, + * when perfectly aligned, return whole block + * eg, p2remain(0x1234, 0x100) == 0xcc + * eg, p2remain(0x5600, 0x100) == 0x100 + */ +template +constexpr inline T p2remain(T x, T align) { + return align - p2phase(x, align); +} + /* * return x rounded up to an align boundary * eg, p2roundup(0x1234, 0x100) == 0x1300 (0x13*align)