spy v2.0.0
Denise Bloch
Loading...
Searching...
No Matches
Main API

Variables

constexpr bool spy::supports::address_sanitizers_status = spy_implementation_defined {}
 Thread sanitizer status indicator.
constexpr arch_type spy::architecture
 Architecture reporting value.
constexpr compiler_type spy::compiler
 Compiler reporting value.
constexpr spy_implementation_defined spy::cpp_standard {}
 C++ standard version reporting value.
constexpr auto spy::supports::cuda = spy_implementation_defined {}
 CUDA usage indicator.
constexpr auto spy::data_model = data_model_type {}
 Data Model reporting value.
constexpr auto spy::libc = libc_type {}
 LIBC version reporting value.
constexpr os_type spy::operating_system
 OS reporting value.
constexpr auto spy::supports::posix_ = spy_implementation_defined {}
 POSIX supports indicator.
constexpr bool spy::supports::sanitizers_status = address_sanitizers_status || thread_sanitizers_status
 Sanitizers status indicator.
constexpr auto spy::simd_instruction_set = spy_implementation_defined {}
 SIMD extensions set reporting value.
constexpr auto spy::stdlib = stdlib_type {}
 C++ Standard Library version reporting value.
constexpr auto spy::supports::sycl = spy_implementation_defined {}
 SYCL usage indicator.
constexpr bool spy::supports::thread_sanitizers_status = spy_implementation_defined {}
 Thread sanitizer status indicator.

Functions

template<char... c>
constexpr auto spy::literal::operator""_clang ()
 User-defined suffix for Clang version definition.
template<char... c>
constexpr auto spy::literal::operator""_clangcl ()
 User-defined suffix for ClangCL version definition.
template<char... c>
constexpr auto spy::literal::operator""_cloud ()
 User-defined suffix for the CloudABI libc version definition.
template<char... c>
constexpr auto spy::literal::operator""_cpp ()
 User-defined suffix for C++ standard definition.
template<char... c>
constexpr auto spy::literal::operator""_dpcpp ()
 User-defined suffix for Intel DCP++/ICPX version definition.
template<char... c>
constexpr auto spy::literal::operator""_em ()
 User-defined suffix for Emscripten version definition.
template<char... c>
constexpr auto spy::literal::operator""_gcc ()
 User-defined suffix for G++ version definition.
template<char... c>
constexpr auto spy::literal::operator""_gnu ()
 User-defined suffix for the GNU libc version definition.
template<char... c>
constexpr auto spy::literal::operator""_intel ()
 User-defined suffix for Intel ICC version definition.
template<char... c>
constexpr auto spy::literal::operator""_mingw32 ()
 User-defined suffix for MINGW32 version definition.
template<char... c>
constexpr auto spy::literal::operator""_mingw64 ()
 User-defined suffix for MINGW64 version definition.
template<char... c>
constexpr auto spy::literal::operator""_msvc ()
 User-defined suffix for MSVC version definition.
template<char... c>
constexpr auto spy::literal::operator""_nvcc ()
 User-defined suffix for NVCC version definition.
template<char... c>
constexpr auto spy::literal::operator""_uc ()
 User-defined suffix for the uClibc version definition.
template<char... c>
constexpr auto spy::literal::operator""_vms ()
 User-defined suffix for the VMS libc version definition.
template<char... c>
constexpr auto spy::literal::operator""_zos ()
 User-defined suffix for the zOS libc version definition.

Variable Documentation

◆ address_sanitizers_status

bool spy::supports::address_sanitizers_status = spy_implementation_defined {}
constexpr

#include <spy/sanitizers.hpp>

Thread sanitizer status indicator.

Indicate if current code is compile using -fsanitize=address.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
std::cout << "Address sanitizers status: " << std::boolalpha
std::cout << "Threads sanitizers status: " << std::boolalpha
std::cout << "Any sanitizers status: " << std::boolalpha << spy::supports::sanitizers_status
<< "\n";
}
constexpr bool thread_sanitizers_status
Thread sanitizer status indicator.
Definition sanitizers.hpp:65
constexpr bool sanitizers_status
Sanitizers status indicator.
Definition sanitizers.hpp:79
constexpr bool address_sanitizers_status
Thread sanitizer status indicator.
Definition sanitizers.hpp:48

◆ architecture

arch_type spy::architecture
inlineconstexpr

#include <spy/arch.hpp>

Architecture reporting value.

The spy::architecture object can be compared to any other architecture related value to verify if the code being compiled is compiled for a given CPU architecture.

Additionally, any of the architecture related value are convertible to bool. They evaluates to true if they matches the correct architecture currently targeted.

Supported Value

Name Architecture
spy::amd64 Intel X86-64 and similar architectures.
spy::arm ARM.
spy::ppc PowerPC.
spy::riscv RISC-V.
spy::wasm WASM pseudo-architecture.
spy::x86 Intel X86.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::architecture == spy::x86_) std::cout << "This code is compiled for X86.\n";
else if constexpr(spy::architecture == spy::amd64_)
std::cout << "This code is compiled for X86-64.\n";
else if constexpr(spy::architecture == spy::ppc_)
std::cout << "This code is compiled for PowerPC.\n";
else if constexpr(spy::architecture == spy::arm_) std::cout << "This code is compiled for ARM.\n";
else if constexpr(spy::architecture == spy::riscv_)
std::cout << "This code is compiled for RISC-V.\n";
// Direct test
if constexpr(spy::x86_) std::cout << "This code is compiled for X86.\n";
else if constexpr(spy::amd64_) std::cout << "This code is compiled for X86-64.\n";
else if constexpr(spy::ppc_) std::cout << "This code is compiled for PowerPC.\n";
else if constexpr(spy::arm_) std::cout << "This code is compiled for ARM.\n";
else if constexpr(spy::riscv_) std::cout << "This code is compiled for RISC-V.\n";
}
constexpr arch_type architecture
Architecture reporting value.
Definition arch.hpp:103

◆ compiler

compiler_type spy::compiler
inlineconstexpr

#include <spy/compiler.hpp>

Compiler reporting value.

The spy::compiler object can be compared to any other compiler related value to verify if the code being compiled with a specific compiler.

Any compiler related value can be checked for equality or ordering for a given version. The targeted version is then specified using a compiler-dependent literal.

Additionally, any of the compiler related value are convertible to bool. They evaluates to true if they matches the correct compiler currently used.

Supported Value

Name Compiler
spy::clang Clang
spy::dpcpp Intel DPC++/ICPX
spy::emscripten Emscripten
spy::gcc G++
spy::intel Intel ICC
spy::msvc Microsoft Visual Studio
spy::nvcc NVIDIA NVCC
spy::mingw32 MINGW32
spy::mingw64 MINGW64

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::compiler == spy::gcc_) std::cout << "This code compiled with g++.\n";
else if constexpr(spy::compiler == spy::clang_) std::cout << "This code compiled with clang.\n";
else if constexpr(spy::compiler == spy::dpcpp_) std::cout << "This code compiled with ICPX.\n";
// Direct test
if constexpr(spy::gcc_) std::cout << "This code compiled with g++.\n";
else if constexpr(spy::clang_) std::cout << "This code compiled with clang.\n";
else if constexpr(spy::dpcpp_) std::cout << "This code compiled with ICPX.\n";
// Version checks
using namespace spy::literal;
if constexpr(spy::compiler == 16'0_clang) std::cout << "This code compiled with clang 16.\n";
if constexpr(spy::compiler >= 15'0_clang)
std::cout << "This code compiled with clang 15 or ulterior.\n";
}
constexpr compiler_type compiler
Compiler reporting value.
Definition compiler.hpp:178

◆ cpp_standard

spy_implementation_defined spy::cpp_standard {}
inlineconstexpr

#include <spy/standard.hpp>

C++ standard version reporting value.

The spy::current_standard object can be compared to any other current_standard related value to verify if the code being compiled with a specific version of the C++ standard.

Example

#include <spy/spy.hpp>
#include <iostream>
int main()
{
std::cout << "This code compiled with " << spy::cpp_standard << ".\n";
// Version checks
using namespace spy::literal;
if constexpr(spy::cpp_standard == 20_cpp) std::cout << "This code compiled with C++ 20.\n";
if constexpr(spy::cpp_standard == 20) std::cout << "This code compiled with C++ 20.\n";
if constexpr(spy::cpp_standard >= 17_cpp)
std::cout << "This code compiled with C++ 17 or ulterior.\n";
if constexpr(spy::cpp_standard >= 17)
std::cout << "This code compiled with C++ 17 or ulterior.\n";
}
constexpr spy_implementation_defined cpp_standard
C++ standard version reporting value.
Definition standard.hpp:75

◆ cuda

auto spy::supports::cuda = spy_implementation_defined {}
inlineconstexpr

#include <spy/accelerator.hpp>

CUDA usage indicator.

Retrieves the information about wether or not current file is compiled using NVCC. Note that this indicator works in both .cpp and .cu files.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
if constexpr(spy::supports::cuda) std::cout << "Compiling with CUDA supports\n";
else std::cout << "No accelerator supports\n";
}
constexpr auto cuda
CUDA usage indicator.
Definition accelerator.hpp:94

◆ data_model

auto spy::data_model = data_model_type {}
inlineconstexpr

#include <spy/data_model.hpp>

Data Model reporting value.

The spy::data_model object can be compared to any other data model related value to verify if the code being compiled for a specific data model

Additionally, any of the data model related value are convertible to bool. They evaluates to true if they matches the correct data model currently used.

Supported Value

Name Data Model
spy::ilp32 ILP32
spy::lp32 LP32
spy::silp64 SILP64
spy::ilp64 ILP64
spy::llp64 LLP64
spy::lp64 LP64

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::data_model == spy::ilp32_)
std::cout << "This code is compiled on a ILP32 system\n";
else if constexpr(spy::data_model == spy::ilp64_)
std::cout << "This code is compiled on a ILP64 system\n";
else if constexpr(spy::data_model == spy::lp64_)
std::cout << "This code is compiled on a LP64 system\n";
// Direct test
if constexpr(spy::ilp32_) std::cout << "This code is compiled on a ILP32 system\n";
else if constexpr(spy::ilp64_) std::cout << "This code is compiled on a ILP64 system\n";
else if constexpr(spy::lp64_) std::cout << "This code is compiled on a LP64 system\n";
}
constexpr auto data_model
Data Model reporting value.
Definition data_model.hpp:68

◆ libc

auto spy::libc = libc_type {}
inlineconstexpr

#include <spy/libc.hpp>

LIBC version reporting value.

The spy::libc object can be compared to any other libc related value to verify if the code being compiled with a specific version of the libc.

Any libc related value can be checked for equality or ordering for a given version. The targeted version is then specified using a libc-dependent literal.

Additionally, any of the libc related value are convertible to bool. They evaluates to true if they matches the correct libc currently used.

Supported Value

Name Vendor
spy::cloudabi_ CloudABI
spy::uc_ uClibc
spy::vms_ VMS
spy::zos_ zOS
spy::gnu_ GNU

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::libc == spy::gnu_) std::cout << "This code is compiled with the GNU libc.\n";
else if constexpr(spy::libc == spy::zos_)
std::cout << "This code is compiled with the zOS libc.\n";
else if constexpr(spy::libc == spy::vms_)
std::cout << "This code is compiled with the VMS libc.\n";
// Direct test
if constexpr(spy::gnu_) std::cout << "This code is compiled with the GNU libc.\n";
else if constexpr(spy::zos_) std::cout << "This code is compiled with the zOS libc.\n";
else if constexpr(spy::vms_) std::cout << "This code is compiled with the VMS libc.\n";
}
constexpr auto libc
LIBC version reporting value.
Definition libc.hpp:130

◆ operating_system

os_type spy::operating_system
inlineconstexpr

#include <spy/os.hpp>

OS reporting value.

The spy::operating_system object can be compared to any other OS related value to verify if the code being compiled is compiled on a given Operating Systems.

Additionally, any of the OS related value are convertible to bool. They evaluates to true if they matches the correct OS currently used.

Supported Value

Name Operating System
spy::android_ Android
spy::bsd BSD
spy::cygwin_ CYGWIN
spy::ios_ iOS
spy::linux_ Linux
spy::macos_ MacOS
spy::unix_ UNIX
spy::windows_ Windows

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::operating_system == spy::bsd_) std::cout << "This code runs on BSD.\n";
else if constexpr(spy::operating_system == spy::linux_) std::cout << "This code runs on Linux.\n";
else if constexpr(spy::operating_system == spy::windows_)
std::cout << "This code runs on Windows.\n";
// Direct test
if constexpr(spy::bsd_) std::cout << "This code runs on BSD.\n";
else if constexpr(spy::linux_) std::cout << "This code runs on Linux.\n";
else if constexpr(spy::windows_) std::cout << "This code runs on Windows.\n";
}
constexpr os_type operating_system
OS reporting value.
Definition os.hpp:115

◆ posix_

auto spy::supports::posix_ = spy_implementation_defined {}
inlineconstexpr

#include <spy/os.hpp>

POSIX supports indicator.

Evaluates to true if current OS supports POSIX system calls and functions.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
if constexpr(spy::supports::posix_)
{
std::cout << "This is a POSIX platform.\n";
}
}
constexpr auto posix_
POSIX supports indicator.
Definition os.hpp:150

◆ sanitizers_status

bool spy::supports::sanitizers_status = address_sanitizers_status || thread_sanitizers_status
constexpr

#include <spy/sanitizers.hpp>

Sanitizers status indicator.

Aggregate the status of all detected sanitizers

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
std::cout << "Address sanitizers status: " << std::boolalpha
std::cout << "Threads sanitizers status: " << std::boolalpha
std::cout << "Any sanitizers status: " << std::boolalpha << spy::supports::sanitizers_status
<< "\n";
}

◆ 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:233

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 set provides supplemental instructions on top of existing system. Those supplemental instruction set can be checked using the spy::supports namespace.

Architecture Supported SIMD instructions sets
X86 AVX xop_, fma_, fma4_
X86 AVX512 bw_, cd_, dq_, er_, ifma_, pf_, vl_, popcntdq_, _4fmaps_, vnniw_, vbmi_
bf16_, bitalg_, vbmi2_, vnni_, vpintersect_

Example - SIMD Architectures

#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";
}

◆ stdlib

auto spy::stdlib = stdlib_type {}
inlineconstexpr

#include <spy/stdlib.hpp>

C++ Standard Library version reporting value.

The spy::stdlib object can be compared to any other stdlib related value to verify if the code being compiled with a specific version of the C++ standard library.

Any stdlib related value can be checked for equality or ordering for a given version. The targeted version is then specified using a stdlib-dependent literal.

Additionally, any of the stdlib related value are convertible to bool. They evaluates to true if they matches the correct standard library currently used.

Supported Value

Name Vendor
spy::libcpp_ Clang libcpp
spy::gnucpp_ GNU C++ standard library

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::stdlib == spy::gnucpp_)
std::cout << "This code is compiled with the GNU stdlib.\n";
else if constexpr(spy::stdlib == spy::libcpp_)
std::cout << "This code is compiled with the Clang stdlib.\n";
// Direct test
if constexpr(spy::gnucpp_) std::cout << "This code is compiled with the GNU stdlib.\n";
else if constexpr(spy::libcpp_) std::cout << "This code is compiled with the Clang stdlib.\n";
}
constexpr auto stdlib
C++ Standard Library version reporting value.
Definition stdlib.hpp:102

◆ sycl

auto spy::supports::sycl = spy_implementation_defined {}
inlineconstexpr

#include <spy/accelerator.hpp>

SYCL usage indicator.

Retrieves the information about wether or not current file is compiled with SYCL supports.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
if constexpr(spy::supports::sycl) std::cout << "Compiling with SYCL supports.\n";
else std::cout << "No accelerator supports\n";
}
constexpr auto sycl
SYCL usage indicator.
Definition accelerator.hpp:68

◆ thread_sanitizers_status

bool spy::supports::thread_sanitizers_status = spy_implementation_defined {}
constexpr

#include <spy/sanitizers.hpp>

Thread sanitizer status indicator.

Indicate if current code is compile using -fsanitize=threads.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
std::cout << "Address sanitizers status: " << std::boolalpha
std::cout << "Threads sanitizers status: " << std::boolalpha
std::cout << "Any sanitizers status: " << std::boolalpha << spy::supports::sanitizers_status
<< "\n";
}