Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x64Emitter: Avoid 8-bit displacement when possible #8556

Merged
merged 5 commits into from
Jan 25, 2020

Conversation

Sintendo
Copy link
Member

Due to the way the ModRM encoding works on x86, memory addressing combinations involving RBP or R13 need an additional byte for an 8-bit displacement of zero.

However, this was also applied in cases where it is unnecessary, effectively wasting a byte.

This PR adds some tests, fixes the issue, refactors the relevant function, and cleans up some unrelated minor things in the neighborhood.

  • MatR with RSP or R12
8B 44 24 00          mov         eax,dword ptr [rsp]
8B 04 24             mov         eax,dword ptr [rsp]
  • MRegSum with base != RBP or R13
46 8D 7C 37 00       lea         r15d,[rdi+r14]
46 8D 3C 37          lea         r15d,[rdi+r14]
  • MComplex without offset
8B 4C CA 00          mov         ecx,dword ptr [rdx+rcx*8]
8B 0C CA             mov         ecx,dword ptr [rdx+rcx*8]

Test the behavior of OpArg::WriteRest by using MOV with the various
addressing modes (MatR, MRegSum, etc.) in the source operand.

Both the instruction and the instruction length are validated.
Due to the way the ModRM encoding works on x86, memory addressing
combinations involving RBP or R13 need an additional byte for an 8-bit
displacement of zero.

However, this was also applied in cases where it is unnecessary,
effectively wasting a byte.

- MatR with RSP or R12

8B 44 24 00          mov         eax,dword ptr [rsp]
8B 04 24             mov         eax,dword ptr [rsp]

- MRegSum with base != RBP or R13

46 8D 7C 37 00       lea         r15d,[rdi+r14]
46 8D 3C 37          lea         r15d,[rdi+r14]

- MComplex without offset

8B 4C CA 00          mov         ecx,dword ptr [rdx+rcx*8]
8B 0C CA             mov         ecx,dword ptr [rdx+rcx*8]
Shorter, displacement is now handled in one location.
TODO was already taken care of in PR dolphin-emu#941.
No users, and one them seems to do the same as stddef.h's offsetof()
already used elsewhere.
@Tilka Tilka merged commit 119ccc5 into dolphin-emu:master Jan 25, 2020
@Sintendo Sintendo deleted the bestrest branch November 30, 2020 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants