History

Emit better x86_64 asm for constant loads

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

Ben Noordhuis committed 2 years ago

Commit c21576f1 parent b668b721 file · +9 −2Browse files

Unified · Split

x86_64-gen.c+9−2
@@ -489,8 +489,15 @@ void load(int r, SValue *sv) · 488 unmodified lines
489489 }
490490 #endif
491491 } else if (is64_type(ft)) {
492− orex(1,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
493− gen_le64(sv->c.i);
492+ if (sv->c.i > UINT32_MAX) {
493+ orex(1,r,0, 0xb8 + REG_VALUE(r)); /* movabs $xx, r */
494+ gen_le64(sv->c.i);
495+ } else if (sv->c.i > 0) {
496+ orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
497+ gen_le32(sv->c.i);
498+ } else {
499+ o(0xc031 + REG_VALUE(r) * 0x900); /* xor r, r */
500+ }
494501 } else {
495502 orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
496503 gen_le32(fc);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t