Make atVec3d 32-byte aligned

This commit is contained in:
Jack Andersen 2017-12-18 17:04:03 -10:00
parent 2c66d56076
commit cee9478773

View File

@ -14,8 +14,7 @@ using atUint64 = uint64_t;
// Vector types // Vector types
#if __SSE__ #if __SSE__
#include <xmmintrin.h> #include <immintrin.h>
#include <emmintrin.h>
#ifndef _WIN32 #ifndef _WIN32
#include <mm_malloc.h> #include <mm_malloc.h>
#endif #endif
@ -32,6 +31,16 @@ void operator delete(void* buf) noexcept \
void operator delete[](void* buf) noexcept \ void operator delete[](void* buf) noexcept \
{_mm_free(buf);} {_mm_free(buf);}
#define AT_ALIGNED_ALLOCATOR32 \
void* operator new(size_t bytes) noexcept \
{return _mm_malloc(bytes, 32);} \
void* operator new[](size_t bytes) noexcept \
{return _mm_malloc(bytes, 32);} \
void operator delete(void* buf) noexcept \
{_mm_free(buf);} \
void operator delete[](void* buf) noexcept \
{_mm_free(buf);}
typedef union alignas(16) typedef union alignas(16)
{ {
#if __clang__ #if __clang__
@ -77,20 +86,30 @@ typedef union alignas(16)
double vec[2]; double vec[2];
} atVec2d; } atVec2d;
typedef union alignas(16) typedef union alignas(32)
{ {
#if __AVX__
__m256d mVec256;
AT_ALIGNED_ALLOCATOR32
#elif __SSE__
AT_ALIGNED_ALLOCATOR
#endif
#if __SSE__ #if __SSE__
__m128d mVec128[2]; __m128d mVec128[2];
AT_ALIGNED_ALLOCATOR
#endif #endif
double vec[3]; double vec[3];
} atVec3d; } atVec3d;
typedef union alignas(16) typedef union alignas(32)
{ {
#if __AVX__
__m256d mVec256;
AT_ALIGNED_ALLOCATOR32
#elif __SSE__
AT_ALIGNED_ALLOCATOR
#endif
#if __SSE__ #if __SSE__
__m128d mVec128[2]; __m128d mVec128[2];
AT_ALIGNED_ALLOCATOR
#endif #endif
double vec[4]; double vec[4];
} atVec4d; } atVec4d;