ROOT  6.06/09
Reference Guide
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Friends | List of all members
ROOT::Vc::Memory< V, Size, 0u > Class Template Reference

template<typename V, size_t Size>
class ROOT::Vc::Memory< V, Size, 0u >

A helper class to simplify usage of correctly aligned and padded memory, allowing both vector and scalar access.

Example:

// scalar access:
for (size_t i = 0; i < array.entriesCount(); ++i) {
int x = array[i]; // read
array[i] = x; // write
}
// more explicit alternative:
for (size_t i = 0; i < array.entriesCount(); ++i) {
int x = array.scalar(i); // read
array.scalar(i) = x; // write
}
// vector access:
for (size_t i = 0; i < array.vectorsCount(); ++i) {
int_v x = array.vector(i); // read
array.vector(i) = x; // write
}

This code allocates a small array and implements three equivalent loops (that do nothing useful). The loops show how scalar and vector read/write access is best implemented.

Since the size of 11 is not a multiple of int_v::Size (unless you use the scalar Vc implementation) the last write access of the vector loop would normally be out of bounds. But the Memory class automatically pads the memory such that the whole array can be accessed with correctly aligned memory addresses.

Parameters
VThe vector type you want to operate on. (e.g. float_v or uint_v)
SizeThe number of entries of the scalar base type the memory should hold. This is thus the same number as you would use for a normal C array (e.g. float mem[11] becomes Memory<float_v, 11> mem).
See also
Memory<V, 0u>

Definition at line 254 of file memory.h.

Public Types

enum  Constants { EntriesCount = Size, VectorsCount = PaddedSize / V::Size }
 
typedef V::EntryType EntryType
 
- Public Types inherited from ROOT::Vc::MemoryBase< V, Memory< V, Size, 0u >, 1, void >
typedef V::EntryType EntryType
 The type of the scalar entries in the array. More...
 

Public Member Functions

_VC_CONSTEXPR size_t entriesCount () const
 
_VC_CONSTEXPR size_t vectorsCount () const
 
Vc_ALWAYS_INLINE Memory ()
 
 Memory (const Memory &rhs)
 
template<size_t S>
 Memory (const Memory< V, S > &rhs)
 
Memoryoperator= (const Memory &rhs)
 
template<size_t S>
Memoryoperator= (const Memory< V, S > &rhs)
 
Vc_ALWAYS_INLINE Memoryoperator= (const EntryType *rhs)
 
Memoryoperator= (const V &v)
 
- Public Member Functions inherited from ROOT::Vc::MemoryBase< V, Memory< V, Size, 0u >, 1, void >
Vc_ALWAYS_INLINE Vc_PURE size_t entriesCount () const
 
Vc_ALWAYS_INLINE Vc_PURE size_t vectorsCount () const
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlagvector (size_t i)
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, AlignedFlagvector (size_t i) const
 Const overload of the above function. More...
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, UnalignedFlagvector (size_t i, int shift)
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, UnalignedFlagvector (size_t i, int shift) const
 Const overload of the above function. More...
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, A > vectorAt (size_t i, A)
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, A > vectorAt (size_t i, A) const
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlagvectorAt (size_t i)
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, AlignedFlagvectorAt (size_t i) const
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlagfirstVector ()
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, AlignedFlagfirstVector () const
 Const overload of the above function. More...
 
Vc_ALWAYS_INLINE Vc_PURE VectorPointerHelper< V, AlignedFlaglastVector ()
 
Vc_ALWAYS_INLINE Vc_PURE const VectorPointerHelperConst< V, AlignedFlaglastVector () const
 Const overload of the above function. More...
 
Vc_ALWAYS_INLINE Vc_PUREgather (const unsigned char *indexes) const
 
Vc_ALWAYS_INLINE Vc_PUREgather (const unsigned short *indexes) const
 
Vc_ALWAYS_INLINE Vc_PUREgather (const unsigned int *indexes) const
 
Vc_ALWAYS_INLINE Vc_PUREgather (const unsigned long *indexes) const
 
Vc_ALWAYS_INLINE void setZero ()
 
Memory< V, Size, 0u > & operator+= (const MemoryBase< V, P2, Dimension, RM > &rhs)
 
Memory< V, Size, 0u > & operator+= (EntryType rhs)
 
Memory< V, Size, 0u > & operator-= (const MemoryBase< V, P2, Dimension, RM > &rhs)
 
Memory< V, Size, 0u > & operator-= (EntryType rhs)
 
Memory< V, Size, 0u > & operator*= (const MemoryBase< V, P2, Dimension, RM > &rhs)
 
Memory< V, Size, 0u > & operator*= (EntryType rhs)
 
Memory< V, Size, 0u > & operator/= (const MemoryBase< V, P2, Dimension, RM > &rhs)
 
Memory< V, Size, 0u > & operator/= (EntryType rhs)
 
bool operator== (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 
bool operator!= (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 
bool operator< (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 
bool operator<= (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 
bool operator> (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 
bool operator>= (const MemoryBase< V, P2, Dimension, RM > &rhs) const
 

Static Public Member Functions

static Vc_ALWAYS_INLINE Vc_CONST Memory< V, Size, 0u > & fromRawData (EntryType *ptr)
 Wrap existing data with the Memory convenience class. More...
 

Private Types

enum  InternalConstants {
  Alignment = V::Size, AlignmentMask = Alignment - 1, MaskedSize = Size & AlignmentMask, Padding = Alignment - MaskedSize,
  PaddedSize = MaskedSize == 0 ? Size : Size + Padding
}
 
typedef MemoryBase< V, Memory< V, Size, 0u >, 1, void > Base
 

Private Attributes

EntryType m_mem [PaddedSize]
 

Friends

class MemoryBase< V, Memory< V, Size, 0u >, 1, void >
 
class MemoryDimensionBase< V, Memory< V, Size, 0u >, 1, void >
 

#include <Vc/Memory>

+ Inheritance diagram for ROOT::Vc::Memory< V, Size, 0u >:
+ Collaboration diagram for ROOT::Vc::Memory< V, Size, 0u >:

Member Typedef Documentation

template<typename V , size_t Size>
typedef MemoryBase<V, Memory<V, Size, 0u>, 1, void> ROOT::Vc::Memory< V, Size, 0u >::Base
private

Definition at line 259 of file memory.h.

template<typename V , size_t Size>
typedef V::EntryType ROOT::Vc::Memory< V, Size, 0u >::EntryType

Definition at line 257 of file memory.h.

Member Enumeration Documentation

template<typename V , size_t Size>
enum ROOT::Vc::Memory< V, Size, 0u >::Constants
Enumerator
EntriesCount 
VectorsCount 

Definition at line 282 of file memory.h.

template<typename V , size_t Size>
enum ROOT::Vc::Memory< V, Size, 0u >::InternalConstants
private
Enumerator
Alignment 
AlignmentMask 
MaskedSize 
Padding 
PaddedSize 

Definition at line 262 of file memory.h.

Constructor & Destructor Documentation

template<typename V , size_t Size>
Vc_ALWAYS_INLINE ROOT::Vc::Memory< V, Size, 0u >::Memory ( )
inline

Definition at line 337 of file memory.h.

template<typename V , size_t Size>
ROOT::Vc::Memory< V, Size, 0u >::Memory ( const Memory< V, Size, 0u > &  rhs)
inline

Definition at line 340 of file memory.h.

template<typename V , size_t Size>
template<size_t S>
ROOT::Vc::Memory< V, Size, 0u >::Memory ( const Memory< V, S > &  rhs)
inline

Definition at line 345 of file memory.h.

Member Function Documentation

template<typename V , size_t Size>
_VC_CONSTEXPR size_t ROOT::Vc::Memory< V, Size, 0u >::entriesCount ( ) const
inline
Returns
the number of scalar entries in the whole array.
Note
This function can be optimized into a compile-time constant.

Definition at line 325 of file memory.h.

template<typename V , size_t Size>
static Vc_ALWAYS_INLINE Vc_CONST Memory<V, Size, 0u>& ROOT::Vc::Memory< V, Size, 0u >::fromRawData ( EntryType ptr)
inlinestatic

Wrap existing data with the Memory convenience class.

This function returns a reference to a Memory<V, Size, 0> object that you must capture to avoid a copy of the whole data:

Memory<float_v, 16> &m = Memory<float_v, 16>::fromRawData(someAlignedPointerToFloat)
Parameters
ptrAn aligned pointer to memory of type V::EntryType (e.g. float for Vc::float_v).
Returns
A Memory object placed at the given location in memory.
Warning
The pointer ptr passed to this function must be aligned according to the alignment restrictions of V.
The size of the accessible memory must match Size. This includes the required padding at the end to allow the last entries to be accessed via vectors. If you know what you are doing you might violate this constraint.
It is your responsibility to ensure that the memory is released correctly (not too early/not leaked). This function simply adds convenience functions to access the memory.

Definition at line 309 of file memory.h.

template<typename V , size_t Size>
Memory& ROOT::Vc::Memory< V, Size, 0u >::operator= ( const Memory< V, Size, 0u > &  rhs)
inline

Definition at line 351 of file memory.h.

template<typename V , size_t Size>
template<size_t S>
Memory& ROOT::Vc::Memory< V, Size, 0u >::operator= ( const Memory< V, S > &  rhs)
inline

Definition at line 357 of file memory.h.

template<typename V , size_t Size>
Vc_ALWAYS_INLINE Memory& ROOT::Vc::Memory< V, Size, 0u >::operator= ( const EntryType rhs)
inline

Definition at line 364 of file memory.h.

template<typename V , size_t Size>
Memory& ROOT::Vc::Memory< V, Size, 0u >::operator= ( const V &  v)
inline

Definition at line 368 of file memory.h.

template<typename V , size_t Size>
_VC_CONSTEXPR size_t ROOT::Vc::Memory< V, Size, 0u >::vectorsCount ( ) const
inline
Returns
the number of vectors in the whole array.
Note
This function can be optimized into a compile-time constant.

Definition at line 332 of file memory.h.

Friends And Related Function Documentation

template<typename V , size_t Size>
friend class MemoryBase< V, Memory< V, Size, 0u >, 1, void >
friend

Definition at line 260 of file memory.h.

template<typename V , size_t Size>
friend class MemoryDimensionBase< V, Memory< V, Size, 0u >, 1, void >
friend

Definition at line 261 of file memory.h.

Member Data Documentation

template<typename V , size_t Size>
EntryType ROOT::Vc::Memory< V, Size, 0u >::m_mem[PaddedSize]
private

Definition at line 279 of file memory.h.


The documentation for this class was generated from the following file: