mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
Fix memory alignment (hence vectorization) on MSVC thanks to help from Armin Berres.
This commit is contained in:
parent
d11c8704e0
commit
703951d5cd
@ -44,6 +44,10 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#if(defined(_MSC_VER) && defined(EIGEN_VECTORIZE))
|
||||
#include <malloc.h> // for _aligned_malloc
|
||||
#endif
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
/** \defgroup Core_Module Core module
|
||||
|
@ -108,6 +108,8 @@ using Eigen::ei_cos;
|
||||
|
||||
#if (defined __GNUC__)
|
||||
#define EIGEN_ALIGN_128 __attribute__ ((aligned(16)))
|
||||
#elif (defined _MSC_VER)
|
||||
#define EIGEN_ALIGN_128 __declspec(align(16))
|
||||
#else
|
||||
#define EIGEN_ALIGN_128
|
||||
#endif
|
||||
|
@ -55,10 +55,14 @@ template<typename T>
|
||||
inline T* ei_aligned_malloc(size_t size)
|
||||
{
|
||||
#ifdef EIGEN_VECTORIZE
|
||||
if (ei_packet_traits<T>::size>1)
|
||||
if(ei_packet_traits<T>::size>1)
|
||||
{
|
||||
void* ptr;
|
||||
if (posix_memalign(&ptr, 16, size*sizeof(T))==0)
|
||||
#ifdef _MSC_VER
|
||||
if(ptr = _aligned_malloc(size*sizeof(T), 16))
|
||||
#else
|
||||
if(posix_memalign(&ptr, 16, size*sizeof(T))==0)
|
||||
#endif
|
||||
return static_cast<T*>(ptr);
|
||||
else
|
||||
return 0;
|
||||
@ -74,7 +78,11 @@ inline void ei_aligned_free(T* ptr)
|
||||
{
|
||||
#ifdef EIGEN_VECTORIZE
|
||||
if (ei_packet_traits<T>::size>1)
|
||||
#ifdef _MSC_VER
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
else
|
||||
#endif
|
||||
delete[] ptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user