File indexing completed on 2025-01-30 10:25:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef VC_COMMON_LOADSTOREFLAGS_H_
0029 #define VC_COMMON_LOADSTOREFLAGS_H_
0030
0031 #include "../traits/type_traits.h"
0032
0033 namespace Vc_VERSIONED_NAMESPACE
0034 {
0035
0036
0037
0038
0039
0040
0041 struct Exclusive {};
0042
0043
0044
0045 struct Shared {};
0046
0047 namespace LoadStoreFlags
0048 {
0049
0050 struct StreamingFlag {};
0051 struct UnalignedFlag {};
0052 struct PrefetchFlagBase {};
0053
0054 template <size_t L1 = 16 * 64, size_t L2 = 128 * 64, typename ExclusiveOrShared_ = void>
0055 struct PrefetchFlag : public PrefetchFlagBase {
0056 typedef ExclusiveOrShared_ ExclusiveOrShared;
0057 static constexpr size_t L1Stride = L1;
0058 static constexpr size_t L2Stride = L2;
0059 static constexpr bool IsExclusive = std::is_same<ExclusiveOrShared, Exclusive>::value;
0060 static constexpr bool IsShared = std::is_same<ExclusiveOrShared, Shared>::value;
0061 };
0062
0063 template<typename Base, typename Default, typename... LoadStoreFlags> struct ExtractType
0064 {
0065 typedef Default type;
0066 };
0067 template<typename Base, typename Default, typename T, typename... LoadStoreFlags> struct ExtractType<Base, Default, T, LoadStoreFlags...>
0068 {
0069 typedef typename std::conditional<std::is_base_of<Base, T>::value, T, typename ExtractType<Base, Default, LoadStoreFlags...>::type>::type type;
0070 };
0071
0072
0073
0074
0075
0076 #ifdef Vc_ICC
0077 #pragma warning(disable: 177)
0078 #endif
0079
0080
0081
0082
0083 template<typename... Flags> struct LoadStoreFlags
0084 {
0085 private:
0086
0087
0088 typedef typename ExtractType<PrefetchFlagBase, PrefetchFlag<0, 0>, Flags...>::type Prefetch;
0089
0090 public:
0091 constexpr LoadStoreFlags() {}
0092
0093 static constexpr bool IsStreaming = !std::is_same<typename ExtractType<StreamingFlag, void, Flags...>::type, void>::value;
0094 static constexpr bool IsUnaligned = !std::is_same<typename ExtractType<UnalignedFlag, void, Flags...>::type, void>::value;
0095 static constexpr bool IsAligned = !IsUnaligned;
0096 static constexpr bool IsPrefetch = !std::is_same<typename ExtractType<PrefetchFlagBase, void, Flags...>::type, void>::value;
0097 static constexpr bool IsExclusivePrefetch = Prefetch::IsExclusive;
0098 static constexpr bool IsSharedPrefetch = Prefetch::IsShared;
0099 static constexpr size_t L1Stride = Prefetch::L1Stride;
0100 static constexpr size_t L2Stride = Prefetch::L2Stride;
0101
0102 typedef LoadStoreFlags<typename std::conditional<std::is_same<Flags, UnalignedFlag>::value, void, Flags>::type...> UnalignedRemoved;
0103
0104
0105
0106
0107
0108 typedef typename std::conditional<IsAligned && !IsStreaming, void *, void>::type EnableIfAligned;
0109 typedef typename std::conditional<IsAligned && IsStreaming, void *, void>::type EnableIfStreaming;
0110 typedef typename std::conditional<IsUnaligned && !IsStreaming, void *, void>::type EnableIfUnalignedNotStreaming;
0111 typedef typename std::conditional<IsUnaligned && IsStreaming, void *, void>::type EnableIfUnalignedAndStreaming;
0112 typedef typename std::conditional<IsUnaligned , void *, void>::type EnableIfUnaligned;
0113 typedef typename std::conditional<!IsUnaligned , void *, void>::type EnableIfNotUnaligned;
0114 typedef typename std::conditional<IsPrefetch , void *, void>::type EnableIfPrefetch;
0115 typedef typename std::conditional<!IsPrefetch , void *, void>::type EnableIfNotPrefetch;
0116 };
0117
0118
0119
0120
0121 template<> struct LoadStoreFlags<>
0122 {
0123 constexpr LoadStoreFlags() {}
0124
0125 static constexpr bool IsStreaming = false;
0126 static constexpr bool IsUnaligned = false;
0127 static constexpr bool IsAligned = !IsUnaligned;
0128 static constexpr bool IsPrefetch = false;
0129 static constexpr bool IsExclusivePrefetch = false;
0130 static constexpr bool IsSharedPrefetch = false;
0131 static constexpr size_t L1Stride = 0;
0132 static constexpr size_t L2Stride = 0;
0133 typedef void* EnableIfAligned;
0134 typedef void* EnableIfNotUnaligned;
0135 typedef void* EnableIfNotPrefetch;
0136 };
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 template<typename... LFlags, typename... RFlags>
0147 constexpr LoadStoreFlags<LFlags..., RFlags...> operator|(LoadStoreFlags<LFlags...>, LoadStoreFlags<RFlags...>)
0148 {
0149 return LoadStoreFlags<LFlags..., RFlags...>();
0150 }
0151
0152 }
0153
0154 using LoadStoreFlags::PrefetchFlag;
0155
0156 typedef LoadStoreFlags::LoadStoreFlags<> AlignedTag;
0157 typedef LoadStoreFlags::LoadStoreFlags<LoadStoreFlags::StreamingFlag> StreamingTag;
0158 typedef LoadStoreFlags::LoadStoreFlags<LoadStoreFlags::UnalignedFlag> UnalignedTag;
0159
0160
0161 typedef UnalignedTag DefaultLoadTag;
0162
0163 typedef UnalignedTag DefaultStoreTag;
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 constexpr AlignedTag Aligned;
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 constexpr UnalignedTag Unaligned;
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 constexpr StreamingTag Streaming;
0207
0208
0209
0210
0211
0212 constexpr LoadStoreFlags::LoadStoreFlags<PrefetchFlag<>> PrefetchDefault;
0213
0214
0215
0216
0217
0218
0219
0220 template <size_t L1 = PrefetchFlag<>::L1Stride,
0221 size_t L2 = PrefetchFlag<>::L2Stride,
0222 typename ExclusiveOrShared = PrefetchFlag<>::ExclusiveOrShared>
0223 struct Prefetch : public LoadStoreFlags::LoadStoreFlags<PrefetchFlag<L1, L2, ExclusiveOrShared>>
0224 {
0225 };
0226
0227 namespace Traits
0228 {
0229
0230 template <typename... Ts>
0231 struct is_loadstoreflag_internal<LoadStoreFlags::LoadStoreFlags<Ts...>> : public std::true_type
0232 {
0233 };
0234
0235
0236 template <size_t L1, size_t L2, typename ExclusiveOrShared>
0237 struct is_loadstoreflag_internal<Prefetch<L1, L2, ExclusiveOrShared>> : public std::true_type
0238 {
0239 };
0240 }
0241 }
0242
0243 #endif