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));
43template <u
intptr_t requiredAlignment = Config::maxSIMDRegisterSize>
44inline constexpr bool isPtrAligned (
const void* ptr)
47 if (std::is_constant_evaluated())
50 return reinterpret_cast<std::uintptr_t
> (ptr) % requiredAlignment == 0;
72template <
class StorageType>
78template <has::sizeAndData StorageType>
82 : dataIsSIMDAligned (
false),
83 hasSIMDExtendedStorage (
false)
86 template <is::storageInfo OtherStorageInfoType>
87 constexpr StorageInfo (
const OtherStorageInfoType& other)
88 : dataIsSIMDAligned (other.dataIsSIMDAligned),
89 hasSIMDExtendedStorage (other.hasSIMDExtendedStorage)
95 dataIsSIMDAligned = detail::isPtrAligned (ptr);
96 hasSIMDExtendedStorage = (s *
sizeof (T)) % Config::maxSIMDRegisterSize == 0;
100 static constexpr size_t memberAlignment =
alignof (StorageType);
102 bool dataIsSIMDAligned;
104 bool hasSIMDExtendedStorage;
107template <
class ElementType,
size_t alignmentInBytes>
108struct StorageInfo<std::vector<ElementType, AlignedAllocator<ElementType, alignmentInBytes>>>
110 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
112 static constexpr size_t memberAlignment =
alignof (std::vector<ElementType, AlignedAllocator<ElementType, alignmentInBytes>>);
114 static constexpr bool dataIsSIMDAligned = alignmentInBytes == Config::maxSIMDRegisterSize;
117 static constexpr bool hasSIMDExtendedStorage =
true;
120template <
class ElementType,
size_t size>
123 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
125 static constexpr size_t memberAlignment = Config::alignedArray ? Config::maxSIMDRegisterSize :
alignof (std::array<ElementType, size>);
128 static constexpr bool dataIsSIMDAligned = Config::alignedArray;
130 static constexpr bool hasSIMDExtendedStorage = (size *
sizeof (ElementType)) % Config::maxSIMDRegisterSize == 0;
133template <
class Allocator>
134struct StorageInfo<detail::VectorBoolWorkaround<Allocator>>
136 constexpr StorageInfo init (
const void*,
size_t) {
return *
this; }
138 static constexpr size_t memberAlignment =
alignof (detail::VectorBoolWorkaround<Allocator>);
140 static constexpr bool dataIsSIMDAligned =
false;
142 static constexpr bool hasSIMDExtendedStorage =
false;
148template <
bool isDataSIMDAligned,
bool isStorageSIMDExtended,
size_t customMemberAlignment>
151 static constexpr bool dataIsSIMDAligned = isDataSIMDAligned;
152 static constexpr bool hasSIMDExtendedStorage = isStorageSIMDExtended;
153 static constexpr size_t memberAlignment = customMemberAlignment;
162template <
size_t alignment,
class WrappedInfo>
169 static constexpr size_t memberAlignment = alignment;
176struct ConstexprStorageInfoChecker
184concept constexprStorageInfo =
requires (
const T&) { detail::ConstexprStorageInfoChecker<T::dataIsSIMDAligned, T::hasSIMDExtendedStorage>(); };
187template <
class InfoA,
class InfoB>
191 : dataIsSIMDAligned (a.dataIsSIMDAligned && b.dataIsSIMDAligned),
192 hasSIMDExtendedStorage (a.hasSIMDExtendedStorage && b.hasSIMDExtendedStorage)
195 bool dataIsSIMDAligned;
197 bool hasSIMDExtendedStorage;
200template <is::constexprStorageInfo InfoA, is::constexprStorageInfo InfoB>
205 static constexpr bool dataIsSIMDAligned = InfoA::dataIsSIMDAligned && InfoB::dataIsSIMDAligned;
207 static constexpr bool hasSIMDExtendedStorage = InfoA::hasSIMDExtendedStorage && InfoB::hasSIMDExtendedStorage;
Definition: SIMDHelpers.h:184
The main namespace of the VCTR project.
Definition: Array.h:24
Definition: SIMDHelpers.h:189
A storage info type especially used to pass compile time constant traits when viewing externally owne...
Definition: SIMDHelpers.h:150
A storage info type especially used for vctr::Span.
Definition: SIMDHelpers.h:164
A helper class to describe some properties regarding the storage class wrapped in a VctrBase instance...
Definition: SIMDHelpers.h:74