Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/xsimd/arch/xsimd_avx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ namespace xsimd
return 0 - self;
}
template <class A>
batch<float, A> neg(batch<float, A> const& self, requires_arch<avx>)
XSIMD_INLINE batch<float, A> neg(batch<float, A> const& self, requires_arch<avx>) noexcept
{
return _mm256_xor_ps(self, _mm256_castsi256_ps(_mm256_set1_epi32(0x80000000)));
}
Expand Down
12 changes: 11 additions & 1 deletion include/xsimd/arch/xsimd_avx512f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,11 +1885,21 @@ namespace xsimd
}

// neg
template <class A, class T>
template <class A, class T, class = std::enable_if_t<std::is_integral_v<T>>>
XSIMD_INLINE batch<T, A> neg(batch<T, A> const& self, requires_arch<avx512f>) noexcept
{
return 0 - self;
}
template <class A>
XSIMD_INLINE batch<float, A> neg(batch<float, A> const& self, requires_arch<avx512f>) noexcept
{
return _mm512_castsi512_ps(_mm512_xor_si512(_mm512_castps_si512(self), _mm512_set1_epi32(0x80000000)));
}
template <class A>
XSIMD_INLINE batch<double, A> neg(batch<double, A> const& self, requires_arch<avx512f>) noexcept
{
return _mm512_castsi512_pd(_mm512_xor_si512(_mm512_castpd_si512(self), _mm512_set1_epi64(0x8000000000000000)));
}

// neq
template <class A>
Expand Down
2 changes: 1 addition & 1 deletion include/xsimd/arch/xsimd_vxe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ namespace xsimd
template <class A, class T>
XSIMD_INLINE batch<T, A> neg(batch<T, A> const& self, requires_arch<vxe>) noexcept
{
return (typename batch<T, A>::register_type) { 0 } - self.data;
return -self.data;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed the issue but I see that one of the checks in CI still continues after 90mins. Is that normal or is there some issue with it ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, but it should be unrelated. i'll manually restart it to be sure

}

// add
Expand Down
17 changes: 17 additions & 0 deletions test/test_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ struct batch_test
INFO("-batch");
CHECK_BATCH_EQ(res, expected);
}
#ifndef __FAST_MATH__
// -batch at signed zero, which CHECK_BATCH_EQ cannot see: it compares
// with ==, and +0 == -0.
if constexpr (std::is_floating_point_v<value_type>)
{
value_type pos_zero(0.0);
value_type neg_zero(-0.0);
batch_type pos_res = -batch_type(pos_zero);
batch_type neg_res = -batch_type(neg_zero);
INFO("-batch (signed zero)");
for (size_t i = 0; i < size; ++i)
{
CHECK(std::signbit(pos_res.get(i)));
CHECK_FALSE(std::signbit(neg_res.get(i)));
}
}
#endif
// batch + batch
{
array_type expected;
Expand Down
18 changes: 18 additions & 0 deletions test/test_xsimd_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <doctest/doctest.h>

#include <cmath>

template <class T>
struct scalar_type
{
Expand Down Expand Up @@ -780,6 +782,15 @@ struct xsimd_api_float_types_functions
value_type val(3.1);
CHECK_EQ(extract(xsimd::nearbyint_as_int(T(val))), long(std::nearbyint(val)));
}
#ifndef __FAST_MATH__
void test_neg_signed_zero()
{
value_type pos_zero(0.0);
value_type neg_zero(-0.0);
CHECK(std::signbit(extract(xsimd::neg(T(pos_zero)))));
CHECK_FALSE(std::signbit(extract(xsimd::neg(T(neg_zero)))));
}
#endif
void test_nextafter()
{
value_type val0(3);
Expand Down Expand Up @@ -1065,6 +1076,13 @@ TEST_CASE_TEMPLATE("[xsimd api | float types functions]", B, FLOAT_TYPES)
Test.test_nearbyint_as_int();
}

#ifndef __FAST_MATH__
SUBCASE("neg_signed_zero")
{
Test.test_neg_signed_zero();
}
#endif

SUBCASE("nextafter")
{
Test.test_nextafter();
Expand Down
Loading