diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-01-20 19:00:09 -0800 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-01-21 19:32:28 +0000 |
commit | b2126fd6b5e232d072ceadb1abb6695ae3352e2e (patch) | |
tree | b86944d559717eeee3589efa21dcfd30cbdd2f3d /test/packetmath_test_shared.h | |
parent | 25d8498f8ba29c8dc055dd56113facbdbe154345 (diff) |
Fix pfrexp/pldexp for half.
The recent addition of vectorized pow (!330) relies on `pfrexp` and
`pldexp`. This was missing for `Eigen::half` and `Eigen::bfloat16`.
Adding tests for these packet ops also exposed an issue with handling
negative values in `pfrexp`, returning an incorrect exponent.
Added the missing implementations, corrected the exponent in `pfrexp1`,
and added `packetmath` tests.
Diffstat (limited to 'test/packetmath_test_shared.h')
-rw-r--r-- | test/packetmath_test_shared.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/packetmath_test_shared.h b/test/packetmath_test_shared.h index 46a42604b..027715a89 100644 --- a/test/packetmath_test_shared.h +++ b/test/packetmath_test_shared.h @@ -143,6 +143,9 @@ struct packet_helper template<typename T> inline void store(T* to, const Packet& x, unsigned long long umask) const { internal::pstoreu(to, x, umask); } + + template<typename T> + inline Packet& forward_reference(Packet& packet, T& /*scalar*/) const { return packet; } }; template<typename Packet> @@ -162,6 +165,9 @@ struct packet_helper<false,Packet> template<typename T> inline void store(T* to, const T& x, unsigned long long) const { *to = x; } + + template<typename T> + inline T& forward_reference(Packet& /*packet*/, T& scalar) const { return scalar; } }; #define CHECK_CWISE1_IF(COND, REFOP, POP) if(COND) { \ @@ -180,6 +186,18 @@ struct packet_helper<false,Packet> VERIFY(test::areApprox(ref, data2, PacketSize) && #POP); \ } +// One input, one output by reference. +#define CHECK_CWISE1_BYREF1_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], ref[i+PacketSize])); \ + Packet pout; \ + Scalar sout; \ + h.store(data2, POP(h.load(data1), h.forward_reference(pout, sout))); \ + h.store(data2+PacketSize, h.forward_reference(pout, sout)); \ + VERIFY(test::areApprox(ref, data2, 2 * PacketSize) && #POP); \ +} + #define CHECK_CWISE3_IF(COND, REFOP, POP) if (COND) { \ test::packet_helper<COND, Packet> h; \ for (int i = 0; i < PacketSize; ++i) \ |