forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_ops.S
More file actions
47 lines (40 loc) · 931 Bytes
/
stack_ops.S
File metadata and controls
47 lines (40 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
.globl stackSave
.globl stackRestore
.globl stackAlloc
.globl emscripten_stack_get_current
#ifdef __wasm64__
#define PTR i64
#define MASK 0xfffffffffffffff0
#else
#define PTR i32
#define MASK 0xfffffff0
#endif
.globaltype __stack_pointer, PTR
stackSave:
.functype stackSave() -> (PTR)
global.get __stack_pointer
end_function
stackRestore:
.functype stackRestore(PTR) -> ()
local.get 0
global.set __stack_pointer
end_function
stackAlloc:
.functype stackAlloc(PTR) -> (PTR)
.local PTR, PTR
global.get __stack_pointer
# Get arg 0 -> number of bytes to allocate
local.get 0
# Stack grows down. Subtract arg0 from __stack_pointer
PTR.sub
# Align result by anding with ~15
PTR.const MASK
PTR.and
local.tee 1
global.set __stack_pointer
local.get 1
end_function
emscripten_stack_get_current:
.functype emscripten_stack_get_current () -> (PTR)
global.get __stack_pointer
end_function