Optimize a ##dispatch that is applied to the result of a ##sub-imm or ##add-imm; this eliminates an instruction from the common 1 fixnum-fast { ... } dispatch and 8 fixnum-fast { ... } dispatch code sequences appearing in generic word expansions
parent
029ee67525
commit
eb05dd3a12
|
@ -190,7 +190,7 @@ M: #if emit-node
|
||||||
|
|
||||||
: emit-dispatch ( node -- )
|
: emit-dispatch ( node -- )
|
||||||
##epilogue
|
##epilogue
|
||||||
ds-pop ^^offset>slot i ##dispatch
|
ds-pop ^^offset>slot i 0 ##dispatch
|
||||||
dispatch-branches ;
|
dispatch-branches ;
|
||||||
|
|
||||||
: <dispatch-block> ( -- word )
|
: <dispatch-block> ( -- word )
|
||||||
|
|
|
@ -62,7 +62,7 @@ INSN: ##jump word ;
|
||||||
INSN: ##return ;
|
INSN: ##return ;
|
||||||
|
|
||||||
! Jump tables
|
! Jump tables
|
||||||
INSN: ##dispatch src temp ;
|
INSN: ##dispatch src temp offset ;
|
||||||
INSN: ##dispatch-label label ;
|
INSN: ##dispatch-label label ;
|
||||||
|
|
||||||
! Slot access
|
! Slot access
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel sequences layouts accessors combinators namespaces
|
USING: kernel sequences layouts accessors combinators namespaces
|
||||||
math
|
math fry
|
||||||
compiler.cfg.instructions
|
compiler.cfg.instructions
|
||||||
compiler.cfg.value-numbering.graph
|
compiler.cfg.value-numbering.graph
|
||||||
compiler.cfg.value-numbering.simplify
|
compiler.cfg.value-numbering.simplify
|
||||||
|
@ -113,4 +113,18 @@ M: ##compare-imm rewrite
|
||||||
] when
|
] when
|
||||||
] when ;
|
] when ;
|
||||||
|
|
||||||
|
: dispatch-offset ( expr -- n )
|
||||||
|
[ in2>> vn>constant tag-bits get neg shift ] [ op>> ] bi
|
||||||
|
\ ##sub-imm eq? [ neg ] when ;
|
||||||
|
|
||||||
|
: add-dispatch-offset? ( insn -- expr ? )
|
||||||
|
src>> vreg>expr dup op>> { ##add-imm ##sub-imm } memq? ; inline
|
||||||
|
|
||||||
|
M: ##dispatch rewrite
|
||||||
|
dup add-dispatch-offset? [
|
||||||
|
[ clone ] dip
|
||||||
|
[ in1>> vn>vreg >>src ]
|
||||||
|
[ dispatch-offset '[ _ + ] change-offset ] bi
|
||||||
|
] [ drop ] if ;
|
||||||
|
|
||||||
M: insn rewrite ;
|
M: insn rewrite ;
|
||||||
|
|
|
@ -34,7 +34,7 @@ compiler.cfg.registers cpu.architecture tools.test kernel math ;
|
||||||
[ t ] [
|
[ t ] [
|
||||||
{
|
{
|
||||||
T{ ##peek f V int-regs 1 D 0 }
|
T{ ##peek f V int-regs 1 D 0 }
|
||||||
T{ ##dispatch f V int-regs 1 V int-regs 2 }
|
T{ ##dispatch f V int-regs 1 V int-regs 2 0 }
|
||||||
} dup value-numbering =
|
} dup value-numbering =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ M: ##return generate-insn drop %return ;
|
||||||
M: ##dispatch-label generate-insn label>> %dispatch-label ;
|
M: ##dispatch-label generate-insn label>> %dispatch-label ;
|
||||||
|
|
||||||
M: ##dispatch generate-insn
|
M: ##dispatch generate-insn
|
||||||
[ src>> register ] [ temp>> register ] bi %dispatch ;
|
[ src>> register ] [ temp>> register ] [ offset>> ] tri %dispatch ;
|
||||||
|
|
||||||
: >slot<
|
: >slot<
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,8 +72,8 @@ SYMBOL: literal-table
|
||||||
: rel-this ( class -- )
|
: rel-this ( class -- )
|
||||||
0 swap rt-label rel-fixup ;
|
0 swap rt-label rel-fixup ;
|
||||||
|
|
||||||
: rel-here ( class -- )
|
: rel-here ( offset class -- )
|
||||||
0 swap rt-here rel-fixup ;
|
rt-here rel-fixup ;
|
||||||
|
|
||||||
: init-fixup ( -- )
|
: init-fixup ( -- )
|
||||||
BV{ } clone relocation-table set
|
BV{ } clone relocation-table set
|
||||||
|
|
|
@ -50,7 +50,7 @@ HOOK: %call cpu ( word -- )
|
||||||
HOOK: %jump-label cpu ( label -- )
|
HOOK: %jump-label cpu ( label -- )
|
||||||
HOOK: %return cpu ( -- )
|
HOOK: %return cpu ( -- )
|
||||||
|
|
||||||
HOOK: %dispatch cpu ( src temp -- )
|
HOOK: %dispatch cpu ( src temp offset -- )
|
||||||
HOOK: %dispatch-label cpu ( word -- )
|
HOOK: %dispatch-label cpu ( word -- )
|
||||||
|
|
||||||
HOOK: %slot cpu ( dst obj slot tag temp -- )
|
HOOK: %slot cpu ( dst obj slot tag temp -- )
|
||||||
|
|
|
@ -111,10 +111,10 @@ M: ppc %call ( label -- ) BL ;
|
||||||
M: ppc %jump-label ( label -- ) B ;
|
M: ppc %jump-label ( label -- ) B ;
|
||||||
M: ppc %return ( -- ) BLR ;
|
M: ppc %return ( -- ) BLR ;
|
||||||
|
|
||||||
M:: ppc %dispatch ( src temp -- )
|
M:: ppc %dispatch ( src temp offset -- )
|
||||||
0 temp LOAD32 rc-absolute-ppc-2/2 rel-here
|
0 temp LOAD32 rc-absolute-ppc-2/2 rel-here
|
||||||
temp temp src ADD
|
temp temp src ADD
|
||||||
temp temp 5 cells LWZ
|
temp temp 5 offset + cells LWZ
|
||||||
temp MTCTR
|
temp MTCTR
|
||||||
BCTR ;
|
BCTR ;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ accessors init combinators command-line cpu.x86.assembler
|
||||||
cpu.x86 cpu.architecture compiler compiler.units
|
cpu.x86 cpu.architecture compiler compiler.units
|
||||||
compiler.constants compiler.alien compiler.codegen
|
compiler.constants compiler.alien compiler.codegen
|
||||||
compiler.codegen.fixup compiler.cfg.instructions
|
compiler.codegen.fixup compiler.cfg.instructions
|
||||||
compiler.cfg.builder compiler.cfg.intrinsics ;
|
compiler.cfg.builder compiler.cfg.intrinsics make ;
|
||||||
IN: cpu.x86.32
|
IN: cpu.x86.32
|
||||||
|
|
||||||
! We implement the FFI for Linux, OS X and Windows all at once.
|
! We implement the FFI for Linux, OS X and Windows all at once.
|
||||||
|
@ -26,6 +26,18 @@ M: x86.32 stack-reg ESP ;
|
||||||
M: x86.32 temp-reg-1 EAX ;
|
M: x86.32 temp-reg-1 EAX ;
|
||||||
M: x86.32 temp-reg-2 ECX ;
|
M: x86.32 temp-reg-2 ECX ;
|
||||||
|
|
||||||
|
M:: x86.32 %dispatch ( src temp offset -- )
|
||||||
|
! Load jump table base.
|
||||||
|
src HEX: ffffffff ADD
|
||||||
|
offset cells rc-absolute-cell rel-here
|
||||||
|
! Go
|
||||||
|
src HEX: 7f [+] JMP
|
||||||
|
! Fix up the displacement above
|
||||||
|
cell code-alignment
|
||||||
|
[ 7 + building get dup pop* push ]
|
||||||
|
[ align-code ]
|
||||||
|
bi ;
|
||||||
|
|
||||||
M: x86.32 reserved-area-size 0 ;
|
M: x86.32 reserved-area-size 0 ;
|
||||||
|
|
||||||
M: x86.32 %alien-global 0 [] MOV rc-absolute-cell rel-dlsym ;
|
M: x86.32 %alien-global 0 [] MOV rc-absolute-cell rel-dlsym ;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays kernel math namespaces make sequences
|
USING: accessors arrays kernel math namespaces make sequences
|
||||||
system layouts alien alien.c-types alien.accessors alien.structs
|
system layouts alien alien.c-types alien.accessors alien.structs
|
||||||
slots splitting assocs combinators cpu.x86.assembler
|
slots splitting assocs combinators make locals cpu.x86.assembler
|
||||||
cpu.x86 cpu.architecture compiler.constants
|
cpu.x86 cpu.architecture compiler.constants
|
||||||
compiler.codegen compiler.codegen.fixup
|
compiler.codegen compiler.codegen.fixup
|
||||||
compiler.cfg.instructions compiler.cfg.builder
|
compiler.cfg.instructions compiler.cfg.builder
|
||||||
|
@ -24,6 +24,19 @@ M: x86.64 stack-reg RSP ;
|
||||||
M: x86.64 temp-reg-1 RAX ;
|
M: x86.64 temp-reg-1 RAX ;
|
||||||
M: x86.64 temp-reg-2 RCX ;
|
M: x86.64 temp-reg-2 RCX ;
|
||||||
|
|
||||||
|
M:: x86.64 %dispatch ( src temp offset -- )
|
||||||
|
! Load jump table base.
|
||||||
|
temp HEX: ffffffff MOV
|
||||||
|
offset cells rc-absolute-cell rel-here
|
||||||
|
! Add jump table base
|
||||||
|
src temp ADD
|
||||||
|
src HEX: 7f [+] JMP
|
||||||
|
! Fix up the displacement above
|
||||||
|
cell code-alignment
|
||||||
|
[ 15 + building get dup pop* push ]
|
||||||
|
[ align-code ]
|
||||||
|
bi ;
|
||||||
|
|
||||||
: param-reg-1 int-regs param-regs first ; inline
|
: param-reg-1 int-regs param-regs first ; inline
|
||||||
: param-reg-2 int-regs param-regs second ; inline
|
: param-reg-2 int-regs param-regs second ; inline
|
||||||
: param-reg-3 int-regs param-regs third ; inline
|
: param-reg-3 int-regs param-regs third ; inline
|
||||||
|
|
|
@ -60,19 +60,6 @@ M: x86 %return ( -- ) 0 RET ;
|
||||||
: align-code ( n -- )
|
: align-code ( n -- )
|
||||||
0 <repetition> % ;
|
0 <repetition> % ;
|
||||||
|
|
||||||
M:: x86 %dispatch ( src temp -- )
|
|
||||||
! Load jump table base. We use a temporary register
|
|
||||||
! since on AMD64 we have to load a 64-bit immediate. On
|
|
||||||
! x86, this is redundant.
|
|
||||||
! Add jump table base
|
|
||||||
temp HEX: ffffffff MOV rc-absolute-cell rel-here
|
|
||||||
src temp ADD
|
|
||||||
src HEX: 7f [+] JMP
|
|
||||||
! Fix up the displacement above
|
|
||||||
cell code-alignment dup bootstrap-cell 8 = 15 9 ? +
|
|
||||||
building get dup pop* push
|
|
||||||
align-code ;
|
|
||||||
|
|
||||||
M: x86 %dispatch-label ( word -- )
|
M: x86 %dispatch-label ( word -- )
|
||||||
0 cell, rc-absolute-cell rel-word ;
|
0 cell, rc-absolute-cell rel-word ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue