x86-64: chkstk, alloca
[tinycc/kirr.git] / lib / alloca86_64.S
blob13c4672eb05c3a9f2a0e35b292c1fc4e6fea1380
1 /* ---------------------------------------------- */
2 /* alloca86_64.S */
4 #include "../config.h"
6 .globl alloca
8 alloca:
9     pop     %rdx
10 #ifdef TCC_TARGET_PE
11     mov     %rcx,%rax
12 #else
13     mov     %rdi,%rax
14 #endif
15     add     $15,%rax
16     and     $-16,%rax
17     jz      p3
19 #ifdef TCC_TARGET_PE
20 p1:
21     cmp     $4096,%rax
22     jle     p2
23     sub     $4096,%rsp
24     sub     $4096,%rax
25     test    %rax,(%rsp)
26     jmp p1
27 p2:
28 #endif
30     sub     %rax,%rsp
31     mov     %rsp,%rax
32 #ifdef TCC_TARGET_PE
33     add     $32,%rax
34 #endif
36 p3:
37     push    %rdx
38     ret
40 /* ---------------------------------------------- */