std::experi...k::simd_mask(3)

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

πŸ’– NAME πŸ’–

okay bestie, welcome to the manual page for std::experi...k::simd_mask(3) from the C++ Standard Libary β€” yes, that's the spelling in the header, and we are not fixing it because details are sacred 😌. The name on the cover is std::experimental::simd_mask::simd_mask - std::experimental::simd_mask::simd_mask, aka the constructor of the mask type. It's giving main character energy for SIMD lanes, and honestly? iconic.

✨ Synopsis ✨

okay so here's the whole constructor lineup, copied with zero changes because code is not a vibe, it's a contract:

simd_mask() noexcept = default;                            (1)
explicit simd_mask( bool value ) noexcept;                 (2)
template< class U >
simd_mask( const simd_mask<U,
simd_abi::fixed_size<size()>>& other ) noexcept;           (3)
template< class U, class Flags >
simd_mask( const bool* mem, Flags flags );                 (4)
simd_mask( const simd_mask& other ) noexcept = default;    (5)
simd_mask( simd_mask&& other ) noexcept = default;         (6)

Every overload above is tagged (parallelism TS v2) in the page, and (5) plus (6) are also (implicitly declared). periodt 🫢

  • 1) Constructs a simd_mask using default initialization (constructed without initializer) or value initialization (constructed with an empty initializer).
  • 2) The broadcast constructor constructs a simd_mask with all values initialized to value.
  • 3) Constructs a simd_mask where the i-th element is initialized to 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()>.
  • 4) The load constructor constructs a simd_mask where the i-th element is initialized to mem[i] for all i in the range of [0, size()).
  • 5, 6) Implicitly declared copy and move constructors. Constructs a simd_mask where each element is initialized from the values of the elements in other.

πŸŽ€ Parameters πŸŽ€

  • value β€” the value used for initialization of all simd_mask elements.
  • other β€” another simd_mask to copy from.
  • 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_mask>.

πŸ¦‹ Type requirements πŸ¦‹

  • is_simd_flag_type_v<Flags> must be true. no cap, that's the whole requirement πŸ’…

🌸 Example 🌸

the page says // Run this code, so let's go, bestie. This is the exact example, no edits:

#include <algorithm>
#include <cstddef>
#include <experimental/simd>
#include <iostream>
namespace stdx = std::experimental;

int main()
{
    [[maybe_unused]]
    stdx::native_simd_mask<int> a;       // uninitialized
    stdx::native_simd_mask<int> b(true); // all elements initialized with true
    stdx::native_simd_mask<int> c{};     // all elements initialized with false

    alignas(stdx::memory_alignment_v<stdx::native_simd_mask<int>>)
        std::array<bool, stdx::native_simd_mask<int>::size() * 2> mem = {};
    std::ranges::generate(mem, [i{0}] mutable -> bool { return i++ & 1; });

    stdx::native_simd_mask<int> d(&mem[0], stdx::vector_aligned);  // {0, 1, 0, 1, ...}
    stdx::native_simd_mask<int> e(&mem[1], stdx::element_aligned); // {1, 0, 1, 0, ...}

    const auto xored = b ^ c ^ d ^ e;

    for (std::size_t i{}; i != xored.size(); ++i)
        std::cout << xored[i] << ' ';
    std::cout << '\n';
}

🌈 Possible output 🌈

0 0 0 0 0 0 0 0

πŸ‘‘ See also πŸ‘‘

okay related lore, all of it:

  • element_aligned_tag β€” flag indicating alignment of the load/store address to element alignment; also element_aligned β€” alignment. This pair is marked (parallelism TS v2) and (class).
  • vector_aligned_tag β€” flag indicating alignment of the load/store address to vector alignment; also vector_aligned β€” alignment. This pair is marked (parallelism TS v2) and (class).
  • overaligned_tag β€” flag indicating alignment of the load/store address to the specified alignment; also overaligned β€” specified alignment. This pair is marked (parallelism TS v2) and (class template).
  • memory_alignment β€” obtains an appropriate alignment for vector_aligned. Marked (parallelism TS v2) and (class template).
  • copy_from β€” loads simd_mask elements from contiguous memory. Marked (parallelism TS v2) and (public member function).

πŸ’Œ source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::experi...k::simd_mask(3) β€” byeee bestie, go construct some iconic masks πŸ’…βœ¨

πŸ“¦ where this page comes from