use built in alloca with align if available

This commit is contained in:
Charles Schlosser 2024-05-19 19:32:49 +00:00
parent b9b1c8661e
commit f78dfe36b0

View File

@ -765,6 +765,9 @@ void swap(scoped_array<T>& a, scoped_array<T>& b) {
// 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 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* eigen_aligned_alloca_helper(void* pt
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