diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-03-03 19:22:15 -0800 |
---|---|---|
committer | Antonio Sanchez <cantonios@google.com> | 2021-03-05 08:54:12 -0800 |
commit | 82d61af3a490154ad1c0ae2fe00c561095854897 (patch) | |
tree | 9137169da76e43ef4908ab87dc5990d801c48eda /test/packetmath_test_shared.h | |
parent | 5f0b4a4010af4cbf6161a0d1a03a747addc44a5d (diff) |
Fix rint SSE/NEON again, using optimization barrier.
This is a new version of !423, which failed for MSVC.
Defined `EIGEN_OPTIMIZATION_BARRIER(X)` that uses inline assembly to
prevent operations involving `X` from crossing that barrier. Should
work on most `GNUC` compatible compilers (MSVC doesn't seem to need
this). This is a modified version adapted from what was used in
`psincos_float` and tested on more platforms
(see #1674, https://godbolt.org/z/73ezTG).
Modified `rint` to use the barrier to prevent the add/subtract rounding
trick from being optimized away.
Also fixed an edge case for large inputs that get bumped up a power of two
and ends up rounding away more than just the fractional part. If we are
over `2^digits` then just return the input. This edge case was missed in
the test since the test was comparing approximate equality, which was still
satisfied. Adding a strict equality option catches it.
Diffstat (limited to 'test/packetmath_test_shared.h')
-rw-r--r-- | test/packetmath_test_shared.h | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/test/packetmath_test_shared.h b/test/packetmath_test_shared.h index 027715a89..8624fe2fe 100644 --- a/test/packetmath_test_shared.h +++ b/test/packetmath_test_shared.h @@ -78,13 +78,18 @@ bool isApproxAbs(const Scalar& a, const Scalar& b, const typename NumTraits<Scal return internal::isMuchSmallerThan(a-b, refvalue); } +template<typename Scalar> +inline void print_mismatch(const Scalar* ref, const Scalar* vec, int size) { + std::cout << "ref: [" << Map<const Matrix<Scalar,1,Dynamic> >(ref,size) << "]" << " != vec: [" << Map<const Matrix<Scalar,1,Dynamic> >(vec,size) << "]\n"; +} + template<typename Scalar> bool areApproxAbs(const Scalar* a, const Scalar* b, int size, const typename NumTraits<Scalar>::Real& refvalue) { for (int i=0; i<size; ++i) { if (!isApproxAbs(a[i],b[i],refvalue)) { - std::cout << "ref: [" << Map<const Matrix<Scalar,1,Dynamic> >(a,size) << "]" << " != vec: [" << Map<const Matrix<Scalar,1,Dynamic> >(b,size) << "]\n"; + print_mismatch(a, b, size); return false; } } @@ -95,13 +100,23 @@ template<typename Scalar> bool areApprox(const Scalar* a, const Scalar* b, int s { for (int i=0; i<size; ++i) { - if (a[i]!=b[i] && !internal::isApprox(a[i],b[i])) + if ( a[i]!=b[i] && !internal::isApprox(a[i],b[i]) + && !((numext::isnan)(a[i]) && (numext::isnan)(b[i])) ) + { + print_mismatch(a, b, size); + return false; + } + } + return true; +} + +template<typename Scalar> bool areEqual(const Scalar* a, const Scalar* b, int size) +{ + for (int i=0; i<size; ++i) + { + if ( (a[i] != b[i]) && !((numext::isnan)(a[i]) && (numext::isnan)(b[i])) ) { - if((numext::isnan)(a[i]) && (numext::isnan)(b[i])) - { - continue; - } - std::cout << "ref: [" << Map<const Matrix<Scalar,1,Dynamic> >(a,size) << "]" << " != vec: [" << Map<const Matrix<Scalar,1,Dynamic> >(b,size) << "]\n"; + print_mismatch(a, b, size); return false; } } @@ -178,6 +193,14 @@ struct packet_helper<false,Packet> VERIFY(test::areApprox(ref, data2, PacketSize) && #POP); \ } +#define CHECK_CWISE1_EXACT_IF(COND, REFOP, POP) if(COND) { \ + test::packet_helper<COND,Packet> h; \ + for (int i=0; i<PacketSize; ++i) \ + ref[i] = Scalar(REFOP(data1[i])); \ + h.store(data2, POP(h.load(data1))); \ + VERIFY(test::areEqual(ref, data2, PacketSize) && #POP); \ +} + #define CHECK_CWISE2_IF(COND, REFOP, POP) if(COND) { \ test::packet_helper<COND,Packet> h; \ for (int i=0; i<PacketSize; ++i) \ |