SSE内在函数:如何将值存储到寄存器中?

时间:2015-08-03 09:31:31

标签: c++ sse intrinsics

我对SSE内在函数很新,并且遇到一个小问题。我需要帮助将整数值加载到__m128i

这是我已经拥有的:

__m128i a = _mm_set_epi16( 1, 1, 2, 2, 3, 3, 4, 4 );
__m128i b = _mm_set_epi16( 5, 5, 6, 6, 7, 7, 8, 8 );

//some magic
__m128i c // = (1,2,3,4,5,6,7,8);

2 个答案:

答案 0 :(得分:1)

如果您不想动态加载值,则可以使用set intrinsics:

intrinsics for loading data to the sse registers

e.g:

__m128i c  = _mm_set_epi16(1,2,3,4,5,6,7,8); //load 8 16-bit integers to the register

答案 1 :(得分:1)

我自己找到了解决方案

__m128i a = _mm_set_epi16( 1, 1, 2, 2, 3, 3, 4, 4 );
__m128i b = _mm_set_epi16( 5, 5, 6, 6, 7, 7, 8, 8 );

//some magic
__m128i mmShufflerVo = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1, 13, 12, 9, 8,5, 4,1, 0);
__m128i mmShufflerHi = _mm_set_epi8(13, 12, 9, 8, 5, 4, 1, 0, -1, -1, -1, 
                                          -1, -1, -1, -1, -1);

__m128i mmResult0_3 = _mm_shuffle_epi8(mmResult0_3, mmShufflerVo);

__m128i mmResult4_7 = _mm_shuffle_epi8(mmResult4_7, mmShufflerHi);


__m128i c = _mm_or_si128(mmResult0_3, mmResult4_7);