File indexing completed on 2025-01-30 10:25:51
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_TYPES_H_
0029 #define VC_COMMON_TYPES_H_
0030
0031 #ifdef Vc_CHECK_ALIGNMENT
0032 #include <cstdlib>
0033 #include <cstdio>
0034 #endif
0035
0036 #include <ratio>
0037 #include "../global.h"
0038 #include "../traits/type_traits.h"
0039 #include "permutation.h"
0040
0041 namespace Vc_VERSIONED_NAMESPACE
0042 {
0043
0044
0045
0046
0047 using std::size_t;
0048
0049
0050 using llong = long long;
0051
0052 using ullong = unsigned long long;
0053
0054 using ulong = unsigned long;
0055
0056 using uint = unsigned int;
0057
0058 using ushort = unsigned short;
0059
0060 using uchar = unsigned char;
0061
0062 using schar = signed char;
0063
0064
0065
0066
0067 struct VectorSpecialInitializerZero {};
0068
0069
0070
0071 struct VectorSpecialInitializerOne {};
0072
0073
0074
0075 struct VectorSpecialInitializerIndexesFromZero {};
0076
0077
0078
0079
0080
0081 constexpr VectorSpecialInitializerZero Zero = {};
0082
0083
0084
0085
0086 constexpr VectorSpecialInitializerOne One = {};
0087
0088
0089
0090
0091 constexpr VectorSpecialInitializerIndexesFromZero IndexesFromZero = {};
0092
0093
0094 namespace Detail
0095 {
0096 template<typename T> struct MayAliasImpl {
0097 #ifdef Vc_ICC
0098 #pragma warning(disable:2621)
0099 #endif
0100 #ifdef __GNUC__
0101 #pragma GCC diagnostic push
0102 #pragma GCC diagnostic ignored "-Wattributes"
0103 #endif
0104 typedef T type Vc_MAY_ALIAS;
0105 #ifdef __GNUC__
0106 #pragma GCC diagnostic pop
0107 #endif
0108 #ifdef Vc_ICC
0109 #pragma warning(enable:2621)
0110 #endif
0111 };
0112
0113 }
0114
0115
0116
0117
0118
0119
0120 template <typename T> using MayAlias = typename Detail::MayAliasImpl<T>::type;
0121
0122 template <class To, class From> MayAlias<To> &aliasing_cast(From &x)
0123 {
0124 return *reinterpret_cast<MayAlias<To> *>(&x);
0125 }
0126 template <class To, class From> const MayAlias<To> &aliasing_cast(const From &x)
0127 {
0128 return *reinterpret_cast<const MayAlias<To> *>(&x);
0129 }
0130
0131 template <class To, class From> MayAlias<To> *aliasing_cast(From *x)
0132 {
0133 return reinterpret_cast<MayAlias<To> *>(x);
0134 }
0135 template <class To, class From> const MayAlias<To> *aliasing_cast(const From *x)
0136 {
0137 return reinterpret_cast<const MayAlias<To> *>(x);
0138 }
0139
0140
0141
0142
0143
0144
0145
0146 enum class Operator : char {
0147 Assign,
0148 Multiply,
0149 MultiplyAssign,
0150 Divide,
0151 DivideAssign,
0152 Remainder,
0153 RemainderAssign,
0154 Plus,
0155 PlusAssign,
0156 Minus,
0157 MinusAssign,
0158 RightShift,
0159 RightShiftAssign,
0160 LeftShift,
0161 LeftShiftAssign,
0162 And,
0163 AndAssign,
0164 Xor,
0165 XorAssign,
0166 Or,
0167 OrAssign,
0168 PreIncrement,
0169 PostIncrement,
0170 PreDecrement,
0171 PostDecrement,
0172 LogicalAnd,
0173 LogicalOr,
0174 Comma,
0175 UnaryPlus,
0176 UnaryMinus,
0177 UnaryNot,
0178 UnaryOnesComplement,
0179 CompareEqual,
0180 CompareNotEqual,
0181 CompareLess,
0182 CompareGreater,
0183 CompareLessEqual,
0184 CompareGreaterEqual
0185 };
0186
0187
0188 template <typename T, std::size_t N> struct array;
0189
0190 namespace Common {
0191 template <typename T, std::ptrdiff_t N> class span;
0192 }
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229 #ifndef Vc_CHECK_ALIGNMENT
0230 template<typename _T> static Vc_ALWAYS_INLINE void assertCorrectAlignment(const _T *){}
0231 #else
0232 template<typename _T> static Vc_ALWAYS_INLINE void assertCorrectAlignment(const _T *ptr)
0233 {
0234 const size_t s = alignof(_T);
0235 if((reinterpret_cast<size_t>(ptr) & ((s ^ (s & (s - 1))) - 1)) != 0) {
0236 fprintf(stderr, "A vector with incorrect alignment has just been created. Look at the stacktrace to find the guilty object.\n");
0237 abort();
0238 }
0239 }
0240 #endif
0241
0242 namespace Common
0243 {
0244
0245 template <typename T, std::size_t Pieces, std::size_t Index> struct Segment;
0246
0247
0248
0249
0250
0251
0252
0253 template<size_t StructSize> class SuccessiveEntries
0254 {
0255 #ifdef Vc_MSVC
0256
0257
0258 using size_type = unsigned;
0259 #else
0260 using size_type = size_t;
0261 #endif
0262 const size_type m_first;
0263
0264 public:
0265 typedef SuccessiveEntries AsArg;
0266 Vc_INTRINSIC SuccessiveEntries(size_type first) : m_first(first) {}
0267 Vc_INTRINSIC Vc_PURE size_type operator[](size_type offset) const
0268 {
0269 return m_first + offset * StructSize;
0270 }
0271 Vc_INTRINSIC Vc_PURE size_type data() const { return m_first; }
0272 Vc_INTRINSIC Vc_PURE SuccessiveEntries operator+(const SuccessiveEntries &rhs) const
0273 {
0274 return SuccessiveEntries(m_first + rhs.m_first);
0275 }
0276 Vc_INTRINSIC Vc_PURE SuccessiveEntries operator*(const SuccessiveEntries &rhs) const
0277 {
0278 return SuccessiveEntries(m_first * rhs.m_first);
0279 }
0280 Vc_INTRINSIC Vc_PURE SuccessiveEntries operator<<(size_type x) const
0281 {
0282 return {m_first << x};
0283 }
0284
0285 friend Vc_INTRINSIC SuccessiveEntries &internal_data(SuccessiveEntries &x)
0286 {
0287 return x;
0288 }
0289 friend Vc_INTRINSIC const SuccessiveEntries &internal_data(const SuccessiveEntries &x)
0290 {
0291 return x;
0292 }
0293 };
0294
0295
0296 template <std::size_t alignment>
0297 Vc_INTRINSIC_L void *aligned_malloc(std::size_t n) Vc_INTRINSIC_R;
0298 Vc_ALWAYS_INLINE_L void free(void *p) Vc_ALWAYS_INLINE_R;
0299
0300
0301
0302
0303 template <typename Mask, typename T, typename U>
0304 using enable_if_mask_converts_implicitly =
0305 enable_if<(!std::is_same<Mask, Traits::decay<U>>::value &&
0306 Traits::is_simd_mask<U>::value && !Traits::isSimdMaskArray<U>::value &&
0307 Traits::is_implicit_cast_allowed_mask<
0308 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value)>;
0309
0310
0311
0312 template <typename T, typename U>
0313 using enable_if_mask_converts_explicitly = enable_if<(
0314 Traits::isSimdMaskArray<U>::value ||
0315 (Traits::is_simd_mask<U>::value &&
0316 !Traits::is_implicit_cast_allowed_mask<
0317 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value))>;
0318
0319
0320
0321
0322 template <typename T> using WidthT = std::integral_constant<std::size_t, sizeof(T)>;
0323
0324
0325 template <std::size_t Bytes> class MaskBool;
0326
0327
0328 template <typename T, typename IndexVector, typename Scale, bool>
0329 class SubscriptOperation;
0330
0331
0332
0333
0334
0335
0336
0337
0338 template <class T, class IndexVector, int Scale = 1>
0339 struct GatherArguments {
0340 static_assert(std::is_same<T, remove_cvref_t<T>>::value && !std::is_pointer<T>::value,
0341 "GatherArguments expects an cv unqualified non-ref/ptr type");
0342 const IndexVector indexes;
0343 const T *const address;
0344 };
0345 template <int Scale, class T, class I>
0346 GatherArguments<T, I, Scale> make_gather(const T *m, const I &i)
0347 {
0348 return {i, m};
0349 }
0350
0351
0352
0353
0354
0355
0356
0357
0358 template <typename T, typename IndexVector> struct ScatterArguments
0359 {
0360 const IndexVector indexes;
0361 T *const address;
0362 };
0363
0364
0365
0366
0367 template <typename I, I Begin, I End, typename F>
0368 Vc_INTRINSIC enable_if<(Begin >= End), void> unrolled_loop(F &&)
0369 {
0370 }
0371
0372
0373
0374
0375
0376
0377 template <typename I, I Begin, I End, typename F>
0378 Vc_INTRINSIC Vc_FLATTEN enable_if<(Begin < End), void> unrolled_loop(F &&f)
0379 {
0380 f(Begin);
0381 unrolled_loop<I, Begin + 1, End>(f);
0382 }
0383
0384
0385
0386
0387
0388 template <std::size_t Size, typename F> Vc_INTRINSIC void for_all_vector_entries(F &&f)
0389 {
0390 unrolled_loop<std::size_t, 0u, Size>(std::forward<F>(f));
0391 }
0392
0393 }
0394 }
0395
0396 #include "vector.h"
0397 #include "mask.h"
0398 #include "memoryfwd.h"
0399
0400 #endif
0401
0402