Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
SIMD Array

Detailed Description

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:

using floatv = Vc::float_v;
using doublev = Vc::SimdArray<double, floatv::size()>;
using intv = Vc::SimdArray<int, floatv::size()>;
using uintv = Vc::SimdArray<unsigned int, floatv::size()>;
Data-parallel arithmetic type with user-defined number of elements.
Definition simdarray.h:617
Vector< float > float_v
vector of single precision
Definition vector.h:54

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.
 
static constexpr std::size_t Size = size()
 Returns the number of boolean components ( \(\mathcal{W}_\mathtt{T}\) ) in a mask of this type.
 
static constexpr std::size_t MemoryAlignment
 Specifies the alignment requirement for aligned load and store calls for objects of this mask type.
 

Arithmetic and Bitwise Operators

Applies the operator component-wise and concurrently on lhs and rhs and returns a new SimdArray object containing the result values.

This operator only participates in overload resolution if:

  • At least one of the template parameters L or R is a SimdArray type.
  • Either L or R is a fundamental arithmetic type but not an integral type larger than int
    or
    L or R is a Vc::Vector type with equal number of elements (Vector::size() == SimdArray::size()).

The return type of the operator is a SimdArray type using the more precise EntryType of L or R and the same number of elements as the SimdArray argument(s).

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 lhs and rhs and returns a new SimdMaskArray object containing the result values.

This operator only participates in overload resolution if (same rules as above):

  • At least one of the template parameters L or R is a SimdArray type.
  • Either L or R is a fundamental arithmetic type but not an integral type larger than int
    or
    L or R is a Vc::Vector type with equal number of elements (Vector::size() == SimdArray::size()).

The return type of the operator is a SimdMaskArray type using the more precise EntryType of L or R and the same number of elements as the SimdArray argument(s).

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

These functions evaluate the

template<typename T , std::size_t N, typename V , std::size_t M>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd_mask< T, N > 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>
fixed_size_simd_mask< T, N > 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>
fixed_size_simd_mask< T, N > 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>
fixed_size_simd_mask< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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>
fixed_size_simd< T, N > 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

fixed_size_simd< T, N > exponent () const
 Returns the exponents of the floating-point values in the vector.
 
MaskType isNegative () const
 Returns whether a value is negative.
 
fixed_size_simd< T, N > copySign (const SimdArray &x) const
 Copies the signs of the components of reference to the components of the current vector, returning the result.
 
static constexpr std::size_t Size = size()
 Returns N, the number of scalar components in an object of this type.
 

Function Documentation

◆ exponent()

template<typename T , size_t N, typename V , size_t Wt>
fixed_size_simd< T, N > exponent ( ) const
inline

Returns the exponents of the floating-point values in the vector.

Returns
A new vector object of the same type containing the exponents.
Deprecated
use Vc::exponent instead.

Definition at line 1432 of file simdarray.h.

◆ isNegative()

template<typename T , size_t N, typename V , size_t Wt>
MaskType isNegative ( ) const
inline

Returns whether a value is negative.

Returns
A new mask object indicating the sign of each vector element.
Deprecated
use Vc::isnegative instead.

Definition at line 1438 of file simdarray.h.

◆ copySign()

template<typename T , size_t N, typename V , size_t Wt>
fixed_size_simd< T, N > copySign ( const SimdArray< T, N, V, Wt > & x) const
inline

Copies the signs of the components of reference to the components of the current vector, returning the result.

Parameters
referenceA vector object that determines the sign of the the result.
Returns
A new vector with sign taken from reference and absolute value taken from the current vector object.
Deprecated
Use Vc::copysign instead.

Definition at line 1445 of file simdarray.h.

Variable Documentation

◆ Size [1/2]

template<typename T , std::size_t N, typename V , std::size_t M>
std::size_t Size = size()
staticconstexpr

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.

Returns
The number of scalar values stored and manipulated concurrently by objects of this type.
Deprecated
Use size() instead.

Definition at line 1428 of file simdarray.h.

◆ MemoryAlignment [1/2]

template<typename T , std::size_t N, typename V , std::size_t M>
std::size_t MemoryAlignment
staticconstexpr
Initial value:
=
storage_type0::MemoryAlignment > storage_type1::MemoryAlignment
? storage_type0::MemoryAlignment
: storage_type1::MemoryAlignment

Specifies the alignment requirement for aligned load and store calls for objects of this vector type.

Definition at line 692 of file simdarray.h.

◆ Size [2/2]

template<typename T , std::size_t N, typename V , std::size_t M>
std::size_t Size = size()
staticconstexpr

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).

Returns
The number of components (i.e. \(\mathcal{W}_\mathtt{T}\) ) objects of this mask type store and manipulate.
Deprecated
Use Vc::Mask::size instead.

Definition at line 346 of file simdmaskarray.h.

◆ MemoryAlignment [2/2]

template<typename T , std::size_t N, typename V , std::size_t M>
std::size_t MemoryAlignment
staticconstexpr
Initial value:
=
static constexpr size_t MemoryAlignment
Specifies the alignment requirement for aligned load and store calls for objects of this mask type.
Definition mask.h:66

Specifies the alignment requirement for aligned load and store calls for objects of this mask type.

Definition at line 348 of file simdmaskarray.h.