Skip to content

Commit

Permalink
Merge pull request #953 from anutosh491/missing_eq_batch_bool
Browse files Browse the repository at this point in the history
Added missing boolean operators in xsimd_api.hpp
  • Loading branch information
JohanMabille authored Oct 11, 2023
2 parents 6363da9 + 76fc72a commit 0f51f66
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/xsimd/arch/xsimd_sse2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ namespace xsimd
template <class A>
inline batch_bool<float, A> neq(batch_bool<float, A> const& self, batch_bool<float, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_cmpneq_ps(self, other);
return _mm_xor_ps(self, other);
}
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
inline batch_bool<T, A> neq(batch_bool<T, A> const& self, batch_bool<T, A> const& other, requires_arch<sse2>) noexcept
Expand All @@ -1174,7 +1174,7 @@ namespace xsimd
template <class A>
inline batch_bool<double, A> neq(batch_bool<double, A> const& self, batch_bool<double, A> const& other, requires_arch<sse2>) noexcept
{
return _mm_cmpneq_pd(self, other);
return _mm_xor_pd(self, other);
}

// reciprocal
Expand Down
30 changes: 30 additions & 0 deletions include/xsimd/types/xsimd_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,21 @@ namespace xsimd
return x == y;
}

/**
* @ingroup batch_logical
*
* Element-wise equality comparison of batches of boolean values \c x and \c y.
* @param x batch of booleans involved in the comparison.
* @param y batch of booleans involved in the comparison.
* @return a boolean batch.
*/
template <class T, class A>
inline auto eq(batch_bool<T, A> const& x, batch_bool<T, A> const& y) noexcept -> decltype(x == y)
{
detail::static_check_supported_config<T, A>();
return x == y;
}

/**
* @ingroup batch_math
*
Expand Down Expand Up @@ -1521,6 +1536,21 @@ namespace xsimd
return x != y;
}

/**
* @ingroup batch_logical
*
* Element-wise inequality comparison of batches of boolean values \c x and \c y.
* @param x batch of booleans involved in the comparison.
* @param y batch of booleans involved in the comparison.
* @return a boolean batch.
*/
template <class T, class A>
inline auto neq(batch_bool<T, A> const& x, batch_bool<T, A> const& y) noexcept -> decltype(x != y)
{
detail::static_check_supported_config<T, A>();
return x != y;
}

/**
* @ingroup batch_arithmetic
*
Expand Down
17 changes: 17 additions & 0 deletions test/test_batch_bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ struct batch_bool_test
CHECK_EQ(batch_bool_type::from_mask(bool_g.interspersed.mask()).mask(), bool_g.interspersed.mask());
}

void test_comparison() const
{
auto bool_g = xsimd::get_bool<batch_bool_type> {};
// eq
{
bool res = xsimd::all(xsimd::eq(bool_g.half, !bool_g.ihalf));
CHECK_UNARY(res);
}
// neq
{
bool res = xsimd::all(xsimd::neq(bool_g.half, bool_g.ihalf));
CHECK_UNARY(res);
}
}

private:
batch_type batch_lhs() const
{
Expand Down Expand Up @@ -469,5 +484,7 @@ TEST_CASE_TEMPLATE("[xsimd batch bool]", B, BATCH_TYPES)
SUBCASE("update operations") { Test.test_update_operations(); }

SUBCASE("mask") { Test.test_mask(); }

SUBCASE("eq neq") { Test.test_comparison(); }
}
#endif

0 comments on commit 0f51f66

Please sign in to comment.