libsimdpp
1.0
|
If the user wants to include several versions of the same code, compiled for different architectures sets into the same executable, then all such code must be put into SIMDPP_ARCH_NAMESPACE
namespace. This macro evaluates to an identifier which is unique for each architecture.
In addition to the above, the source file must not define any of the architecture select macros; they must be supplied via the compiler options. The code for NONE_NULL
architecture must be linked to the resulting executable.
To use dynamic dispatch mechanism, declare the function within an SIMDPP_ARCH_NAMESPACE
and then use one of SIMDPP_MAKE_DISPATCHER_***
macros.
Dynamic dispatch example
The following example demonstrates the simpliest usage of dynamic dispatch:
If compiled, the above example selects the "fastest" of SSE2, SSE3 or SSE4.1 instruction sets, whichever is available on the target processor and outputs an integer that identifiers that instruction set.
Note, that the object files must be linked directly to the executable. If static libraries are used, the linker may throw out static dispatcher registration code and break the mechanism. Do prevent this behavior, -Wl
,–whole-archive or an equivalent flag must be used.
CMake
For CMake users, cmake/SimdppMultiarch.cmake
contains several useful functions:
simdpp_get_compilable_archs
: checks what architectures are supported by the compiler.simdpp_get_runnable_archs
: checks what architectures are supported by both the compiler and the current processor.simdpp_multiversion
: given a list of architectures (possibly generated bysimdpp_get_compilable_archs
orsimdpp_get_runnable_archs
), automatically configures compilation of additional objects. The user only needs to add the returned list of source files toadd_library
oradd_executable
.
The above example may be build with CMakeLists.txt
as simple as follows:
Generated on Tue Apr 8 2014 03:14:34 for libsimdpp by
