Fix memory alignment (hence vectorization) on MSVC thanks to help from Armin Berres.

This commit is contained in:
Benoit Jacob 2008-12-15 15:54:33 +00:00
parent d11c8704e0
commit 703951d5cd
3 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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;