How to specify alignment with _mm_mul_ps

回眸只為那壹抹淺笑 提交于 2019-12-11 02:19:09

问题


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

I have a doubt which will be faster:

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

or:

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

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


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/31315892/how-to-specify-alignment-with-mm-mul-ps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!