The encoding for INC reg and DEC reg is one byte shorter so using it
shaves of a few bytes from the generated code.
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
{ } [
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
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 ;