tcc/lib: reduce number of files
[tinycc.git] / lib / alloca-bt.S
blobc161488609e255b3c2b330556f5c0763ccfa5c6d
1 /* ---------------------------------------------- */
2 /* alloca-bt.S */
4 #ifdef __leading_underscore
5 # define _(s) _##s
6 #else
7 # define _(s) s
8 #endif
10 /* ---------------------------------------------- */
11 #if defined __i386__
13 .globl _(__bound_alloca)
14 _(__bound_alloca):
15     pop     %edx
16     pop     %eax
17     mov     %eax, %ecx
18     add     $3+1,%eax
19     and     $-4,%eax
20     jz      p6
22 #ifdef _WIN32
23 p4:
24     cmp     $4096,%eax
25     jbe     p5
26     test    %eax,-4096(%esp)
27     sub     $4096,%esp
28     sub     $4096,%eax
29     jmp p4
31 p5:
32 #endif
34     sub     %eax,%esp
35     mov     %esp,%eax
37     push    %edx
38     push    %eax
39     push    %ecx
40     push    %eax
41     call    _(__bound_new_region)
42     add     $8, %esp
43     pop     %eax
44     pop     %edx
46 p6:
47     push    %edx
48     push    %edx
49     ret
51 /* ---------------------------------------------- */
52 #elif defined __x86_64__
54 .globl _(__bound_alloca)
55 _(__bound_alloca):
56 #ifdef _WIN32
57     inc %rcx            # add one extra to separate regions
58     jmp _(alloca)
59 .globl _(__bound_alloca_nr)
60 _(__bound_alloca_nr):
61     dec     %rcx
62     push    %rax
63     mov     %rcx,%rdx
64     mov     %rax,%rcx
65     sub     $32,%rsp
66     call    _(__bound_new_region)
67     add     $32,%rsp
68     pop     %rax
69     ret
70 #else
71     pop     %rdx
72     mov     %rdi,%rax
73     mov     %rax,%rsi   # size, a second parm to the __bound_new_region
75     add     $15 + 1,%rax  # add one extra to separate regions
76     and     $-16,%rax
77     jz      p3
80     sub     %rax,%rsp
81     mov     %rsp,%rdi   # pointer, a first parm to the __bound_new_region
82     mov     %rsp,%rax
84     push    %rdx
85     push    %rax
86     call    _(__bound_new_region)
87     pop     %rax
88     pop     %rdx
90 p3:
91     push    %rdx
92     ret
93 #endif
95 /* ---------------------------------------------- */
96 #endif