添加SSE寄存器的组件 [英] adding the components of an SSE register

查看:234
本文介绍了添加SSE寄存器的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个SSE寄存器的四个组件来获得一个浮点数。这是我现在这样做:

  float a [4]; 
_mm_storeu_ps(a,foo128);
float x = a [0] + a [1] + a [2] + a [3];

是否有一个SSE指令可以直接实现这个?

HADDPS SSE3指令或其编译器固有的 _mm_hadd_ps



例如,请参阅 http:// msdn如果你有两个寄存器v1和v2:

/ p>

  v = _mm_hadd_ps(v1,v2); 
v = _mm_hadd_ps(v,v);




$ b现在,v [0]包含了v1的分量之和,v [1]的v2组件。


I want to add the four components of an SSE register to get a single float. This is how I do it now:

float a[4];
_mm_storeu_ps(a, foo128);
float x = a[0] + a[1] + a[2] + a[3];

Is there an SSE instruction that directly achieves this?

解决方案

You could probably use the HADDPS SSE3 instruction, or its compiler intrinsic _mm_hadd_ps,

For example, see http://msdn.microsoft.com/en-us/library/yd9wecaa(v=vs.80).aspx

If you have two registers v1 and v2 :

v = _mm_hadd_ps(v1, v2);
v = _mm_hadd_ps(v, v);

Now, v[0] contains the sum of v1's components, and v[1] contains the sum of v2's components.

这篇关于添加SSE寄存器的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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