aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/packetmath.cpp
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2020-06-23 08:58:34 -0700
committerGravatar Antonio Sanchez <cantonios@google.com>2020-06-24 14:03:35 -0700
commit7222f0b6b58759b2207e6ec3224adb246fd23349 (patch)
tree28ac31a00f7b1ed717f915ee10c9ab07f0512441 /test/packetmath.cpp
parent14f84978e8a96a8aea412fb418f86da01e52eb9b (diff)
Fix packetmath_1 float tests for arm/aarch64.
Added missing `pmadd<Packet2f>` for NEON. This leads to significant improvement in precision than previous `pmul+padd`, which was causing the `pcos` tests to fail. Also added an approx test with `std::sin`/`std::cos` since otherwise returning any `a^2+b^2=1` would pass. Modified `log(denorm)` tests. Denorms are not always supported by all systems (returns `::min`), are always flushed to zero on 32-bit arm, and configurably flush to zero on sse/avx/aarch64. This leads to inconsistent results across different systems (i.e. `-inf` vs `nan`). Added a check for existence and exclude ARM. Removed logistic exactness test, since scalar and vectorized versions follow different code-paths due to differences in `pexp` and `pmadd`, which result in slightly different values. For example, exactness always fails on arm, aarch64, and altivec.
Diffstat (limited to 'test/packetmath.cpp')
-rw-r--r--test/packetmath.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/packetmath.cpp b/test/packetmath.cpp
index a57a3b6a5..72a9c8d51 100644
--- a/test/packetmath.cpp
+++ b/test/packetmath.cpp
@@ -8,6 +8,7 @@
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#include <limits>
#include "packetmath_test_shared.h"
template <typename T>
@@ -666,9 +667,6 @@ void packetmath_real() {
h.store(data2, logistic.packetOp(h.load(data1)));
for (int i = 0; i < PacketSize; ++i) {
VERIFY_IS_APPROX(data2[i], logistic(data1[i]));
-#ifdef EIGEN_VECTORIZE // don't check for exactness when using the i387 FPU
- VERIFY_IS_EQUAL(data2[i], logistic(data1[i]));
-#endif
}
}
@@ -702,11 +700,16 @@ void packetmath_real() {
VERIFY_IS_EQUAL(std::log((std::numeric_limits<Scalar>::min)()), data2[0]);
VERIFY((numext::isnan)(data2[1]));
- data1[0] = std::numeric_limits<Scalar>::denorm_min();
- data1[1] = -std::numeric_limits<Scalar>::denorm_min();
- h.store(data2, internal::plog(h.load(data1)));
- // VERIFY_IS_EQUAL(std::log(std::numeric_limits<Scalar>::denorm_min()), data2[0]);
- VERIFY((numext::isnan)(data2[1]));
+ // Note: 32-bit arm always flushes denorms to zero.
+#if !EIGEN_ARCH_ARM
+ if (std::numeric_limits<Scalar>::has_denorm == std::float_denorm_style::denorm_present) {
+ data1[0] = std::numeric_limits<Scalar>::denorm_min();
+ data1[1] = -std::numeric_limits<Scalar>::denorm_min();
+ h.store(data2, internal::plog(h.load(data1)));
+ // VERIFY_IS_EQUAL(std::log(std::numeric_limits<Scalar>::denorm_min()), data2[0]);
+ VERIFY((numext::isnan)(data2[1]));
+ }
+#endif
data1[0] = Scalar(-1.0f);
h.store(data2, internal::plog(h.load(data1)));
@@ -745,6 +748,11 @@ void packetmath_real() {
VERIFY(data2[PacketSize + 0] <= Scalar(1.) && data2[PacketSize + 0] >= Scalar(-1.));
VERIFY(data2[PacketSize + 1] <= Scalar(1.) && data2[PacketSize + 1] >= Scalar(-1.));
+ VERIFY_IS_APPROX(data2[0], std::cos(data1[0]));
+ VERIFY_IS_APPROX(data2[1], std::cos(data1[1]));
+ VERIFY_IS_APPROX(data2[PacketSize + 0], std::sin(data1[0]));
+ VERIFY_IS_APPROX(data2[PacketSize + 1], std::sin(data1[1]));
+
VERIFY_IS_APPROX(numext::abs2(data2[0]) + numext::abs2(data2[PacketSize + 0]), Scalar(1));
VERIFY_IS_APPROX(numext::abs2(data2[1]) + numext::abs2(data2[PacketSize + 1]), Scalar(1));
}