]> gitweb.factorcode.org Git - factor.git/commitdiff
cpu.x86: use INC and DEC in favor of ADD reg, 1 and SUB reg, 1
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 8 May 2016 16:44:31 +0000 (18:44 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 8 May 2016 16:44:31 +0000 (18:44 +0200)
The encoding for INC reg and DEC reg is one byte shorter so using it
shaves of a few bytes from the generated code.

basis/cpu/x86/x86-tests.factor
basis/cpu/x86/x86.factor

index bc00d5ba3cb72b1799810c6fcb318b7d942de88f..b224efa62a4eb33e633124a7fb1248a874763c98 100644 (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
index e3125ecc30f3295838c356b0fd199bbff33a8ec5..2507365b154935ecbebe27e04b6f9cbe24dfc3a5 100644 (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 ;