diff options
author | Gael Guennebaud <g.gael@free.fr> | 2018-11-30 15:56:08 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2018-11-30 15:56:08 +0100 |
commit | 69ace742be6f00f4280d312e046b0b1422fd112c (patch) | |
tree | 83d296bd2070b1617791dcf0ee8c3bcd6c5ade2a /test/packetmath.cpp | |
parent | fa87f9d876f38e470e5070a451f92a3c19c9d0fe (diff) |
Several improvements regarding packet-bitwise operations:
- add unit tests
- optimize their AVX512f implementation
- add missing implementations (half, Packet4f, ...)
Diffstat (limited to 'test/packetmath.cpp')
-rw-r--r-- | test/packetmath.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 43c33ba94..144083f1b 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -27,7 +27,44 @@ bool g_first_pass = true; namespace Eigen { namespace internal { + template<typename T> T negate(const T& x) { return -x; } + +template<typename T> +Map<const Array<unsigned char,sizeof(T),1> > +bits(const T& x) { + return Map<const Array<unsigned char,sizeof(T),1> >(reinterpret_cast<const unsigned char *>(&x)); +} + +// The following implement bitwise operations on floating point types +template<typename T,typename Bits,typename Func> +T apply_bit_op(Bits a, Bits b, Func f) { + Array<unsigned char,sizeof(T),1> res; + for(Index i=0; i<res.size();++i) res[i] = f(a[i],b[i]); + return *reinterpret_cast<T*>(&res); +} + +#define EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,T) \ + template<> T EIGEN_CAT(p,OP)(const T& a,const T& b) { \ + return apply_bit_op<T>(bits(a),bits(b),FUNC); \ + } + +#define EIGEN_TEST_MAKE_BITWISE(OP,FUNC) \ + EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,float) \ + EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,double) \ + EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,half) \ + EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,std::complex<float>) \ + EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,std::complex<double>) + +EIGEN_TEST_MAKE_BITWISE(xor,std::bit_xor<unsigned char>()) +EIGEN_TEST_MAKE_BITWISE(and,std::bit_and<unsigned char>()) +EIGEN_TEST_MAKE_BITWISE(or, std::bit_or<unsigned char>()) +struct bit_andnot{ + template<typename T> T + operator()(T a, T b) const { return a & (~b); } +}; +EIGEN_TEST_MAKE_BITWISE(andnot, bit_andnot()) + } } @@ -304,6 +341,11 @@ template<typename Scalar,typename Packet> void packetmath() } } + CHECK_CWISE2_IF(true, internal::por, internal::por); + CHECK_CWISE2_IF(true, internal::pxor, internal::pxor); + CHECK_CWISE2_IF(true, internal::pand, internal::pand); + CHECK_CWISE2_IF(true, internal::pandnot, internal::pandnot); + if (PacketTraits::HasBlend) { Packet thenPacket = internal::pload<Packet>(data1); Packet elsePacket = internal::pload<Packet>(data2); |