From 132f281f501380faeba1b5b1fe7e4f237099c2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Sat, 14 Sep 2024 01:31:21 +0000 Subject: [PATCH] Fix generic ceil for SSE2. --- Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h index 0e841582a..5bce19464 100644 --- a/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +++ b/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h @@ -2598,11 +2598,14 @@ template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet generic_ceil(const Packet& a) { using Scalar = typename unpacket_traits::type; const Packet cst_1 = pset1(Scalar(1)); + const Packet sign_mask = pset1(static_cast(-0.0)); Packet rint_a = generic_rint(a); // if rint(a) < a, then rint(a) == floor(a) Packet mask = pcmp_lt(rint_a, a); Packet offset = pand(cst_1, mask); Packet result = padd(rint_a, offset); + // Signed zero must remain signed (e.g. ceil(-0.02) == -0). + result = por(result, pand(sign_mask, a)); return result; }