Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

_mm_shuffle

k3nn4nt
Beginner
6,574 Views
Hello there,
I have no idea how _mm_shuffleXXXXX works. Does anyone out there know?
I especially having problem with the _mm_shuffle_epi32(), _mm_shufflehi_epi16() and _mm_shufflelo_epi16(). I have read numerous explaination on those instrinsics on the net, but they seem to be too difficult for me to understand including this one, the most comprehensive one that I have found. http://www.tommesani.com/SSE2MMX.html
Regards,
Kennant
0 Kudos
1 Reply
lingchuanmeng
Beginner
6,574 Views
Hi Kennant,

I found your question when searching for code examples on shuffle. It has been more than 6 years, and I hope this can still be helpful.

_mm_shuffle_epi32() shuffles a 128bit vector that consists for 4 signed/unsigned integers. It usually works together with the _MM_SHUFFLE() macro. You can view _MM_SHUFFLE() as a permutation, that is, it permutes elements based the operands of _MM_SHUFFLE().

Here is a code snippet that better explains how it works:

[cpp]void test(int32_t *Y, int32_t *X)
{
__m128i *v1, *v2;
__m128i v3, v4;
int32_t * rslt;
int64_t * rslt64;
v1 = (__m128i *) X;
v2 = (__m128i *) Y;
rslt = (int32_t * ) v1;
printf("In test, V1 after MUL SHUFFLE: %dt%dt%dt%dtn", rslt[0], rslt[1], rslt[2], rslt[3]);
rslt = (int32_t * ) v2;
printf("In test, V2 before MUL SHUFFLE: %dt%dt%dt%dtn", rslt[0], rslt[1], rslt[2], rslt[3]);
v3 = _mm_mul_epi32(*v1, *v2);
v4 = _mm_mul_epi32(_mm_shuffle_epi32(*v1, _MM_SHUFFLE(2, 3, 0, 1)), _mm_shuffle_epi32(*v2, _MM_SHUFFLE(2, 3, 0, 1))); rslt64 = (int64_t * ) &v3;
printf("In REDC, product before SHUFFLE: %ldt%ldn", rslt64[0], rslt64[1]); rslt64 = (int64_t * ) &v4; printf("In REDC, product after SHUFFLE: %ldt%ldn", rslt64[0], rslt64[1]);
rslt = (int32_t * ) v1; printf("In REDC, 4-way vect before SHUFFLE: %dt%dt%dt%dtn", rslt[0], rslt[1], rslt[2], rslt[3]); *v1 = _mm_shuffle_epi32(*v1, _MM_SHUFFLE(2, 3, 0, 1)); rslt = (int32_t * ) v1; printf("In REDC, 4-way vect after SHUFFLE: %dt%dt%dt%dtn", rslt[0], rslt[1], rslt[2], rslt[3]); }[/cpp]

_MM_SHUFFLE(2, 3, 0, 1) permutes [a3, a2, a1, a0] to [a2, a3, a0, a1].


LC
0 Kudos
Reply