mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x64: optimize mov <reg>, 0 (#7733)
This commit is contained in:
parent
bf9b0c6345
commit
3e44393152
@ -514,6 +514,37 @@ pub fn (mut g Gen) gen_exit() {
|
||||
}
|
||||
|
||||
fn (mut g Gen) mov(reg Register, val int) {
|
||||
if val == 0 {
|
||||
// Optimise to xor reg, reg when val is 0
|
||||
match reg {
|
||||
.eax, .rax {
|
||||
g.write8(0x31)
|
||||
g.write8(0xc0)
|
||||
}
|
||||
.edi, .rdi {
|
||||
g.write8(0x31)
|
||||
g.write8(0xff)
|
||||
}
|
||||
.edx {
|
||||
g.write8(0x31)
|
||||
g.write8(0xd2)
|
||||
}
|
||||
.rsi {
|
||||
g.write8(0x48)
|
||||
g.write8(0x31)
|
||||
g.write8(0xf6)
|
||||
}
|
||||
.r12 {
|
||||
g.write8(0x4d)
|
||||
g.write8(0x31)
|
||||
g.write8(0xe4)
|
||||
}
|
||||
else {
|
||||
panic('unhandled mov $reg')
|
||||
}
|
||||
}
|
||||
g.println('xor $reg, $reg')
|
||||
} else {
|
||||
match reg {
|
||||
.eax, .rax {
|
||||
g.write8(0xb8)
|
||||
@ -538,6 +569,7 @@ fn (mut g Gen) mov(reg Register, val int) {
|
||||
}
|
||||
g.write32(val)
|
||||
g.println('mov $reg, $val')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) mov_reg(a Register, b Register) {
|
||||
|
Loading…
Reference in New Issue
Block a user