From 0fd636b4b9e998350b32431fcd34775a1453daa7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 Jul 2010 19:49:29 -0400 Subject: [PATCH] compiler.cfg: ##unbox-long-long can have multiple outputs now, clean up long long parameter passing code using this --- .../cfg/builder/alien/boxing/boxing.factor | 3 +-- .../cfg/instructions/instructions.factor | 7 +++--- basis/cpu/architecture/architecture.factor | 2 +- basis/cpu/x86/32/32.factor | 22 ++++++++----------- vm/math.cpp | 8 +++---- vm/math.hpp | 4 ++-- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/basis/compiler/cfg/builder/alien/boxing/boxing.factor b/basis/compiler/cfg/builder/alien/boxing/boxing.factor index 48652737be..fb57700c80 100644 --- a/basis/compiler/cfg/builder/alien/boxing/boxing.factor +++ b/basis/compiler/cfg/builder/alien/boxing/boxing.factor @@ -57,8 +57,7 @@ M: c-type unbox [ drop f 2array 1array ] 2bi ; M: long-long-type unbox - [ 8 cell f ^^local-allot ] dip '[ _ unboxer>> ##unbox-long-long ] keep - 0 cell [ int-rep f ^^load-memory-imm ] bi-curry@ bi 2array + [ next-vreg next-vreg 2dup ] 2dip unboxer>> ##unbox-long-long 2array int-rep long-long-on-stack? 2array dup 2array ; M: struct-c-type unbox ( src c-type -- vregs reps ) diff --git a/basis/compiler/cfg/instructions/instructions.factor b/basis/compiler/cfg/instructions/instructions.factor index 1b7aa94fae..7efd1b3a5d 100644 --- a/basis/compiler/cfg/instructions/instructions.factor +++ b/basis/compiler/cfg/instructions/instructions.factor @@ -645,7 +645,8 @@ use: src/tagged-rep literal: unboxer rep ; FOLDABLE-INSN: ##unbox-long-long -use: src/tagged-rep out/int-rep +def: dst1/int-rep dst2/int-rep +use: src/tagged-rep literal: unboxer ; FLUSHABLE-INSN: ##local-allot @@ -875,7 +876,8 @@ UNION: hairy-clobber-insn ##call-gc alien-call-insn ##callback-inputs -##callback-outputs ; +##callback-outputs +##unbox-long-long ; ! Instructions that clobber registers but are allowed to produce ! outputs in registers. Inputs are in spill slots, except for @@ -886,7 +888,6 @@ hairy-clobber-insn ##unary-float-function ##binary-float-function ##unbox -##unbox-long-long ##box ##box-long-long ##allot-byte-array ; diff --git a/basis/cpu/architecture/architecture.factor b/basis/cpu/architecture/architecture.factor index 277896130e..b4b5132ed5 100644 --- a/basis/cpu/architecture/architecture.factor +++ b/basis/cpu/architecture/architecture.factor @@ -585,7 +585,7 @@ HOOK: struct-return-on-stack? cpu ( -- ? ) ! can be passed to a C function, or returned from a callback HOOK: %unbox cpu ( dst src func rep -- ) -HOOK: %unbox-long-long cpu ( src out func -- ) +HOOK: %unbox-long-long cpu ( dst1 dst2 src func -- ) HOOK: %local-allot cpu ( dst size align offset -- ) diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index 12a067c684..ee6082425b 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -158,27 +158,23 @@ M:: x86.32 %unbox ( dst src func rep -- ) src func call-unbox-func dst rep %load-return ; -M:: x86.32 %unbox-long-long ( src out func -- ) - EAX src int-rep %copy - 0 stack@ EAX MOV - EAX out int-rep %copy - 4 stack@ EAX MOV - 8 save-vm-ptr - func f f %c-invoke ; +M:: x86.32 %unbox-long-long ( dst1 dst2 src func -- ) + src int-rep 0 %store-stack-param + 4 save-vm-ptr + func f f %c-invoke + dst1 EAX int-rep %copy + dst2 EDX int-rep %copy ; M:: x86.32 %box ( dst src func rep gc-map -- ) + src rep 0 %store-stack-param rep rep-size save-vm-ptr - src rep %store-return - 0 stack@ rep %load-return func f gc-map %c-invoke dst EAX tagged-rep %copy ; M:: x86.32 %box-long-long ( dst src1 src2 func gc-map -- ) + src1 int-rep 0 %store-stack-param + src2 int-rep 4 %store-stack-param 8 save-vm-ptr - EAX src1 int-rep %copy - 0 stack@ EAX int-rep %copy - EAX src2 int-rep %copy - 4 stack@ EAX int-rep %copy func f gc-map %c-invoke dst EAX tagged-rep %copy ; diff --git a/vm/math.cpp b/vm/math.cpp index 737b35ab85..e64db2690e 100755 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -491,9 +491,9 @@ s64 factor_vm::to_signed_8(cell obj) } } -VM_C_API void to_signed_8(cell obj, s64 *out, factor_vm *parent) +VM_C_API s64 to_signed_8(cell obj, factor_vm *parent) { - *out = parent->to_signed_8(obj); + return parent->to_signed_8(obj); } cell factor_vm::from_unsigned_8(u64 n) @@ -524,9 +524,9 @@ u64 factor_vm::to_unsigned_8(cell obj) } } -VM_C_API void to_unsigned_8(cell obj, u64 *out, factor_vm *parent) +VM_C_API u64 to_unsigned_8(cell obj, factor_vm *parent) { - *out = parent->to_unsigned_8(obj); + return parent->to_unsigned_8(obj); } VM_C_API cell from_float(float flo, factor_vm *parent) diff --git a/vm/math.hpp b/vm/math.hpp index 13934048cd..dc6d37bcfd 100644 --- a/vm/math.hpp +++ b/vm/math.hpp @@ -90,8 +90,8 @@ VM_C_API cell from_unsigned_cell(cell integer, factor_vm *vm); VM_C_API cell from_signed_8(s64 n, factor_vm *vm); VM_C_API cell from_unsigned_8(u64 n, factor_vm *vm); -VM_C_API void to_signed_8(cell obj, s64 *out, factor_vm *parent); -VM_C_API void to_unsigned_8(cell obj, u64 *out, factor_vm *parent); +VM_C_API s64 to_signed_8(cell obj, factor_vm *parent); +VM_C_API u64 to_unsigned_8(cell obj, factor_vm *parent); VM_C_API fixnum to_fixnum(cell tagged, factor_vm *vm); VM_C_API cell to_cell(cell tagged, factor_vm *vm);