Shift right every DW in a __m128i by a different amount

浪尽此生 提交于 2019-12-13 03:31:49

问题


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);


来源:https://stackoverflow.com/questions/50108396/shift-right-every-dw-in-a-m128i-by-a-different-amount

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!