Vc
1.3.2-dev
SIMD Vector Classes for C++
|
|
This set of class templates and associated functions and operators enables data-parallel algorithms and data structures requiring a user-defined number of elements (fixed at compile time, in contrast to std::valarray
where the number of elements is only determined at run time). The main motivation for a user-defined number of elements is the need for type conversion and thus a guaranteed equal number of elements in data-parallel vectors for e.g. float
and int
. A typical pattern looks like this:
The second motivation for a user-defined number of elements is that many vertical vectorizations require a fixed number of elements (i.e. number known at development time and not chosen at compile time). The implementation can then choose how to support this number most efficiently with the available hardware resources. Consider, for example, a need for processing 12 values in parallel. On x86 with AVX, the implementation could build such a type from one AVX and one SSE register.
In contrast to std::array
the types behave like the Vc::Vector types, implementing the same operators and functions. The semantics with regard to implicit conversions differ slightly: The Vc::Vector conversion rules are safer with regard to source compatibility. The Vc::SimdArray conversion rules are less strict and could potentially lead to portability issues. Therefore, it is best to stick to the pattern of type aliases shown above.
Classes | |
class | SimdArray< T, N, V, Wt > |
Data-parallel arithmetic type with user-defined number of elements. More... | |
class | SimdMaskArray< T, N, V, Wt > |
Data-parallel mask type with user-defined number of boolean elements. More... | |
Variables | |
static constexpr std::size_t | MemoryAlignment |
Specifies the alignment requirement for aligned load and store calls for objects of this vector type. More... | |
static constexpr std::size_t | Size = size() |
Returns the number of boolean components ( \(\mathcal{W}_\mathtt{T}\)) in a mask of this type. More... | |
static constexpr std::size_t | MemoryAlignment |
Specifies the alignment requirement for aligned load and store calls for objects of this mask type. More... | |
Arithmetic and Bitwise Operators | |
Applies the operator component-wise and concurrently on This operator only participates in overload resolution if:
The return type of the operator is a SimdArray type using the more precise EntryType of | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator+ (L &&lhs, R &&rhs) |
Applies + component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator- (L &&lhs, R &&rhs) |
Applies - component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator* (L &&lhs, R &&rhs) |
Applies * component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator/ (L &&lhs, R &&rhs) |
Applies / component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator% (L &&lhs, R &&rhs) |
Applies % component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator| (L &&lhs, R &&rhs) |
Applies | component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator& (L &&lhs, R &&rhs) |
Applies & component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R > | operator^ (L &&lhs, R &&rhs) |
Applies ^ component-wise and concurrently. | |
Compare Operators | |
Applies the operator component-wise and concurrently on This operator only participates in overload resolution if (same rules as above):
The return type of the operator is a SimdMaskArray type using the more precise EntryType of | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator== (L &&lhs, R &&rhs) |
Applies == component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator!= (L &&lhs, R &&rhs) |
Applies != component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator<= (L &&lhs, R &&rhs) |
Applies <= component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator>= (L &&lhs, R &&rhs) |
Applies >= component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator< (L &&lhs, R &&rhs) |
Applies < component-wise and concurrently. | |
template<typename L , typename R > | |
result_vector_type< L, R >::mask_type | operator> (L &&lhs, R &&rhs) |
Applies > component-wise and concurrently. | |
Math functions | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | abs (const SimdArray< T, N, V, M > &x) |
Applies the std:: abs function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | asin (const SimdArray< T, N, V, M > &x) |
Applies the std:: asin function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | atan (const SimdArray< T, N, V, M > &x) |
Applies the std:: atan function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | atan2 (const SimdArray< T, N, V, M > &x, const SimdArray< T, N, V, M > &y) |
Applies the std:: atan2 function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | ceil (const SimdArray< T, N, V, M > &x) |
Applies the std:: ceil function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | copysign (const SimdArray< T, N, V, M > &x, const SimdArray< T, N, V, M > &y) |
Applies the std:: copysign function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | cos (const SimdArray< T, N, V, M > &x) |
Applies the std:: cos function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | exp (const SimdArray< T, N, V, M > &x) |
Applies the std:: exp function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | exponent (const SimdArray< T, N, V, M > &x) |
Applies the std:: exponent function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | floor (const SimdArray< T, N, V, M > &x) |
Applies the std:: floor function component-wise and concurrently. | |
template<typename T , std::size_t N> | |
SimdArray< T, N > | fma (const SimdArray< T, N > &a, const SimdArray< T, N > &b, const SimdArray< T, N > &c) |
Applies the std::fma function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdMaskArray< T, N, V, M > | isfinite (const SimdArray< T, N, V, M > &x) |
Applies the std:: isfinite function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdMaskArray< T, N, V, M > | isinf (const SimdArray< T, N, V, M > &x) |
Applies the std:: isinf function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdMaskArray< T, N, V, M > | isnan (const SimdArray< T, N, V, M > &x) |
Applies the std:: isnan function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdMaskArray< T, N, V, M > | isnegative (const SimdArray< T, N, V, M > &x) |
Applies the std:: isnegative function component-wise and concurrently. | |
template<typename T , std::size_t N> | |
SimdArray< T, N > | frexp (const SimdArray< T, N > &x, SimdArray< int, N > *e) |
Applies the std::frexp function component-wise and concurrently. | |
template<typename T , std::size_t N> | |
SimdArray< T, N > | ldexp (const SimdArray< T, N > &x, const SimdArray< int, N > &e) |
Applies the std::ldexp function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | log (const SimdArray< T, N, V, M > &x) |
Applies the std:: log function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | log10 (const SimdArray< T, N, V, M > &x) |
Applies the std:: log10 function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | log2 (const SimdArray< T, N, V, M > &x) |
Applies the std:: log2 function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | reciprocal (const SimdArray< T, N, V, M > &x) |
Applies the std:: reciprocal function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | round (const SimdArray< T, N, V, M > &x) |
Applies the std:: round function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | rsqrt (const SimdArray< T, N, V, M > &x) |
Applies the std:: rsqrt function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | sin (const SimdArray< T, N, V, M > &x) |
Applies the std:: sin function component-wise and concurrently. | |
template<typename T , std::size_t N> | |
void | sincos (const SimdArray< T, N > &x, SimdArray< T, N > *sin, SimdArray< T, N > *cos) |
Determines sine and cosine concurrently and component-wise on x . | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | sqrt (const SimdArray< T, N, V, M > &x) |
Applies the std:: sqrt function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | trunc (const SimdArray< T, N, V, M > &x) |
Applies the std:: trunc function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | min (const SimdArray< T, N, V, M > &x, const SimdArray< T, N, V, M > &y) |
Applies the std:: min function component-wise and concurrently. | |
template<typename T , std::size_t N, typename V , std::size_t M> | |
SimdArray< T, N, V, M > | max (const SimdArray< T, N, V, M > &x, const SimdArray< T, N, V, M > &y) |
Applies the std:: max function component-wise and concurrently. | |
Deprecated Members | |
static constexpr std::size_t | Size = size() |
Returns N , the number of scalar components in an object of this type. More... | |
template<typename S1 , typename IT > | |
SimdArray (const S1 *array, const EntryType S1::*member1, IT indexes) | |
template<typename S1 , typename IT > | |
SimdArray (const S1 *array, const EntryType S1::*member1, IT indexes, MaskArgument mask) | |
template<typename S1 , typename S2 , typename IT > | |
SimdArray (const S1 *array, const S2 S1::*member1, const EntryType S2::*member2, IT indexes) | |
template<typename S1 , typename S2 , typename IT > | |
SimdArray (const S1 *array, const S2 S1::*member1, const EntryType S2::*member2, IT indexes, MaskArgument mask) | |
template<typename S1 , typename IT1 , typename IT2 > | |
SimdArray (const S1 *array, const EntryType *const S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes) | |
template<typename S1 , typename IT1 , typename IT2 > | |
SimdArray (const S1 *array, const EntryType *const S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes, MaskArgument mask) | |
template<typename S1 , typename IT > | |
void | gather (const S1 *array, const EntryType S1::*member1, IT indexes) |
template<typename S1 , typename IT > | |
void | gather (const S1 *array, const EntryType S1::*member1, IT indexes, MaskArgument mask) |
template<typename S1 , typename S2 , typename IT > | |
void | gather (const S1 *array, const S2 S1::*member1, const EntryType S2::*member2, IT indexes) |
template<typename S1 , typename S2 , typename IT > | |
void | gather (const S1 *array, const S2 S1::*member1, const EntryType S2::*member2, IT indexes, MaskArgument mask) |
template<typename S1 , typename IT1 , typename IT2 > | |
void | gather (const S1 *array, const EntryType *const S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes) |
template<typename S1 , typename IT1 , typename IT2 > | |
void | gather (const S1 *array, const EntryType *const S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes, MaskArgument mask) |
template<typename S1 , typename IT > | |
void | scatter (S1 *array, EntryType S1::*member1, IT indexes) const |
template<typename S1 , typename IT > | |
void | scatter (S1 *array, EntryType S1::*member1, IT indexes, MaskArgument mask) const |
template<typename S1 , typename S2 , typename IT > | |
void | scatter (S1 *array, S2 S1::*member1, EntryType S2::*member2, IT indexes) const |
template<typename S1 , typename S2 , typename IT > | |
void | scatter (S1 *array, S2 S1::*member1, EntryType S2::*member2, IT indexes, MaskArgument mask) const |
template<typename S1 , typename IT1 , typename IT2 > | |
void | scatter (S1 *array, EntryType *S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes) const |
template<typename S1 , typename IT1 , typename IT2 > | |
void | scatter (S1 *array, EntryType *S1::*ptrMember1, IT1 outerIndexes, IT2 innerIndexes, MaskArgument mask) const |
SimdArray | exponent () const |
Returns the exponents of the floating-point values in the vector. More... | |
MaskType | isNegative () const |
Returns whether a value is negative. More... | |
SimdArray | copySign (const SimdArray &reference) const |
Copies the signs of the components of reference to the components of the current vector, returning the result. More... | |
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 236 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 260 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 286 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 313 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes |
Definition at line 338 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes | |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 362 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 387 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 410 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 437 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 462 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes |
Definition at line 485 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes | |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 508 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 133 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 156 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
Definition at line 181 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
member1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
member2 | If member1 is a struct then member2 selects the member to be read from that struct (i.e. array[i].*member1.*member2 is read). |
indexes | Determines the offsets into array where the values are gathered from/scattered to. The type of indexes can either be an integer vector or a type that supports operator[] access. |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 207 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes |
Definition at line 230 of file simdarray.h.
|
inline |
array | A pointer into memory (without alignment restrictions). |
ptrMember1 | If array points to a struct, member1 determines the member in the struct to be read. Thus the offsets in indexes are relative to the array and not to the size of the gathered type (i.e. array[i].*member1 is accessed instead of (&(array->*member1))[i]) |
outerIndexes | |
innerIndexes | |
mask | If a mask is given only the active entries will be gathered/scattered. |
Definition at line 253 of file simdarray.h.
|
inline |
Returns the exponents of the floating-point values in the vector.
Definition at line 1363 of file simdarray.h.
|
inline |
Returns whether a value is negative.
Definition at line 1369 of file simdarray.h.
|
inline |
Copies the signs of the components of reference
to the components of the current vector, returning the result.
reference | A vector object that determines the sign of the the result. |
reference
and absolute value taken from the current vector object.Definition at line 1376 of file simdarray.h.
|
static |
Returns N
, the number of scalar components in an object of this type.
The size of the SimdArray, i.e. the number of scalar elements in the vector. In contrast to Vector::size() you have control over this value via the N
template parameter of the SimdArray class template.
Definition at line 1360 of file simdarray.h.
|
static |
Specifies the alignment requirement for aligned load and store calls for objects of this vector type.
Definition at line 635 of file simdarray.h.
|
static |
Returns the number of boolean components ( \(\mathcal{W}_\mathtt{T}\)) in a mask of this type.
The size of the mask. I.e. the number of boolean entries in the mask. Do not make any assumptions about the size of masks.
In addition, you can easily use if clauses that compare sizes. The compiler can statically evaluate and fully optimize dead code away (very much like #ifdef, but with syntax checking).
Definition at line 328 of file simdmaskarray.h.
|
static |
Specifies the alignment requirement for aligned load and store calls for objects of this mask type.
Definition at line 330 of file simdmaskarray.h.