From 6e811f92b234f01ccdb7846e75cd231a194bef43 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sat, 30 May 2020 20:41:25 +0200 Subject: [PATCH] Alignment helpers for possibly any sizes --- src/sfizz/SIMDHelpers.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index 5bce8a78..b8915297 100644 --- a/src/sfizz/SIMDHelpers.h +++ b/src/sfizz/SIMDHelpers.h @@ -74,30 +74,30 @@ enum class SIMDOps { void setSIMDOpStatus(SIMDOps op, bool status); bool getSIMDOpStatus(SIMDOps op); -constexpr uintptr_t ByteAlignmentMask { config::defaultAlignment - 1 }; +constexpr uintptr_t ByteAlignmentMask(unsigned N) { return N - 1; } -template +template T* nextAligned(const T* ptr) { - return reinterpret_cast(reinterpret_cast(ptr) + ByteAlignmentMask & (~ByteAlignmentMask)); + return reinterpret_cast(reinterpret_cast(ptr) + ByteAlignmentMask(N) & (~ByteAlignmentMask(N))); } -template +template T* prevAligned(const T* ptr) { - return reinterpret_cast(reinterpret_cast(ptr) & (~ByteAlignmentMask)); + return reinterpret_cast(reinterpret_cast(ptr) & (~ByteAlignmentMask(N))); } -template +template bool unaligned(const T* ptr) { - return (reinterpret_cast(ptr) & ByteAlignmentMask )!= 0; + return (reinterpret_cast(ptr) & ByteAlignmentMask(N) )!= 0; } -template +template bool unaligned(const T* ptr1, Args... rest) { - return unaligned(ptr1) || unaligned(rest...); + return unaligned(ptr1) || unaligned(rest...); } /**