From b838e58d63c817aef365e023d2865033bcad0ac4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 31 Mar 2020 14:15:43 -0400 Subject: [PATCH] common: alignment: Add a helper function for generic alignment checking. --- src/common/alignment.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/alignment.h b/src/common/alignment.h index cdd4833f81..f8c49e0797 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -38,6 +38,13 @@ constexpr bool IsWordAligned(T value) { return (value & 0b11) == 0; } +template +constexpr bool IsAligned(T value, std::size_t alignment) { + using U = typename std::make_unsigned::type; + const U mask = static_cast(alignment - 1); + return (value & mask) == 0; +} + template class AlignmentAllocator { public: