std::experi...::simd::simd(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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)
  1. Constructs a simd using default initialization (constructed without initializer) or value initialization (constructed with an empty initializer).
  2. The broadcast constructor constructs a simd with all values initialized to value. This overload participates in overload resolution only if the conversion from U to T is value-preserving, or U is either int or unsigned int if T is an unsigned integral type.
  3. Constructs a simd where the i-th element is initialized to static_cast<T>(other[i]) for all i in the range of [0, size()). This overload participates in overload resolution only if Abi is simd_abi::fixed_size<size()> and the conversion from U to T is value-preserving, and, if both U and T are integral, the integer conversion rank of T is greater than the integer conversion rank of U.
  4. The generator constructor constructs a simd where the i-th element is initialized to generator(std::integral_constant<std::size_t, i>()). This overload participates in overload resolution only if simd(gen(std::integral_constant<std::size_t, i>())) is well-formed for all i in the range of [0, size()). The calls to generator are unsequenced with respect to each other. Vectorization-unsafe standard library functions may not be invoked by generator.
  5. The load constructor constructs a simd where the i-th element is initialized to static_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 all simd elements.
  • other β€” another simd to copy from.
  • generator β€” a function object used for initialization of each simd element.
  • mem β€” a pointer into an array where [mem, mem + size()) is a valid range.
  • flags β€” if of type vector_aligned_tag, the load constructor may assume mem to point to storage aligned by memory_alignment_v<simd, U>.

🌈 Type requirements 🌈

  • The conversion from U to T must be value-preserving. The broadcast constructor (2) additionally allows U to be int or to be unsigned int if T is 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 β€” loads simd elements 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