Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine two __m128 values to __m256?

Tags:

I would like to combine two __m128 values to one __m256.

Something like this:

__m128 a = _mm_set_ps(1, 2, 3, 4); __m128 b = _mm_set_ps(5, 6, 7, 8); 

to something like:

__m256 c = { 1, 2, 3, 4, 5, 6, 7, 8 }; 

are there any intrinsics that I can use to do this?

like image 356
user1468756 Avatar asked Jun 20 '12 09:06

user1468756


1 Answers

This should do what you want:

__m128 a = _mm_set_ps(1,2,3,4); __m128 b = _mm_set_ps(5,6,7,8);  __m256 c = _mm256_castps128_ps256(a); c = _mm256_insertf128_ps(c,b,1); 

If the order is reversed from what you want, then just switch a and b.


The intrinsic of interest is _mm256_insertf128_ps which will let you insert a 128-bit register into either lower or upper half of a 256-bit AVX register:

http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011/compiler_c/intref_cls/common/intref_avx_insertf128_ps.htm

The complete family of them is here:

  • _mm256_insertf128_pd()
  • _mm256_insertf128_ps()
  • _mm256_insertf128_si256()
like image 99
Mysticial Avatar answered Sep 18 '22 14:09

Mysticial