]> gitweb.factorcode.org Git - factor.git/commitdiff
flatten non-integral types to (stack-value) on x86.32
authorJoe Groff <arcata@gmail.com>
Fri, 2 Apr 2010 03:56:43 +0000 (20:56 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 2 Apr 2010 03:56:43 +0000 (20:56 -0700)
basis/compiler/alien/alien.factor
basis/compiler/codegen/codegen.factor
basis/cpu/architecture/architecture.factor
basis/cpu/ppc/ppc.factor
basis/cpu/x86/32/32.factor
basis/cpu/x86/64/64.factor
basis/cpu/x86/64/unix/unix.factor

index 7426d7e9408770a921027d075010bd99c621cecb..63df85be05aef215a475c7b6474f849af3001604 100644 (file)
@@ -9,7 +9,7 @@ IN: compiler.alien
 
 : alien-parameters ( params -- seq )
     dup parameters>>
-    swap return>> large-struct? [ void* prefix ] when ;
+    swap return>> large-struct? [ struct-return-pointer-type prefix ] when ;
 
 : alien-return ( params -- type )
     return>> dup large-struct? [ drop void ] when ;
index 12e263a3f43e943614ac8dcb8bd42a2c4b26e5a6..4ffe062090f70c6daee198d07792374505720a47 100755 (executable)
@@ -320,8 +320,17 @@ M: reg-class reg-class-full?
     [ alloc-stack-param ] [ alloc-fastcall-param ] if
     [ abi param-reg ] dip ;
 
+SYMBOL: (stack-value)
+<< void* c-type clone \ (stack-value) define-primitive-type
+stack-params \ (stack-value) c-type (>>rep) >>
+
+: ((flatten-type)) ( type to-type -- seq )
+    [ stack-size cell align cell /i ] dip c-type <repetition> ; inline
+
 : (flatten-int-type) ( type -- seq )
-    stack-size cell align cell /i void* c-type <repetition> ;
+    void* ((flatten-type)) ;
+: (flatten-stack-type) ( type -- seq )
+    (stack-value) ((flatten-type)) ;
 
 GENERIC: flatten-value-type ( type -- types )
 
index 9a50b0a2e26fdb551250daf7066a22bae62b72bb..6f3865497b8c9721508265b624293e00cd3784d7 100644 (file)
@@ -502,6 +502,9 @@ HOOK: immediate-arithmetic? cpu ( n -- ? )
 ! %and-imm, %or-imm, and %xor-imm?
 HOOK: immediate-bitwise? cpu ( n -- ? )
 
+! What c-type describes the implicit struct return pointer for large structs?
+HOOK: struct-return-pointer-type cpu ( -- c-type )
+
 ! Is this structure small enough to be returned in registers?
 HOOK: return-struct-in-registers? cpu ( c-type -- ? )
 
index f81d8705bf649207829c16cf5c95b25e5eba4cc5..dd9252129a20be6f28088ed215c4e757d1153c20 100644 (file)
@@ -704,6 +704,8 @@ M: ppc immediate-arithmetic? ( n -- ? ) -32768 32767 between? ;
 
 M: ppc immediate-bitwise? ( n -- ? ) 0 65535 between? ;
 
+M: ppc struct-return-pointer-type void* ;
+
 M: ppc return-struct-in-registers? ( c-type -- ? )
     c-type return-in-registers?>> ;
 
index e346f8ab8c411372b90430588f20766ed36c045d..71439373c04a143d2a93502f9adb4bc70a390c66 100755 (executable)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: locals alien alien.c-types alien.libraries alien.syntax
 arrays kernel fry math namespaces sequences system layouts io
-vocabs.loader accessors init combinators command-line make
-compiler compiler.units compiler.constants compiler.alien
+vocabs.loader accessors init classes.struct combinators command-line
+make compiler compiler.units compiler.constants compiler.alien
 compiler.codegen compiler.codegen.fixup
 compiler.cfg.instructions compiler.cfg.builder
 compiler.cfg.intrinsics compiler.cfg.stack-frame
@@ -357,6 +357,12 @@ M: x86.32 callback-return-rewind ( params -- n )
     } cond ;
 
 ! Dreadful
-M: object flatten-value-type (flatten-int-type) ;
+M: object flatten-value-type (flatten-stack-type) ;
+M: struct-c-type flatten-value-type (flatten-stack-type) ;
+M: long-long-type flatten-value-type (flatten-stack-type) ;
+M: c-type flatten-value-type
+    dup rep>> int-rep? [ (flatten-int-type) ] [ (flatten-stack-type) ] if ;
+
+M: x86.64 struct-return-pointer-type (stack-value) ;
 
 check-sse
index ab75dbf00bcc24ee1915946c47c25cdebc2663ea..87578dd8db8300482e4bee2b3ae5a454af8bab51 100644 (file)
@@ -275,6 +275,8 @@ M:: x86.64 %call-gc ( gc-root-count temp -- )
     ! Call GC
     "inline_gc" f %alien-invoke ;
 
+M: x86.64 struct-return-pointer-type void* ;
+
 ! The result of reading 4 bytes from memory is a fixnum on
 ! x86-64.
 enable-alien-4-intrinsics
index 01e02d274d37cb454e7c0450d2c960d9a9e548cb..a1868a3bc89ca60d666395bf50ad429b59067df1 100644 (file)
@@ -14,11 +14,6 @@ M: float-regs param-regs
 
 M: x86.64 reserved-stack-space 0 ;
 
-SYMBOL: (stack-value)
-! The ABI for passing structs by value is pretty great
-<< void* c-type clone \ (stack-value) define-primitive-type
-stack-params \ (stack-value) c-type (>>rep) >>
-
 : struct-types&offset ( struct-type -- pairs )
     fields>> [
         [ type>> ] [ offset>> ] bi 2array
@@ -36,8 +31,7 @@ stack-params \ (stack-value) c-type (>>rep) >>
     ] map ;
 
 : flatten-large-struct ( c-type -- seq )
-    heap-size cell align
-    cell /i \ (stack-value) c-type <repetition> ;
+    (flatten-stack-type) ;
 
 : flatten-struct ( c-type -- seq )
     dup heap-size 16 > [