Skip to content

Commit be56a35

Browse files
authored
Merge pull request #980 from maxmarsc/master
Fixed `constants::signmask` for GCC when using `ffast-math`
2 parents e7edad8 + 72adc23 commit be56a35

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/xsimd/arch/generic/xsimd_generic_math.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ namespace xsimd
9595
template <class A>
9696
inline batch<float, A> bitofsign(batch<float, A> const& self, requires_arch<generic>) noexcept
9797
{
98-
return self & constants::minuszero<batch<float, A>>();
98+
return self & constants::signmask<batch<float, A>>();
9999
}
100100
template <class A>
101101
inline batch<double, A> bitofsign(batch<double, A> const& self, requires_arch<generic>) noexcept
102102
{
103-
return self & constants::minuszero<batch<double, A>>();
103+
return self & constants::signmask<batch<double, A>>();
104104
}
105105

106106
// bitwise_cast

include/xsimd/arch/xsimd_constants.hpp

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

59+
// Under fast-math, GCC might replace signmask (minus zero) by zero
60+
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
61+
#pragma GCC push_options
62+
#pragma GCC optimize("signed-zeros")
63+
#endif
5964
XSIMD_DEFINE_CONSTANT(infinity, (std::numeric_limits<float>::infinity()), (std::numeric_limits<double>::infinity()))
6065
XSIMD_DEFINE_CONSTANT(invlog_2, 1.442695040888963407359924681001892137426645954152986f, 1.442695040888963407359924681001892137426645954152986)
6166
XSIMD_DEFINE_CONSTANT_HEX(invlog_2hi, 0x3fb8b000, 0x3ff7154765200000)
@@ -79,7 +84,6 @@ namespace xsimd
7984
XSIMD_DEFINE_CONSTANT(minlog2, -127.0f, -1023.)
8085
XSIMD_DEFINE_CONSTANT(minlog10, -37.89999771118164f, -308.2547155599167)
8186
XSIMD_DEFINE_CONSTANT(minusinfinity, (-infinity<float>()), (-infinity<double>()))
82-
XSIMD_DEFINE_CONSTANT(minuszero, -0.0f, -0.0)
8387
XSIMD_DEFINE_CONSTANT_HEX(nan, 0xffffffff, 0xffffffffffffffff)
8488
XSIMD_DEFINE_CONSTANT_HEX(oneosqrteps, 0x453504f3, 0x4190000000000000)
8589
XSIMD_DEFINE_CONSTANT_HEX(oneotwoeps, 0x4a800000, 0x4320000000000000)
@@ -104,6 +108,9 @@ namespace xsimd
104108
XSIMD_DEFINE_CONSTANT_HEX(twoopi, 0x3f22f983, 0x3fe45f306dc9c883)
105109
XSIMD_DEFINE_CONSTANT(twotonmb, 8388608.0f, 4503599627370496.0)
106110
XSIMD_DEFINE_CONSTANT_HEX(twotonmbo3, 0x3ba14518, 0x3ed428a2f98d7286)
111+
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
112+
#pragma GCC pop_options
113+
#endif
107114

108115
#undef XSIMD_DEFINE_CONSTANT
109116
#undef XSIMD_DEFINE_CONSTANT_HEX

0 commit comments

Comments
 (0)