Fix special packetmath erfc flushing for ARM32.

This commit is contained in:
Antonio Sánchez 2024-12-07 01:42:30 +00:00 committed by Rasmus Munk Larsen
parent fd48fbb260
commit 7b6623af30

View File

@ -12,6 +12,20 @@
#include "packetmath_test_shared.h" #include "packetmath_test_shared.h"
#include "../Eigen/SpecialFunctions" #include "../Eigen/SpecialFunctions"
#if EIGEN_ARCH_ARM
// Note: 32-bit arm always flushes subnormals to zero.
#define MAYBE_FLUSH(op) \
[](Scalar x) { \
Scalar y = static_cast<Scalar>(op(x)); \
if (Eigen::numext::abs(y) < (std::numeric_limits<decltype(y)>::min)()) { \
y = y * decltype(y)(0); /* Preserve sign. */ \
} \
return y; \
}
#else
#define MAYBE_FLUSH(op) op
#endif
template <typename Scalar, typename Packet> template <typename Scalar, typename Packet>
void packetmath_real() { void packetmath_real() {
using std::abs; using std::abs;
@ -119,7 +133,7 @@ void packetmath_real() {
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErf, std::erf, internal::perf); CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErf, std::erf, internal::perf);
// FIXME(rmlarsen): This test occasionally fails due to difference in tiny subnormal results // FIXME(rmlarsen): This test occasionally fails due to difference in tiny subnormal results
// near the underflow boundary. I am not sure which version is correct. // near the underflow boundary. I am not sure which version is correct.
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErfc, std::erfc, internal::perfc); CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErfc, MAYBE_FLUSH(std::erfc), internal::perfc);
#endif #endif
} }