]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/intarith: introduce p2aligned()
authorIgor Fedotov <igor.fedotov@croit.io>
Mon, 29 Jan 2024 16:21:51 +0000 (19:21 +0300)
committerJoshua Baergen <jbaergen@digitalocean.com>
Thu, 27 Mar 2025 16:33:01 +0000 (10:33 -0600)
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/include/intarith.h

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