You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/vectorized_code.rst
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,3 +81,40 @@ architecture and pass the appropriate flag to the compiler. For instance:
81
81
82
82
This can be useful to implement runtime dispatching, based on the instruction set detected at runtime. `xsimd` provides a generic machinery :cpp:func:`xsimd::dispatch()` to implement
83
83
this pattern. Based on the above example, instead of calling ``mean{}(arch, a, b, res, tag)``, one can use ``xsimd::dispatch(mean{})(a, b, res, tag)``. More about this can be found in the :ref:`Arch Dispatching` section.
84
+
85
+
Breaking out of xsimd
86
+
---------------------
87
+
88
+
Sometimes ``xsimd`` may not give you the whole availability of the instruction set you
89
+
are targeting. This is not specific to this library but to all libraries that
90
+
abstract something.
91
+
92
+
``xsimd`` give you the possibility to break out of its :cpp:class:`~xsimd::batch` class
93
+
and getting the underlying intrinsic register type.
94
+
This is useful when an instruction set expose some intrinsicts for applications (*e.g.* video
95
+
processing, cryptography...) that are too specific to include in ``xsimd``, or when some
96
+
instructions are currently missing.
97
+
98
+
There are many ways a user could add a special cases in their arch-independent SIMD code.
99
+
One that is simple and compiles on all platforms is using C++17 ``if constexpr``.
100
+
101
+
.. code:: cpp
102
+
103
+
template<typename Arch>
104
+
auto sign_i8(
105
+
xsimd::batch<int8_t, Arch> const& x,
106
+
xsimd::batch<int8_t, Arch> const& y
107
+
) -> xsimd::batch<uint8_t, Arch> {
108
+
// Dedicated instruction dispatch at compile time
109
+
if constexpr(std::is_same_v<Arch, xsimd::avx2>){
110
+
// Automatic conversion back and forth between xsimd::batch and native types
111
+
return _mm256_sign_epi8(x, y);
112
+
// When compiler complains we can be more explicit
0 commit comments