Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

BOOST_HW hardware macros

Using the BOOST_HW_SIMD_* predefs
BOOST_HW_SIMD_*
BOOST_HW_SIMD_X86_*_VERSION
BOOST_HW_SIMD_X86_AMD_*_VERSION
BOOST_HW_SIMD_ARM_*_VERSION
BOOST_HW_SIMD_PPC_*_VERSION

SIMD predefs depend on compiler options. For example, you will have to add the option -msse3 to clang or gcc to enable SSE3. SIMD predefs are also inclusive. This means that if SSE3 is enabled, then every other extensions with a lower version number will implicitly be enabled and detected. However, some extensions are CPU specific, they may not be detected nor enabled when an upper version is enabled.

[Note] Note

SSE(1) and SSE2 are automatically enabled by default when using x86-64 architecture.

To check if any SIMD extension has been enabled, you can use:

#include <boost/predef/hardware/simd.h>
#include <iostream>

int main()
{
#if defined(BOOST_HW_SIMD_AVAILABLE)
    std::cout << "SIMD detected!" << std::endl;
#endif
    return 0;
}

When writing SIMD specific code, you may want to check if a particular extension has been detected. To do so you have to use the right architecture predef and compare it. Those predef are of the form BOOST_HW_SIMD_"ARCH" (where "ARCH" is either ARM, PPC, or X86). For example, if you compile code for x86 architecture, you will have to use BOOST_HW_SIMD_X86. Its value will be the version number of the most recent SIMD extension detected for the architecture.

To check if an extension has been enabled:

#include <boost/predef/hardware/simd.h>
#include <iostream>

int main()
{
#if BOOST_HW_SIMD_X86 >= BOOST_HW_SIMD_X86_SSE3_VERSION
    std::cout << "This is SSE3!" << std::endl;
#endif
    return 0;
}
[Note] Note

The _VERSION defines that map version number to actual real identifiers. This way it is easier to write comparisons without messing up with version numbers.

To "stricly" check the most recent detected extension:

#include <boost/predef/hardware/simd.h>
#include <iostream>

int main()
{
#if BOOST_HW_SIMD_X86 == BOOST_HW_SIMD_X86_SSE3_VERSION
    std::cout << "This is SSE3 and this is the most recent enabled extension!"
        << std::endl;
#endif
    return 0;
}

Because of the version systems of predefs and of the inclusive property of SIMD extensions macros, you can easily check for ranges of supported extensions:

#include <boost/predef/hardware/simd.h>
#include <iostream>

int main()
{
#if BOOST_HW_SIMD_X86 >= BOOST_HW_SIMD_X86_SSE2_VERSION &&\
    BOOST_HW_SIMD_X86 <= BOOST_HW_SIMD_X86_SSSE3_VERSION
    std::cout << "This is SSE2, SSE3 and SSSE3!" << std::endl;
#endif
    return 0;
}
[Note] Note

Unlike gcc and clang, Visual Studio does not allow you to specify precisely the SSE variants you want to use, the only detections that will take place are SSE, SSE2, AVX and AVX2. For more informations, see here.

BOOST_HW_SIMD

The SIMD extension detected for a specific architectures. Version number depends on the detected extension.

Symbol

Version

BOOST_HW_SIMD_X86_AVAILABLE

detection

BOOST_HW_SIMD_X86_AMD_AVAILABLE

detection

BOOST_HW_SIMD_ARM_AVAILABLE

detection

BOOST_HW_SIMD_PPC_AVAILABLE

detection

BOOST_HW_SIMD_X86

The SIMD extension for x86 (if detected). Version number depends on the most recent detected extension.

Symbol

Version

__SSE__

detection

_M_X64

detection

_M_IX86_FP >= 1

detection

__SSE2__

detection

_M_X64

detection

_M_IX86_FP >= 2

detection

__SSE3__

detection

__SSSE3__

detection

__SSE4_1__

detection

__SSE4_2__

detection

__AVX__

detection

__FMA__

detection

__AVX2__

detection

Symbol

Version

__SSE__

BOOST_HW_SIMD_X86_SSE_VERSION

_M_X64

BOOST_HW_SIMD_X86_SSE_VERSION

_M_IX86_FP >= 1

BOOST_HW_SIMD_X86_SSE_VERSION

__SSE2__

BOOST_HW_SIMD_X86_SSE2_VERSION

_M_X64

BOOST_HW_SIMD_X86_SSE2_VERSION

_M_IX86_FP >= 2

BOOST_HW_SIMD_X86_SSE2_VERSION

__SSE3__

BOOST_HW_SIMD_X86_SSE3_VERSION

__SSSE3__

BOOST_HW_SIMD_X86_SSSE3_VERSION

__SSE4_1__

BOOST_HW_SIMD_X86_SSE4_1_VERSION

__SSE4_2__

BOOST_HW_SIMD_X86_SSE4_2_VERSION

__AVX__

BOOST_HW_SIMD_X86_AVX_VERSION

__FMA__

BOOST_HW_SIMD_X86_FMA3_VERSION

__AVX2__

BOOST_HW_SIMD_X86_AVX2_VERSION

BOOST_HW_SIMD_X86_AMD

The SIMD extension for x86 (AMD) (if detected). Version number depends on the most recent detected extension.

Symbol

Version

__SSE4A__

detection

__FMA4__

detection

__XOP__

detection

BOOST_HW_SIMD_X86

detection

Symbol

Version

__SSE4A__

BOOST_HW_SIMD_X86_SSE4A_VERSION

__FMA4__

BOOST_HW_SIMD_X86_FMA4_VERSION

__XOP__

BOOST_HW_SIMD_X86_XOP_VERSION

BOOST_HW_SIMD_X86

BOOST_HW_SIMD_X86

[Note] Note

This predef includes every other x86 SIMD extensions and also has other more specific extensions (FMA4, XOP, SSE4a). You should use this predef instead of BOOST_HW_SIMD_X86 to test if those specific extensions have been detected.

BOOST_HW_SIMD_ARM

The SIMD extension for ARM (if detected). Version number depends on the most recent detected extension.

Symbol

Version

__ARM_NEON__

detection

__aarch64__

detection

_M_ARM

detection

Symbol

Version

__ARM_NEON__

BOOST_HW_SIMD_ARM_NEON_VERSION

__aarch64__

BOOST_HW_SIMD_ARM_NEON_VERSION

_M_ARM

BOOST_HW_SIMD_ARM_NEON_VERSION

BOOST_HW_SIMD_PPC

The SIMD extension for PowerPC (if detected). Version number depends on the most recent detected extension.

Symbol

Version

__VECTOR4DOUBLE__

detection

__ALTIVEC__

detection

__VEC__

detection

__VSX__

detection

Symbol

Version

__VECTOR4DOUBLE__

BOOST_HW_SIMD_PPC_QPX_VERSION

__ALTIVEC__

BOOST_HW_SIMD_PPC_VMX_VERSION

__VEC__

BOOST_HW_SIMD_PPC_VMX_VERSION

__VSX__

BOOST_HW_SIMD_PPC_VSX_VERSION

Those defines represent x86 SIMD extensions versions.

[Note] Note

You MUST compare them with the predef BOOST_HW_SIMD_X86.

BOOST_HW_SIMD_X86_MMX_VERSION

The MMX x86 extension version number.

Version number is: 0.99.0.

BOOST_HW_SIMD_X86_SSE_VERSION

The SSE x86 extension version number.

Version number is: 1.0.0.

BOOST_HW_SIMD_X86_SSE2_VERSION

The SSE2 x86 extension version number.

Version number is: 2.0.0.

BOOST_HW_SIMD_X86_SSE3_VERSION

The SSE3 x86 extension version number.

Version number is: 3.0.0.

BOOST_HW_SIMD_X86_SSSE3_VERSION

The SSSE3 x86 extension version number.

Version number is: 3.1.0.

BOOST_HW_SIMD_X86_SSE4_1_VERSION

The SSE4_1 x86 extension version number.

Version number is: 4.1.0.

BOOST_HW_SIMD_X86_SSE4_2_VERSION

The SSE4_2 x86 extension version number.

Version number is: 4.2.0.

BOOST_HW_SIMD_X86_AVX_VERSION

The AVX x86 extension version number.

Version number is: 5.0.0.

BOOST_HW_SIMD_X86_FMA3_VERSION

The FMA3 x86 extension version number.

Version number is: 5.2.0.

BOOST_HW_SIMD_X86_AVX2_VERSION

The AVX2 x86 extension version number.

Version number is: 5.3.0.

BOOST_HW_SIMD_X86_MIC_VERSION

The MIC (Xeon Phi) x86 extension version number.

Version number is: 9.0.0.

Those defines represent x86 (AMD specific) SIMD extensions versions.

[Note] Note

You MUST compare them with the predef BOOST_HW_SIMD_X86_AMD.

BOOST_HW_SIMD_X86_SSE4A_VERSION

SSE4A x86 extension (AMD specific).

Version number is: 4.0.0.

BOOST_HW_SIMD_X86_FMA4_VERSION

FMA4 x86 extension (AMD specific).

Version number is: 5.1.0.

BOOST_HW_SIMD_X86_XOP_VERSION

XOP x86 extension (AMD specific).

Version number is: 5.1.1.

Those defines represent ARM SIMD extensions versions.

[Note] Note

You MUST compare them with the predef BOOST_HW_SIMD_ARM.

BOOST_HW_SIMD_ARM_NEON_VERSION

The NEON ARM extension version number.

Version number is: 1.0.0.

Those defines represent Power PC SIMD extensions versions.

[Note] Note

You MUST compare them with the predef BOOST_HW_SIMD_PPC.

BOOST_HW_SIMD_PPC_VMX_VERSION

The VMX powerpc extension version number.

Version number is: 1.0.0.

BOOST_HW_SIMD_PPC_VSX_VERSION

The VSX powerpc extension version number.

Version number is: 1.1.0.

BOOST_HW_SIMD_PPC_QPX_VERSION

The QPX powerpc extension version number.

Version number is: 2.0.0.


PrevUpHomeNext