25template <
size_t value>
26requires (is::powerOfTwoInt<value>)
27constexpr size_t previousMultipleOf (
size_t numElements)
29 constexpr auto numMaskBits = std::bit_width (value) - 1;
30 constexpr auto allBitsOne = size_t (-1);
31 constexpr auto mask = allBitsOne << numMaskBits;
33 return numElements & mask;
36template <
size_t value>
37requires (is::powerOfTwoInt<value>)
38constexpr size_t nextMultipleOf (
size_t numElements)
40 return size_t ((int64_t (numElements) + int64_t (value) - 1) & -int64_t (value));
56template <u
intptr_t requiredAlignment = Config::maxSIMDRegisterSize>
60 if (std::is_constant_evaluated())
63 return reinterpret_cast<std::uintptr_t
> (ptr) % requiredAlignment == 0;
81template <
class StorageType>
87template <has::sizeAndData StorageType>
91 : dataIsSIMDAligned (
false),
92 hasSIMDExtendedStorage (
false)
95 template <is::storageInfo OtherStorageInfoType>
96 constexpr StorageInfo (
const OtherStorageInfoType& other)
97 : dataIsSIMDAligned (other.dataIsSIMDAligned),
98 hasSIMDExtendedStorage (other.hasSIMDExtendedStorage)
102 constexpr StorageInfo init (
const T* ptr,
size_t s)
105 hasSIMDExtendedStorage = (s *
sizeof (T)) % Config::maxSIMDRegisterSize == 0;
109 static constexpr size_t memberAlignment =
alignof (StorageType);
111 bool dataIsSIMDAligned;
113 bool hasSIMDExtendedStorage;
116template <
class ElementType,
size_t alignmentInBytes>
117struct StorageInfo<std::vector<ElementType, AlignedAllocator<ElementType, alignmentInBytes>>>
119 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
121 static constexpr size_t memberAlignment =
alignof (std::vector<ElementType, AlignedAllocator<ElementType, alignmentInBytes>>);
123 static constexpr bool dataIsSIMDAligned = alignmentInBytes == Config::maxSIMDRegisterSize;
126 static constexpr bool hasSIMDExtendedStorage =
true;
129template <
class ElementType,
size_t size>
132 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
134 static constexpr size_t memberAlignment = Config::alignedArray ? Config::maxSIMDRegisterSize :
alignof (std::array<ElementType, size>);
137 static constexpr bool dataIsSIMDAligned = Config::alignedArray;
139 static constexpr bool hasSIMDExtendedStorage = (size *
sizeof (ElementType)) % Config::maxSIMDRegisterSize == 0;
142template <
class Allocator>
143struct StorageInfo<detail::VectorBoolWorkaround<Allocator>>
145 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
147 static constexpr size_t memberAlignment =
alignof (detail::VectorBoolWorkaround<Allocator>);
149 static constexpr bool dataIsSIMDAligned =
false;
151 static constexpr bool hasSIMDExtendedStorage =
false;
157template <
bool isDataSIMDAligned,
bool isStorageSIMDExtended,
size_t customMemberAlignment>
160 static constexpr bool dataIsSIMDAligned = isDataSIMDAligned;
161 static constexpr bool hasSIMDExtendedStorage = isStorageSIMDExtended;
162 static constexpr size_t memberAlignment = customMemberAlignment;
171template <
size_t alignment,
class WrappedInfo>
178 static constexpr size_t memberAlignment = alignment;
185struct ConstexprStorageInfoChecker
193concept constexprStorageInfo =
requires (
const T&) { detail::ConstexprStorageInfoChecker<T::dataIsSIMDAligned, T::hasSIMDExtendedStorage>(); };
196template <
class First,
class... Others>
200 : dataIsSIMDAligned (first.dataIsSIMDAligned && (others.dataIsSIMDAligned && ...)),
201 hasSIMDExtendedStorage (first.hasSIMDExtendedStorage && (others.hasSIMDExtendedStorage && ...))
204 bool dataIsSIMDAligned;
206 bool hasSIMDExtendedStorage;
214 static constexpr bool dataIsSIMDAligned = First::dataIsSIMDAligned && (Others::dataIsSIMDAligned && ...);
216 static constexpr bool hasSIMDExtendedStorage = First::hasSIMDExtendedStorage && (Others::hasSIMDExtendedStorage && ...);
Definition: SIMDHelpers.h:193
The main namespace of the VCTR project.
Definition: Array.h:24
constexpr bool isPtrAligned(const void *ptr)
Helper function to check if a pointer is aligned to the required alignment value.
Definition: SIMDHelpers.h:57
Definition: SIMDHelpers.h:198
A storage info type especially used to pass compile time constant traits when viewing externally owne...
Definition: SIMDHelpers.h:159
A storage info type especially used for vctr::Span.
Definition: SIMDHelpers.h:173
A helper class to describe some properties regarding the storage class wrapped in a VctrBase instance...
Definition: SIMDHelpers.h:83