mirror of
https://github.com/boostorg/predef.git
synced 2025-07-29 11:37:13 +02:00
Add main documentation
The SIMD documentation is in the BOOST_HW_SIMD_* reference instead of in the main page
This commit is contained in:
89
doc/hardware_simd.qbk
Normal file
89
doc/hardware_simd.qbk
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
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 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 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 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 [@https://msdn.microsoft.com/en-us/library/b0084kay.aspx here].]
|
||||||
|
|
@ -229,91 +229,6 @@ name of what the detection is.
|
|||||||
|
|
||||||
[heading The `BOOST_HW_SIMD_*` predefs]
|
[heading The `BOOST_HW_SIMD_*` predefs]
|
||||||
|
|
||||||
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 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 defined(BOOST_HW_SIMD_X86_SSE3_AVAILABLE)
|
|
||||||
std::cout << "This is SSE3!" << std::endl;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
``
|
|
||||||
|
|
||||||
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
|
|
||||||
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 &&\
|
|
||||||
BOOST_HW_SIMD_X86 <= BOOST_HW_SIMD_X86_SSSE3
|
|
||||||
std::cout << "This is SSE2, SSE3 and SSSE3!" << std::endl;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
``
|
|
||||||
|
|
||||||
[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 [@https://msdn.microsoft.com/en-us/library/b0084kay.aspx here].
|
|
||||||
|
|
||||||
[heading The `*_EMULATED` macros]
|
[heading The `*_EMULATED` macros]
|
||||||
|
|
||||||
Predef definitions are guaranteed to be uniquely detected within one category.
|
Predef definitions are guaranteed to be uniquely detected within one category.
|
||||||
@ -638,6 +553,10 @@ and "Y", "M", "D" for dates.
|
|||||||
[include ../include/boost/predef/platform/*.h]
|
[include ../include/boost/predef/platform/*.h]
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD` hardware SIMD macros]
|
||||||
|
[include ../include/boost/predef/hardware/simd.h]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
[section Other macros]
|
[section Other macros]
|
||||||
[include ../include/boost/predef/other/*.h]
|
[include ../include/boost/predef/other/*.h]
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@ -16,6 +16,14 @@ http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
#include <boost/predef/version_number.h>
|
#include <boost/predef/version_number.h>
|
||||||
|
|
||||||
/*`
|
/*`
|
||||||
|
[section Using the `BOOST_HW_SIMD_*` predefs]
|
||||||
|
[include ../doc/hardware_simd.qbk]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[/ --------------------------- ]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD_*`]
|
||||||
|
|
||||||
[heading `BOOST_HW_SIMD`]
|
[heading `BOOST_HW_SIMD`]
|
||||||
|
|
||||||
The SIMD extension detected for a specific architectures.
|
The SIMD extension detected for a specific architectures.
|
||||||
@ -29,6 +37,32 @@ http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
[[`BOOST_HW_SIMD_ARM_AVAILABLE`] [__predef_detection__]]
|
[[`BOOST_HW_SIMD_ARM_AVAILABLE`] [__predef_detection__]]
|
||||||
[[`BOOST_HW_SIMD_PPC_AVAILABLE`] [__predef_detection__]]
|
[[`BOOST_HW_SIMD_PPC_AVAILABLE`] [__predef_detection__]]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[include ../include/boost/predef/hardware/simd/x86.h]
|
||||||
|
[include ../include/boost/predef/hardware/simd/x86_amd.h]
|
||||||
|
[include ../include/boost/predef/hardware/simd/arm.h]
|
||||||
|
[include ../include/boost/predef/hardware/simd/ppc.h]
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[/ --------------------------- ]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD_X86_*_VERSION`]
|
||||||
|
[include ../include/boost/predef/hardware/simd/x86/versions.h]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD_X86_AMD_*_VERSION`]
|
||||||
|
[include ../include/boost/predef/hardware/simd/x86_amd/versions.h]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD_ARM_*_VERSION`]
|
||||||
|
[include ../include/boost/predef/hardware/simd/arm/versions.h]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
[section `BOOST_HW_SIMD_PPC_*_VERSION`]
|
||||||
|
[include ../include/boost/predef/hardware/simd/ppc/versions.h]
|
||||||
|
[endsect]
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// We check if SIMD extension of multiples architectures have been detected,
|
// We check if SIMD extension of multiples architectures have been detected,
|
||||||
|
@ -71,7 +71,6 @@ http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
[[`__AVX2__`] [BOOST_HW_SIMD_x86_AVX2_VERSION]]
|
[[`__AVX2__`] [BOOST_HW_SIMD_x86_AVX2_VERSION]]
|
||||||
]
|
]
|
||||||
|
|
||||||
[include x86/versions.h]
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BOOST_HW_SIMD_X86 BOOST_VERSION_NUMBER_NOT_AVAILABLE
|
#define BOOST_HW_SIMD_X86 BOOST_VERSION_NUMBER_NOT_AVAILABLE
|
||||||
|
Reference in New Issue
Block a user