-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
basic-assembly.s
144 lines (141 loc) · 4.5 KB
/
basic-assembly.s
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s
# this one is just here to see if it converts to .o without errors, but doesn't check any output:
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+simd128,+nontrapping-fptoint,+exception-handling < %s
.text
.section .text.main,"",@
.type test0,@function
test0:
# Test all types:
.functype test0 (i32, i64) -> (i32)
.eventtype __cpp_exception i32
.local f32, f64, v128, v128
# Explicit getlocal/setlocal:
get_local 2
set_local 2
# Immediates:
i32.const -1
f64.const 0x1.999999999999ap1
v128.const 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
v128.const 0, 1, 2, 3, 4, 5, 6, 7
# Indirect addressing:
get_local 0
f64.store 0
# Loops, conditionals, binary ops, calls etc:
block
i32.const 1
get_local 0
i32.ge_s
br_if 0 # 0: down to label0
.LBB0_1:
loop # label1:
call something1@FUNCTION
i64.const 1234
i32.call something2@FUNCTION
i32.const 0
call_indirect 0
i32.const 1
i32.add
tee_local 0
get_local 0
i32.lt_s
br_if 0 # 0: up to label1
.LBB0_2:
end_loop
end_block # label0:
get_local 4
get_local 5
block
block
block
block
br_table {0, 1, 2} # 2 entries, default
end_block # first entry jumps here.
i32.const 1
br 2
end_block # second entry jumps here.
i32.const 2
br 1
end_block # default jumps here.
i32.const 3
end_block # "switch" exit.
f32x4.add
# Test correct parsing of instructions with / and : in them:
# TODO: enable once instruction has been added.
#i32x4.trunc_s/f32x4:sat
i32.trunc_s/f32
try
.LBB0_3:
i32.catch 0
.LBB0_4:
catch_all
.LBB0_5:
end_try
#i32.trunc_s:sat/f32
get_global __stack_pointer@GLOBAL
end_function
.Lfunc_end0:
.size test0, .Lfunc_end0-test0
.globaltype __stack_pointer, i32
# CHECK: .text
# CHECK-LABEL: test0:
# CHECK-NEXT: .functype test0 (i32, i64) -> (i32)
# CHECK-NEXT: .eventtype __cpp_exception i32
# CHECK-NEXT: .local f32, f64
# CHECK-NEXT: get_local 2
# CHECK-NEXT: set_local 2
# CHECK-NEXT: i32.const -1
# CHECK-NEXT: f64.const 0x1.999999999999ap1
# CHECK-NEXT: v128.const 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
# CHECK-NEXT: v128.const 0, 1, 2, 3, 4, 5, 6, 7
# CHECK-NEXT: get_local 0
# CHECK-NEXT: f64.store 0:p2align=0
# CHECK-NEXT: block
# CHECK-NEXT: i32.const 1
# CHECK-NEXT: get_local 0
# CHECK-NEXT: i32.ge_s
# CHECK-NEXT: br_if 0 # 0: down to label0
# CHECK-NEXT: .LBB0_1:
# CHECK-NEXT: loop # label1:
# CHECK-NEXT: call something1@FUNCTION
# CHECK-NEXT: i64.const 1234
# CHECK-NEXT: i32.call something2@FUNCTION
# CHECK-NEXT: i32.const 0
# CHECK-NEXT: call_indirect 0
# CHECK-NEXT: i32.const 1
# CHECK-NEXT: i32.add
# CHECK-NEXT: tee_local 0
# CHECK-NEXT: get_local 0
# CHECK-NEXT: i32.lt_s
# CHECK-NEXT: br_if 0 # 0: up to label1
# CHECK-NEXT: .LBB0_2:
# CHECK-NEXT: end_loop
# CHECK-NEXT: end_block # label0:
# CHECK-NEXT: get_local 4
# CHECK-NEXT: get_local 5
# CHECK-NEXT: block
# CHECK-NEXT: block
# CHECK-NEXT: block
# CHECK-NEXT: block
# CHECK-NEXT: br_table {0, 1, 2} # 1: down to label4
# CHECK-NEXT: # 2: down to label3
# CHECK-NEXT: end_block # label5:
# CHECK-NEXT: i32.const 1
# CHECK-NEXT: br 2 # 2: down to label2
# CHECK-NEXT: end_block # label4:
# CHECK-NEXT: i32.const 2
# CHECK-NEXT: br 1 # 1: down to label2
# CHECK-NEXT: end_block # label3:
# CHECK-NEXT: i32.const 3
# CHECK-NEXT: end_block # label2:
# CHECK-NEXT: f32x4.add
# CHECK-NEXT: i32.trunc_s/f32
# CHECK-NEXT: try
# CHECK-NEXT: .LBB0_3:
# CHECK-NEXT: i32.catch 0
# CHECK-NEXT: .LBB0_4:
# CHECK-NEXT: catch_all
# CHECK-NEXT: .LBB0_5:
# CHECK-NEXT: end_try
# CHECK-NEXT: get_global __stack_pointer@GLOBAL
# CHECK-NEXT: end_function
# CHECK: .globaltype __stack_pointer, i32