use built in alloca with align if available
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 4409d64..7edd0a1 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h
@@ -765,6 +765,9 @@ // We always manually re-align the result of EIGEN_ALLOCA. // If alloca is already aligned, the compiler should be smart enough to optimize away the re-alignment. +#if (EIGEN_COMP_GNUC || EIGEN_COMP_CLANG) +#define EIGEN_ALIGNED_ALLOCA(SIZE) __builtin_alloca_with_align(SIZE, CHAR_BIT* EIGEN_DEFAULT_ALIGN_BYTES) +#else EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* eigen_aligned_alloca_helper(void* ptr) { constexpr std::uintptr_t mask = EIGEN_DEFAULT_ALIGN_BYTES - 1; std::uintptr_t ptr_int = std::uintptr_t(ptr); @@ -772,8 +775,9 @@ std::uintptr_t offset = aligned_ptr_int - ptr_int; return static_cast<void*>(static_cast<uint8_t*>(ptr) + offset); } - #define EIGEN_ALIGNED_ALLOCA(SIZE) eigen_aligned_alloca_helper(EIGEN_ALLOCA(SIZE + EIGEN_DEFAULT_ALIGN_BYTES - 1)) +#endif + #else #define EIGEN_ALIGNED_ALLOCA(SIZE) EIGEN_ALLOCA(SIZE) #endif