Question

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]
Was it helpful?

Solution

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.

OTHER TIPS

vpcmpeqq  xmm1,xmm1,xmm1          ; xmm1 = [ -1 | -1 | -1 | -1 ] as ints
vmovsd    xmm0,dword ptr [ecx]    ; xmm0 = VALUE as int
vsubsd    xmm0,xmm0,xmm1          ; xmm0 = VALUE - (-1) = VALUE + 1

The above should be

vpcmpeqq  xmm1,xmm1,xmm1          ; xmm1 = [ -1 | -1 | -1 | -1 ] as ints
vmovd     xmm0,dword ptr [ecx]    ; xmm0 = VALUE as int
vpsubd    xmm0,xmm0,xmm1          ; xmm0 = VALUE - (-1) = VALUE + 1

for integer increment by 1 and

vpcmpeqq  xmm1,xmm1,xmm1          ; xmm1 = [ -1 | -1 ] as quads
vmovsd    xmm0,dword ptr [ecx]    ; xmm0 = VALUE as double
vcvtdq2pd xmm1,xmm1               ; xmm1 = [ -1.0 | -1.0 ] as doubles
vsubsd    xmm0,xmm0,xmm1          ; xmm0 = VALUE - (-1.0) = VALUE + 1.0

for double increment by 1.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top