Skip to content
Open
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
26 changes: 22 additions & 4 deletions include/xsimd/arch/common/xsimd_common_trigo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ namespace xsimd
}
namespace detail
{
// The sign-bit mask -0.0 hidden from the optimizer: under -fno-signed-zeros (part of -ffast-math) -0.0 and
// 0.0 compare equal, so the compiler may fold select(c, -0.0, 0.0) to one of them and lose the selection.
// Other builds use constants::signmask itself, so their code is unchanged.
#if XSIMD_REASSOCIATIVE_MATH
namespace trigo_constants
{
template <class B>
XSIMD_INLINE B signmask() noexcept
{
B mask = constants::signmask<B>();
reassociation_barrier(mask, "keep the sign-bit mask -0.0 under -fno-signed-zeros");
return mask;
}
}
#else
namespace trigo_constants = constants;
#endif

// For z = x + iy, returns Re sqrt(1 - z^2) as the real part and |Im asin(z)| as the imaginary part.
// With p = sqrt(1 + z) and q = sqrt(1 - z):
// Re sqrt(1 - z^2) = Re(q * p), |Im asin(z)| = asinh(Im(conj(q) p))
Expand Down Expand Up @@ -693,7 +711,7 @@ namespace xsimd
const batch_type n = detail::trigo_reducer<batch_type>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
auto sign_bit = select((swap_bit ^ tmp) != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
auto sign_bit = select((swap_bit ^ tmp) != batch_type(0.), detail::trigo_constants::signmask<batch_type>(), batch_type(0.));
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
Expand Down Expand Up @@ -750,7 +768,7 @@ namespace xsimd
const batch_type n = detail::trigo_reducer<batch_type, Tag>::reduce(x, xr);
auto tmp = select(n >= batch_type(2.), batch_type(1.), batch_type(0.));
auto swap_bit = fma(batch_type(-2.), tmp, n);
auto sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
auto sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), detail::trigo_constants::signmask<batch_type>(), batch_type(0.));
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
Expand Down Expand Up @@ -784,9 +802,9 @@ namespace xsimd
const batch_type z = xr * xr;
const batch_type se = detail::sin_eval(z, xr);
const batch_type ce = detail::cos_eval(z);
auto sin_sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
auto sin_sign_bit = bitofsign(self) ^ select(tmp != batch_type(0.), detail::trigo_constants::signmask<batch_type>(), batch_type(0.));
const batch_type sin_z1 = select(swap_bit == batch_type(0.), se, ce);
auto cos_sign_bit = select((swap_bit ^ tmp) != batch_type(0.), constants::signmask<batch_type>(), batch_type(0.));
auto cos_sign_bit = select((swap_bit ^ tmp) != batch_type(0.), detail::trigo_constants::signmask<batch_type>(), batch_type(0.));
const batch_type cos_z1 = select(swap_bit != batch_type(0.), se, ce);
return std::make_pair(sin_z1 ^ sin_sign_bit, cos_z1 ^ cos_sign_bit);
}
Expand Down
8 changes: 0 additions & 8 deletions include/xsimd/arch/xsimd_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ namespace xsimd
return bit_cast<double>((uint64_t)DOUBLE); \
}

// Under fast-math, GCC might replace signmask (minus zero) by zero
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
#pragma GCC push_options
#pragma GCC optimize("signed-zeros")
#endif
#ifndef __FAST_MATH__
XSIMD_DEFINE_CONSTANT(infinity, (std::numeric_limits<float>::infinity()), (std::numeric_limits<double>::infinity()))
XSIMD_DEFINE_CONSTANT(minusinfinity, (-infinity<float>()), (-infinity<double>()))
Expand Down Expand Up @@ -110,9 +105,6 @@ namespace xsimd
XSIMD_DEFINE_CONSTANT_HEX(twoopi, 0x3f22f983, 0x3fe45f306dc9c883)
XSIMD_DEFINE_CONSTANT(twotonmb, 8388608.0f, 4503599627370496.0)
XSIMD_DEFINE_CONSTANT_HEX(twotonmbo3, 0x3ba14518, 0x3ed428a2f98d7286)
#if defined(__FAST_MATH__) && defined(__GNUC__) && !defined(__clang__)
#pragma GCC pop_options
#endif

#undef XSIMD_DEFINE_CONSTANT
#undef XSIMD_DEFINE_CONSTANT_HEX
Expand Down