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 GCC diagnostic push
99#pragma GCC diagnostic ignored "-Wattributes"
101 typedef T type Vc_MAY_ALIAS;
103#pragma GCC diagnostic pop
115template <
typename T>
using MayAlias [[gnu::may_alias]] = T;
117template <
typename T>
using MayAlias =
typename Detail::MayAliasImpl<T>::type;
120template <
class To,
class From> MayAlias<To> &aliasing_cast(From &x)
122 return *
reinterpret_cast<MayAlias<To> *
>(&x);
124template <
class To,
class From>
const MayAlias<To> &aliasing_cast(
const From &x)
126 return *
reinterpret_cast<const MayAlias<To> *
>(&x);
129template <
class To,
class From> MayAlias<To> *aliasing_cast(From *x)
131 return reinterpret_cast<MayAlias<To> *
>(x);
133template <
class To,
class From>
const MayAlias<To> *aliasing_cast(
const From *x)
135 return reinterpret_cast<const MayAlias<To> *
>(x);
144enum class Operator :
char {
186template <
typename T, std::
size_t N>
struct array;
189template <
typename T, std::ptrdiff_t N>
class span;
227#ifndef Vc_CHECK_ALIGNMENT
228template<
typename _T>
static Vc_ALWAYS_INLINE
void assertCorrectAlignment(
const _T *){}
230template<
typename _T>
static Vc_ALWAYS_INLINE
void assertCorrectAlignment(
const _T *ptr)
232 const size_t s =
alignof(_T);
233 if((
reinterpret_cast<size_t>(ptr) & ((s ^ (s & (s - 1))) - 1)) != 0) {
234 fprintf(stderr,
"A vector with incorrect alignment has just been created. Look at the stacktrace to find the guilty object.\n");
243template <
typename T, std::
size_t Pieces, std::
size_t Index>
struct Segment;
251template<
size_t StructSize>
class SuccessiveEntries
256 using size_type = unsigned;
258 using size_type = size_t;
260 const size_type m_first;
263 typedef SuccessiveEntries AsArg;
264 Vc_INTRINSIC SuccessiveEntries(size_type first) : m_first(first) {}
265 Vc_INTRINSIC Vc_PURE size_type operator[](size_type offset)
const
267 return m_first + offset * StructSize;
269 Vc_INTRINSIC Vc_PURE size_type data()
const {
return m_first; }
270 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator+(
const SuccessiveEntries &rhs)
const
272 return SuccessiveEntries(m_first + rhs.m_first);
274 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator*(
const SuccessiveEntries &rhs)
const
276 return SuccessiveEntries(m_first * rhs.m_first);
278 Vc_INTRINSIC Vc_PURE SuccessiveEntries
operator<<(size_type x)
const
280 return {m_first << x};
283 friend Vc_INTRINSIC SuccessiveEntries &internal_data(SuccessiveEntries &x)
287 friend Vc_INTRINSIC
const SuccessiveEntries &internal_data(
const SuccessiveEntries &x)
294template <std::
size_t alignment>
295Vc_INTRINSIC_L
void *aligned_malloc(std::size_t n) Vc_INTRINSIC_R;
296Vc_ALWAYS_INLINE_L
void free(
void *p) Vc_ALWAYS_INLINE_R;
301template <
typename Mask,
typename T,
typename U>
302using enable_if_mask_converts_implicitly =
303 enable_if<(!std::is_same<Mask, Traits::decay<U>>::value &&
304 Traits::is_simd_mask<U>::value && !Traits::isSimdMaskArray<U>::value &&
305 Traits::is_implicit_cast_allowed_mask<
306 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value)>;
310template <
typename T,
typename U>
311using enable_if_mask_converts_explicitly = enable_if<(
312 Traits::isSimdMaskArray<U>::value ||
313 (Traits::is_simd_mask<U>::value &&
314 !Traits::is_implicit_cast_allowed_mask<
315 Traits::entry_type_of<typename Traits::decay<U>::Vector>, T>::value))>;
320template <
typename T>
using WidthT = std::integral_constant<std::size_t,
sizeof(T)>;
323template <std::
size_t Bytes>
class MaskBool;
326template <
typename T,
typename IndexVector,
typename Scale,
bool>
327class SubscriptOperation;
336template <
class T,
class IndexVector,
int Scale = 1>
337struct GatherArguments {
338 static_assert(std::is_same<T, remove_cvref_t<T>>::value && !std::is_pointer<T>::value,
339 "GatherArguments expects an cv unqualified non-ref/ptr type");
340 const IndexVector indexes;
341 const T *
const address;
343template <
int Scale,
class T,
class I>
344GatherArguments<T, I, Scale> make_gather(
const T *m,
const I &i)
356template <
typename T,
typename IndexVector>
struct ScatterArguments
358 const IndexVector indexes;
365template <
typename I, I Begin, I End,
typename F>
366Vc_INTRINSIC enable_if<(Begin >= End),
void> unrolled_loop(F &&)
375template <
typename I, I Begin, I End,
typename F>
376Vc_INTRINSIC Vc_FLATTEN enable_if<(Begin < End), void> unrolled_loop(F &&f)
379 unrolled_loop<I, Begin + 1, End>(f);
386template <std::
size_t Size,
typename F> Vc_INTRINSIC
void for_all_vector_entries(F &&f)
388 unrolled_loop<std::size_t, 0u, Size>(std::forward<F>(f));
396#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.