Optimize addition/subtraction of immediate 1 and zeroring registers
This commit is contained in:
parent
2141a17d1e
commit
1e8bdf6cd2
|
@ -341,6 +341,7 @@ class CompileData:
|
||||||
continue
|
continue
|
||||||
instructions.pop(i)
|
instructions.pop(i)
|
||||||
changed = True
|
changed = True
|
||||||
|
if changed: continue
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
# Optimize movq to register followed by pushq register
|
# Optimize movq to register followed by pushq register
|
||||||
|
@ -355,6 +356,7 @@ class CompileData:
|
||||||
instructions.pop(i + 1)
|
instructions.pop(i + 1)
|
||||||
i -= 1
|
i -= 1
|
||||||
changed = True
|
changed = True
|
||||||
|
if changed: continue
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
# Optimize movq to rax followed by movq from rax
|
# Optimize movq to rax followed by movq from rax
|
||||||
|
@ -375,6 +377,34 @@ class CompileData:
|
||||||
instructions.pop(i + 1)
|
instructions.pop(i + 1)
|
||||||
i -= 1
|
i -= 1
|
||||||
changed = True
|
changed = True
|
||||||
|
if changed: continue
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
# Optimize addq/subq for immediate 1
|
||||||
|
while i < len(instructions):
|
||||||
|
if instructions[i].opcode not in ['addq', 'subq']:
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
if instructions[i].operands[0] != '$1':
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
new_opcode = 'incq' if instructions[i].opcode == 'addq' else 'decq'
|
||||||
|
instructions[i] = Instruction(new_opcode, [instructions[i].operands[1]])
|
||||||
|
changed = True
|
||||||
|
if changed: continue
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
# Optimize zeroing of register
|
||||||
|
while i < len(instructions):
|
||||||
|
if instructions[i].opcode != 'movq':
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
if instructions[i].operands[0] != '$0' or instructions[i].operands[1][0] != '%':
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
instructions[i] = Instruction('xorq', [instructions[i].operands[1], instructions[i].operands[1]])
|
||||||
|
changed = True
|
||||||
|
if changed: continue
|
||||||
|
|
||||||
def add_builtin_functions(self) -> None:
|
def add_builtin_functions(self) -> None:
|
||||||
today = []
|
today = []
|
||||||
|
|
Loading…
Reference in New Issue