Dear SBCL maintainers,
I noticed that the x86-64 assembler often generates a REX prefix where
none is needed, e.g., for the CALL, PUSH or POP instructions and for
operations on bytes. Here are some examples:
48FF5009 CALL QWORD PTR [RAX+9]
485A POP RDX
40240F AND AL, 15
40803C257803004000 CMP BYTE PTR [#x40000378], 0
As this unnecessarily increases code size, I would like to change it.
Additionally, for some cases of the MOVSX/MOVZX instruction no REX
prefix is generated while needed, so that for example "MOVSX EAX, SIL"
is assembled as "0FBEC6", meaning "MOVSX EAX, DH". (Admittedly, this
is only a latent bug as AFAIK the compiler uses extending moves only
for combinations of source and destination sizes and storage types that
don't trigger this bug, but the assembler might as well work correctly
in these cases, too.)
So, I would like to propose the attached patch which removes the
unneeded REX prefixes and corrects this bug. See the comments at
MAYBE-EMIT-REX-PREFIX and MAYBE-EMIT-REX-FOR-EA for some details.
Additionally, the patch
- adds the four "high byte" registers to the register printer of the
disassembler (for robustness)
- fixes a typo in a comment in "defstruct ea"
- removes redundant calls of (operand-size dst) in
- improves a comment in "push" about the size of immediates
- changes the emitter for "call" to not emit a REX prefix if the target
is a label or a fixup.
With kind regards