From 29c8e3c754db4d2bb7a469676bb6e96d1f9c0226 Mon Sep 17 00:00:00 2001 From: Charles Schlosser Date: Fri, 21 Apr 2023 05:47:56 +0000 Subject: [PATCH] fix pow for uint32_t, disable pmul --- Eigen/src/Core/arch/AVX/PacketMath.h | 2 +- .../arch/Default/GenericPacketMathFunctions.h | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/arch/AVX/PacketMath.h b/Eigen/src/Core/arch/AVX/PacketMath.h index e4aac9e6f..d61e548c1 100644 --- a/Eigen/src/Core/arch/AVX/PacketMath.h +++ b/Eigen/src/Core/arch/AVX/PacketMath.h @@ -276,7 +276,7 @@ template<> struct packet_traits : default_packet_traits HasTranspose = 0, HasNegate = 0, HasSqrt = 0, - + HasMul = 0, HasCmp = 1, HasShift = 1 }; diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index be215328a..13fafe309 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -2152,15 +2152,15 @@ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet handle_nonint_nonint_errors( return result; } -template +template ::type>::IsSigned, bool> = true> static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet handle_int_int(const Packet& x, const ScalarExponent& exponent) { typedef typename unpacket_traits::type Scalar; - // integer base, integer exponent case + // signed integer base, integer exponent case // This routine handles negative and very large positive exponents // Signed integer overflow and divide by zero is undefined behavior - // Unsigned intgers do not overflow + // Unsigned integers do not overflow const bool exponent_is_odd = unary_pow::is_odd::run(exponent); @@ -2181,6 +2181,31 @@ static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet handle_int_int(const Packet& result = pselect(pand(pow_is_one, pow_is_neg), pnegate(cst_pos_one), result); return result; } + +template ::type>::IsSigned, bool> = true> +static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet handle_int_int(const Packet& x, const ScalarExponent& exponent) { + typedef typename unpacket_traits::type Scalar; + + // unsigned integer base, integer exponent case + + // This routine handles negative and very large positive exponents + // Signed integer overflow and divide by zero is undefined behavior + // Unsigned integers do not overflow + + const Scalar zero = Scalar(0); + const Scalar pos_one = Scalar(1); + + const Packet cst_zero = pset1(zero); + const Packet cst_pos_one = pset1(pos_one); + + const Packet pow_is_zero = exponent < 0 ? pcmp_lt(cst_pos_one, x) : pzero(x); + const Packet pow_is_one = pcmp_eq(cst_pos_one, x); + + Packet result = pselect(pow_is_zero, cst_zero, x); + result = pselect(pow_is_one, cst_pos_one, result); + return result; +} + } // end namespace unary_pow template