Shift right every DW in a __m128i by a different a

2019-08-19 10:13发布

问题:

I want to shift right every element of a __m128i register by a different amount.I know this is possible by multiplication if we want to shift left like below:

__m128i mul_constant = _mm_set_epi32(8, 4, 2, 1);
__m128i left_vshift = _mm_mullo_epi32(R, mul_constant);

But, what is the solution if we want to shift it right?

回答1:

I finally did it like below: Shifting every byte by a different amount to left and then a 32-bit right shift by 3 gave me what I wanted.

 R = _mm_mullo_epi32(R, _mm_set_epi32(1, 2, 4, 8));
 R = _mm_srli_epi32(R, 3);


标签: sse simd