SSE and primitive data types

advertisements

In most tutorials or code snippets on the net one sees the following:

float *arr= (float*) _aligned_malloc(length * sizeof(float), 16);
__m128 *m1 = (__m128*)arr;

Does this violate strict aliasing rules or not? I'd think it does, but then surely all those tutorial writers don't ignore it just for convenience and since __m128 is a union containing float[4] maybe I misunderstand some intricate parts about it.


That hasn't violated it -- yet. However, writing through one pointer and reading through the other would violate strict aliasing.

Instead, you should use functions like: