c - Is strict aliasing only for the first element? -


using gcc 4.7.2, why cause strict alias violation:

#include <stdint.h> #include "emmintrin.h"  int f(){     int ret = 0;      __m128i vec_zero __attribute__ ((aligned (16))) = _mm_set1_epi32(0);     __m128i vec_one __attribute__ ((aligned (16))) = _mm_set1_epi32(1);     __m128i vec_result __attribute__ ((aligned (16)));     vec_result = _mm_cmpgt_epi32(vec_zero, vec_one);     ret += (((uint32_t*)&vec_result)[0] != 0);      ret += (((uint32_t*)&vec_result)[1] != 0);      return ret; }    

while ok:

#include <stdint.h> #include "emmintrin.h"  int f(){     int ret = 0;      __m128i vec_zero __attribute__ ((aligned (16))) = _mm_set1_epi32(0);     __m128i vec_one __attribute__ ((aligned (16))) = _mm_set1_epi32(1);     __m128i vec_result __attribute__ ((aligned (16)));     vec_result = _mm_cmpgt_epi32(vec_zero, vec_one); //    ret += (((uint32_t*)&vec_result)[0] != 0);      ret += (((uint32_t*)&vec_result)[1] != 0);      return ret; }    

is issue of gcc not being accurate or missing how strict aliasing works.

also, there simple way around use of __attribute__((__may_alias__)) or off casting temp char*?

i think it's failure of gcc catch problem. it's ub (aliasing violation). solving __attribute__((__may_alias__)) easy though:

typedef uint32_t __attribute__((__may_alias__)) u32ma; 

then use u32ma instead of uint32_t in pointer cast.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -