Implement spilling on x86

db4
Slava Pestov 2008-10-19 01:10:45 -05:00
parent c0d89b061e
commit 774ecf61e9
4 changed files with 46 additions and 9 deletions

View File

@ -43,7 +43,7 @@ GENERIC# load-literal 1 ( obj reg -- )
HOOK: load-indirect cpu ( obj reg -- ) HOOK: load-indirect cpu ( obj reg -- )
HOOK: stack-frame-size cpu ( frame-size -- n ) HOOK: stack-frame-size cpu ( stack-frame -- n )
! Set up caller stack frame ! Set up caller stack frame
HOOK: %prologue cpu ( n -- ) HOOK: %prologue cpu ( n -- )
@ -197,3 +197,12 @@ HOOK: %write-barrier cpu ( src card# table -- )
! GC check ! GC check
HOOK: %gc cpu ( -- ) HOOK: %gc cpu ( -- )
! Spilling
HOOK: %spill-integer cpu ( src n -- )
HOOK: %spill-float cpu ( src n -- )
HOOK: %reload-integer cpu ( dst n -- )
HOOK: %reload-float cpu ( dst n -- )

View File

@ -267,7 +267,10 @@ M: x86.32 %callback-return ( n -- )
#! b) If the callback is returning a large struct, we have #! b) If the callback is returning a large struct, we have
#! to fix ESP. #! to fix ESP.
{ {
{ [ dup abi>> "stdcall" = ] [ <alien-stack-frame> size>> ] } { [ dup abi>> "stdcall" = ] [
<alien-stack-frame>
[ params>> ] [ return>> ] bi +
] }
{ [ dup return>> large-struct? ] [ drop 4 ] } { [ dup return>> large-struct? ] [ drop 4 ] }
[ drop 0 ] [ drop 0 ]
} cond RET ; } cond RET ;

View File

@ -1,10 +1,11 @@
! Copyright (C) 2005, 2008 Slava Pestov. ! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays cpu.x86.assembler USING: accessors assocs alien alien.c-types arrays
cpu.x86.assembler.private cpu.architecture kernel kernel.private cpu.x86.assembler cpu.x86.assembler.private cpu.architecture
math memory namespaces make sequences words system kernel kernel.private math memory namespaces make sequences
layouts combinators math.order locals compiler.constants words system layouts combinators math.order locals
compiler.cfg.registers compiler.cfg.instructions compiler.constants compiler.cfg.registers
compiler.cfg.instructions compiler.codegen
compiler.codegen.fixup ; compiler.codegen.fixup ;
IN: cpu.x86.architecture IN: cpu.x86.architecture
@ -14,6 +15,13 @@ HOOK: stack-reg cpu ( -- reg )
: stack@ ( n -- op ) stack-reg swap [+] ; : stack@ ( n -- op ) stack-reg swap [+] ;
: spill-integer@ ( n -- op )
cells stack-frame get [ params>> ] [ return>> ] bi + + stack@ ;
: spill-float@ ( n -- op )
#! XXX
cells stack-frame get [ params>> ] [ return>> ] bi + + stack@ ;
: next-stack@ ( n -- operand ) : next-stack@ ( n -- operand )
#! nth parameter from the next stack frame. Used to box #! nth parameter from the next stack frame. Used to box
#! input values to callbacks; the callback has its own #! input values to callbacks; the callback has its own
@ -60,8 +68,13 @@ M: fixnum load-literal
: align-stack ( n -- n' ) : align-stack ( n -- n' )
os macosx? cpu x86.64? or [ 16 align ] when ; os macosx? cpu x86.64? or [ 16 align ] when ;
M: x86 stack-frame-size ( n -- i ) M: x86 stack-frame-size ( stack-frame -- i )
3 cells + align-stack ; [ spill-counts>> [ swap reg-size * ] { } assoc>map sum ]
[ params>> ]
[ return>> ]
tri + +
3 cells +
align-stack ;
: decr-stack-reg ( n -- ) : decr-stack-reg ( n -- )
dup 0 = [ drop ] [ stack-reg swap SUB ] if ; dup 0 = [ drop ] [ stack-reg swap SUB ] if ;
@ -193,3 +206,9 @@ M: x86 %unbox-any-c-ptr ( dst src -- )
rs-reg POP rs-reg POP
! Restore ds-reg ! Restore ds-reg
ds-reg POP ; ds-reg POP ;
M: x86 %spill-integer ( src n -- )
spill-integer@ swap MOV ;
M: x86 %reload-integer ( dst n -- )
spill-integer@ MOV ;

View File

@ -8,6 +8,12 @@ compiler.cfg.registers compiler.cfg.builder cpu.architecture
cpu.x86.assembler cpu.x86.architecture cpu.x86.intrinsics ; cpu.x86.assembler cpu.x86.architecture cpu.x86.intrinsics ;
IN: cpu.x86.sse2 IN: cpu.x86.sse2
M: x86 %spill-float ( src n -- )
spill-float@ swap MOVSD ;
M: x86 %reload-float ( dst n -- )
spill-float@ MOVSD ;
M: x86 %copy-float MOVSD ; M: x86 %copy-float MOVSD ;
M:: x86 %box-float ( dst src temp -- ) M:: x86 %box-float ( dst src temp -- )