英文:
Split 16-bit vector (__m128i) into 2 vectors of odd and even positions with Intel intrinsics
问题
__m128i a = {1,2,3,4,5,6,7,8}; //8x16bit
我想将这个寄存器分成两个包含4x32bit的向量:
```c
__m128i x = {1,3,5,7}
__m128i y = {2,4,6,8}
使用内置代码是否可能?
在RAM中,我有16位字的原始数据。例如:1,2,3,4,5,6,7,8
目标是将此流分成实部(1,3,5,7)和虚部(2,4,6,8)。
<details>
<summary>英文:</summary>
__m128i a = {1,2,3,4,5,6,7,8}; //8x16bit
I want to split this register into 2 vectors each contains 4x32bit :
__m128i x = {1,3,5,7}
__m128i y = {2,4,6,8}
Is it possible with intrinsic code ?
In RAM, I have raw data of 16bits words. e.g: 1,2,3,4,5,6,7,8
The goal is to split this stream into real part (1,3,5,7) and imaginary part (2,4,6,8)
</details>
# 答案1
**得分**: 2
```c
假设您已将所有内容加载到`__m128i`中,并且正在处理带符号整数,我认为最简单的方法是:
```c
__m128i x = _mm_srai_epi32(_mm_slli_epi32(a, 16), 16);
__m128i y = _mm_srai_epi32(a, 16);
对于无符号整数,如Peter在评论中提到的:
__m127i x = _mm_and_si128(v, _mm_set1_epi32(0x0000FFFF));
__m128i y = _mm_srli_epi32(a, 16);
<details>
<summary>英文:</summary>
Assuming you have everything loaded into an `__m128i` and you're dealing with signed integers, I think the easiest way would be:
```c
__m128i x = _mm_srai_epi32(_mm_slli_epi32(a, 16), 16);
__m128i y = _mm_srai_epi32(a, 16);
For unsigned integers, as Peter mentioned in the comments:
__m127i x = _mm_and_si128(v, _mm_set1_epi32(0x0000FFFF));
__m128i y = _mm_srli_epi32(a, 16);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论