From 37de4329075110d38085d3651b24a7882e4d3cbe Mon Sep 17 00:00:00 2001 From: Alexander Richardson Date: Wed, 14 Dec 2022 20:06:16 +0000 Subject: [PATCH] Avoid using std::raise() for divide by zero --- Eigen/Core | 4 ---- Eigen/src/Core/functors/BinaryFunctors.h | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Eigen/Core b/Eigen/Core index 48c212189..623d735d6 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -177,10 +177,6 @@ using std::ptrdiff_t; #include "src/Core/arch/Default/TypeCasting.h" #include "src/Core/arch/Default/GenericPacketMathFunctionsFwd.h" -#ifndef EIGEN_GPU_COMPILE_PHASE - #include -#endif - #if defined EIGEN_VECTORIZE_AVX512 #if defined EIGEN_VECTORIZE_AVX512FP16 #include "src/Core/arch/AVX512/PacketMathFP16.h" diff --git a/Eigen/src/Core/functors/BinaryFunctors.h b/Eigen/src/Core/functors/BinaryFunctors.h index eaa4352b8..c8bb4e775 100644 --- a/Eigen/src/Core/functors/BinaryFunctors.h +++ b/Eigen/src/Core/functors/BinaryFunctors.h @@ -388,7 +388,11 @@ template struct maybe_raise_div_by_zero { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Packet x) { if (EIGEN_PREDICT_FALSE(predux_any(pcmp_eq(x, pzero(x))))) { - std::raise(SIGFPE); + // Use volatile variables to force a division by zero, which will + // result in the default platform behaviour (usually SIGFPE). + volatile typename unpacket_traits::type zero = 0; + volatile typename unpacket_traits::type val = 1; + val = val / zero; } } };