Question

Suppose I have a __m128i containing 4 32-bit integer values.

Is there some way I can store it inside a char[4], where the lower char from each int value is stored in a char value?

Desired result:

           r1          r2          r3          r4
__m128i    0x00000012  0x00000034  0x00000056  0x00000078

  |
  V

char[4]    0x12        0x34        0x56        0x78     

SSE2 and below is preferred. Compiling on MSVC++.

Était-ce utile?

La solution

With SSE2 you can use the following code:

char[4] array;
x = _mm_packs_epi32(x, x);
x = _mm_packus_epi16(x, x);
*((int*)array) = _mm_cvtsi128_si32(x);

Autres conseils

Just for completeness, with SSSE3 you can do it with only one shuffling operation using _mm_shuffle_epi8. See here. You do consume one register more though, it depends on what is more important for you.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top