I have the following line of code in a game:
movss xmm0,[eax+000000F0]
It basically loads the float speed of the current speed category into the XMM0 register. I already made a jump to an empty code section to get some more space, because I now want to multiply this speed by a hardcoded value of 2 after it was loaded. Sadly, easy-thinking like this doesn't work:
movss xmm0,[eax+000000F0]
mulss xmm0,2
I can't simply multiply an XMM register with an integer or float immediate. I read that I can only multiply with another XMM register. But then again I can't push and pop an existing XMM register to the stack to abuse it for that operation temporarily.
How would I create such a simple multiplication operation?
movd xmm0, eax
. Otherwise you can use the generating constant technique in Agner Fog's optimizing guide section 13.8 Generating constantspcmpeqw xmm0, xmm0; pslld xmm0, 31; psrld xmm0, 1
What are the best instruction sequences to generate vector constants on the fly?addss xmm0,xmm0
.