stub out AMD64 float parameter code

cvs
Slava Pestov 2006-01-25 01:20:20 +00:00
parent 9ea2332a2b
commit 1177038cec
8 changed files with 74 additions and 15 deletions

View File

@ -71,7 +71,7 @@ C: alien-node make-node ;
[ [ c-aligned - dup ] keep unbox-parameter , ] each drop ;
: reg-class-full? ( class -- ? )
dup class get swap fastcall-regs >= ;
dup class get swap fastcall-regs length >= ;
: spill-param ( reg-class -- n reg-class )
reg-size stack-params [ tuck + ] change

View File

@ -14,7 +14,15 @@ M: int-regs store-insn
drop stack@ RAX MOV ;
M: int-regs load-insn
drop param-regs nth swap stack@ MOV ;
fastcall-regs nth swap stack@ MOV ;
: MOVSS/LPD float-regs-size 4 = [ MOVSS ] [ MOVLPD ] if ;
M: float-regs store-insn
>r stack@ XMM0 r> MOVSS/LPD ;
M: float-regs load-insn
[ fastcall-regs nth swap stack@ ] keep MOVSS/LPD ;
M: %unbox generate-node ( vop -- )
drop
@ -27,10 +35,11 @@ M: %parameter generate-node ( vop -- )
! Move a value from the C stack into the fastcall register
drop 0 input 1 input 2 input load-insn ;
: load-return-value ( reg-class -- )
dup fastcall-regs first swap return-reg
2dup eq? [ 2drop ] [ MOV ] if ;
M: %box generate-node ( vop -- )
drop
! Move return value of C function into input register
param-regs first RAX MOV
0 input f compile-c-call ;
drop 1 input load-return-value 0 input f compile-c-call ;
M: %cleanup generate-node ( vop -- ) drop ;

View File

@ -19,19 +19,22 @@ kernel-internals math sequences ;
: vregs { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; inline
: param-regs { RDI RSI RDX RCX R8 R9 } ; inline
M: int-regs return-reg drop RAX ;
M: int-regs fastcall-regs drop { RDI RSI RDX RCX R8 R9 } ;
: compile-c-call ( symbol dll -- )
2dup dlsym 0 scratch swap MOV
rel-absolute-cell rel-dlsym 0 scratch CALL ;
: compile-c-call* ( symbol dll -- operands )
param-regs swap [ MOV ] 2each compile-c-call ;
: compile-c-call* ( symbol dll args -- )
T{ int-regs } fastcall-regs
swap [ MOV ] 2each compile-c-call ;
M: int-regs return-reg drop RAX ;
M: int-regs fastcall-regs drop param-regs length ;
M: float-regs return-reg drop XMM0 ;
M: float-regs fastcall-regs drop 0 ;
M: float-regs fastcall-regs
drop { XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 } ;
: dual-fp/int-regs? f ;

View File

@ -27,7 +27,7 @@ TUPLE: float-regs size ;
GENERIC: return-reg ( register-class -- reg )
GENERIC: fastcall-regs ( register-class -- n )
GENERIC: fastcall-regs ( register-class -- regs )
GENERIC: reg-size ( register-class -- n )

View File

@ -27,9 +27,9 @@ kernel-internals sequences ;
! On x86, parameters are never passed in registers.
M: int-regs return-reg drop EAX ;
M: int-regs fastcall-regs drop 0 ;
M: int-regs fastcall-regs drop { } ;
M: float-regs fastcall-regs drop 0 ;
M: float-regs fastcall-regs drop { } ;
: dual-fp/int-regs? f ;

View File

@ -50,6 +50,15 @@ SYMBOL: EBP \ EBP 5 32 define-register
SYMBOL: ESI \ ESI 6 32 define-register
SYMBOL: EDI \ EDI 7 32 define-register
SYMBOL: XMM0
SYMBOL: XMM1
SYMBOL: XMM2
SYMBOL: XMM3
SYMBOL: XMM4
SYMBOL: XMM5
SYMBOL: XMM6
SYMBOL: XMM7
PREDICATE: word register "register" word-prop ;
PREDICATE: register register-32 "register-size" word-prop 32 = ;
@ -267,3 +276,8 @@ M: operand CMP OCT: 071 2-operand ;
: (FSTP) BIN: 100 f HEX: 1c 1-operand ;
: FSTPS ( operand -- ) HEX: d9 assemble-1 (FSTP) ;
: FSTPL ( operand -- ) HEX: dd assemble-1 (FSTP) ;
( SSE multimedia instructions )
: MOVLPD ( dest src -- ) 2drop ;
: MOVSS ( dest src -- ) 2drop ;

View File

@ -12,3 +12,12 @@ FUNCTION: int ffi_test_2 int x int y ; compiled
FUNCTION: int ffi_test_3 int x int y int z int t ; compiled
[ 25 ] [ 2 3 4 5 ffi_test_3 ] unit-test
FUNCTION: float ffi_test_4 ; compiled
[ 1.5 ] [ ffi_test_4 ] unit-test
FUNCTION: double ffi_test_5 ; compiled
[ 1.5 ] [ ffi_test_5 ] unit-test
FUNCTION: double ffi_test_6 float x float y ; compiled
[ 6.0 ] [ 3.0 2.0 ffi_test_6 ] unit-test

View File

@ -1,5 +1,6 @@
/* This file is linked into the runtime for the sole purpose
* of testing FFI code. */
#include <stdio.h>
void ffi_test_0(void)
{
@ -23,3 +24,26 @@ int ffi_test_3(int x, int y, int z, int t)
printf("ffi_test_3(%d,%d,%d,%d)\n",x,y,z,t);
return x + y + z * t;
}
float ffi_test_4(void)
{
printf("ffi_test_4()\n");
return 1.5;
}
double ffi_test_5(void)
{
printf("ffi_test_5()\n");
return 1.5;
}
double ffi_test_6(float x, float y)
{
printf("ffi_test_6(%f,%f)\n",x,y);
return x * y;
}
double ffi_test_7(void)
{
return 1.5;
}