DSPJit: Replace/optimize LEAs

- LEA is a bit silly when the source and the destination are the same. A
simple ADD or SHL will do in those cases.

66 8D 04 45 00 00 00 00 lea         ax,[rax*2]
66 03 C0                add         ax,ax

48 8D 04 00             lea         rax,[rax+rax]
48 03 C0                add         rax,rax

66 8D 14 D5 00 00 00 00 lea         dx,[rdx*8]
66 C1 E2 03             shl         dx,3

- When scaling by 2, consider summing the register with itself instead.
The former always needs a 32-bit displacement, so the sum is more
compact.

66 8D 14 45 00 00 00 00 lea dx,[rax*2]
66 8D 14 00             lea dx,[rax+rax]
This commit is contained in:
Sintendo 2020-01-29 23:01:57 +01:00
parent afd25de85e
commit 49a4e09719
2 changed files with 5 additions and 5 deletions

View File

@ -38,7 +38,7 @@ void DSPEmitter::ReJitConditional(const UDSPInstruction opc,
case 0x3: // LE - Less Equal case 0x3: // LE - Less Equal
LEA(16, EDX, MScaled(EAX, SCALE_4, 0)); LEA(16, EDX, MScaled(EAX, SCALE_4, 0));
XOR(16, R(EAX), R(EDX)); XOR(16, R(EAX), R(EDX));
LEA(16, EAX, MScaled(EAX, SCALE_2, 0)); ADD(16, R(EAX), R(EAX));
OR(16, R(EAX), R(EDX)); OR(16, R(EAX), R(EDX));
TEST(16, R(EAX), Imm16(0x10)); TEST(16, R(EAX), Imm16(0x10));
break; break;
@ -56,9 +56,9 @@ void DSPEmitter::ReJitConditional(const UDSPInstruction opc,
break; break;
case 0xa: // ? case 0xa: // ?
case 0xb: // ? case 0xb: // ?
LEA(16, EDX, MScaled(EAX, SCALE_2, 0)); LEA(16, EDX, MRegSum(EAX, EAX));
OR(16, R(EAX), R(EDX)); OR(16, R(EAX), R(EDX));
LEA(16, EDX, MScaled(EDX, SCALE_8, 0)); SHL(16, R(EDX), Imm8(3));
NOT(16, R(EAX)); NOT(16, R(EAX));
OR(16, R(EAX), R(EDX)); OR(16, R(EAX), R(EDX));
TEST(16, R(EAX), Imm16(0x20)); TEST(16, R(EAX), Imm16(0x20));

View File

@ -30,7 +30,7 @@ void DSPEmitter::multiply()
TEST(16, sr_reg, Imm16(SR_MUL_MODIFY)); TEST(16, sr_reg, Imm16(SR_MUL_MODIFY));
FixupBranch noMult2 = J_CC(CC_NZ); FixupBranch noMult2 = J_CC(CC_NZ);
// prod <<= 1; // prod <<= 1;
LEA(64, RAX, MRegSum(RAX, RAX)); ADD(64, R(RAX), R(RAX));
SetJumpTarget(noMult2); SetJumpTarget(noMult2);
m_gpr.PutReg(DSP_REG_SR, false); m_gpr.PutReg(DSP_REG_SR, false);
// return prod; // return prod;
@ -130,7 +130,7 @@ void DSPEmitter::multiply_mulx(u8 axh0, u8 axh1)
TEST(16, sr_reg, Imm16(SR_MUL_MODIFY)); TEST(16, sr_reg, Imm16(SR_MUL_MODIFY));
FixupBranch noMult2 = J_CC(CC_NZ); FixupBranch noMult2 = J_CC(CC_NZ);
// prod <<= 1; // prod <<= 1;
LEA(64, RAX, MRegSum(RAX, RAX)); ADD(64, R(RAX), R(RAX));
SetJumpTarget(noMult2); SetJumpTarget(noMult2);
m_gpr.PutReg(DSP_REG_SR, false); m_gpr.PutReg(DSP_REG_SR, false);
// return prod; // return prod;