如何反转 __m128 类型变量? [英] How to reverse an __m128 type variable?

查看:33
本文介绍了如何反转 __m128 类型变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这应该是一个谷歌搜索问题,但我就是找不到答案.

假设我有一个__m128变量a,其内容为a[0],a[1]a[2]a[3].是否有单个函数可以将其反转为a[3]a[2]a[1], a[0]?

解决方案

使用

反转向量中的 32 位分量

__m128 input = ...;__m128 反转 = _mm_shuffle_ps(input,input,_MM_SHUFFLE(0, 1, 2, 3));

注意:掩码是一个直接值.它不能是动态的,因为它是生成的机器指令的一部分.

英特尔内部指南:https://software.intel.com/sites/landingpage/内在指南/

I know this should be a Googling question but I just cannot find the answer.

Say I have an __m128 variable a, whose content is a[0], a[1], a[2], a[3]. Is there a single function that can reverse it to be a[3], a[2], a[1], a[0]?

解决方案

Use _mm_shuffle_ps(). This instruction was already available in SSE and can gather 4 32-bit components in a single vector by combining two arbitrary 32-bit components from each of the two input vectors.

How to create the mask using the macro _MM_SHUFFLE()

The macro is defined as follows:

/* Create a selector for use with the SHUFPS instruction.  */
#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) \
 (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | (fp0))

Source and destination indices run from right to left in ascending order. The first two selector values (fp0 and fp1) designate source components in m1, the last two (fp2 and fp3) the ones in m2. Each selected source component is assigned to m3[index], where index corresponds to its selector parameter fp<index>.

Reversing 32-bit components in a vector

__m128 input = ...;
__m128 reversed = _mm_shuffle_ps(input,input,_MM_SHUFFLE(0, 1, 2, 3));

Note: The mask is an immediate value. It cannot be dynamic, as it is part of the resulting machine instruction.

Intel Intrinsics Guide: https://software.intel.com/sites/landingpage/IntrinsicsGuide/

这篇关于如何反转 __m128 类型变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆