Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Divide 8-bit integers by 4 (or shift) using SSE

How can I divide 16 8-bit integers by 4 (or shift them 2 to the right) using SSE intrinsics?

like image 795
miho Avatar asked Jan 09 '17 19:01

miho


1 Answers

Unfortunately there are no SSE shift instructions for 8 bit elements. If the elements are 8 bit unsigned then you can use a 16 bit shift and mask out the unwanted high bits, e.g.

v = _mm_srli_epi16(v, 2);
v = _mm_and_si128(v, _mm_set1_epi8(0x3f));

For 8 bit signed elements it's a little fiddlier, but still possible, although it might just be easier to unpack to 16 bits, do the shifts, then pack back to 8 bits.

like image 78
Paul R Avatar answered Oct 19 '22 17:10

Paul R