How to extract a 32 x 4-bit integer from a 16 x 8-bit __m128i value

Suppose I have this line of code that loads a 16 x 8-bit unsigned integer using SSE2

// ptr is a pointer to uint8_t array __m128i b = _mm_load_si128((const __m128i*) ptr); 

I would like to split each 8-bit unsigned integer in b (a total of 16 of them) into 4-bit high and 4-bit bits. How can i do this?

+4
source share
1 answer

You need to mask the lower part and move the upper part to the correct position. Since the SSE instruction is non-byte-shifted, the top must also be masked after the shift.

 __m128i b = _mm_load_si128((const __m128i*) ptr); __m128i mask = _mm_set1_epi8(0xf); __m128i lower = _mm_and_si128(b, mask); __m128i upper = _mm_and_si128(_mm_srli_epi16(b, 4), mask); 
+3
source

Source: https://habr.com/ru/post/1438591/


All Articles