 |
Vc
1.4.1
SIMD Vector Classes for C++
|
|
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);
297 #include "../common/loadinterface.h"
299 #include "../common/storeinterface.h"
337 #define Vc_CURRENT_CLASS_NAME Vector
338 #include "../common/gatherinterface.h"
339 #include "../common/scatterinterface.h"
340 #undef Vc_CURRENT_CLASS_NAME
406 inline Vector &operator++();
408 inline Vector operator++(
int);
409 inline Vector &operator--();
410 inline Vector operator--(
int);
413 #define Vc_OP(symbol) \
414 inline Vc_PURE Vector operator symbol(const Vector &x) const;
440 Vc_ALL_ARITHMETICS(Vc_OP);
462 Vc_ALL_BINARY(Vc_OP);
483 Vc_ALL_SHIFTS(Vc_OP);
505 #define Vc_CMP_OP(symbol) inline Vc_PURE MaskType operator symbol(const Vector &x) const;
507 Vc_ALL_COMPARES(Vc_CMP_OP);
707 template <
typename F>
inline void call(F &&f)
const;
743 inline VectorType &data();
745 inline const VectorType &data()
const;
771 static constexpr
size_t Size = VectorTraits<T, Abi>::size();
780 template <typename V2> inline V2 staticCast() const;
789 template <typename V2>
791 reinterpretCast() const;
807 Vc_FREE_STORE_OPERATORS_ALIGNED(alignof(
Vector));
831 template <typename V, typename T, typename Abi>
832 Vc_ALWAYS_INLINE Vc_CONST enable_if<
833 (V::size() ==
Vector<T, Abi>::size() &&
834 sizeof(typename V::VectorEntryType) ==
835 sizeof(typename
Vector<T, Abi>::VectorEntryType) &&
836 sizeof(V) == sizeof(
Vector<T, Abi>) && alignof(V) <= alignof(
Vector<T, Abi>)),
840 return reinterpret_cast<const V &
>(x);
843 #define Vc_OP(symbol) \
844 template <typename T, typename Abi> \
845 inline Vector<T, Abi> &operator symbol##=(Vector<T, Abi> &, \
846 const Vector<T, Abi> &x);
854 #endif // VC_COMMON_VECTOR_H_
Vector operator-() const
Returns a new vector object with all entries negated.
static constexpr size_t size()
Returns the number of scalar components ( ) in a vector of this type.
reference operator[](size_t index) noexcept
This operator can be used to modify scalar entries of the vector.
Abi abi
The ABI tag type of the current template instantiation.
constexpr std::size_t MemoryAlignment
Vector(VectorSpecialInitializerIndexesFromZero)
Construct a vector with the entries initialized to 0, 1, 2, 3, 4, 5, ...
constexpr VectorSpecialInitializerZero Zero
The special object Vc::Zero can be used to construct Vector and Mask objects initialized to zero/fals...
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 product() const
Returns the product of all entries in the vector.
void setQnan()
Set all entries to the bit representation of a QNaN.
void call(F &&f) const
Call f with the scalar entries of the vector.
Vector(VectorSpecialInitializerZero)
Construct a vector with the entries initialized to zero.
Vector(VectorSpecialInitializerOne)
Construct a vector with the entries initialized to one.
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)
Vector< T, detail::not_fixed_size_abi< Abi > >::MaskType isnegative(Vector< T, Abi > x)
static Vector IndexesFromZero()
Returns a vector with the entries initialized to 0, 1, 2, 3, 4, 5, ...
Vector< T, Abi > exponent(Vector< T, Abi > x)
Vector apply(F &&f, MaskType mask) const
As above, but skip the entries where mask is not set.
void setQnan(MaskType mask)
Set all entries to the bit representation of a QNaN where the mask is set.
Vector partialSum() const
Returns a vector containing the sum of all entries with smaller index.
void fill(EntryType(&f)())
Fill the vector with the values [f(), f(), f(), ...].
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.
EntryType max() const
Returns the largest entry in the vector.
EntryType value_type
The type of the entries in the vector.
void fill(EntryType(&f)(IndexT))
Fill the vector with the values [f(0), f(1), f(2), ...].
static Vector Random()
Returns a vector with pseudo-random entries.
void callWithValuesSorted(F &&f)
Call f sequentially, starting with the minimum up to the maximum value.
Vector rotated(int amount) const
Rotate vector entries to the left by amount.
EntryType sum() const
Returns the sum of all entries in the vector.
Vector sorted() const
Return a sorted copy of the vector.
EntryType max(MaskType mask) const
Returns the largest entry of the vector components selected by mask.
EntryType sum(MaskType mask) const
Returns the sum of the vector components selected by mask.
Common::WriteMaskedVector< Vector, MaskType > operator()(MaskType mask)
Writemask the vector before an assignment.
MaskType operator!() const
Determine where the vector is null.
Vector()=default
Construct a zero-initialized vector object.
EntryType min() const
Returns the smallest entry in the vector.
Vector shifted(int amount, Vector shiftIn) const
Shift vector entries to the left by amount; shifting in values from shiftIn (instead of zeros).
void call(F &&f, MaskType mask) const
As above, but skip the entries where mask is not set.
static Vector generate(G gen)
Generate a vector object from return values of gen (static variant of fill).
Vector operator~() const
Inverts all bits.
Vector apply(F &&f) const
Call f on every entry of the vector and return the results as a new vector.
EntryType product(MaskType mask) const
Returns the product of the vector components selected by mask.
static Vector Zero()
Returns a vector with the entries initialized to zero.
EntryType operator[](size_t index) const noexcept
This operator can be used to read scalar entries of the vector.
EntryType min(MaskType mask) const
Returns the smallest entry of the vector components selected by mask.
typename VectorTraits< T, Abi >::EntryType EntryType
The type of the entries in the vector.
void setZeroInverted(MaskType mask)
Set all entries to zero where the mask is not set.
void setZero(MaskType mask)
Set all entries to zero where the mask is set.
Vector< T, Abi > copysign(Vector< T, Abi > magnitude, Vector< T, Abi > sign)
Vector reversed() const
Returns a vector with all components reversed.
Vector(EntryType a)
Broadcast Constructor.
Vector shifted(int amount) const
Shift vector entries to the left by amount; shifting in zeros.
static Vector One()
Returns a vector with the entries initialized to one.
void setZero()
Set all entries to zero.
Vector operator+() const
Returns a copy of the vector object.