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

Detailed Description

The vector classes abstract the SIMD registers and their according instructions into types that feel very familiar to C++ developers.

Note that the documented types Vc::float_v, Vc::double_v, Vc::int_v, Vc::uint_v, Vc::short_v, and Vc::ushort_v are actually typedefs of the Vc::Vector<T> class:

namespace Vc {
template<typename T> class Vector;
typedef Vector<double> double_v;
typedef Vector<float> float_v;
// ...
}
Vector< double > double_v
vector of double precision
Definition vector.h:52
Vector< float > float_v
vector of single precision
Definition vector.h:54
Vector Classes Namespace.
Definition dox.h:585
Some general information on using the vector classes:

Generally you can always mix scalar values with vectors as Vc will automatically broadcast the scalar to a vector and then execute a vector operation. But, in order to ensure that implicit type conversions only happen as defined by the C standard, there is only a very strict implicit scalar to vector constructor:

int_v a = 1; // good: int_v(int)
uint_v b = 1u; // good: uint_v(unsigned int)
uint_v c = 1; // does not compile: uint_v(int)
float_v d = 1; // does not compile: float_v(int)
float_v e = 1.; // does not compile: float_v(double)
float_v f = 1.f; // good: float_v(float)
Vector< uint > uint_v
vector of unsigned integers
Definition vector.h:58
Vector< int > int_v
vector of signed integers
Definition vector.h:56

The following ways of initializing a vector are not allowed:

int_v v(3, 2, 8, 0); // constructor does not exist because it is not portable
v[0] = 3; v[1] = 2; v[2] = 8; v[3] = 0; // do not hardcode the number of entries!
// You can not know whether somebody will compile with %Vc Scalar where int_v::Size == 1

Instead, if really necessary you can do:

for (int i = 0; i < int_v::Size; ++i) {
v[i] = f(i);
}
// which is equivalent to:
v.fill(f);
// or:
The main vector class for expressing data parallelism.
Definition vector.h:126
static Vector IndexesFromZero()
Returns a vector with the entries initialized to 0, 1, 2, 3, 4, 5, ...
Vector apply(F &&f) const
Call f on every entry of the vector and return the results as a new vector.
static constexpr size_t Size
Returns the number of scalar components ( ) in a vector of this type.
Definition vector.h:772
void fill(EntryType(&f)(IndexT))
Fill the vector with the values [f(0), f(1), f(2), ...].

Classes

class  Vector< T, Abi >
 The main vector class for expressing data parallelism. More...
 

Functions

template<typename T , typename Abi >
std::ostream & operator<< (std::ostream &out, const Vc::Vector< T, Abi > &v)
 Prints the contents of a vector into a stream object.
 
template<typename V , typename M , typename A >
void deinterleave (V *a, V *b, const M *memory, A align)
 

Variables

constexpr std::size_t VectorAlignment = alignof(VectorAlignedBase)
 Specifies the most conservative memory alignment necessary for Vector<T> objects with default VectorAbi.
 
constexpr std::size_t MemoryAlignment = alignof(MemoryAlignedBase)
 Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector types.
 

Vector Type Aliases

using double_v = Vector<double>
 vector of double precision
 
using float_v = Vector<float>
 vector of single precision
 
using int_v = Vector<int>
 vector of signed integers
 
using uint_v = Vector<uint>
 vector of unsigned integers
 
using short_v = Vector<short>
 vector of signed short integers
 
using ushort_v = Vector<ushort>
 vector of unsigned short integers
 

Function Documentation

◆ operator<<()

template<typename T , typename Abi >
std::ostream & operator<< ( std::ostream & out,
const Vc::Vector< T, Abi > & v )
inline

Prints the contents of a vector into a stream object.

std::cout << v << std::endl;
constexpr VectorSpecialInitializerIndexesFromZero IndexesFromZero
The special object Vc::IndexesFromZero can be used to construct Vector objects initialized to values ...
Definition types.h:91

will output (with SSE):

[0, 1, 2, 3]
Parameters
outAny standard C++ ostream object. For example std::cout or a std::stringstream object.
vAny Vc::Vector object.
Returns
The ostream object: to chain multiple stream operations.
Note
With the GNU standard library this function will check whether the output stream is a tty in which case it colorizes the output.

Definition at line 117 of file IO.

◆ deinterleave()

template<typename V , typename M , typename A >
void deinterleave ( V * a,
V * b,
const M * memory,
A align )
inline
Deprecated
Turn to InterleavedMemoryWrapper for a more flexible and complete solution.

Loads two vectors of values from an interleaved array.

Parameters
a,bThe vectors to load the values from memory into.
memoryThe memory location where to read the next 2 * V::Size values from
alignEither pass Vc::Aligned or Vc::Unaligned. It defaults to Vc::Aligned if nothing is specified.

If you store your data as

struct { float x, y; } m[1000];

then the deinterleave function allows you to read Size concurrent x and y values like this:

constexpr UnalignedTag Unaligned
Use this object for a flags parameter to request unaligned loads and stores.
void deinterleave(V *a, V *b, const M *memory, A align)

This code will load m[10], m[12], m[14], ... into x and m[11], m[13], m[15], ... into y.

The deinterleave function supports the following type combinations:

  V \  M | float | double | ushort | short | uint | int
=========|=======|========|========|=======|======|=====
 float_v |   X   |        |    X   |   X   |      |
---------|-------|--------|--------|-------|------|-----
double_v |       |    X   |        |       |      |
---------|-------|--------|--------|-------|------|-----
   int_v |       |        |        |   X   |      |  X
---------|-------|--------|--------|-------|------|-----
  uint_v |       |        |    X   |       |   X  |
---------|-------|--------|--------|-------|------|-----
 short_v |       |        |        |   X   |      |
---------|-------|--------|--------|-------|------|-----
ushort_v |       |        |    X   |       |      |

Definition at line 76 of file deinterleave.h.

Referenced by Vc::deinterleave().

Variable Documentation

◆ VectorAlignment

std::size_t VectorAlignment = alignof(VectorAlignedBase)
constexpr

Specifies the most conservative memory alignment necessary for Vector<T> objects with default VectorAbi.

Use this value e.g. with an alignas expression or when allocating aligned memory dynamically (Vc::malloc).

See also
Vc::MemoryAlignment
Vc::VectorAlignedBase

Definition at line 204 of file vector.h.

◆ MemoryAlignment

std::size_t MemoryAlignment = alignof(MemoryAlignedBase)
constexpr

Specifies the most conservative memory alignment necessary for aligned loads and stores of Vector types.

Use this value e.g. with an alignas expression or when allocating aligned memory dynamically (Vc::malloc).

See also
Vc::VectorAlignment
Vc::Vector<T, Abi>::MemoryAlignment

Definition at line 215 of file vector.h.

Referenced by SimdArray< T, N, V, Wt >::reversed(), and SimdArray< T, N, V, Wt >::rotated().