28 #ifndef VC_COMMON_LOADSTOREFLAGS_H_
29 #define VC_COMMON_LOADSTOREFLAGS_H_
31 #include "../traits/type_traits.h"
33 namespace Vc_VERSIONED_NAMESPACE
47 namespace LoadStoreFlags
50 struct StreamingFlag {};
51 struct UnalignedFlag {};
52 struct PrefetchFlagBase {};
54 template<
size_t L1 = 8 * 64,
size_t L2 = 64 * 64,
57 template<
size_t L1 = 16 * 64,
size_t L2 = 128 * 64,
59 typename ExclusiveOrShared_ =
void>
struct PrefetchFlag :
public PrefetchFlagBase
61 typedef ExclusiveOrShared_ ExclusiveOrShared;
62 static constexpr
size_t L1Stride = L1;
63 static constexpr
size_t L2Stride = L2;
64 static constexpr
bool IsExclusive = std::is_same<ExclusiveOrShared, Exclusive>::value;
65 static constexpr
bool IsShared = std::is_same<ExclusiveOrShared, Shared>::value;
68 template<
typename Base,
typename Default,
typename... LoadStoreFlags>
struct ExtractType
72 template<
typename Base,
typename Default,
typename T,
typename... LoadStoreFlags>
struct ExtractType<Base, Default, T, LoadStoreFlags...>
74 typedef typename std::conditional<std::is_base_of<Base, T>::value, T,
typename ExtractType<Base, Default, LoadStoreFlags...>::type>::type type;
82 #pragma warning(disable: 177)
88 template<
typename... Flags>
struct LoadStoreFlags
93 typedef typename ExtractType<PrefetchFlagBase, PrefetchFlag<0, 0>, Flags...>::type Prefetch;
96 constexpr LoadStoreFlags() {}
98 static constexpr
bool IsStreaming = !std::is_same<
typename ExtractType<StreamingFlag, void, Flags...>::type,
void>::value;
99 static constexpr
bool IsUnaligned = !std::is_same<
typename ExtractType<UnalignedFlag, void, Flags...>::type,
void>::value;
100 static constexpr
bool IsAligned = !IsUnaligned;
101 static constexpr
bool IsPrefetch = !std::is_same<
typename ExtractType<PrefetchFlagBase, void, Flags...>::type,
void>::value;
102 static constexpr
bool IsExclusivePrefetch = Prefetch::IsExclusive;
103 static constexpr
bool IsSharedPrefetch = Prefetch::IsShared;
104 static constexpr
size_t L1Stride = Prefetch::L1Stride;
105 static constexpr
size_t L2Stride = Prefetch::L2Stride;
107 typedef LoadStoreFlags<typename std::conditional<std::is_same<Flags, UnalignedFlag>::value, void, Flags>::type...> UnalignedRemoved;
113 typedef typename std::conditional<IsAligned && !IsStreaming, void *, void>::type EnableIfAligned;
114 typedef typename std::conditional<IsAligned && IsStreaming, void *, void>::type EnableIfStreaming;
115 typedef typename std::conditional<IsUnaligned && !IsStreaming, void *, void>::type EnableIfUnalignedNotStreaming;
116 typedef typename std::conditional<IsUnaligned && IsStreaming, void *, void>::type EnableIfUnalignedAndStreaming;
117 typedef typename std::conditional<IsUnaligned , void *, void>::type EnableIfUnaligned;
118 typedef typename std::conditional<!IsUnaligned , void *, void>::type EnableIfNotUnaligned;
119 typedef typename std::conditional<IsPrefetch , void *, void>::type EnableIfPrefetch;
120 typedef typename std::conditional<!IsPrefetch , void *, void>::type EnableIfNotPrefetch;
126 template<>
struct LoadStoreFlags<>
128 constexpr LoadStoreFlags() {}
130 static constexpr
bool IsStreaming =
false;
131 static constexpr
bool IsUnaligned =
false;
132 static constexpr
bool IsAligned = !IsUnaligned;
133 static constexpr
bool IsPrefetch =
false;
134 static constexpr
bool IsExclusivePrefetch =
false;
135 static constexpr
bool IsSharedPrefetch =
false;
136 static constexpr
size_t L1Stride = 0;
137 static constexpr
size_t L2Stride = 0;
138 typedef void* EnableIfAligned;
139 typedef void* EnableIfNotUnaligned;
140 typedef void* EnableIfNotPrefetch;
151 template<
typename... LFlags,
typename... RFlags>
152 constexpr LoadStoreFlags<LFlags..., RFlags...>
operator|(LoadStoreFlags<LFlags...>, LoadStoreFlags<RFlags...>)
154 return LoadStoreFlags<LFlags..., RFlags...>();
159 using LoadStoreFlags::PrefetchFlag;
161 typedef LoadStoreFlags::LoadStoreFlags<> AlignedTag;
162 typedef LoadStoreFlags::LoadStoreFlags<LoadStoreFlags::StreamingFlag> StreamingTag;
163 typedef LoadStoreFlags::LoadStoreFlags<LoadStoreFlags::UnalignedFlag> UnalignedTag;
225 template <size_t L1 = PrefetchFlag<>::L1Stride,
226 size_t L2 = PrefetchFlag<>::L2Stride,
227 typename ExclusiveOrShared = PrefetchFlag<>::ExclusiveOrShared>
228 struct Prefetch :
public LoadStoreFlags::LoadStoreFlags<PrefetchFlag<L1, L2, ExclusiveOrShared>>
235 template <
typename... Ts>
236 struct is_loadstoreflag_internal<LoadStoreFlags::LoadStoreFlags<Ts...>> :
public std::true_type
241 template <
size_t L1,
size_t L2,
typename ExclusiveOrShared>
242 struct is_loadstoreflag_internal<Prefetch<L1, L2, ExclusiveOrShared>> :
public std::true_type
248 #endif // VC_COMMON_LOADSTOREFLAGS_H_
Hint for Prefetch to select prefetches that mark the memory as shared.
result_vector_type< L, R > operator|(L &&lhs, R &&rhs)
Applies | component-wise and concurrently.
UnalignedTag DefaultLoadTag
The default load tag type uses unaligned (non-streaming) loads.
constexpr LoadStoreFlags::LoadStoreFlags< PrefetchFlag<> > PrefetchDefault
Use this object for a flags parameter to request default software prefetches to be emitted...
Hint for Prefetch to select prefetches that mark the memory as exclusive.
UnalignedTag DefaultStoreTag
The default store tag type uses unaligned (non-streaming) stores.
constexpr AlignedTag Aligned
Use this object for a flags parameter to request aligned loads and stores.
constexpr StreamingTag Streaming
Use this object for a flags parameter to request streaming loads and stores.
constexpr UnalignedTag Unaligned
Use this object for a flags parameter to request unaligned loads and stores.