Difference between revisions of "cpp/experimental/simd"
(Add an introduction on top) |
|||
Line 2: | Line 2: | ||
{{cpp/experimental/simd/navbar}} | {{cpp/experimental/simd/navbar}} | ||
+ | The SIMD library provides portable types for explicitly stating data-parallelism and structuring data for more efficient SIMD access. | ||
+ | |||
+ | An object of type {{ltt|cpp/experimental/simd/simd|simd<T>}} behaves analogue to objects of type {{tt|T}}. But while {{tt|T}} stores and manipulates one value, {{tt|simd<T>}} stores and manipulates multiple values (called ''width'' but identified as ''size'' for consistency with the rest of the standard library {{ltt|cpp/experimental/simd/simd_size}}). Every ''operator on {{tt|simd<T>}} acts element-wise''. | ||
+ | |||
+ | The width of the types {{tt|simd<T>}} and {{ltt|cpp/experimental/simd/simd|native_simd<T>}} is determined by the implementation at compile-time. In contrast, the width of the type {{ltt|cpp/experimental/simd/simd|fixed_size_simd<T, N>}} is fixed by the developer to a certain size. | ||
+ | |||
+ | A recommended pattern for using a mix of different SIMD types with high efficiency uses {{ltt|cpp/experimental/simd/simd|native_simd}} and {{ltt|cpp/experimental/simd/rebind_simd}}: | ||
+ | {{example|code= | ||
+ | #include <experimental/simd> | ||
+ | |||
+ | namespace stdx = std::experimental; | ||
+ | |||
+ | using floatv = stdx::native_simd<float>; | ||
+ | using doublev = stdx::rebind_simd_t<double, floatv>; | ||
+ | using intv = stdx::rebind_simd_t<int floatv>; | ||
+ | }} | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc header | experimental/simd }} | {{dsc header | experimental/simd }} |
Revision as of 08:09, 26 January 2023
The SIMD library provides portable types for explicitly stating data-parallelism and structuring data for more efficient SIMD access.
An object of type simd<T> behaves analogue to objects of type T
. But while T
stores and manipulates one value, simd<T>
stores and manipulates multiple values (called width but identified as size for consistency with the rest of the standard library simd_size). Every operator on simd<T>
acts element-wise.
The width of the types simd<T>
and native_simd<T> is determined by the implementation at compile-time. In contrast, the width of the type fixed_size_simd<T, N> is fixed by the developer to a certain size.
A recommended pattern for using a mix of different SIMD types with high efficiency uses native_simd and rebind_simd:
#include <experimental/simd> namespace stdx = std::experimental; using floatv = stdx::native_simd<float>; using doublev = stdx::rebind_simd_t<double, floatv>; using intv = stdx::rebind_simd_t<int floatv>;
Defined in header
<experimental/simd> |
Contents |
Main classes
(parallelism TS v2) |
data-parallel vector type (class template) |
(parallelism TS v2) |
data-parallel type with the element type bool (class template) |
ABI tags
Defined in namespace
std::experimental::simd_abi | |
(parallelism TS v2) |
tag type for storing a single element (typedef) |
(parallelism TS v2) |
tag type for storing specified number of elements (alias template) |
(parallelism TS v2) |
tag type that ensures ABI compatibility (alias template) |
(parallelism TS v2) |
tag type that is most efficient (alias template) |
(parallelism TS v2) |
the maximum number of elements guaranteed to be supported by fixed (constant) |
(parallelism TS v2) |
obtains an ABI type for given element type and number of elements (class template) |
Alignment tags
(parallelism TS v2) |
flag indicating alignment of the load/store address to element alignment (class) |
(parallelism TS v2) |
flag indicating alignment of the load/store address to vector alignment (class) |
(parallelism TS v2) |
flag indicating alignment of the load/store address to the specified alignment (class template) |
Where expression
(parallelism TS v2) |
selected elements with non-mutating operations (class template) |
(parallelism TS v2) |
selected elements with mutating operations (class template) |
(parallelism TS v2) |
produces const_where_expression and where_expression (function template) |
Casts
(parallelism TS v2) |
element-wise static_cast (function template) |
(parallelism TS v2) |
element-wise ABI cast (function template) |
(parallelism TS v2) |
splits single simd object to multiple ones (function template) |
(parallelism TS v2) |
concatenates multiple simd objects to a single one (function template) |
Algorithms
(parallelism TS v2) |
element-wise min operation (function template) |
(parallelism TS v2) |
element-wise max operation (function template) |
(parallelism TS v2) |
element-wise minmax operation (function template) |
(parallelism TS v2) |
element-wise clamp operation (function template) |
Reduction
(parallelism TS v2) |
reduces the vector to a single element (function template) |
(parallelism TS v2) |
returns the minimum element (function template) |
(parallelism TS v2) |
returns the maximum element (function template) |
Mask reduction
(parallelism TS v2) |
predicates on the number of true values (function template) |
(parallelism TS v2) |
returns the number of true values (function template) |
(parallelism TS v2) |
returns the position of the first or last true value (function template) |
Traits
(parallelism TS v2) |
checks if a type is a simd or simd_mask type (class template) |
(parallelism TS v2) |
checks if a type is an ABI tag type (class template) |
(parallelism TS v2) |
checks if a type is a simd flag type (class template) |
(parallelism TS v2) |
obtains the number of elements of a given element type and ABI tag (class template) |
(parallelism TS v2) |
obtains an appropriate alignment for vector_aligned (class template) |
(parallelism TS v2) |
change element type or the number of elements of simd or simd_mask (class template) |
Math functions
This section is incomplete |
Example
This section is incomplete Reason: no example |