28#ifndef VC_COMMON_TYPES_H_
29#define VC_COMMON_TYPES_H_
31#ifdef Vc_CHECK_ALIGNMENT
38#include "../traits/type_traits.h"
39#include "permutation.h"
41namespace Vc_VERSIONED_NAMESPACE
67struct VectorSpecialInitializerZero {};
71struct VectorSpecialInitializerOne {};
75struct VectorSpecialInitializerIndexesFromZero {};
81constexpr VectorSpecialInitializerZero
Zero = {};
86constexpr VectorSpecialInitializerOne
One = {};
96template<
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)
120template <
typename T>
using MayAlias =
typename Detail::MayAliasImpl<T>::type;
122template <
class To,
class From> MayAlias<To> &aliasing_cast(From &x)
124 return *
reinterpret_cast<MayAlias<To> *
>(&x);
126template <
class To,
class From>
const MayAlias<To> &aliasing_cast(
const From &x)
128 return *
reinterpret_cast<const MayAlias<To> *
>(&x);
131template <
class To,
class From> MayAlias<To> *aliasing_cast(From *x)
133 return reinterpret_cast<MayAlias<To> *
>(x);
135template <
class To,
class From>
const MayAlias<To> *aliasing_cast(
const From *x)
137 return reinterpret_cast<const MayAlias<To> *
>(x);
146enum class Operator :
char {
188template <
typename T, std::
size_t N>
struct array;
191template <
typename T, std::ptrdiff_t N>
class span;
229#ifndef Vc_CHECK_ALIGNMENT
230template<
typename _T>
static Vc_ALWAYS_INLINE
void assertCorrectAlignment(
const _T *){}
232template<
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");
245template <
typename T, std::
size_t Pieces, std::
size_t Index>
struct Segment;
253template<
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)
296template <std::
size_t alignment>
297Vc_INTRINSIC_L
void *aligned_malloc(std::size_t n) Vc_INTRINSIC_R;
298Vc_ALWAYS_INLINE_L
void free(
void *p) Vc_ALWAYS_INLINE_R;
303template <
typename Mask,
typename T,
typename U>
304using 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)>;
312template <
typename T,
typename U>
313using 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))>;
322template <
typename T>
using WidthT = std::integral_constant<std::size_t,
sizeof(T)>;
325template <std::
size_t Bytes>
class MaskBool;
328template <
typename T,
typename IndexVector,
typename Scale,
bool>
329class SubscriptOperation;
338template <
class T,
class IndexVector,
int Scale = 1>
339struct 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;
345template <
int Scale,
class T,
class I>
346GatherArguments<T, I, Scale> make_gather(
const T *m,
const I &i)
358template <
typename T,
typename IndexVector>
struct ScatterArguments
360 const IndexVector indexes;
367template <
typename I, I Begin, I End,
typename F>
368Vc_INTRINSIC enable_if<(Begin >= End),
void> unrolled_loop(F &&)
377template <
typename I, I Begin, I End,
typename F>
378Vc_INTRINSIC Vc_FLATTEN enable_if<(Begin < End), void> unrolled_loop(F &&f)
381 unrolled_loop<I, Begin + 1, End>(f);
388template <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.
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
This is std::array with additional subscript operators supporting gather and scatter operations.