将16位向量 (__m128i) 拆分为奇偶位置的两个向量,使用Intel内嵌函数。

huangapple go评论50阅读模式
英文:

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&#39;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);

huangapple
  • 本文由 发表于 2023年4月11日 05:21:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定