diff options
Diffstat (limited to 'src/common/alignment.h')
| -rw-r--r-- | src/common/alignment.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h index cdd4833f8..f8c49e079 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -38,6 +38,13 @@ constexpr bool IsWordAligned(T value) { | |||
| 38 | return (value & 0b11) == 0; | 38 | return (value & 0b11) == 0; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | template <typename T> | ||
| 42 | constexpr bool IsAligned(T value, std::size_t alignment) { | ||
| 43 | using U = typename std::make_unsigned<T>::type; | ||
| 44 | const U mask = static_cast<U>(alignment - 1); | ||
| 45 | return (value & mask) == 0; | ||
| 46 | } | ||
| 47 | |||
| 41 | template <typename T, std::size_t Align = 16> | 48 | template <typename T, std::size_t Align = 16> |
| 42 | class AlignmentAllocator { | 49 | class AlignmentAllocator { |
| 43 | public: | 50 | public: |