From e8a43a9c480a0fae1700cc59514137f76fbae228 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 6 Dec 2024 14:12:03 -0800 Subject: [PATCH] Fix special packetmath erfc flushing for ARM32. On ARM32, subnormals are flushed to zero. Modified the reference function to also flush. --- unsupported/test/special_packetmath.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/unsupported/test/special_packetmath.cpp b/unsupported/test/special_packetmath.cpp index 044ce671e..1a53a09ff 100644 --- a/unsupported/test/special_packetmath.cpp +++ b/unsupported/test/special_packetmath.cpp @@ -12,6 +12,20 @@ #include "packetmath_test_shared.h" #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(op(x)); \ + if (Eigen::numext::abs(y) < (std::numeric_limits::min)()) { \ + y = y * decltype(y)(0); /* Preserve sign. */ \ + } \ + return y; \ + } +#else +#define MAYBE_FLUSH(op) op +#endif + template void packetmath_real() { using std::abs; @@ -119,7 +133,7 @@ void packetmath_real() { CHECK_CWISE1_IF(internal::packet_traits::HasErf, std::erf, internal::perf); // 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. - CHECK_CWISE1_IF(internal::packet_traits::HasErfc, std::erfc, internal::perfc); + CHECK_CWISE1_IF(internal::packet_traits::HasErfc, MAYBE_FLUSH(std::erfc), internal::perfc); #endif } -- GitLab