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

Register R12 requires special encoding in modrm bytes - Avoid using it to simplify x64 code gen #77

Closed
Alan-Jowett opened this issue Jun 1, 2021 · 1 comment · Fixed by #78

Comments

@Alan-Jowett
Copy link
Collaborator

Register R12 requires special encoding in modrm byte - Avoid using it to simplify x64 code gen.

0: 45 8b 3b mov r15d,DWORD PTR [r11]
0: 45 8b 3c 24 mov r15d,DWORD PTR [r12]

For reason not yet understood, a move operations with R12 as indirect source results in a 4 byte instruction.

Switch the register mapping to avoid R12.

@Alan-Jowett Alan-Jowett changed the title Register R1 requires special encoding in modrm bytes - Avoid using it to simplify x64 code gen Register R12 requires special encoding in modrm bytes - Avoid using it to simplify x64 code gen Jun 1, 2021
@Alan-Jowett
Copy link
Collaborator Author

More background on this:
R12 and RSP use the same register encoding (excluding the bit in REX).
R13 and RBP use the same register encoding (excluding the bit in REX).

emit_modrm_and_displacement correctly handles encoding R13 as an EBP relative addressing, but doesn't do RSP relative addressing correctly. This results in malformed instruction.

if (d == 0 && (m & 7) != RBP) {

@rlane rlane closed this as completed in #78 Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant