我有两个变量__m128i(a和b),我只对bit63和bit127感兴趣。
最后,我想要一个变量__m128i(c),其中包含位31,位63,位95和位127的变量a和b的四位。
总之(伪代码):
c.bit31 = a.bit63
c.bit63 = a.bit127
c.bit95 = b.bit63
c.bit127 = b.bit127
如果我使用商店(浮点数组),转换为int数组[4],最后加载(int数组),我将失去很多时间。
我不知道如何使用intrinsecs操作(SSEx x <= 4.2)。
答案 0 :(得分:1)
你可以只使用像这样的SSE2
__m128i t1 = _mm_shuffle_epi32(a,0xd0); //0xd0 = 3100 in base 4
__m128i t2 = _mm_shuffle_epi32(b,0xd0); //0xd0 = 3100 in base 4
__m128i t3 = _mm_unpackhi_epi32(t1,t2);
__m128i t4 = _mm_shuffle_epi32(t3,0xd8); //0xd8 = 3120 in base 4
__m128i t5 = _mm_and_si128(t4,_mm_set1_epi32(0x8000000));
这是一个工作示例
#include <x86intrin.h>
#include <stdio.h>
int main(void) {
__m128i a = _mm_setr_epi32(1,-2,3,-4);
__m128i b = _mm_setr_epi32(5,-6,7,-8);
__m128i t1 = _mm_shuffle_epi32(a,0xd0); //0xd0 = 3100 in base 4
__m128i t2 = _mm_shuffle_epi32(b,0xd0); //0xd0 = 3100 in base 4
__m128i t3 = _mm_unpackhi_epi32(t1,t2);
__m128i t4 = _mm_shuffle_epi32(t3,0xd8); //0xd8 = 3120 in base 4
__m128i t5 = _mm_and_si128(t4,_mm_set1_epi32(0x8000000));
int x[4];
_mm_store_si128((__m128i*)x,t5);
for(int i=0; i<4; i++) printf("%x ", x[i]); printf("\n");
}