]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler: simplify ##unbox-small/large-struct by emitting an ##unbox-any-c-ptr first
authorSlava Pestov <slava@factorcode.org>
Mon, 10 May 2010 05:38:34 +0000 (01:38 -0400)
committerSlava Pestov <slava@factorcode.org>
Mon, 10 May 2010 05:38:34 +0000 (01:38 -0400)
basis/compiler/cfg/builder/alien/alien.factor
basis/compiler/cfg/instructions/instructions.factor
basis/cpu/x86/32/32.factor
basis/cpu/x86/64/64.factor
vm/alien.cpp
vm/alien.hpp
vm/vm.hpp

index d098d665dc1fcbf4fca17c28cd9799fc62ecd31f..bf674fa9b9be9706381630c2a23c63def58a06dc 100644 (file)
@@ -84,7 +84,9 @@ M: long-long-type unbox-parameter
     unboxer>> ##unbox-long-long ;\r
 \r
 M: struct-c-type unbox-parameter\r
-    [ ##unbox-large-struct ] [ base-type unbox-parameter ] if-value-struct ;\r
+    [ [ ^^unbox-any-c-ptr ] 2dip ##unbox-large-struct ]\r
+    [ base-type unbox-parameter ]\r
+    if-value-struct ;\r
 \r
 : unbox-parameters ( offset node -- )\r
     parameters>> swap\r
@@ -271,6 +273,7 @@ M: long-long-type unbox-return
     [ f ] dip unboxer>> ##unbox-long-long ;\r
 \r
 M: struct-c-type unbox-return\r
+    [ ^^unbox-any-c-ptr ] dip\r
     [ ##unbox-small-struct ] [ ##unbox-large-struct ] if-small-struct ;\r
 \r
 M: #alien-callback emit-node\r
index ce63a0350349a15e41c71593a25a778e1d03ead7..36e840fc9e400612821e45dd88057f856b38dfc2 100644 (file)
@@ -637,11 +637,11 @@ use: src/tagged-rep
 literal: n unboxer ;
 
 INSN: ##unbox-large-struct
-use: src/tagged-rep
+use: src/int-rep
 literal: n c-type ;
 
 INSN: ##unbox-small-struct
-use: src/tagged-rep
+use: src/int-rep
 literal: c-type ;
 
 INSN: ##prepare-box-struct ;
index ab3ac4788e99dd4f59daa09cf8a4d520b363762f..bb091a2fe7f5062d027fc8bf292fd6aaf6f36a30 100755 (executable)
@@ -218,32 +218,30 @@ M:: x86.32 %unbox-long-long ( src n func -- )
     ] when* ;
 
 M: x86 %unbox-small-struct ( src size -- )
-    [ "alien_offset" call-unbox-func ]
+    [ [ EAX ] dip int-rep %copy ]
     [
         heap-size 4 > [ EDX EAX 4 [+] MOV ] when
         EAX EAX [] MOV
     ] bi* ;
 
 M:: x86.32 %unbox-large-struct ( src n c-type -- )
-    EAX src tagged-rep %copy
-    ! Compute destination address
+    EAX src int-rep %copy
     EDX n local@ LEA
-    12 save-vm-ptr
     8 stack@ c-type heap-size MOV
-    4 stack@ EDX MOV
-    0 stack@ EAX MOV
-    "to_value_struct" f %alien-invoke ;
+    4 stack@ EAX MOV
+    0 stack@ EDX MOV
+    "memcpy" "libc" load-library %alien-invoke ;
 
 M: x86.32 %alien-indirect ( src -- )
     ?spill-slot CALL ;
 
 M: x86.32 %begin-callback ( -- )
     0 save-vm-ptr
-    ESP 4 [+] 0 MOV
+    4 stack@ 0 MOV
     "begin_callback" f %alien-invoke ;
 
 M: x86.32 %alien-callback ( quot -- )
-    EAX swap %load-reference
+    [ EAX ] dip %load-reference
     EAX quot-entry-point-offset [+] CALL ;
 
 M: x86.32 %end-callback ( -- )
index c55d02e654b81788fb88aa4c87036426eb7dd375..8da9b6ac17ff9707bcb7b4ff7a3d55476c3f56f5 100644 (file)
@@ -134,26 +134,18 @@ M:: x86.64 %unbox ( src n rep func -- )
     } case ;
 
 M:: x86.64 %unbox-small-struct ( src c-type -- )
-    param-reg-0 src tagged-rep %copy
-    param-reg-1 %mov-vm-ptr
-    "alien_offset" f %alien-invoke
-    ! Move alien_offset() return value to R11 so that we don't
-    ! clobber it.
-    R11 RAX MOV
+    ! Move src to R11 so that we don't clobber it.
+    R11 src int-rep %copy
     [
         c-type flatten-struct-type
         [ %unbox-struct-field ] each-index
     ] with-return-regs ;
 
 M:: x86.64 %unbox-large-struct ( src n c-type -- )
-    param-reg-0 src tagged-rep %copy
-    ! Load destination address into param-reg-1
-    param-reg-1 n param@ LEA
-    ! Load structure size into param-reg-2
+    param-reg-1 src int-rep %copy
+    param-reg-0 n param@ LEA
     param-reg-2 c-type heap-size MOV
-    param-reg-3 %mov-vm-ptr
-    ! Copy the struct to the C stack
-    "to_value_struct" f %alien-invoke ;
+    "memcpy" "libc" load-library %alien-invoke ;
 
 : load-return-value ( rep -- )
     [ [ 0 ] dip reg-class-of cdecl param-reg ]
@@ -226,7 +218,7 @@ M: x86.64 %begin-callback ( -- )
     "begin_callback" f %alien-invoke ;
 
 M: x86.64 %alien-callback ( quot -- )
-    param-reg-0 swap %load-reference
+    [ param-reg-0 ] dip %load-reference
     param-reg-0 quot-entry-point-offset [+] CALL ;
 
 M: x86.64 %end-callback ( -- )
index 5354c959aedce6d61545c6445429cea2eeb21ec6..6d6199b6bc83e6a4e8aef513926daae1e4002ce0 100755 (executable)
@@ -187,17 +187,6 @@ VM_C_API char *alien_offset(cell obj, factor_vm *parent)
        return parent->alien_offset(obj);
 }
 
-/* For FFI calls passing structs by value. Cannot allocate */
-void factor_vm::to_value_struct(cell src, void *dest, cell size)
-{
-       memcpy(dest,alien_offset(src),size);
-}
-
-VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *parent)
-{
-       return parent->to_value_struct(src,dest,size);
-}
-
 /* For FFI callbacks receiving structs by value */
 cell factor_vm::from_value_struct(void *src, cell size)
 {
index add6f4ba728ebd1e86946ba787f83403c8cbad6a..2b530c6b83836af3550702eae20995b7297d3c3e 100755 (executable)
@@ -4,7 +4,6 @@ namespace factor
 VM_C_API char *alien_offset(cell object, factor_vm *vm);
 VM_C_API char *pinned_alien_offset(cell object, factor_vm *vm);
 VM_C_API cell allot_alien(void *address, factor_vm *vm);
-VM_C_API void to_value_struct(cell src, void *dest, cell size, factor_vm *vm);
 VM_C_API cell from_value_struct(void *src, cell size, factor_vm *vm);
 VM_C_API cell from_small_struct(cell x, cell y, cell size, factor_vm *vm);
 VM_C_API cell from_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size, factor_vm *vm);
index bfe105e67d958d58df980d51fd612f258da8b3f4..8a3ee56e271880235809b6bf4b9b26814b41436e 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -615,7 +615,6 @@ struct factor_vm
        void primitive_dlclose();
        void primitive_dll_validp();
        char *alien_offset(cell obj);
-       void to_value_struct(cell src, void *dest, cell size);
        cell from_value_struct(void *src, cell size);
        cell from_small_struct(cell x, cell y, cell size);
        cell from_medium_struct(cell x1, cell x2, cell x3, cell x4, cell size);