From ffcd7bdbd638921fee83cfb903c00c80cf75ea8a Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen <4643818-rmlarsen1@users.noreply.gitlab.com> Date: Fri, 7 Nov 2025 21:25:09 +0000 Subject: [PATCH] Avoid breaking the build on older compilers. See merge request libeigen/eigen!2068 Co-authored-by: Rasmus Munk Larsen --- Eigen/src/Core/arch/clang/PacketMath.h | 14 +++++++------- Eigen/src/Core/arch/clang/Reductions.h | 7 ++++--- Eigen/src/Core/arch/clang/TypeCasting.h | 2 +- Eigen/src/Core/util/Macros.h | 9 ++++++++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Eigen/src/Core/arch/clang/PacketMath.h b/Eigen/src/Core/arch/clang/PacketMath.h index 359f1e4d3..b6ddabfc7 100644 --- a/Eigen/src/Core/arch/clang/PacketMath.h +++ b/Eigen/src/Core/arch/clang/PacketMath.h @@ -458,8 +458,8 @@ EIGEN_CLANG_PACKET_BITWISE_FLOAT(Packet8d, detail::pcast_double_to_long, detail: #undef EIGEN_CLANG_PACKET_BITWISE_FLOAT // --- Min/Max operations --- -#if __has_builtin(__builtin_elementwise_min) && __has_builtin(__builtin_elementwise_max) && \ - __has_builtin(__builtin_elementwise_abs) +#if EIGEN_HAS_BUILTIN(__builtin_elementwise_min) && EIGEN_HAS_BUILTIN(__builtin_elementwise_max) && \ + EIGEN_HAS_BUILTIN(__builtin_elementwise_abs) #define EIGEN_CLANG_PACKET_ELEMENTWISE(PACKET_TYPE) \ template <> \ EIGEN_STRONG_INLINE PACKET_TYPE pmin(const PACKET_TYPE& a, const PACKET_TYPE& b) { \ @@ -506,9 +506,9 @@ EIGEN_CLANG_PACKET_ELEMENTWISE(Packet8l) // --- Math functions (float/double only) --- -#if __has_builtin(__builtin_elementwise_floor) && __has_builtin(__builtin_elementwise_ceil) && \ - __has_builtin(__builtin_elementwise_round) && __has_builtin(__builtin_elementwise_roundeven) && \ - __has_builtin(__builtin_elementwise_trunc) && __has_builtin(__builtin_elementwise_sqrt) +#if EIGEN_HAS_BUILTIN(__builtin_elementwise_floor) && EIGEN_HAS_BUILTIN(__builtin_elementwise_ceil) && \ + EIGEN_HAS_BUILTIN(__builtin_elementwise_round) && EIGEN_HAS_BUILTIN(__builtin_elementwise_roundeven) && \ + EIGEN_HAS_BUILTIN(__builtin_elementwise_trunc) && EIGEN_HAS_BUILTIN(__builtin_elementwise_sqrt) #define EIGEN_CLANG_PACKET_MATH_FLOAT(PACKET_TYPE) \ template <> \ EIGEN_STRONG_INLINE PACKET_TYPE pfloor(const PACKET_TYPE& a) { \ @@ -541,7 +541,7 @@ EIGEN_CLANG_PACKET_MATH_FLOAT(Packet8d) #endif // --- Fused Multiply-Add (MADD) --- -#if defined(__FMA__) && __has_builtin(__builtin_elementwise_fma) +#if defined(__FMA__) && EIGEN_HAS_BUILTIN(__builtin_elementwise_fma) #define EIGEN_CLANG_PACKET_MADD(PACKET_TYPE) \ template <> \ EIGEN_STRONG_INLINE PACKET_TYPE pmadd(const PACKET_TYPE& a, const PACKET_TYPE& b, \ @@ -603,7 +603,7 @@ EIGEN_CLANG_PACKET_SCATTER_GATHER(Packet8l) #undef EIGEN_CLANG_PACKET_SCATTER_GATHER // ---- Various operations that depend on __builtin_shufflevector. -#if __has_builtin(__builtin_shufflevector) +#if EIGEN_HAS_BUILTIN(__builtin_shufflevector) namespace detail { template EIGEN_STRONG_INLINE Packet preverse_impl_8(const Packet& a) { diff --git a/Eigen/src/Core/arch/clang/Reductions.h b/Eigen/src/Core/arch/clang/Reductions.h index 8454a9a85..d9cc5585d 100644 --- a/Eigen/src/Core/arch/clang/Reductions.h +++ b/Eigen/src/Core/arch/clang/Reductions.h @@ -14,7 +14,8 @@ namespace Eigen { namespace internal { // --- Reductions --- -#if __has_builtin(__builtin_reduce_min) && __has_builtin(__builtin_reduce_max) && __has_builtin(__builtin_reduce_or) +#if EIGEN_HAS_BUILTIN(__builtin_reduce_min) && EIGEN_HAS_BUILTIN(__builtin_reduce_max) && \ + EIGEN_HAS_BUILTIN(__builtin_reduce_or) #define EIGEN_CLANG_PACKET_REDUX_MINMAX(PACKET_TYPE) \ template <> \ EIGEN_STRONG_INLINE unpacket_traits::type predux_min(const PACKET_TYPE& a) { \ @@ -36,7 +37,7 @@ EIGEN_CLANG_PACKET_REDUX_MINMAX(Packet8l) #undef EIGEN_CLANG_PACKET_REDUX_MINMAX #endif -#if __has_builtin(__builtin_reduce_add) && __has_builtin(__builtin_reduce_mul) +#if EIGEN_HAS_BUILTIN(__builtin_reduce_add) && EIGEN_HAS_BUILTIN(__builtin_reduce_mul) #define EIGEN_CLANG_PACKET_REDUX_INT(PACKET_TYPE) \ template <> \ EIGEN_STRONG_INLINE unpacket_traits::type predux(const PACKET_TYPE& a) { \ @@ -53,7 +54,7 @@ EIGEN_CLANG_PACKET_REDUX_INT(Packet8l) #undef EIGEN_CLANG_PACKET_REDUX_INT #endif -#if __has_builtin(__builtin_shufflevector) +#if EIGEN_HAS_BUILTIN(__builtin_shufflevector) namespace detail { template EIGEN_STRONG_INLINE scalar_type_of_vector_t ReduceAdd16(const VectorT& a) { diff --git a/Eigen/src/Core/arch/clang/TypeCasting.h b/Eigen/src/Core/arch/clang/TypeCasting.h index 0aa44963f..164056b31 100644 --- a/Eigen/src/Core/arch/clang/TypeCasting.h +++ b/Eigen/src/Core/arch/clang/TypeCasting.h @@ -37,7 +37,7 @@ EIGEN_STRONG_INLINE Packet8l preinterpret(const Packet8d& a) //============================================================================== // pcast //============================================================================== -#if __has_builtin(__builtin_convertvector) +#if EIGEN_HAS_BUILTIN(__builtin_convertvector) template <> EIGEN_STRONG_INLINE Packet16i pcast(const Packet16f& a) { return __builtin_convertvector(a, Packet16i); diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 2b5697aca..e644211f3 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -700,6 +700,13 @@ #define EIGEN_HAS_BUILTIN(x) 0 #endif +// Cross compiler wrapper around LLVM's __has_attribute +#ifdef __has_attribute +#define EIGEN_HAS_ATTRIBUTE(x) __has_attribute(x) +#else +#define EIGEN_HAS_ATTRIBUTE(x) 0 +#endif + // A Clang feature extension to determine compiler features. // We use it to determine 'cxx_rvalue_references' #ifndef __has_feature @@ -831,7 +838,7 @@ #endif // Does the compiler support vector types? -#if __has_attribute(ext_vector_type) && __has_builtin(__builtin_vectorelements) +#if EIGEN_HAS_ATTRIBUTE(ext_vector_type) && EIGEN_HAS_BUILTIN(__builtin_vectorelements) #define EIGEN_ARCH_VECTOR_EXTENSIONS 1 #else #define EIGEN_ARCH_VECTOR_EXTENSIONS 0