Skip to content

Commit 085a732

Browse files
committed
Fixed signmask by disabling no-signed-zeros and stopped using minuszero
1 parent d303f97 commit 085a732

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

include/xsimd/arch/generic/xsimd_generic_math.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../xsimd_scalar.hpp"
1616
#include "./xsimd_generic_details.hpp"
1717
#include "./xsimd_generic_trigo.hpp"
18+
#include "xsimd/arch/xsimd_constants.hpp"
1819

1920
#include <type_traits>
2021

@@ -95,22 +96,12 @@ namespace xsimd
9596
template <class A>
9697
inline batch<float, A> bitofsign(batch<float, A> const& self, requires_arch<generic>) noexcept
9798
{
98-
// Under fast-math, the compiler might replace minus zero by zero
99-
#ifdef __FAST_MATH__
100-
return self & bitwise_cast<float>(batch<uint32_t, A>::broadcast(0x80000000u));
101-
#else
102-
return self & constants::minuszero<batch<float, A>>();
103-
#endif
99+
return self & constants::signmask<batch<float, A>>();
104100
}
105101
template <class A>
106102
inline batch<double, A> bitofsign(batch<double, A> const& self, requires_arch<generic>) noexcept
107103
{
108-
// Under fast-math, the compiler might replace minus zero by zero
109-
#ifdef __FAST_MATH__
110-
return self & bitwise_cast<double>(batch<uint64_t, A>::broadcast(0x8000000000000000lu));
111-
#else
112-
return self & constants::minuszero<batch<double, A>>();
113-
#endif
104+
return self & constants::signmask<batch<double, A>>();
114105
}
115106

116107
// bitwise_cast

include/xsimd/arch/xsimd_constants.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ namespace xsimd
5656
return bit_cast<double>((uint64_t)DOUBLE); \
5757
}
5858

59+
// Under fast-math, GCC might replace minus zero by zero
60+
// minuszero wouldn't be patched, but this works for signmask
61+
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
62+
#pragma GCC push_options
63+
#pragma GCC optimize("signed-zeros")
64+
#endif
5965
XSIMD_DEFINE_CONSTANT(infinity, (std::numeric_limits<float>::infinity()), (std::numeric_limits<double>::infinity()))
6066
XSIMD_DEFINE_CONSTANT(invlog_2, 1.442695040888963407359924681001892137426645954152986f, 1.442695040888963407359924681001892137426645954152986)
6167
XSIMD_DEFINE_CONSTANT_HEX(invlog_2hi, 0x3fb8b000, 0x3ff7154765200000)
@@ -104,6 +110,9 @@ namespace xsimd
104110
XSIMD_DEFINE_CONSTANT_HEX(twoopi, 0x3f22f983, 0x3fe45f306dc9c883)
105111
XSIMD_DEFINE_CONSTANT(twotonmb, 8388608.0f, 4503599627370496.0)
106112
XSIMD_DEFINE_CONSTANT_HEX(twotonmbo3, 0x3ba14518, 0x3ed428a2f98d7286)
113+
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
114+
#pragma GCC pop_options
115+
#endif
107116

108117
#undef XSIMD_DEFINE_CONSTANT
109118
#undef XSIMD_DEFINE_CONSTANT_HEX

0 commit comments

Comments
 (0)