Alignment helpers for possibly any sizes
This commit is contained in:
parent
b74e376e16
commit
6e811f92b2
1 changed files with 9 additions and 9 deletions
|
|
@ -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<class T>
|
||||
template<unsigned N = config::defaultAlignment, class T>
|
||||
T* nextAligned(const T* ptr)
|
||||
{
|
||||
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(ptr) + ByteAlignmentMask & (~ByteAlignmentMask));
|
||||
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(ptr) + ByteAlignmentMask(N) & (~ByteAlignmentMask(N)));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<unsigned N = config::defaultAlignment, class T>
|
||||
T* prevAligned(const T* ptr)
|
||||
{
|
||||
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(ptr) & (~ByteAlignmentMask));
|
||||
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(ptr) & (~ByteAlignmentMask(N)));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<unsigned N = config::defaultAlignment, class T>
|
||||
bool unaligned(const T* ptr)
|
||||
{
|
||||
return (reinterpret_cast<uintptr_t>(ptr) & ByteAlignmentMask )!= 0;
|
||||
return (reinterpret_cast<uintptr_t>(ptr) & ByteAlignmentMask(N) )!= 0;
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
template<unsigned N = config::defaultAlignment, class T, class... Args>
|
||||
bool unaligned(const T* ptr1, Args... rest)
|
||||
{
|
||||
return unaligned(ptr1) || unaligned(rest...);
|
||||
return unaligned<N>(ptr1) || unaligned<N>(rest...);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue