28 #ifndef VC_COMMON_VECTOR_H_
29 #define VC_COMMON_VECTOR_H_
32 #include "elementreference.h"
34 #include "vectorabi.h"
35 #include "vectortraits.h"
36 #include "simdarrayfwd.h"
37 #include "loadstoreflags.h"
38 #include "writemaskedvector.h"
41 namespace Vc_VERSIONED_NAMESPACE
54 template <
typename T,
typename Abi,
55 typename = enable_if<std::is_floating_point<T>::value &&
56 !detail::is_fixed_size_abi<Abi>::value>>
92 template <
typename T,
typename Abi,
93 typename = enable_if<std::is_floating_point<T>::value &&
94 !detail::is_fixed_size_abi<Abi>::value>>
104 template <
typename T,
typename Abi>
125 template<
typename T,
typename Abi = VectorAbi::Best<T>>
class Vector
142 static constexpr
size_t size() {
return VectorTraits<T, Abi>::size(); }
154 using EntryType =
typename VectorTraits<T, Abi>::EntryType;
158 using VectorEntryType =
typename VectorTraits<T, Abi>::VectorEntryType;
162 using VectorType =
typename VectorTraits<T, Abi>::VectorType;
166 using vector_type = VectorType;
181 using reference = Detail::ElementReference<Vector>;
237 explicit inline Vector(VectorSpecialInitializerZero);
244 explicit inline Vector(VectorSpecialInitializerOne);
251 explicit inline Vector(VectorSpecialInitializerIndexesFromZero);
259 template <
typename U>
261 enable_if<Traits::is_implicit_cast_allowed<U, T>::value> = nullarg);
274 template <
typename U>
275 Vc_DEPRECATED(
"use simd_cast instead of explicit type casting to convert between "
278 enable_if<!Traits::is_implicit_cast_allowed<U, T>::value> = nullarg);
289 template <
typename U>
290 inline Vector(U a, enable_if<std::is_same<U, int>::value &&
291 !std::is_same<U, EntryType>::value> = nullarg);
292 inline explicit Vector(reference a);
299 #include "../common/loadinterface.h"
300 #include "../common/storeinterface.h"
338 #define Vc_CURRENT_CLASS_NAME Vector
339 #include "../common/gatherinterface.h"
340 #include "../common/scatterinterface.h"
341 #undef Vc_CURRENT_CLASS_NAME
408 inline Vector &operator++();
409 inline Vector operator++(
int);
410 inline Vector &operator--();
411 inline Vector operator--(
int);
414 #define Vc_OP(symbol) \
415 inline Vc_PURE Vector operator symbol(const Vector &x) const;
442 Vc_ALL_ARITHMETICS(Vc_OP);
464 Vc_ALL_BINARY(Vc_OP);
485 Vc_ALL_SHIFTS(Vc_OP);
507 #define Vc_CMP_OP(symbol) inline Vc_PURE MaskType operator symbol(const Vector &x) const;
508 Vc_ALL_COMPARES(Vc_CMP_OP);
708 template <
typename F>
inline void call(F &&f)
const;
745 inline VectorType &data();
746 inline const VectorType &data()
const;
772 static constexpr
size_t Size = VectorTraits<T, Abi>::size();
781 template <typename V2> inline V2 staticCast() const;
790 template <typename V2>
792 reinterpretCast() const;
808 Vc_FREE_STORE_OPERATORS_ALIGNED(alignof(
Vector));
832 template <typename V, typename T, typename Abi>
833 Vc_ALWAYS_INLINE Vc_CONST enable_if<
834 (V::size() ==
Vector<T, Abi>::size() &&
835 sizeof(typename V::VectorEntryType) ==
836 sizeof(typename
Vector<T, Abi>::VectorEntryType) &&
837 sizeof(V) == sizeof(
Vector<T, Abi>) && alignof(V) <= alignof(
Vector<T, Abi>)),
841 return reinterpret_cast<const V &
>(x);
844 #define Vc_OP(symbol) \
845 template <typename T, typename Abi> \
846 inline Vector<T, Abi> &operator symbol##=(Vector<T, Abi> &, \
847 const Vector<T, Abi> &x);
The main SIMD mask class.
The main vector class for expressing data parallelism.
void setZeroInverted(MaskType mask)
Set all entries to zero where the mask is not set.
static constexpr size_t size()
Returns the number of scalar components ( ) in a vector of this type.
Vector operator~() const
Inverts all bits.
EntryType sum(MaskType mask) const
Returns the sum of the vector components selected by mask.
Vector apply(F &&f, MaskType mask) const
As above, but skip the entries where mask is not set.
void fill(EntryType(&f)())
Fill the vector with the values [f(), f(), f(), ...].
EntryType operator[](size_t index) const noexcept
This operator can be used to read scalar entries of the vector.
void setQnan(MaskType mask)
Set all entries to the bit representation of a QNaN where the mask is set.
void setQnan()
Set all entries to the bit representation of a QNaN.
void call(F &&f, MaskType mask) const
As above, but skip the entries where mask is not set.
void setZero()
Set all entries to zero.
static Vector IndexesFromZero()
Returns a vector with the entries initialized to 0, 1, 2, 3, 4, 5, ...
static Vector One()
Returns a vector with the entries initialized to one.
Vector(VectorSpecialInitializerZero)
Construct a vector with the entries initialized to zero.
EntryType sum() const
Returns the sum of all entries in the vector.
Vector operator+() const
Returns a copy of the vector object.
Vector operator-() const
Returns a new vector object with all entries negated.
Vector shifted(int amount) const
Shift vector entries to the left by amount; shifting in zeros.
EntryType product() const
Returns the product of all entries in the vector.
Common::WriteMaskedVector< Vector, MaskType > operator()(MaskType mask)
Writemask the vector before an assignment.
void call(F &&f) const
Call f with the scalar entries of the vector.
void callWithValuesSorted(F &&f)
Call f sequentially, starting with the minimum up to the maximum value.
Vector(EntryType a)
Broadcast Constructor.
void setZero(MaskType mask)
Set all entries to zero where the mask is set.
Vector apply(F &&f) const
Call f on every entry of the vector and return the results as a new vector.
void fill(EntryType(&f)(IndexT))
Fill the vector with the values [f(0), f(1), f(2), ...].
EntryType max() const
Returns the largest entry in the vector.
Vector(VectorSpecialInitializerIndexesFromZero)
Construct a vector with the entries initialized to 0, 1, 2, 3, 4, 5, ...
Vector rotated(int amount) const
Rotate vector entries to the left by amount.
static Vector generate(G gen)
Generate a vector object from return values of gen (static variant of fill).
static Vector Random()
Returns a vector with pseudo-random entries.
Vector(Vector< U, abi > x, enable_if< Traits::is_implicit_cast_allowed< U, T >::value >=nullarg)
Implict conversion from compatible Vector<U, Abi> types.
EntryType min() const
Returns the smallest entry in the vector.
Vector()=default
Construct a zero-initialized vector object.
Vector sorted() const
Return a sorted copy of the vector.
Abi abi
The ABI tag type of the current template instantiation.
Vector reversed() const
Returns a vector with all components reversed.
Vector(VectorSpecialInitializerOne)
Construct a vector with the entries initialized to one.
Vector partialSum() const
Returns a vector containing the sum of all entries with smaller index.
reference operator[](size_t index) noexcept
This operator can be used to modify scalar entries of the vector.
EntryType min(MaskType mask) const
Returns the smallest entry of the vector components selected by mask.
EntryType product(MaskType mask) const
Returns the product of the vector components selected by mask.
typename VectorTraits< T, Abi >::EntryType EntryType
The type of the entries in the vector.
EntryType value_type
The type of the entries in the vector.
MaskType operator!() const
Determine where the vector is null.
EntryType max(MaskType mask) const
Returns the largest entry of the vector components selected by mask.
static Vector Zero()
Returns a vector with the entries initialized to zero.
Vector shifted(int amount, Vector shiftIn) const
Shift vector entries to the left by amount; shifting in values from shiftIn (instead of zeros).
Vector< T, Abi > copysign(Vector< T, Abi > magnitude, Vector< T, Abi > sign)
Copies the sign(s) of sign to the value(s) in magnitude and returns the resulting vector.
Vector< T, detail::not_fixed_size_abi< Abi > >::MaskType isnegative(Vector< T, Abi > x)
Returns for each vector component whether it stores a negative value.
Vector< T, Abi > exponent(Vector< T, Abi > x)
Extracts the exponent of each floating-point vector component.
enable_if<(V::size()==Vector< T, Abi >::size() &&sizeof(typename V::VectorEntryType)==sizeof(typename Vector< T, Abi >::VectorEntryType) &&sizeof(V)==sizeof(Vector< T, Abi >) &&alignof(V)<=alignof(Vector< T, Abi >)), V > reinterpret_components_cast(const Vector< T, Abi > &x)
Constructs a new Vector object of type V from the Vector x, reinterpreting the bits of x for the new ...
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
constexpr std::size_t MemoryAlignment
Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector typ...
void assign(SimdizeDetail::Adapter< S, T, N > &a, size_t i, const S &x)
Assigns one scalar object x to a SIMD slot at offset i in the simdized object a.