_mm_load_pd vs. casting to __m128d

_mm_load_pd vs. casting to __m128d

Do you need to call _m_load_pd, or is it kosher to cast an array to __m128d* and then call _mm_add_pd (etc) on elements of that array? I've tested this out, and it seems that casting approach works and is an order of magnitude faster than calling _mm_load_pd.

Some example code below:

double *r = (double*)_aligned_malloc(sizeof(double)*SIZE, SIMD_WORD_SIZE_BYTES);
double *d1 = (double*)_aligned_malloc(sizeof(double)*SIZE, SIMD_WORD_SIZE_BYTES);
double *d2 = (double*)_aligned_malloc(sizeof(double)*SIZE, SIMD_WORD_SIZE_BYTES);

for (int x=0;xr[x] = 0;
d1[x] = x;
d2[x] = x/2;

__m128d *md1 = (__m128d*)d1;
__m128d *md2 = (__m128d*)d2;

for (int x=0;x__m128d mr = _mm_add_pd(*(md1+x), *(md2+x));


3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

There should be no difference, the compile is smart enough to replace = with movaps/dqa, butonly works if the pointers arealigned, obviously. If you are unsure check the generated assembly code.

Intel C is sometimes more flexible about this than other compilers. If you have something which works with VC and gcc, you probably have it covered.
As to performance of the alternatives, it seemed to make less difference in my tests on Core i7 in 64-bit mode than on some older platforms.

Leave a Comment

Please sign in to add a comment. Not a member? Join today