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 <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#if(defined(_MSC_VER) && defined(EIGEN_VECTORIZE))
|
||||||
|
#include <malloc.h> // for _aligned_malloc
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Eigen {
|
namespace Eigen {
|
||||||
|
|
||||||
/** \defgroup Core_Module Core module
|
/** \defgroup Core_Module Core module
|
||||||
|
@ -108,6 +108,8 @@ using Eigen::ei_cos;
|
|||||||
|
|
||||||
#if (defined __GNUC__)
|
#if (defined __GNUC__)
|
||||||
#define EIGEN_ALIGN_128 __attribute__ ((aligned(16)))
|
#define EIGEN_ALIGN_128 __attribute__ ((aligned(16)))
|
||||||
|
#elif (defined _MSC_VER)
|
||||||
|
#define EIGEN_ALIGN_128 __declspec(align(16))
|
||||||
#else
|
#else
|
||||||
#define EIGEN_ALIGN_128
|
#define EIGEN_ALIGN_128
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,7 +58,11 @@ inline T* ei_aligned_malloc(size_t size)
|
|||||||
if(ei_packet_traits<T>::size>1)
|
if(ei_packet_traits<T>::size>1)
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
if(ptr = _aligned_malloc(size*sizeof(T), 16))
|
||||||
|
#else
|
||||||
if(posix_memalign(&ptr, 16, size*sizeof(T))==0)
|
if(posix_memalign(&ptr, 16, size*sizeof(T))==0)
|
||||||
|
#endif
|
||||||
return static_cast<T*>(ptr);
|
return static_cast<T*>(ptr);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
@ -74,7 +78,11 @@ inline void ei_aligned_free(T* ptr)
|
|||||||
{
|
{
|
||||||
#ifdef EIGEN_VECTORIZE
|
#ifdef EIGEN_VECTORIZE
|
||||||
if (ei_packet_traits<T>::size>1)
|
if (ei_packet_traits<T>::size>1)
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
_aligned_free(ptr);
|
||||||
|
#else
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
delete[] ptr;
|
delete[] ptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user