Vc  1.4.1
SIMD Vector Classes for C++
Mask< T, Abi > Class Template Reference

Detailed Description

template<typename T, typename Abi = VectorAbi::Best<T>>
class Vc::Mask< T, Abi >

The main SIMD mask class.

Definition at line 52 of file fwddecl.h.

#include <Vc/vector.h>

Public Types

using abi = Abi
 The ABI tag type of the current template instantiation.
 
using EntryType = bool
 The EntryType of masks is always bool, independent of T.
 
using value_type = EntryType
 The EntryType of masks is always bool, independent of T. More...
 
using EntryReference = typename VectorTraits< T, Abi >::EntryReference
 The reference wrapper type used for accessing individual mask components.
 
using value_reference = EntryReference
 The reference wrapper type used for accessing individual mask components. More...
 
using VectorEntryType = typename VectorTraits< T, Abi >::VectorEntryType
 The VectorEntryType, in contrast to EntryType, reveals information about the SIMD implementation. More...
 

Public Member Functions

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...
 
int toInt () const
 Convert the boolean components of the mask into bits of an integer. More...
 
Mask shifted (int amount) const
 Returns a mask with components shifted by amount places.
 
Compile-Time Constant Initialization
 Mask ()=default
 Construct a zero-initialized vector object. More...
 
 Mask (VectorSpecialInitializerZero)
 Zero-initialize the new mask object (false). More...
 
 Mask (VectorSpecialInitializerOne)
 Initialize the new mask object to one (true). More...
 
Conversion/Broadcast Constructors
 Mask (bool b)
 Broadcast constructor. More...
 
template<typename U >
 Mask (U &&otherMask, Common::enable_if_mask_converts_implicitly< Mask, T, U >=nullarg)
 Implicit conversion from a compatible (equal \(\mathcal{W}_\mathtt{T}\) on every platform) mask object. More...
 
template<typename U >
 Mask (U &&otherMask, Common::enable_if_mask_converts_explicitly< T, U >=nullarg) 1
 Explicit conversion (static_cast) from a mask object that potentially has a different \(\mathcal{W}_\mathtt{T}\). More...
 
Loads & Stores
 Mask (const bool *mem)
 Load constructor from an array of bool. More...
 
template<typename Flags >
 Mask (const bool *mem, Flags flags)
 Overload of the above with a load/store flag argument. More...
 
void load (const bool *mem)
 Load the components of the mask from an array of bool. More...
 
template<typename Flags >
void load (const bool *mem, Flags flags)
 Overload of the above with a load/store flag argument. More...
 
void store (bool *mem) const
 Store the values of the mask to an array of bool. More...
 
template<typename Flags >
void store (bool *mem, Flags flags) const
 Overload of the above with a load/store flag argument. More...
 
Comparison Operators
bool operator== (const Mask &mask) const
 Returns whether the two masks are equal in all components. More...
 
bool operator!= (const Mask &mask) const
 Returns whether the two masks are different in at least one component. More...
 
Logical and Binary Operators

Component-wise logical/binary operations on mask objects.

The effect of logical and binary AND and OR is equivalent for mask types (as it is for bool).

Mask operator && (const Mask &mask) const
 Returns the component-wise application of a logical AND to mask.
 
Mask operator & (const Mask &mask) const
 Returns the component-wise application of a binary AND to mask.
 
Mask operator|| (const Mask &mask) const
 Returns the component-wise application of a logical OR to mask.
 
Mask operator| (const Mask &mask) const
 Returns the component-wise application of a binary OR to mask.
 
Mask operator^ (const Mask &mask) const
 Returns the component-wise application of a binary XOR to mask.
 
Mask operator! () const
 Returns a mask with inverted components.
 
Maskoperator &= (const Mask &mask)
 Modifies the mask using an AND operation with mask.
 
Maskoperator|= (const Mask &mask)
 Modifies the mask using an OR operation with mask.
 
Maskoperator^= (const Mask &mask)
 Modifies the mask using an XOR operation with mask.
 
Reductions
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().
 
Scalar Subscript Operators
EntryReference operator[] (size_t index)
 Lvalue-reference-like access to mask entries. More...
 
EntryType operator[] (size_t index) const
 Read-only access to mask entries. More...
 
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.
 

Static Public Member Functions

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

Static Public Attributes

static constexpr size_t Size = VectorTraits<T, Abi>::size()
 Returns the number of boolean components ( \(\mathcal{W}_\mathtt{T}\)) in a mask of this type. More...
 
static constexpr size_t MemoryAlignment = VectorTraits<T, Abi>::maskMemoryAlignment()
 Specifies the alignment requirement for aligned load and store calls for objects of this mask type.
 

Member Typedef Documentation

◆ value_type

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

Definition at line 76 of file mask.h.

◆ value_reference

The reference wrapper type used for accessing individual mask components.

Definition at line 81 of file mask.h.

◆ VectorEntryType

using VectorEntryType = typename VectorTraits<T, Abi>::VectorEntryType

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 88 of file mask.h.

Constructor & Destructor Documentation

◆ Mask() [1/8]

Mask ( )
inlinedefault

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.

◆ Mask() [2/8]

Mask ( VectorSpecialInitializerZero  )
inlineexplicit

Zero-initialize the new mask object (false).

See also
Vc::Zero, Zero()

◆ Mask() [3/8]

Mask ( VectorSpecialInitializerOne  )
inlineexplicit

Initialize the new mask object to one (true).

See also
Vc::One, One()

◆ Mask() [4/8]

Mask ( bool  b)
inlineexplicit

Broadcast constructor.

Set all components of the new mask object to b.

Parameters
bDetermines the initial state of the mask.

◆ Mask() [5/8]

Mask ( U &&  otherMask,
Common::enable_if_mask_converts_implicitly< Mask< T, Abi >, T, U >  = nullarg 
)
inline

Implicit conversion from a compatible (equal \(\mathcal{W}_\mathtt{T}\) on every platform) mask object.

Parameters
otherMaskThe mask to be converted.

◆ Mask() [6/8]

Mask ( U &&  otherMask,
Common::enable_if_mask_converts_explicitly< T, U >  = nullarg 
)
inlineexplicit

Explicit conversion (static_cast) from a mask object that potentially has a different \(\mathcal{W}_\mathtt{T}\).

Parameters
otherMaskThe mask to be converted.

◆ Mask() [7/8]

Mask ( const bool *  mem)
inlineexplicit

Load constructor from an array of bool.

This constructor implements an explicit conversion from an array of booleans to a mask object. It corresponds to a Vector load constructor.

Parameters
memA pointer to the start of the array of booleans.
See also
Mask(const bool *, Flags), load(const bool *)

◆ Mask() [8/8]

Mask ( const bool *  mem,
Flags  flags 
)
inlineexplicit

Overload of the above with a load/store flag argument.

Parameters
memA pointer to the start of the array of booleans.
flagsChoose a combination of flags such as Vc::Aligned, Vc::Streaming, Vc::Unaligned, Vc::PrefetchDefault, ...
See also
load(const bool *, Flags)

Member Function Documentation

◆ size()

static constexpr 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 57 of file mask.h.

◆ Zero()

static Mask Zero ( )
inlinestatic

Creates a new mask object initialized to zero/false.

Returns
A mask object with zero-initialized components.

◆ One()

static Mask One ( )
inlinestatic

Creates a mask object initialized to one/true.

Returns
A mask object with components initialized to true.

◆ load() [1/2]

void load ( const bool *  mem)
inline

Load the components of the mask from an array of bool.

Parameters
memA pointer to the start of the array of booleans.
See also
load(const bool *, Flags), Mask(const bool *)

◆ load() [2/2]

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

Overload of the above with a load/store flag argument.

Parameters
memA pointer to the start of the array of booleans.
flagsChoose a combination of flags such as Vc::Aligned, Vc::Streaming, Vc::Unaligned, Vc::PrefetchDefault, ...
See also
Mask(const bool *, Flags)

◆ store() [1/2]

void store ( bool *  mem) const
inline

Store the values of the mask to an array of bool.

Parameters
memA pointer to the start of the array of booleans.
See also
store(bool *, Flags)

◆ store() [2/2]

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

Overload of the above with a load/store flag argument.

Parameters
memA pointer to the start of the array of booleans.
flagsChoose a combination of flags such as Vc::Aligned, Vc::Streaming, Vc::Unaligned, Vc::PrefetchDefault, ...

◆ operator==()

bool operator== ( const Mask< T, Abi > &  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.

◆ operator!=()

bool operator!= ( const Mask< T, Abi > &  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 &)

◆ operator[]() [1/2]

EntryReference operator[] ( size_t  index)
inline

Lvalue-reference-like access to mask entries.

Parameters
indexDetermines the boolean to be accessed.
Returns
a temporary proxy object referencing the index th entry of the mask.
Warning
This operator does not return an lvalue reference (to bool), but rather a temporary (rvalue) object that mimics an lvalue reference (as much as is possible with C++11/14).

◆ operator[]() [2/2]

EntryType operator[] ( size_t  index) const
inline

Read-only access to mask entries.

Parameters
indexDetermines the boolean to be accessed.
Returns
The index th entry of the mask as a bool (rvalue).
Warning
This operator does not return an lvalue reference (to const bool), but rather a temporary (rvalue) bool.

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

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

Member Data Documentation

◆ Size

constexpr size_t Size = VectorTraits<T, Abi>::size()
static

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 60 of file mask.h.


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