SSE2 instruction to load integers in reverse order

Is there any SSE2 instruction to load a 128-bit vector register int from an int buffer in reverse order?

+7
source share
2 answers

It is very easy to undo 32-bit int elements after normal loading:

 __m128i v = _mm_load_si128(buff); // MOVDQA v = _mm_shuffle_epi32(v, _MM_SHUFFLE(0, 1, 2, 3)); // PSHUFD - mask = 00 01 10 11 = 0x1b 

You can do the same for 16-bit short elements, but more instructions are required:

 __m128i v = _mm_load_si128(buff); // MOVDQA v = _mm_shuffle_epi32(v, _MM_SHUFFLE(0, 1, 2, 3)); // PSHUFD - mask = 00 01 10 11 = 0x1b v = _mm_shufflelo_epi16(v, _MM_SHUFFLE(2, 3, 0, 1)); // PSHUFLW - mask = 10 11 00 01 = 0xb1 v = _mm_shufflehi_epi16(v, _MM_SHUFFLE(2, 3, 0, 1)); // PSHUFHW - mask = 10 11 00 01 = 0xb1 

Note that you can do this with fewer commands using _mm_shuffle_epi8 ( PSHUFB ) if SSSE3 is available:

 const __m128i vm = _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); // initialise vector mask for use with PSHUFB // NB: do this once, outside any processing loop ... __m128i v = _mm_load_si128(buff); // MOVDQA v = _mm_shuffle_epi8(v, vm); // PSHUFB 
+10
source

EDIT: (Below are for single precision floating point scalars, leaving them here just in case)

The most approximate (and convenient) is _mm_loadr_ps intrinsic. Remember that the address must be 16 byte aligned.

Despite the fact that this internal expression matches more than the instruction ( MOVAPS + shuffle).

-2
source

All Articles