mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Implement assume_aligned using the standard API
This implements `Eigen::internal::assume_aligned` to match the API for C++20 standard as best as possible using either `std::assume_aligned` or `__builtin_assume_aligned` if available. If neither is available, the function is a no-op. The override macro `EIGEN_ASSUME_ALIGNED` was changed to a `EIGEN_DONT_ASSUME_ALIGNED`, which now forces the function to be a no-op. See merge request libeigen/eigen!2052
This commit is contained in:
committed by
Charles Schlosser
parent
ce70a507c0
commit
8716f109e4
@@ -1354,19 +1354,21 @@ EIGEN_DEVICE_FUNC void destroy_at(T* p) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* This informs the implementation that PTR is aligned to at least ALIGN_BYTES
|
||||
*/
|
||||
#ifndef EIGEN_ASSUME_ALIGNED
|
||||
#if defined(__cpp_lib_assume_aligned) && (__cpp_lib_assume_aligned >= 201811L)
|
||||
#define EIGEN_ASSUME_ALIGNED(PTR, ALIGN_BYTES) \
|
||||
{ PTR = std::assume_aligned<ALIGN_BYTES>(PTR); }
|
||||
#elif EIGEN_HAS_BUILTIN(__builtin_assume_aligned)
|
||||
#define EIGEN_ASSUME_ALIGNED(PTR, ALIGN_BYTES) \
|
||||
{ PTR = static_cast<decltype(PTR)>(__builtin_assume_aligned(PTR, ALIGN_BYTES)); }
|
||||
#if !defined(EIGEN_DONT_ASSUME_ALIGNED) && defined(__cpp_lib_assume_aligned) && (__cpp_lib_assume_aligned >= 201811L)
|
||||
template <std::size_t N, typename T>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr T* assume_aligned(T* ptr) {
|
||||
return std::assume_aligned<N, T>(ptr);
|
||||
}
|
||||
#elif !defined(EIGEN_DONT_ASSUME_ALIGNED) && EIGEN_HAS_BUILTIN(__builtin_assume_aligned)
|
||||
template <std::size_t N, typename T>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC T* assume_aligned(T* ptr) {
|
||||
return static_cast<T*>(__builtin_assume_aligned(ptr, N));
|
||||
}
|
||||
#else
|
||||
#define EIGEN_ASSUME_ALIGNED(PTR, ALIGN_BYTES) /* do nothing */
|
||||
#endif
|
||||
template <std::size_t N, typename T>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr T* assume_aligned(T* ptr) {
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
Reference in New Issue
Block a user