Access __m128 fields through compilers

I noticed that accessing fields __m128by index is possible in gcc, without using a trick union.

__m128 t;

float r(t[0] + t[1] + t[2] + t[3]);

I can also load the __m128same as an array:

__m128 t{1.f, 2.f, 3.f, 4.f};

All this corresponds to vector extensions gcc. However, they may not be available elsewhere. Are the boot and access functions supported by the Intel compiler and msvc supported?

+2
source share
2 answers

To download __m128, you can write _mm_setr_ps(1.f, 2.f, 3.f, 4.f)that is supported by GCC, ICC, MSVC and clang.

, clang GCC __m128 . , ICC MSVC. , _mm_extract_ps 4 , , .

+2

, , GCC. set/load/store. _mm_setr_ps , . , .

a, /

__m128 t = _mm_loadu_ps(a);
_mm_storeu_ps(a, t);

16 , /, , .

__m128 t = _mm_load_ps(a);
_mm_store_ps(a, t);

16- ,

__declspec(align(16)) const float a[] = ...//MSVC
__attribute__((aligned(16))) const float a[] ...//GCC, ICC

16- :

float *a = (float*)_mm_malloc(sizeof(float)*n, 16); //MSVC, GCC, ICC, MinGW 
+3

All Articles