Vc  0.7.5-dev
SIMD Vector Classes for C++
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;
// ...
}
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)

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
int_v v;
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:
v = int_v::IndexesFromZero().apply(f);

Classes

class  Vector< T >
 The main SIMD vector class. More...
class  float_v
 SIMD Vector of single precision floats. More...
class  double_v
 SIMD Vector of double precision floats. More...
class  int_v
 SIMD Vector of 32 bit signed integers. More...
class  uint_v
 SIMD Vector of 32 bit unsigned integers. More...
class  short_v
 SIMD Vector of 16 bit signed integers. More...
class  ushort_v
 SIMD Vector of 16 bit unsigned integers. More...
class  sfloat_v
 SIMD Vector of single precision floats that is guaranteed to have as many entries as a Vc::short_v and Vc::ushort_v. More...

Enumerations

enum  PlatformConstants { VectorAlignment }
 Enum to declare platform specific constants. More...
enum  SpecialInitializer { Zero, One, IndexesFromZero }
 Enum to declare special initializers for vector constructors. More...
enum  LoadStoreFlags { Aligned, Unaligned, Streaming }
 Enum for load and store functions to select the optimizations that are safe to use. More...

Functions

template<typename T >
std::ostream & operator<< (std::ostream &s, const Vc::Vector< T > &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)

Enumeration Type Documentation

enum PlatformConstants

Enum to declare platform specific constants.

Enumerator:
VectorAlignment 

Specifies the byte boundary for memory alignments necessary for aligned loads and stores.

enum SpecialInitializer

Enum to declare special initializers for vector constructors.

Enumerator:
Zero 

Used for optimized construction of vectors initialized to zero.

One 

Used for optimized construction of vectors initialized to one.

IndexesFromZero 

Parameter to create a vector with the entries 0, 1, 2, 3, 4, 5, ...

(depending on the vector's size, of course).

enum LoadStoreFlags

Enum for load and store functions to select the optimizations that are safe to use.

Enumerator:
Aligned 

Tells Vc that the load/store can expect a memory address that is aligned on the correct boundary.

If you specify Aligned, but the memory address is not aligned the program will most likely crash.

Unaligned 

Tells Vc that the load/store can not expect a memory address that is aligned on the correct boundary.

If you specify Unaligned, but the memory address is aligned the load/store will execute slightly slower than necessary.

Streaming 

Tells Vc to bypass the cache for the load/store.

Whether this will actually be done depends on the instruction set in use.

Streaming stores can be interesting when the code calculates values that, after being written to memory, will not be used for a long time or used by a different thread.

Note
Passing Streaming as only alignment flag implies Aligned! If you need unaligned memory access you can use

Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const Vc::Vector< T > &  v 
)

Prints the contents of a vector into a stream object.

std::cout << v << std::endl;

will output (with SSE):

[0, 1, 2, 3]
Parameters
sAny 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 that case it will colorize the output.
void Vc::deinterleave ( V *  a,
V *  b,
const M *  memory,
align 
)
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:

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   |      |
---------|-------|--------|--------|-------|------|-----
sfloat_v |   X   |        |    X   |   X   |      |
---------|-------|--------|--------|-------|------|-----
double_v |       |    X   |        |       |      |
---------|-------|--------|--------|-------|------|-----
   int_v |       |        |        |   X   |      |  X
---------|-------|--------|--------|-------|------|-----
  uint_v |       |        |    X   |       |   X  |
---------|-------|--------|--------|-------|------|-----
 short_v |       |        |        |   X   |      |
---------|-------|--------|--------|-------|------|-----
ushort_v |       |        |    X   |       |      |