From: Timmons C. Player <[email protected]> Committer: Nadav Har'El <[email protected]> Branch: master
align: add helper to check alignment Signed-off-by: Timmons C. Player <[email protected]> Message-Id: <[email protected]> --- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
