]> gitweb.factorcode.org Git - factor.git/blob - basis/cpu/x86/64/unix/unix.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / cpu / x86 / 64 / unix / unix.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays sequences math splitting make assocs kernel
4 layouts system alien.c-types classes.struct cpu.architecture 
5 cpu.x86.assembler cpu.x86.assembler.operands cpu.x86 compiler.codegen
6 compiler.cfg.registers ;
7 IN: cpu.x86.64.unix
8
9 M: int-regs param-regs
10     drop { RDI RSI RDX RCX R8 R9 } ;
11
12 M: float-regs param-regs
13     drop { XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 } ;
14
15 M: x86.64 reserved-stack-space 0 ;
16
17 SYMBOL: (stack-value)
18 ! The ABI for passing structs by value is pretty great
19 << void* c-type clone \ (stack-value) define-primitive-type
20 stack-params \ (stack-value) c-type (>>rep) >>
21
22 : struct-types&offset ( struct-type -- pairs )
23     fields>> [
24         [ type>> ] [ offset>> ] bi 2array
25     ] map ;
26
27 : split-struct ( pairs -- seq )
28     [
29         [ 8 mod zero? [ t , ] when , ] assoc-each
30     ] { } make { t } split harvest ;
31
32 : flatten-small-struct ( c-type -- seq )
33     struct-types&offset split-struct [
34         [ c-type c-type-rep reg-class-of ] map
35         int-regs swap member? void* double ? c-type
36     ] map ;
37
38 : flatten-large-struct ( c-type -- seq )
39     heap-size cell align
40     cell /i \ (stack-value) c-type <repetition> ;
41
42 : flatten-struct ( c-type -- seq )
43     dup heap-size 16 > [
44         flatten-large-struct
45     ] [
46         flatten-small-struct
47     ] if ;
48
49 M: struct-c-type flatten-value-type ( type -- seq )
50     flatten-struct ;
51
52 M: x86.64 return-struct-in-registers? ( c-type -- ? )
53     heap-size 2 cells <= ;
54
55 M: x86.64 dummy-stack-params? f ;
56
57 M: x86.64 dummy-int-params? f ;
58
59 M: x86.64 dummy-fp-params? f ;
60
61 M: x86.64 temp-reg R8 ;