diff --git a/basis/cpu/architecture/architecture.factor b/basis/cpu/architecture/architecture.factor index 1931187779..2d3f8a8b40 100644 --- a/basis/cpu/architecture/architecture.factor +++ b/basis/cpu/architecture/architecture.factor @@ -43,7 +43,7 @@ GENERIC# load-literal 1 ( 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 HOOK: %prologue cpu ( n -- ) @@ -197,3 +197,12 @@ HOOK: %write-barrier cpu ( src card# table -- ) ! GC check 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 -- ) diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index a170878eec..e7e654c8f7 100644 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -267,7 +267,10 @@ M: x86.32 %callback-return ( n -- ) #! b) If the callback is returning a large struct, we have #! to fix ESP. { - { [ dup abi>> "stdcall" = ] [ size>> ] } + { [ dup abi>> "stdcall" = ] [ + + [ params>> ] [ return>> ] bi + + ] } { [ dup return>> large-struct? ] [ drop 4 ] } [ drop 0 ] } cond RET ; diff --git a/basis/cpu/x86/architecture/architecture.factor b/basis/cpu/x86/architecture/architecture.factor index 83876d72f8..bfcb79d41d 100644 --- a/basis/cpu/x86/architecture/architecture.factor +++ b/basis/cpu/x86/architecture/architecture.factor @@ -1,10 +1,11 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien alien.c-types arrays cpu.x86.assembler -cpu.x86.assembler.private cpu.architecture kernel kernel.private -math memory namespaces make sequences words system -layouts combinators math.order locals compiler.constants -compiler.cfg.registers compiler.cfg.instructions +USING: accessors assocs alien alien.c-types arrays +cpu.x86.assembler cpu.x86.assembler.private cpu.architecture +kernel kernel.private math memory namespaces make sequences +words system layouts combinators math.order locals +compiler.constants compiler.cfg.registers +compiler.cfg.instructions compiler.codegen compiler.codegen.fixup ; IN: cpu.x86.architecture @@ -14,6 +15,13 @@ HOOK: stack-reg cpu ( -- reg ) : 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 ) #! nth parameter from the next stack frame. Used to box #! input values to callbacks; the callback has its own @@ -60,8 +68,13 @@ M: fixnum load-literal : align-stack ( n -- n' ) os macosx? cpu x86.64? or [ 16 align ] when ; -M: x86 stack-frame-size ( n -- i ) - 3 cells + align-stack ; +M: x86 stack-frame-size ( stack-frame -- i ) + [ spill-counts>> [ swap reg-size * ] { } assoc>map sum ] + [ params>> ] + [ return>> ] + tri + + + 3 cells + + align-stack ; : decr-stack-reg ( n -- ) dup 0 = [ drop ] [ stack-reg swap SUB ] if ; @@ -193,3 +206,9 @@ M: x86 %unbox-any-c-ptr ( dst src -- ) rs-reg POP ! Restore ds-reg ds-reg POP ; + +M: x86 %spill-integer ( src n -- ) + spill-integer@ swap MOV ; + +M: x86 %reload-integer ( dst n -- ) + spill-integer@ MOV ; diff --git a/basis/cpu/x86/sse2/sse2.factor b/basis/cpu/x86/sse2/sse2.factor index 9650a4ce11..1f3090fcbd 100644 --- a/basis/cpu/x86/sse2/sse2.factor +++ b/basis/cpu/x86/sse2/sse2.factor @@ -8,6 +8,12 @@ compiler.cfg.registers compiler.cfg.builder cpu.architecture cpu.x86.assembler cpu.x86.architecture cpu.x86.intrinsics ; 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 %box-float ( dst src temp -- )