28 #ifndef VC_COMMON_TYPES_H_
29 #define VC_COMMON_TYPES_H_
31 #ifdef Vc_CHECK_ALIGNMENT
37 #include "../global.h"
38 #include "../traits/type_traits.h"
39 #include "permutation.h"
41 namespace Vc_VERSIONED_NAMESPACE
67 struct VectorSpecialInitializerZero {};
71 struct VectorSpecialInitializerOne {};
75 struct VectorSpecialInitializerIndexesFromZero {};
81 constexpr VectorSpecialInitializerZero
Zero = {};
86 constexpr VectorSpecialInitializerOne
One = {};
96 template<
typename T>
struct MayAliasImpl {
98 #pragma warning(disable:2621)
101 #pragma GCC diagnostic push
102 #pragma GCC diagnostic ignored "-Wattributes"
104 typedef T type Vc_MAY_ALIAS;
106 #pragma GCC diagnostic pop
109 #pragma warning(enable:2621)
120 template <
typename T>
using MayAlias =
typename Detail::MayAliasImpl<T>::type;
122 template <
class To,
class From> MayAlias<To> &aliasing_cast(From &x)
124 return *
reinterpret_cast<MayAlias<To> *
>(&x);
126 template <
class To,
class From>
const MayAlias<To> &aliasing_cast(
const From &x)
128 return *
reinterpret_cast<const MayAlias<To> *
>(&x);
131 template <
class To,
class From> MayAlias<To> *aliasing_cast(From *x)
133 return reinterpret_cast<MayAlias<To> *
>(x);
135 template <
class To,
class From>
const MayAlias<To> *aliasing_cast(
const From *x)
137 return reinterpret_cast<const MayAlias<To> *
>(x);
146 enum class Operator : char {
188 template <
typename T, std::
size_t N>
struct array;
191 template <
typename T, std::ptrdiff_t N>
class span;
229 #ifndef Vc_CHECK_ALIGNMENT
230 template<
typename _T>
static Vc_ALWAYS_INLINE
void assertCorrectAlignment(
const _T *){}
232 template<
typename _T>
static Vc_ALWAYS_INLINE
void assertCorrectAlignment(
const _T *ptr)
234 const size_t s =
alignof(_T);
235 if((
reinterpret_cast<size_t>(ptr) & ((s ^ (s & (s - 1))) - 1)) != 0) {
236 fprintf(stderr,
"A vector with incorrect alignment has just been created. Look at the stacktrace to find the guilty object.\n");
245 template <
typename T, std::
size_t Pieces, std::
size_t Index>
struct Segment;
253 template<
size_t StructSize>
class SuccessiveEntries
258 using size_type = unsigned;
260 using size_type = size_t;
262 const size_type m_first;
265 typedef SuccessiveEntries AsArg;
266 Vc_INTRINSIC SuccessiveEntries(size_type first) : m_first(first) {}
267 Vc_INTRINSIC Vc_PURE size_type operator[](size_type offset)
const
269 return m_first + offset * StructSize;
271 Vc_INTRINSIC Vc_PURE size_type data()
const {
return m_first; }
272 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator+(
const SuccessiveEntries &rhs)
const
274 return SuccessiveEntries(m_first + rhs.m_first);
276 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator*(
const SuccessiveEntries &rhs)
const
278 return SuccessiveEntries(m_first * rhs.m_first);
280 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator<<(size_type x)
const
282 return {m_first << x};
285 friend Vc_INTRINSIC SuccessiveEntries &internal_data(SuccessiveEntries &x)
289 friend Vc_INTRINSIC
const SuccessiveEntries &internal_data(
const SuccessiveEntries &x)
296 template <std::
size_t alignment>
297 Vc_INTRINSIC_L
void *aligned_malloc(std::size_t n) Vc_INTRINSIC_R;
298 Vc_ALWAYS_INLINE_L
void free(
void *p) Vc_ALWAYS_INLINE_R;
303 template <
typename Mask,
typename T,
typename U>
304 using enable_if_mask_converts_implicitly =
305 enable_if<(!std::is_same<Mask, Traits::decay<U>>::value &&
306 Traits::is_simd_mask<U>::value && !Traits::isSimdMaskArray<U>::value &&
307 Traits::is_implicit_cast_allowed_mask<
308 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value)>;
312 template <
typename T,
typename U>
313 using enable_if_mask_converts_explicitly = enable_if<(
314 Traits::isSimdMaskArray<U>::value ||
315 (Traits::is_simd_mask<U>::value &&
316 !Traits::is_implicit_cast_allowed_mask<
317 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value))>;
322 template <
typename T>
using WidthT = std::integral_constant<std::size_t,
sizeof(T)>;
325 template <std::
size_t Bytes>
class MaskBool;
328 template <
typename T,
typename IndexVector,
typename Scale,
bool>
329 class SubscriptOperation;
338 template <
class T,
class IndexVector,
int Scale = 1>
339 struct GatherArguments {
340 static_assert(std::is_same<T, remove_cvref_t<T>>::value && !std::is_pointer<T>::value,
341 "GatherArguments expects an cv unqualified non-ref/ptr type");
342 const IndexVector indexes;
343 const T *
const address;
345 template <
int Scale,
class T,
class I>
346 GatherArguments<T, I, Scale> make_gather(
const T *m,
const I &i)
358 template <
typename T,
typename IndexVector>
struct ScatterArguments
360 const IndexVector indexes;
367 template <
typename I, I Begin, I End,
typename F>
368 Vc_INTRINSIC enable_if<(Begin >= End),
void> unrolled_loop(F &&)
377 template <
typename I, I Begin, I End,
typename F>
378 Vc_INTRINSIC Vc_FLATTEN enable_if<(Begin < End), void> unrolled_loop(F &&f)
381 unrolled_loop<I, Begin + 1, End>(f);
388 template <std::
size_t Size,
typename F> Vc_INTRINSIC
void for_all_vector_entries(F &&f)
390 unrolled_loop<std::size_t, 0u, Size>(std::forward<F>(f));
398 #include "memoryfwd.h"
Common::AdaptSubscriptOperator< Common::span< T, Extent > > span
An adapted std::span with additional subscript operators supporting gather and scatter operations.
result_vector_type< L, R > operator+(L &&lhs, R &&rhs)
Applies + component-wise and concurrently.
result_vector_type< L, R > operator*(L &&lhs, R &&rhs)
Applies * component-wise and concurrently.
constexpr VectorSpecialInitializerIndexesFromZero IndexesFromZero
The special object Vc::IndexesFromZero can be used to construct Vector objects initialized to values ...
unsigned long long ullong
unsigned long long shorthand
unsigned long ulong
unsigned long shorthand
long long llong
long long shorthand
unsigned int uint
unsigned int shorthand
constexpr VectorSpecialInitializerOne One
The special object Vc::One can be used to construct Vector and Mask objects initialized to one/true.
signed char schar
signed char shorthand
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
unsigned char uchar
unsigned char shorthand
unsigned short ushort
unsigned short shorthand
void free(T *p)
Frees memory that was allocated with Vc::malloc.
std::ostream & operator<<(std::ostream &out, const Vc::Vector< T, Abi > &v)
Prints the contents of a vector into a stream object.