From: Timmons C. Player <timmons.pla...@spirent.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

align: add helper to check alignment

Signed-off-by: Timmons C. Player <timmons.pla...@spirent.com>
Message-Id: <1483547132-22868-2-git-send-email-timmons.pla...@spirent.com>

---
diff --git a/include/osv/align.hh b/include/osv/align.hh
--- a/include/osv/align.hh
+++ b/include/osv/align.hh
@@ -25,6 +25,13 @@ T align_up(T n, T alignment)
     return align_down(n + alignment - 1, alignment);
 }

+template <typename T>
+inline
+bool align_check(T n, T alignment)
+{
+    return align_down(n, alignment) == n;
+}
+
 template <class T>
 inline
 T* align_down(T* ptr, size_t alignment)
@@ -43,4 +50,11 @@ T* align_up(T* ptr, size_t alignment)
     return reinterpret_cast<T*>(n);
 }

+template <class T>
+inline
+bool align_check(T* ptr, size_t alignment)
+{
+    auto n = reinterpret_cast<uintptr_t>(ptr);
+    return align_down(n, alignment) == n;
+}
 #endif

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to