开发者

SSE data types and primitives

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开发者_JAVA技巧'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:

  • _mm_load_ps
  • _mm_store_ps


This is a compiler specific answer for GCC

The xmmintrin header for GCC 4.4.3 defines the following:

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));

So, yes, you violate strict aliasing, but you are allowed to do so with that type. Oddly, the __v4sf type is not marked as __may_alias__, so it cannot be used in this manner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜