Corrade::Cpu::Features class

Feature set.

Provides storage and comparison as well as runtime detection of CPU instruction set. Provides an interface similar to an Containers::EnumSet, with values being the Sse2, Sse3 etc. tags.

See the Cpu namespace for an overview and usage examples.

Constructors, destructors, conversion operators

Features() explicit constexpr noexcept
Default constructor.
template<class T, class = decltype(TypeTraits<T>::Index)>
Features(T) constexpr noexcept
Construct from a tag.
operator bool() const explicit constexpr
Boolean conversion.
operator unsigned int() const explicit constexpr
Integer representation.

Public functions

auto operator==(Features other) const -> bool constexpr
Equality comparison.
auto operator!=(Features other) const -> bool constexpr
Non-equality comparison.
auto operator>=(Features other) const -> bool constexpr
Whether other is a subset of this ( $ a \supseteq o $ )
auto operator<=(Features other) const -> bool constexpr
Whether other is a superset of this ( $ a \subseteq o $ )
auto operator|(Features other) const -> Features constexpr
Union of two feature sets.
auto operator|=(Features other) -> Features&
Union two feature sets and assign.
auto operator&(Features other) const -> Features constexpr
Intersection of two feature sets.
auto operator&=(Features other) -> Features&
Intersect two feature sets and assign.
auto operator^(Features other) const -> Features constexpr
XOR of two feature sets.
auto operator^=(Features other) -> Features&
XOR two feature sets and assign.
auto operator~() const -> Features constexpr
Feature set complement.

Friends

template<class>
auto features() -> Features constexpr
Feature set for a tag type.
auto compiledFeatures() -> Features constexpr
CPU instruction sets enabled at compile time.

Function documentation

Corrade::Cpu::Features::Features() explicit constexpr noexcept

Default constructor.

Equivalent to Scalar.

template<class T, class = decltype(TypeTraits<T>::Index)>
Corrade::Cpu::Features::Features(T) constexpr noexcept

Construct from a tag.

Corrade::Cpu::Features::operator bool() const explicit constexpr

Boolean conversion.

Returns true if at least one feature apart from Scalar is present, false otherwise.

Corrade::Cpu::Features::operator unsigned int() const explicit constexpr

Integer representation.

For testing purposes. Cpu::Scalar is always 0, values corresponding to other feature tags are unspecified.

bool Corrade::Cpu::Features::operator>=(Features other) const constexpr

Whether other is a subset of this ( $ a \supseteq o $ )

Equivalent to (a & other) == other.

bool Corrade::Cpu::Features::operator<=(Features other) const constexpr

Whether other is a superset of this ( $ a \subseteq o $ )

Equivalent to (a & other) == a.

template<class>
Features features() constexpr

Feature set for a tag type.

Returns Features with a tag corresponding to tag type T, avoiding a need to form the tag value in order to pass it to Features::Features(T). The following two expressions are equivalent:

Cpu::Features a = Cpu::Avx2;
Cpu::Features b = Cpu::features<Cpu::Avx2T>();

Features compiledFeatures() constexpr

CPU instruction sets enabled at compile time.

On x86 returns a combination of Sse2, Sse3, Ssse3, Sse41, Sse42, Popcnt, Lzcnt, Bmi1, Bmi2, Avx, AvxF16c, AvxFma, Avx2 and Avx512f based on what all CORRADE_TARGET_SSE2 etc. preprocessor variables are defined.

On ARM, returns a combination of Neon, NeonFma and NeonFp16 based on what all CORRADE_TARGET_NEON etc. preprocessor variables are defined.

On WebAssembly, returns Simd128 based on whether the CORRADE_TARGET_SIMD128 preprocessor variable is defined.

On other platforms or if no known CPU instruction set is enabled, the returned value is equal to Scalar, which in turn is equivalent to empty (or default-constructed) Features.

template<class T, class = decltype(TypeTraits<T>::Index)>
bool operator==(T a, Features b) constexpr

Equality comparison of a tag and a feature set.

Same as Features::operator==().

template<class T, class U, class = decltype(TypeTraits<T>::Index), class = decltype(TypeTraits<U>::Index)>
bool operator==(T, U) constexpr

Equality comparison of two tags.

Same as Features::operator==(). Needs to be present to avoid ambiguity in C++20.

template<class T, class = decltype(TypeTraits<T>::Index)>
bool operator!=(T a, Features b) constexpr

Non-equality comparison of a tag and a feature set.

Same as Features::operator!=().

template<class T, class U, class = decltype(TypeTraits<T>::Index), class = decltype(TypeTraits<U>::Index)>
bool operator!=(T, U) constexpr

Non-equality comparison of two tags.

Same as Features::operator!=(). Needs to be present to avoid ambiguity in C++20.

template<class T, class = decltype(TypeTraits<T>::Index)>
bool operator>=(T a, Features b) constexpr

Whether a is a superset of b ( $ a \supseteq b $ )

Same as Features::operator>=().

template<class T, class = decltype(TypeTraits<T>::Index)>
bool operator<=(T a, Features b) constexpr

Whether a is a subset of b ( $ a \subseteq b $ )

Same as Features::operator<=().

template<class T, class = decltype(TypeTraits<T>::Index)>
Features operator|(T a, Features b) constexpr

Union of two feature sets.

Same as Features::operator|().

template<class T, class = decltype(TypeTraits<T>::Index)>
Features operator&(T a, Features b) constexpr

Intersection of two feature sets.

Same as Features::operator&().

template<class T, class = decltype(TypeTraits<T>::Index)>
Features operator^(T a, Features b) constexpr

XOR of two feature sets.

Same as Features::operator^().

template<class T>
Features operator~(T a) constexpr

Feature set complement.

Same as Features::operator~().

Utility::Debug& operator<<(Utility::Debug& debug, Features value)

Debug output operator.

template<class T, class = decltype(TypeTraits<T>::Index)>
Utility::Debug& operator<<(Utility::Debug& debug, T value)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.