Add a constant value to a xmm register in x86

穿精又带淫゛_ 提交于 2019-12-07 12:02:51

问题


How would I add 1 or 2 to the register xmm0 (double)?

I can do it like this, but sure there must be an easier way:

movsd xmm0, [ecx]

xor eax, eax
inc eax
cvtsi2sd xmm1, eax
addsd xmm0, xmm1

movsd [ecx], xmm0

Also would it be possible to do this with the floating point x87 instructions?

This doesn't work for me:

fld dword ptr [ecx]
fld1
faddp
fstp dword ptr [ecx]

回答1:


You can keep a constant in memory or in another register:

_1      dq      1.0

and

addsd   xmm1,[_1]

or

movsd   xmm0,[_1]
addsd   xmm1,xmm0

If you are on x64, you can do this:

mov     rax,1.0
movq    xmm0,rax
addsd   xmm1,xmm0  

or use the stack if the type mismatch bothers you:

mov     rax,1.0
push    rax
movsd   xmm0,[rsp]
pop     rax
addsd   xmm1,xmm0 

As for the x87 code, doubles are qwords, not dwords.



来源:https://stackoverflow.com/questions/14088228/add-a-constant-value-to-a-xmm-register-in-x86

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