spy v3.0.0
Andrée Borrel
Loading...
Searching...
No Matches
Instruction Sets

The SIMD extensions the flags turn on, and what they can compute. More...

Detailed Description

The SIMD extensions the flags turn on, and what they can compute.

spy::simd_instruction_set names the extension the flags enabled and the width of its registers, and the spy::supports::fp16 indicators say what that unit does with half-precision, which the same architecture macros decide.

Topics

 Supplemental Instruction Sets
 The instructions some extensions add on top of an existing set.

Variables

constexpr bool spy::supports::fp16::scalar_ops = spy_implementation_defined {}
 Half-precision scalar arithmetic indicator.
constexpr auto spy::simd_instruction_set = spy_implementation_defined {}
 SIMD extensions set reporting value.
constexpr bool spy::supports::fp16::type = spy_implementation_defined {}
 Half-precision type availability indicator.
constexpr bool spy::supports::fp16::vector_conversion = spy_implementation_defined {}
 Half-precision packed conversion indicator.
constexpr bool spy::supports::fp16::vector_ops = spy_implementation_defined {}
 Half-precision vector arithmetic indicator.

Variable Documentation

◆ scalar_ops

bool spy::supports::fp16::scalar_ops = spy_implementation_defined {}
inlineconstexpr

#include <spy/types.hpp>

Half-precision scalar arithmetic indicator.

Evaluates to true when the current architecture supports scalar operations on IEEE-754 half-precision floating-point numbers.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
{
std::cout << "_Float16 is available.\n";
std::cout << "Scalar half-precision arithmetic is available.\n";
std::cout << "Vector half-precision arithmetic is available.\n";
std::cout << "Packed half-precision conversions are available.\n";
}
else
{
std::cout << "_Float16 is not available.\n";
}
}
constexpr bool vector_conversion
Half-precision packed conversion indicator.
Definition types.hpp:106
constexpr bool type
Half-precision type availability indicator.
Definition types.hpp:69
constexpr bool vector_ops
Half-precision vector arithmetic indicator.
Definition types.hpp:124
constexpr bool scalar_ops
Half-precision scalar arithmetic indicator.
Definition types.hpp:87

◆ simd_instruction_set

auto spy::simd_instruction_set = spy_implementation_defined {}
inlineconstexpr

#include <spy/simd.hpp>

SIMD extensions set reporting value.

SIMD Instructions Sets

SIMD extensions set detection is made so that one can ask if the current SIMD extension is exactly, below or above a given reference instruction set. Detectable instructions sets depends on SIMD hardware vendor

Architecture Supported SIMD instructions sets
X86 SSE spy::sse1_, spy::sse2_, spy::sse3_, spy::ssse3_, spy::sse41_, spy::sse42_
X86 AVX spy::avx_, spy::avx2_, spy::avx512_
Power PC VMX spy::vmx_, spy::vmx_2_03_, spy::vmx_2_05_, spy::vmx_2_06_, spy::vmx_2_07_, spy::vmx_3_00_, spy::vmx_3_01_
Power PC VSX spy::vsx_, spy::vsx_2_06_, spy::vsx_2_07_, spy::vsx_3_00_, spy::vsx_3_01_
ARM NEON spy::neon_, spy::asimd_
ARM SVE spy::sve_, spy::sve128_, spy::sve256_, spy::sve512_, spy::sve1024_
WASM spy::simd128_
RISC-V spy::rvv_

Complete set of comparison operators is provided for those sets. Order of instructions sets are built so that if an instructions set supersedes another, it is considered greater than. For example, spy::avx_ is greater than spy::sse41_ as the former is a super-set of the later. Comparing SIMD descriptors across architecture is undefined behavior.

Moreover, the spy::simd_instruction_set object exposes a constexpr width static field that contains the size in bits of the current SIMD instructions set registers.

Example - SIMD Instructions Sets

#include <iostream>
#include <spy/spy.hpp>
int main()
{
std::cout << spy::simd_instruction_set << "\n";
if constexpr(spy::simd_instruction_set == spy::avx_)
{
std::cout << "This code has been compiled with AVX instructions set.\n";
}
if constexpr(spy::simd_instruction_set >= spy::sse41_)
{
std::cout << "This code has been compiled with at least support for SSE 4.1\n";
}
if constexpr(spy::simd_instruction_set <= spy::sse2_)
{
std::cout << "This code has been compiled with support for SSE2 at most.\n";
}
std::cout << "This code can use " << spy::simd_instruction_set.width << " bits register.\n";
}
constexpr auto simd_instruction_set
SIMD extensions set reporting value.
Definition simd.hpp:230

SIMD Architectures

One can also simply asks if a given family of instructions set is available.

Architecture Generic indicator
X86 spy::x86_simd_
Power PC spy::ppc_simd_
ARM spy::arm_simd_
WASM spy::wasm_simd_
RISC-V spy::riscv_simd_

Example - SIMD Architectures

#include <iostream>
#include <spy/spy.hpp>
int main()
{
if constexpr(spy::simd_instruction_set == spy::x86_simd_)
{
std::cout << "This code has been compiled with some Intel SIMD instructions set.\n";
}
if constexpr(spy::simd_instruction_set == spy::arm_simd_)
{
std::cout << "This code has been compiled with some ARM SIMD instructions set.\n";
}
if constexpr(spy::simd_instruction_set == spy::ppc_simd_)
{
std::cout << "This code has been compiled with some Power PC SIMD instructions set.\n";
}
if constexpr(spy::simd_instruction_set == spy::wasm_simd_)
{
std::cout << "This code has been compiled with WASM enabled.\n";
}
}

Supplemental Instructions sets

Some SIMD instructions sets provide supplemental instructions on top of an existing one. The spy::supports namespace carries one indicator per supplemental set, spy::supports::fma_, spy::supports::fma4_, spy::supports::xop_ and spy::supports::f16c_ for the AVX family, and the spy::supports::avx512 namespace for the AVX-512 subsets. Each of them is documented on its own in this group.

Example - Supplemental Instructions Sets

#include <iostream>
#include <spy/spy.hpp>
int main()
{
if constexpr(spy::supports::fma_) std::cout << "This code has been compiled with FMA3 support.\n";
else if constexpr(spy::supports::fma4_)
std::cout << "This code has been compiled with FMA4 support.\n";
else if constexpr(spy::supports::xop_)
std::cout << "This code has been compiled with XOP support.\n";
else if constexpr(spy::supports::avx512::cd_)
std::cout << "This code has been compiled with AV512-CD support.\n";
}
constexpr bool fma_
Fused multiply-add availability indicator.
Definition x86.hpp:143
constexpr bool xop_
XOP availability indicator.
Definition x86.hpp:179
constexpr bool fma4_
FMA4 availability indicator.
Definition x86.hpp:161
constexpr bool cd_
AVX-512 Conflict Detection availability indicator.
Definition x86.hpp:236

◆ type

bool spy::supports::fp16::type = spy_implementation_defined {}
inlineconstexpr

#include <spy/types.hpp>

Half-precision type availability indicator.

Evaluates to true when the _Float16 type is provided by the compiler on the current platform. The three other indicators of this namespace are meaningful only when this one is true.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
{
std::cout << "_Float16 is available.\n";
std::cout << "Scalar half-precision arithmetic is available.\n";
std::cout << "Vector half-precision arithmetic is available.\n";
std::cout << "Packed half-precision conversions are available.\n";
}
else
{
std::cout << "_Float16 is not available.\n";
}
}

◆ vector_conversion

bool spy::supports::fp16::vector_conversion = spy_implementation_defined {}
inlineconstexpr

#include <spy/types.hpp>

Half-precision packed conversion indicator.

Evaluates to true when the current architecture supports packed conversion operations between IEEE-754 half-precision floating-point numbers and at least one other IEEE-754 floating-point type. It is implied by spy::supports::fp16::vector_ops.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
{
std::cout << "_Float16 is available.\n";
std::cout << "Scalar half-precision arithmetic is available.\n";
std::cout << "Vector half-precision arithmetic is available.\n";
std::cout << "Packed half-precision conversions are available.\n";
}
else
{
std::cout << "_Float16 is not available.\n";
}
}

◆ vector_ops

bool spy::supports::fp16::vector_ops = spy_implementation_defined {}
inlineconstexpr

#include <spy/types.hpp>

Half-precision vector arithmetic indicator.

Evaluates to true when the current architecture supports vector operations on IEEE-754 half-precision floating-point numbers.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
{
std::cout << "_Float16 is available.\n";
std::cout << "Scalar half-precision arithmetic is available.\n";
std::cout << "Vector half-precision arithmetic is available.\n";
std::cout << "Packed half-precision conversions are available.\n";
}
else
{
std::cout << "_Float16 is not available.\n";
}
}