我有两个变量m128i(a和b),我只对bit63和bit127感兴趣。
最后,我想要一个变量m128i(c),变量a和b的四位在位31、位63、位95和位127上。
总之(伪代码):

c.bit31  = a.bit63
c.bit63  = a.bit127
c.bit95  = b.bit63
c.bit127 = b.bit127

如果我使用存储(float array),强制转换为int array[4],最后是加载(int array),我将损失很多时间。
我不知道如何使用intrinsecs操作(SSEx x

最佳答案

你可以这样只用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");
}

10-04 21:19