cpu.x86: use INC and DEC in favor of ADD reg, 1 and SUB reg, 1

The encoding for INC reg and DEC reg is one byte shorter so using it
shaves of a few bytes from the generated code.
locals-and-roots
Björn Lindqvist 2016-05-08 18:44:31 +02:00
parent 5a2e1c953e
commit 274a0174fd
2 changed files with 21 additions and 4 deletions

View File

@ -1,8 +1,8 @@
USING: compiler.cfg.debugger compiler.cfg.instructions
compiler.cfg.registers compiler.codegen.gc-maps
compiler.codegen.relocation cpu.architecture cpu.x86 cpu.x86.assembler
cpu.x86.features kernel kernel.private layouts make math math.libm
namespaces sequences system tools.test ;
cpu.x86.assembler.operands cpu.x86.features kernel kernel.private
layouts make math math.libm namespaces sequences system tools.test ;
IN: cpu.x86.tests
{ } [
@ -12,6 +12,15 @@ IN: cpu.x86.tests
assert=
] unit-test
! %add-imm
{
B{ 72 255 192 }
B{ 72 131 192 29 }
} [
[ RAX RAX 1 %add-imm ] B{ } make
[ RAX RAX 29 %add-imm ] B{ } make
] unit-test
! %call-gc
{ V{ } } [
init-relocation init-gc-maps

View File

@ -130,9 +130,17 @@ M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ;
dst ; inline
M: x86 %add 2over eq? [ nip ADD ] [ [+] LEA ] if ;
M: x86 %add-imm 2over eq? [ nip ADD ] [ [+] LEA ] if ;
M: x86 %add-imm ( dst src1 src2 -- )
2over eq? [
nip { { 1 [ INC ] } { -1 [ DEC ] } [ ADD ] } case
] [ [+] LEA ] if ;
M: x86 %sub int-rep two-operand SUB ;
M: x86 %sub-imm 2over eq? [ nip SUB ] [ neg [+] LEA ] if ;
M: x86 %sub-imm ( dst src1 src2 -- )
2over eq? [
nip { { 1 [ DEC ] } { -1 [ INC ] } [ SUB ] } case
] [ neg [+] LEA ] if ;
M: x86 %mul int-rep two-operand IMUL2 ;
M: x86 %mul-imm IMUL3 ;
M: x86 %and int-rep two-operand AND ;