]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/intarith: add p2remain
authorAdam Kupczyk <akupczyk@ibm.com>
Thu, 9 Nov 2023 01:06:38 +0000 (01:06 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Wed, 7 Aug 2024 10:55:45 +0000 (10:55 +0000)
p2remain gives remaining data in a block.
It simialar to p2nphase, but for 0 offset returns full size.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/include/intarith.h

index 92f827d88e580b78f6612c320a0566f488f05ffc..260083edeb6308f663b23fd3a1a91f932a0b9ddf 100644 (file)
@@ -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<typename T>
+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)