From 1c0048a08c07f4f42995c2f0dc142a0752ecfb0d Mon Sep 17 00:00:00 2001 From: Cheng Wang Date: Sat, 9 Aug 2025 19:32:30 +0000 Subject: [PATCH] Fix inconsistency between ptrue and pcmp_* in HVX --- Eigen/src/Core/arch/HVX/PacketMath.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/arch/HVX/PacketMath.h b/Eigen/src/Core/arch/HVX/PacketMath.h index b9080d988..9b6ceb320 100644 --- a/Eigen/src/Core/arch/HVX/PacketMath.h +++ b/Eigen/src/Core/arch/HVX/PacketMath.h @@ -399,9 +399,26 @@ EIGEN_STRONG_INLINE Packet8f pnegate(const Packet8f& a) { return pnegate_hvx(a); } +template +EIGEN_STRONG_INLINE HVXPacket ptrue_hvx(const HVXPacket& a) { + return HVXPacket::Create(Q6_V_vsplat_R(0x3f800000)); +} +template <> +EIGEN_STRONG_INLINE Packet32f ptrue(const Packet32f& a) { + return ptrue_hvx(a); +} +template <> +EIGEN_STRONG_INLINE Packet16f ptrue(const Packet16f& a) { + return ptrue_hvx(a); +} +template <> +EIGEN_STRONG_INLINE Packet8f ptrue(const Packet8f& a) { + return ptrue_hvx(a); +} + template EIGEN_STRONG_INLINE HVXPacket pcmp_le_hvx(const HVXPacket& a, const HVXPacket& b) { - HVX_Vector v_true = Q6_V_vsplat_R(0x3f800000); + HVX_Vector v_true = ptrue(a).Get(); HVX_VectorPred pred = Q6_Q_vcmp_gt_VsfVsf(a.Get(), b.Get()); return HVXPacket::Create(Q6_V_vmux_QVV(pred, Q6_V_vzero(), v_true)); } @@ -420,7 +437,7 @@ EIGEN_STRONG_INLINE Packet8f pcmp_le(const Packet8f& a, const Packet8f& b) { template EIGEN_STRONG_INLINE HVXPacket pcmp_eq_hvx(const HVXPacket& a, const HVXPacket& b) { - HVX_Vector v_true = Q6_V_vsplat_R(0x3f800000); + HVX_Vector v_true = ptrue(a).Get(); HVX_VectorPred pred = Q6_Q_vcmp_eq_VwVw(a.Get(), b.Get()); return HVXPacket::Create(Q6_V_vmux_QVV(pred, v_true, Q6_V_vzero())); } @@ -439,7 +456,7 @@ EIGEN_STRONG_INLINE Packet8f pcmp_eq(const Packet8f& a, const Packet8f& b) { template EIGEN_STRONG_INLINE HVXPacket pcmp_lt_hvx(const HVXPacket& a, const HVXPacket& b) { - HVX_Vector v_true = Q6_V_vsplat_R(0x3f800000); + HVX_Vector v_true = ptrue(a).Get(); HVX_VectorPred pred = Q6_Q_vcmp_gt_VsfVsf(b.Get(), a.Get()); return HVXPacket::Create(Q6_V_vmux_QVV(pred, v_true, Q6_V_vzero())); } @@ -458,7 +475,7 @@ EIGEN_STRONG_INLINE Packet8f pcmp_lt(const Packet8f& a, const Packet8f& b) { template EIGEN_STRONG_INLINE HVXPacket pcmp_lt_or_nan_hvx(const HVXPacket& a, const HVXPacket& b) { - HVX_Vector v_true = Q6_V_vsplat_R(0x3f800000); + HVX_Vector v_true = ptrue(a).Get(); HVX_VectorPred pred = Q6_Q_vcmp_gt_VsfVsf(b.Get(), a.Get()); return HVXPacket::Create(Q6_V_vmux_QVV(pred, v_true, Q6_V_vzero())); }