std::experi...::simd::simd(3)
π std::experi...::simd::simd(3) π
okay so we're on the std::experi...::simd::simd(3) page in the C++ Standard Libary (that spelling is literally in the manual, bestie π
), and it's all about constructing a simd. iconic behavior fr fr.
β¨ NAME β¨
std::experimental::simd::simd β literally std::experimental::simd::simd. no notes, we love a self-titled moment π
π¦ Synopsis π¦
simd() noexcept = default; (1)
(parallelism TS v2)
template< class U > (2)
(parallelism TS v2)
simd( U&& value ) noexcept;
template< class U >
simd( const simd<U, simd_abi::fixed_size<size()>>& other ) (3)
(parallelism TS v2)
noexcept;
template< class G > (4)
(parallelism TS v2)
explicit simd( G&& generator ) noexcept;
template< class U, class Flags > (5)
(parallelism TS v2)
simd( const U* mem, Flags flags );
simd( const simd& other ) noexcept = default; (6)
(parallelism TS v2)
(implicitly
declared)
simd( simd&& other ) noexcept = default; (7)
(parallelism TS v2)
(implicitly
declared)
- Constructs a
simdusing default initialization (constructed without initializer) or value initialization (constructed with an empty initializer). - The broadcast constructor constructs a
simdwith all values initialized tovalue. This overload participates in overload resolution only if the conversion fromUtoTis value-preserving, orUis eitherintorunsigned intifTis an unsigned integral type. - Constructs a
simdwhere the i-th element is initialized tostatic_cast<T>(other[i])for all i in the range of[0, size()). This overload participates in overload resolution only ifAbiissimd_abi::fixed_size<size()>and the conversion fromUtoTis value-preserving, and, if bothUandTare integral, the integer conversion rank ofTis greater than the integer conversion rank ofU. - The generator constructor constructs a
simdwhere the i-th element is initialized togenerator(std::integral_constant<std::size_t, i>()). This overload participates in overload resolution only ifsimd(gen(std::integral_constant<std::size_t, i>()))is well-formed for all i in the range of[0, size()). The calls togeneratorare unsequenced with respect to each other. Vectorization-unsafe standard library functions may not be invoked bygenerator. - The load constructor constructs a
simdwhere the i-th element is initialized tostatic_cast<T>(mem[i])for all i in the range of[0, size()).
6,7) Implicitly declared copy and move constructors. Constructs a simd where each element is initialized from the values of the elements in other.
πΈ Parameters πΈ
valueβ the value used for initialization of allsimdelements.otherβ anothersimdto copy from.generatorβ a function object used for initialization of eachsimdelement.memβ a pointer into an array where[mem, mem + size())is a valid range.flagsβ if of typevector_aligned_tag, the load constructor may assumememto point to storage aligned bymemory_alignment_v<simd, U>.
π Type requirements π
- The conversion from
UtoTmust be value-preserving. The broadcast constructor (2) additionally allowsUto beintor to beunsigned intifTis an unsigned integral type. is_simd_flag_type_v<Flags>must be true.
π Example π
// Run this code
#include <cstddef>
#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;
int main()
{
stdx::native_simd<int> a; // uninitialized
a = 1; // all elements set to 1
stdx::native_simd<int> b([](int i) { return i; }); // {0, 1, 2, 3, ...}
alignas(stdx::memory_alignment_v<stdx::native_simd<int>>)
std::array<int, stdx::native_simd<int>::size() * 2> mem = {};
for (std::size_t i = 0; i < mem.size(); ++i)
mem[i] = i & 1;
stdx::native_simd<int> c(&mem[0], stdx::vector_aligned); // {0, 1, 0, 1, ...}
stdx::native_simd<int> d(&mem[1], stdx::element_aligned); // {1, 0, 1, 0, ...}
auto sum = a + b + c + d;
for (std::size_t i = 0; i < sum.size(); ++i)
std::cout << sum[i] << ' ';
std::cout << '\n';
}
Possible output:
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
π See also π
copy_fromβ loadssimdelements from contiguous memory (parallelism TS v2) (public member function).
k bye bestie, this iconic page is from http://cppreference.com, dated 2024.06.10, and it is literally std::experi...::simd::simd(3) β slay π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms