Setting __m256i to two __m128i values

Thus, AVX has a function from immintrin.h , which should allow the concatenation of two __m128i values ​​to one __m256i value. Function

 __m256i _mm256_set_m128i (__m128i hi, __m128i lo) 

However, when I use it, like this:

 __m256i as[2]; __m128i s[4]; as[0] = _mm256_setr_m128i(s[0], s[1]); 

I get a compilation error:

 error: incompatible types when assigning to type '__m256i' from type 'int' 

I do not understand why this is happening. Any help is much appreciated!

+5
source share
1 answer

Not all compilers have _mm256_setr_m128i or even _mm256_set_m128i defined in immintrin.h . Therefore, I usually just define macros as needed, enclosed in brackets with suitable #ifdef , which are checked for the compiler and version:

 #define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1) #define _mm256_setr_m128i(v0, v1) _mm256_set_m128i((v1), (v0)) 
  • Intel ICC 11.1 and later have both _mm256_set_m128i and _mm256_setr_m128i .

  • MSVC 2012 and later have only _mm256_set_m128i .

  • gcc / clang doesn't seem to be there either, although I have not checked the latest versions to make sure this is still fixed.

+9
source

All Articles