Fix EIGEN_OPTIMIZATION_BARRIER for clang-cl

This commit is contained in:
Antonio Sanchez 2025-07-31 17:02:43 +00:00
parent f5ead2d34c
commit e4493233e8

View File

@ -993,8 +993,9 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(cons
#endif #endif
#if !defined(EIGEN_OPTIMIZATION_BARRIER) #if !defined(EIGEN_OPTIMIZATION_BARRIER)
#if EIGEN_COMP_GNUC // Implement the barrier on GNUC compilers or clang-cl.
// According to https://gcc.gnu.org/onlinedocs/gcc/Constraints.html: #if EIGEN_COMP_GNUC || (defined(__clang__) && defined(_MSC_VER))
// According to https://gcc.gnu.org/onlinedocs/gcc/Constraints.html:
// X: Any operand whatsoever. // X: Any operand whatsoever.
// r: A register operand is allowed provided that it is in a general // r: A register operand is allowed provided that it is in a general
// register. // register.
@ -1027,37 +1028,37 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void ignore_unused_variable(cons
// directly for std::complex<T>, Eigen::half, Eigen::bfloat16. For these, // directly for std::complex<T>, Eigen::half, Eigen::bfloat16. For these,
// you will need to apply to the underlying POD type. // you will need to apply to the underlying POD type.
#if EIGEN_ARCH_PPC && EIGEN_COMP_GNUC_STRICT #if EIGEN_ARCH_PPC && EIGEN_COMP_GNUC_STRICT
// This seems to be broken on clang. Packet4f is loaded into a single // This seems to be broken on clang. Packet4f is loaded into a single
// register rather than a vector, zeroing out some entries. Integer // register rather than a vector, zeroing out some entries. Integer
// types also generate a compile error. // types also generate a compile error.
#if EIGEN_OS_MAC #if EIGEN_OS_MAC
// General, Altivec for Apple (VSX were added in ISA v2.06): // General, Altivec for Apple (VSX were added in ISA v2.06):
#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+r,v"(X)); #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+r,v"(X));
#else #else
// General, Altivec, VSX otherwise: // General, Altivec, VSX otherwise:
#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+r,v,wa"(X)); #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+r,v,wa"(X));
#endif #endif
#elif EIGEN_ARCH_ARM_OR_ARM64 #elif EIGEN_ARCH_ARM_OR_ARM64
#ifdef __ARM_FP #ifdef __ARM_FP
// General, VFP or NEON. // General, VFP or NEON.
// Clang doesn't like "r", // Clang doesn't like "r",
// error: non-trivial scalar-to-vector conversion, possible invalid // error: non-trivial scalar-to-vector conversion, possible invalid
// constraint for vector typ // constraint for vector typ
#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,w"(X)); #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,w"(X));
#else #else
// Arm without VFP or NEON. // Arm without VFP or NEON.
// "w" constraint will not compile. // "w" constraint will not compile.
#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g"(X)); #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g"(X));
#endif #endif
#elif EIGEN_ARCH_i386_OR_x86_64 #elif EIGEN_ARCH_i386_OR_x86_64
// General, SSE. // General, SSE.
#define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,x"(X)); #define EIGEN_OPTIMIZATION_BARRIER(X) __asm__("" : "+g,x"(X));
#else #else
// Not implemented for other architectures. // Not implemented for other architectures.
#define EIGEN_OPTIMIZATION_BARRIER(X) #define EIGEN_OPTIMIZATION_BARRIER(X)
#endif #endif
#else #else
// Not implemented for other compilers. // Not implemented for other compilers.
#define EIGEN_OPTIMIZATION_BARRIER(X) #define EIGEN_OPTIMIZATION_BARRIER(X)
#endif #endif
#endif #endif