如何指定_mm_mul_ps的对齐方式 [英] How to specify alignment with _mm_mul_ps

查看:185
本文介绍了如何指定_mm_mul_ps的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有参数之一的SSE内在函数作为存储位置(_mm_mul_ps(xmm1,mem)).

I am using an SSE intrinsic with one of the argument as a memory location (_mm_mul_ps(xmm1,mem)).

我怀疑会更快:

xmm1 = _mm_mul_ps(xmm0,mem)  // mem is 16 byte aligned

或:

xmm0 = _mm_load_ps(mem);
xmm1 = _mm_mul_ps(xmm1,xmm0);

有没有一种方法可以指定与_mm_mul_ps()固有的对齐方式?

Is there a way to specify alignment with _mm_mul_ps() intrinsic ?

推荐答案

即使存在mulps reg,mem指令形式,也没有_mm_mul_ps(reg,mem)形式-

There are no _mm_mul_ps(reg,mem) form even though mulps reg,mem instruction form exists - https://msdn.microsoft.com/en-us/library/22kbk6t9(v=vs.90).aspx

您可以做的是_mm_mul_ps(reg,_mm_load_ps(mem)),它将与两行编写的内容完全相同.

What you can do is _mm_mul_ps(reg,_mm_load_ps(mem)) and it is going to be exactly the same as writing it in 2 lines.

您可以使用_mm_load_ps& _mm_loadu_ps指定是否希望数据对齐.顺便说一句,对从Haswell微arch开始的对齐数据进行未对齐加载不会有任何惩罚.

You can use _mm_load_ps & _mm_loadu_ps to specify if you expect you data to be aligned. BTW, there are no penalty for doing unaligned loads on aligned data starting from Haswell microarch.

另一方面,编译器应该足够聪明,可以判断出先执行加载然后进行乘法运算,还是从内存中进行乘法运算是更好的选择.

On the other side compiler should be smart enough to figure out if it would be better to do the load first and then do the multiply, or do the multiply from the memory.

在某些情况下,可能需要提前一点负载来改善软件流水线,但是通常这将是下一个优化级别.

In some cases it might make sense to do the load a bit in advance to improve software pipelining, but usually this is going to be the next level of optimization.

这篇关于如何指定_mm_mul_ps的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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