Vc  1.4.1
SIMD Vector Classes for C++
SimdMaskArray< T, N, V, Wt > Class Template Reference

Detailed Description

template<typename T, size_t N, typename V, size_t Wt>
class Vc::SimdMaskArray< T, N, V, Wt >

Data-parallel mask type with user-defined number of boolean elements.

Template Parameters
TThe value type of the corresponding SimdArray. Depending on the target platform this type determines a different bit representation to work most efficient with SimdArray types instantiated for T.
NThe number of boolean elements to store and process concurrently. You can choose an arbitrary number, though not every number is a good idea. Generally, a power of two value or the sum of two power of two values might work efficiently, though this depends a lot on the target system.
VDon't change the default value unless you really know what you are doing. This type is set to the underlying native Vc::Vector type used in the implementation of the type. Having it as part of the type name guards against some cases of ODR violations (i.e. linking incompatible translation units / libraries).
WtDon't ever change the default value. This parameter is an unfortunate implementation detail shining through.

Definition at line 86 of file fwddecl.h.

#include <Vc/SimdArray>

Public Types

using value_type = typename storage_type0::EntryType
 The EntryType of masks is always bool, independent of T. More...
 
using MaskType = mask_type
 Construct a zero-initialized vector object. More...
 
using VectorEntryType = vectorentry_type
 The VectorEntryType, in contrast to EntryType, reveals information about the SIMD implementation. More...
 
using EntryType = value_type
 The EntryType of masks is always bool, independent of T. More...
 
using EntryReference = Vc::Detail::ElementReference< SimdMaskArray >
 The reference wrapper type used for accessing individual mask components. More...
 
using Vector = fixed_size_simd< T, N >
 An alias for the corresponding SimdArray type.
 

Public Member Functions

 SimdMaskArray ()=default
 Construct a zero-initialized vector object. More...
 
 SimdMaskArray (VectorSpecialInitializerOne one)
 Initialize the new mask object to one (true).
 
 SimdMaskArray (VectorSpecialInitializerZero zero)
 Zero-initialize the new mask object (false).
 
 SimdMaskArray (bool b)
 Broadcast constructor. More...
 
bool operator== (const SimdMaskArray &mask) const
 Returns whether the two masks are equal in all components. More...
 
bool operator!= (const SimdMaskArray &mask) const
 Returns whether the two masks are different in at least one component. More...
 
fixed_size_simd_mask< T, N > operator! () const
 Returns a mask with inverted components.
 
SimdMaskArrayoperator &= (const SimdMaskArray &rhs)
 
SimdMaskArrayoperator|= (const SimdMaskArray &rhs)
 Modifies the mask using an OR operation with mask.
 
SimdMaskArrayoperator^= (const SimdMaskArray &rhs)
 Modifies the mask using an XOR operation with mask.
 
fixed_size_simd_mask< T, N > operator & (const SimdMaskArray &rhs) const
 
fixed_size_simd_mask< T, N > operator| (const SimdMaskArray &rhs) const
 Returns the component-wise application of a binary OR to mask.
 
fixed_size_simd_mask< T, N > operator^ (const SimdMaskArray &rhs) const
 Returns the component-wise application of a binary XOR to mask.
 
fixed_size_simd_mask< T, N > operator && (const SimdMaskArray &rhs) const
 
fixed_size_simd_mask< T, N > operator|| (const SimdMaskArray &rhs) const
 Returns the component-wise application of a logical OR to mask.
 
bool isFull () const
 Returns a logical AND of all components.
 
bool isNotEmpty () const
 Returns a logical OR of all components.
 
bool isEmpty () const
 Returns true if components are false, false otherwise.
 
bool isMix () const
 Returns !isFull() && !isEmpty().
 
int toInt () const
 Convert the boolean components of the mask into bits of an integer. More...
 
reference operator[] (size_t index) noexcept
 Return a smart reference to the boolean element at index index. More...
 
value_type operator[] (size_t index) const noexcept
 Return a copy of the boolean element at index index. More...
 
int count () const
 Returns how many components of the mask are true.
 
int firstOne () const
 Returns the index of the first one in the mask. More...
 
fixed_size_simd_mask< T, N > shifted (int amount) const
 Returns a mask with components shifted by amount places.
 
new/delete overloads for correct alignment
void * operator new (size_t size)
 Allocates correctly aligned memory.
 
void * operator new (size_t, void *p)
 Returns p.
 
void * operator new[] (size_t size)
 Allocates correctly aligned memory.
 
void * operator new[] (size_t, void *p)
 Returns p.
 
void operator delete (void *ptr, size_t)
 Frees aligned memory.
 
void operator delete (void *, void *)
 Does nothing.
 
void operator delete[] (void *ptr, size_t)
 Frees aligned memory.
 
void operator delete[] (void *, void *)
 Does nothing.
 
Loads & Stores
template<typename Flags = DefaultLoadTag>
 SimdMaskArray (const bool *mem, Flags f=Flags())
 Load N boolean values from the consecutive addresses starting at mem. More...
 
void load (const bool *mem)
 Load N boolean values from the consecutive addresses starting at mem. More...
 
template<typename Flags >
void load (const bool *mem, Flags f)
 Load N boolean values from the consecutive addresses starting at mem. More...
 
void store (bool *mem) const
 Store N boolean values to the consecutive addresses starting at mem. More...
 
template<typename Flags >
void store (bool *mem, Flags f) const
 Store N boolean values to the consecutive addresses starting at mem. More...
 

Static Public Member Functions

static constexpr std::size_t size ()
 Returns the number of boolean components ( \(\mathcal{W}_\mathtt{T}\)) in a mask of this type. More...
 
static fixed_size_simd_mask< T, N > Zero ()
 Creates a new mask object initialized to zero/false. More...
 
static fixed_size_simd_mask< T, N > One ()
 Creates a mask object initialized to one/true. More...
 
template<typename G >
static fixed_size_simd_mask< T, N > generate (const G &gen)
 Generate a mask object from booleans returned from the function gen.
 

Static Public Attributes

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

Member Typedef Documentation

◆ value_type

The EntryType of masks is always bool, independent of T.

Definition at line 358 of file simdmaskarray.h.

◆ MaskType

Construct a zero-initialized vector object.

This constructor follows the behavior of the underlying bool type in that the expression bool() zero-initializes the object (to false). On the other hand the variable x in bool x; is uninitialized. Since, for class types, both expressions call the default constructor Mask<T> x must zero-initialize x as well.

Definition at line 360 of file simdmaskarray.h.

◆ VectorEntryType

using VectorEntryType = vectorentry_type

The VectorEntryType, in contrast to EntryType, reveals information about the SIMD implementation.

This type is useful for the sizeof operator in generic functions.

Definition at line 362 of file simdmaskarray.h.

◆ EntryType

The EntryType of masks is always bool, independent of T.

Definition at line 364 of file simdmaskarray.h.

◆ EntryReference

using EntryReference = Vc::Detail::ElementReference<SimdMaskArray>

The reference wrapper type used for accessing individual mask components.

Definition at line 366 of file simdmaskarray.h.

Constructor & Destructor Documentation

◆ SimdMaskArray() [1/3]

SimdMaskArray ( )
default

Construct a zero-initialized vector object.

This constructor follows the behavior of the underlying bool type in that the expression bool() zero-initializes the object (to false). On the other hand the variable x in bool x; is uninitialized. Since, for class types, both expressions call the default constructor Mask<T> x must zero-initialize x as well.

◆ SimdMaskArray() [2/3]

SimdMaskArray ( bool  b)
inlineexplicit

Broadcast constructor.

Set all components of the new mask object to b.

Parameters
bDetermines the initial state of the mask.

Definition at line 435 of file simdmaskarray.h.

◆ SimdMaskArray() [3/3]

SimdMaskArray ( const bool *  mem,
Flags  f = Flags() 
)
inlineexplicit

Load N boolean values from the consecutive addresses starting at mem.

Parameters
memA pointer to an array of booleans.
fA combination of flags to modify specific behavior of the load.

Definition at line 458 of file simdmaskarray.h.

Member Function Documentation

◆ size()

static constexpr std::size_t size ( )
inlinestatic

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.

Definition at line 344 of file simdmaskarray.h.

◆ Zero()

static fixed_size_simd_mask<T, N> Zero ( )
inlinestatic

Creates a new mask object initialized to zero/false.

Returns
A mask object with zero-initialized components.

Definition at line 438 of file simdmaskarray.h.

◆ One()

static fixed_size_simd_mask<T, N> One ( )
inlinestatic

Creates a mask object initialized to one/true.

Returns
A mask object with components initialized to true.

Definition at line 443 of file simdmaskarray.h.

◆ load() [1/2]

void load ( const bool *  mem)
inline

Load N boolean values from the consecutive addresses starting at mem.

Parameters
memA pointer to an array of booleans.

Definition at line 468 of file simdmaskarray.h.

◆ load() [2/2]

void load ( const bool *  mem,
Flags  f 
)
inline

Load N boolean values from the consecutive addresses starting at mem.

Parameters
memA pointer to an array of booleans.
fA combination of flags to modify specific behavior of the load.

Definition at line 480 of file simdmaskarray.h.

◆ store() [1/2]

void store ( bool *  mem) const
inline

Store N boolean values to the consecutive addresses starting at mem.

Parameters
memA pointer to an array of booleans.

Definition at line 491 of file simdmaskarray.h.

◆ store() [2/2]

void store ( bool *  mem,
Flags  f 
) const
inline

Store N boolean values to the consecutive addresses starting at mem.

Parameters
memA pointer to an array of booleans.
fA combination of flags to modify specific behavior of the load.

Definition at line 503 of file simdmaskarray.h.

◆ operator==()

bool operator== ( const SimdMaskArray< T, N, V, Wt > &  mask) const
inline

Returns whether the two masks are equal in all components.

Parameters
maskThe other mask to compare against.
Returns
A scalar boolean value that says whether all components of the two masks are equal.
Note
If you expected a behavior similar to the compare operator of Vc::Vector, consider that the bitwise operators already implement such functionality. There is little use, typically, in having a == b return the same as a ^ b. In general, it is more useful to query all_of(a ^ b) which is the same as this equality operator.

Definition at line 511 of file simdmaskarray.h.

◆ operator!=()

bool operator!= ( const SimdMaskArray< T, N, V, Wt > &  mask) const
inline

Returns whether the two masks are different in at least one component.

Parameters
maskThe other mask to compare against.
Returns
A scalar boolean value that says whether at least one component of the two masks is different.
Note
(a == b) == !(a != b) holds
See also
Mask::operator==(const Mask &)

Definition at line 516 of file simdmaskarray.h.

◆ toInt()

int toInt ( ) const
inline

Convert the boolean components of the mask into bits of an integer.

Returns
An int where each bit corresponds to the boolean value in the mask.

For example, the mask [true, false, false, true] results in a 9 (in binary: 1001).

Definition at line 591 of file simdmaskarray.h.

◆ operator[]() [1/2]

reference operator[] ( size_t  index)
inlinenoexcept

Return a smart reference to the boolean element at index index.

Parameters
indexThe element index to be accessed.
Returns
A temporary smart reference object which acts as much as an lvalue reference as possible.

Definition at line 627 of file simdmaskarray.h.

◆ operator[]() [2/2]

value_type operator[] ( size_t  index) const
inlinenoexcept

Return a copy of the boolean element at index index.

Parameters
indexThe element index to be accessed.
Returns
A temporary boolean object with the value of the element at index index.

Definition at line 639 of file simdmaskarray.h.

◆ firstOne()

int firstOne ( ) const
inline

Returns the index of the first one in the mask.

Returns
the index of the first component that is true.
Warning
The return value is undefined if the mask is empty.

Thus, unless none_of(mask), mask[mask.firstOne()] == true holds and mask[i] == false for all i < mask.firstOne().

Definition at line 648 of file simdmaskarray.h.


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