SSE Error - Using m128i_i32 to define fields of a __m128i variable

雨燕双飞 提交于 2021-01-04 07:06:25

问题


Upon defining a __m128i variable in this manner:

__m128i a;
a.m128i_i32[0] = 65000;

I get the following error:

error: request for member ‘m128i_i32’ in ‘a’, which is of non-class type ‘__m128i {aka __vector(2) long long int}’ a.m128i_i32[0] = 65000;

I have included the followinf header files:

#include <x86intrin.h>
#include <emmintrin.h>
#include <smmintrin.h>

回答1:


Your code will work under Visual where __m128 is defined as

typedef union __declspec(intrin_type) __declspec(align(16)) __m128i {
__int8              m128i_i8[16];
__int16             m128i_i16[8];
__int32             m128i_i32[4];
__int64             m128i_i64[2];
unsigned __int8     m128i_u8[16];
unsigned __int16    m128i_u16[8];
unsigned __int32    m128i_u32[4];
unsigned __int64    m128i_u64[2];
} __m128i;

so you can access m128_i32, but under g++ __m128 is defined as

typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));

and your code won't be compiled.

You can assign value by

int32_t* p = (int32_t*)&a;
p[0] = 65000;



回答2:


m128i_i32 is MSVC specific. And you are compiling with GCC or Clang (judging by your error message). Use _mm_setr_epi32 instead.

__m128i a = _mm_setr_epi32(0, 1, 2, 3);


来源:https://stackoverflow.com/questions/47882091/sse-error-using-m128i-i32-to-define-fields-of-a-m128i-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!