x64Emitter: Short MOVs for 32bit immediates

Prior to this commit, the emitter would emit a 7-byte instruction when
loading a 32-bit immediate to a 64-bit register.

0:  48 c7 c0 ff ff ff 7f    mov    rax,0x7fffffff

With this change, it will check if it can instead emit a load to a
32-bit register, which takes only 5 or 6 bytes.

0:  b8 ff ff ff 7f          mov    eax,0x7fffffff
This commit is contained in:
Sintendo 2019-05-29 00:47:12 +02:00
parent 992c8bfc4e
commit c84f34bd50
1 changed files with 3 additions and 2 deletions

View File

@ -1591,8 +1591,9 @@ void XEmitter::XOR(int bits, const OpArg& a1, const OpArg& a2)
}
void XEmitter::MOV(int bits, const OpArg& a1, const OpArg& a2)
{
if (bits == 64 && a1.IsSimpleReg() && a2.scale == SCALE_IMM64 &&
a2.offset == static_cast<u32>(a2.offset))
if (bits == 64 && a1.IsSimpleReg() &&
((a2.scale == SCALE_IMM64 && a2.offset == static_cast<u32>(a2.offset)) ||
(a2.scale == SCALE_IMM32 && static_cast<s32>(a2.offset) >= 0)))
{
WriteNormalOp(32, NormalOp::MOV, a1, a2.AsImm32());
return;