Skip to content

Commit

Permalink
Emit better x86_64 asm for constant loads
Browse files Browse the repository at this point in the history
Instead of always emitting movabs, emit a regular mov or a xor.
Slims down sequences like:

    movabs $0,%rax
    mov %rsi,%rax

To:

    xor %eax,%eax  // also zeroes upper word
    mov %rsi,%rax

Future work is to just emit:

    xor %esi,%esi
  • Loading branch information
bnoordhuis committed Oct 10, 2024
1 parent b668b72 commit c21576f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions x86_64-gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,15 @@ void load(int r, SValue *sv)
}
#endif
} else if (is64_type(ft)) {
orex(1,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
gen_le64(sv->c.i);
if (sv->c.i > UINT32_MAX) {
orex(1,r,0, 0xb8 + REG_VALUE(r)); /* movabs $xx, r */
gen_le64(sv->c.i);
} else if (sv->c.i > 0) {
orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
gen_le32(sv->c.i);
} else {
o(0xc031 + REG_VALUE(r) * 0x900); /* xor r, r */
}
} else {
orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
gen_le32(fc);
Expand Down

0 comments on commit c21576f

Please sign in to comment.