From 66ca41bd47b1f61787d12ed0deaf2512b9821483 Mon Sep 17 00:00:00 2001 From: derekjchow Date: Mon, 19 Jul 2021 16:51:17 -0700 Subject: [PATCH] Add support for vectorizing logical comparisons. --- Eigen/src/Core/arch/NEON/PacketMath.h | 2 ++ Eigen/src/Core/functors/BinaryFunctors.h | 30 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index d2aeef430..8cac1bea2 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -219,6 +219,7 @@ struct packet_traits : default_packet_traits size = 16, HasHalfPacket = 1, + HasCmp = 1, HasAdd = 1, HasSub = 1, HasShift = 1, @@ -248,6 +249,7 @@ struct packet_traits : default_packet_traits size = 16, HasHalfPacket = 1, + HasCmp = 1, HasAdd = 1, HasSub = 1, HasShift = 1, diff --git a/Eigen/src/Core/functors/BinaryFunctors.h b/Eigen/src/Core/functors/BinaryFunctors.h index 63f09ab93..71f894eaf 100644 --- a/Eigen/src/Core/functors/BinaryFunctors.h +++ b/Eigen/src/Core/functors/BinaryFunctors.h @@ -110,13 +110,13 @@ struct scalar_conj_product_op : binary_op_base enum { Conj = NumTraits::IsComplex }; - + typedef typename ScalarBinaryOpTraits::ReturnType result_type; - + EIGEN_EMPTY_STRUCT_CTOR(scalar_conj_product_op) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return conj_helper().pmul(a,b); } - + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const { return conj_helper().pmul(a,b); } @@ -205,7 +205,8 @@ template struct functor_traits > { enum { Cost = (NumTraits::AddCost+NumTraits::AddCost)/2, - PacketAccess = false + PacketAccess = is_same::value && + packet_traits::HasCmp }; }; @@ -221,6 +222,9 @@ struct scalar_cmp_op : binary_op_base + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_eq(a,b); } }; template struct scalar_cmp_op : binary_op_base @@ -228,6 +232,9 @@ struct scalar_cmp_op : binary_op_base + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_lt(a,b); } }; template struct scalar_cmp_op : binary_op_base @@ -235,6 +242,9 @@ struct scalar_cmp_op : binary_op_base + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_le(a,b); } }; template struct scalar_cmp_op : binary_op_base @@ -242,6 +252,9 @@ struct scalar_cmp_op : binary_op_baseb;} + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_lt(b,a); } }; template struct scalar_cmp_op : binary_op_base @@ -249,6 +262,9 @@ struct scalar_cmp_op : binary_op_base=b;} + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_le(b,a); } }; template struct scalar_cmp_op : binary_op_base @@ -256,6 +272,9 @@ struct scalar_cmp_op : binary_op_base + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_eq(internal::por(internal::pcmp_le(a, b), internal::pcmp_le(b, a)), internal::pzero(a)); } }; template struct scalar_cmp_op : binary_op_base @@ -263,6 +282,9 @@ struct scalar_cmp_op : binary_op_base + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& a, const Packet& b) const + { return internal::pcmp_eq(internal::pcmp_eq(a, b), internal::pzero(a)); } }; /** \internal