From 1177038cec41fce2534ccedfaa51851a33f9fd05 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 25 Jan 2006 01:20:20 +0000 Subject: [PATCH] stub out AMD64 float parameter code --- library/alien/compiler.factor | 2 +- library/compiler/amd64/alien.factor | 19 ++++++++++++----- library/compiler/amd64/architecture.factor | 15 ++++++++------ library/compiler/vops.factor | 2 +- library/compiler/x86/architecture.factor | 4 ++-- library/compiler/x86/assembler.factor | 14 +++++++++++++ library/test/compiler/alien.factor | 9 ++++++++ native/ffi_test.c | 24 ++++++++++++++++++++++ 8 files changed, 74 insertions(+), 15 deletions(-) diff --git a/library/alien/compiler.factor b/library/alien/compiler.factor index 1f745b4566..2db28fc514 100644 --- a/library/alien/compiler.factor +++ b/library/alien/compiler.factor @@ -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 diff --git a/library/compiler/amd64/alien.factor b/library/compiler/amd64/alien.factor index 88b73fb931..d6a88f25a4 100644 --- a/library/compiler/amd64/alien.factor +++ b/library/compiler/amd64/alien.factor @@ -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 ; diff --git a/library/compiler/amd64/architecture.factor b/library/compiler/amd64/architecture.factor index 8aff995125..41ba6c451a 100644 --- a/library/compiler/amd64/architecture.factor +++ b/library/compiler/amd64/architecture.factor @@ -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 ; diff --git a/library/compiler/vops.factor b/library/compiler/vops.factor index baf4a06202..77d42dcbf9 100644 --- a/library/compiler/vops.factor +++ b/library/compiler/vops.factor @@ -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 ) diff --git a/library/compiler/x86/architecture.factor b/library/compiler/x86/architecture.factor index d77b446f7c..9da48f41c6 100644 --- a/library/compiler/x86/architecture.factor +++ b/library/compiler/x86/architecture.factor @@ -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 ; diff --git a/library/compiler/x86/assembler.factor b/library/compiler/x86/assembler.factor index 51e52a2f96..64007b3dc4 100644 --- a/library/compiler/x86/assembler.factor +++ b/library/compiler/x86/assembler.factor @@ -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 ; diff --git a/library/test/compiler/alien.factor b/library/test/compiler/alien.factor index cb4396a7a6..04febd73bb 100644 --- a/library/test/compiler/alien.factor +++ b/library/test/compiler/alien.factor @@ -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 + diff --git a/native/ffi_test.c b/native/ffi_test.c index 12e56a2a92..b9e6ed5c19 100644 --- a/native/ffi_test.c +++ b/native/ffi_test.c @@ -1,5 +1,6 @@ /* This file is linked into the runtime for the sole purpose * of testing FFI code. */ +#include 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; +}