std::experi...k::simd_mask(3)
π 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_maskusing default initialization (constructed without initializer) or value initialization (constructed with an empty initializer). - 2) The broadcast constructor constructs a
simd_maskwith all values initialized tovalue. - 3) Constructs a
simd_maskwhere the i-th element is initialized toother[i]for all i in the range of[0, size()). This overload participates in overload resolution only ifAbiissimd_abi::fixed_size<size()>. - 4) The load constructor constructs a
simd_maskwhere the i-th element is initialized tomem[i]for all i in the range of[0, size()). - 5, 6) Implicitly declared copy and move constructors. Constructs a
simd_maskwhere each element is initialized from the values of the elements inother.
π Parameters π
valueβ the value used for initialization of allsimd_maskelements.otherβ anothersimd_maskto copy from.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_mask>.
π¦ Type requirements π¦
is_simd_flag_type_v<Flags>must betrue. 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; alsoelement_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; alsovector_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; alsooveralignedβ specified alignment. This pair is marked(parallelism TS v2)and(class template).memory_alignmentβ obtains an appropriate alignment forvector_aligned. Marked(parallelism TS v2)and(class template).copy_fromβ loadssimd_maskelements 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
- 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