std::experi...or==,!=,,>=(3)

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

πŸ’– C++ Standard Libary: std::experi...or==,!=,,>=(3) πŸ’–

Manual page for std::experimental::simd::operator==,!=,<,<=,>,>= β€” and yeah, the β€œLibary” spelling is straight from the header, don’t come for me πŸ’€. This is the C++ Standard Library page for all the element-wise comparison operators on std::experimental::simd.


πŸŽ€ NAME πŸŽ€

  • std::experimental::simd::operator==,!=,,>= β€” std::experimental::simd::operator==,!=,,>=

✨ Synopsis ✨

Six friend functions, each one noexcept, each one tagged (parallelism TS v2). Numbered like the original:

  1. friend simd_mask operator==( const simd& lhs, const simd& rhs ) noexcept; β€” (1) (parallelism TS v2)
  2. friend simd_mask operator!=( const simd& lhs, const simd& rhs ) noexcept; β€” (2) (parallelism TS v2)
  3. friend simd_mask operator<( const simd& lhs, const simd& rhs ) noexcept; β€” (3) (parallelism TS v2)
  4. friend simd_mask operator<=( const simd& lhs, const simd& rhs ) noexcept; β€” (4) (parallelism TS v2)
  5. friend simd_mask operator>( const simd& lhs, const simd& rhs ) noexcept; β€” (5) (parallelism TS v2)
  6. friend simd_mask operator>=( const simd& lhs, const simd& rhs ) noexcept; β€” (6) (parallelism TS v2)

Okay so the tea β˜•: these apply the given comparison element-wise to each corresponding element of the operands. You get back a simd_mask such that for all i in the range of [0, size()) the i^th element equals:

  1. lhs[i] == rhs[i].
  2. lhs[i] != rhs[i].
  3. lhs[i] < rhs[i].
  4. lhs[i] <= rhs[i].
  5. lhs[i] > rhs[i].
  6. lhs[i] >= rhs[i].

🫢 Parameters 🫢

  • lhs β€” left operands. The left side of the comparison, bestie.
  • rhs β€” right operands. The right side, obviously.

🌸 Example 🌸

Run this code, bestie β€” here’s the whole example, no skips πŸ’–:

// Run this code

#include <cassert>
#include <iostream>
#include <initializer_list>
#include <iterator>

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

int main()
{
    using V = stdx::fixed_size_simd<int, 4>;
    using M = stdx::fixed_size_simd_mask<int, 4>;

    auto assert_equivalence = [](M&& x, std::initializer_list<int>&& y)
    {
        for (decltype(M::size()) i{}; i != M::size(); ++i)
            assert(x[i] == std::cbegin(y)[i]);
    };

    V a{2}, b, c{3};
    b[0] = 1, b[1] = 2, b[2] = 3, b[3] = 4;

    // a == {2, 2, 2, 2}
    // b == {1, 2, 3, 4}
    // c == {3, 3, 3, 3}

    assert_equivalence(a == a, {1, 1, 1, 1});
    assert_equivalence(a == b, {0, 1, 0, 0});
    assert_equivalence(b == c, {0, 0, 1, 0});
    assert_equivalence(a == c, {0, 0, 0, 0});

    assert_equivalence(a != a, {0, 0, 0, 0});
    assert_equivalence(a != b, {1, 0, 1, 1});
    assert_equivalence(b != c, {1, 1, 0, 1});
    assert_equivalence(a != c, {1, 1, 1, 1});

    assert_equivalence(a < a, {0, 0, 0, 0});
    assert_equivalence(a < b, {0, 0, 1, 1});
    assert_equivalence(b < c, {1, 1, 0, 0});
    assert_equivalence(a < c, {1, 1, 1, 1});
}

πŸ¦‹ See also πŸ¦‹

  • all_of, any_of, none_of, some_of β€” reductions of simd_mask to bool (function template) (parallelism TS v2)
  • popcount β€” reduction of simd_mask to the number of true values (function template) (parallelism TS v2)
  • find_first_set, find_last_set β€” reductions of simd_mask to the index of the first or last true value (function template) (parallelism TS v2)
  • simd_mask β€” data-parallel type with the element type bool (class template) (parallelism TS v2)

Source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::experi...or==,!=,,>=(3). Stay slay, bestie πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from