-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathglobals.wast
More file actions
441 lines (407 loc) · 13.6 KB
/
globals.wast
File metadata and controls
441 lines (407 loc) · 13.6 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
;; Check the `shared` attribute on globals.
(module
;; Imported.
(global (import "spectest" "global_i32") (shared i32))
(global (import "spectest" "global_i32_mut") (shared mut i32))
(global (import "spectest" "global_i64") (shared i64))
(global (import "spectest" "global_i64_mut") (shared mut i64))
(global (import "spectest" "global_f32") (shared i32))
(global (import "spectest" "global_f32_mut") (shared mut f32))
(global (import "spectest" "global_f64") (shared f64))
(global (import "spectest" "global_f64_mut") (shared mut f64))
(global (import "spectest" "global_v128") (shared v128))
(global (import "spectest" "global_v128_mut") (shared mut v128))
;; Initialized.
(global (shared i32) (i32.const 0))
(global (shared mut i32) (i32.const 0))
(global (shared i64) (i64.const 0))
(global (shared mut i64) (i64.const 0))
(global (shared f32) (f32.const 0))
(global (shared mut f32) (f32.const 0))
(global (shared f64) (f64.const 0))
(global (shared mut f64) (f64.const 0))
(global (shared v128) (v128.const i64x2 0 0))
(global (shared mut v128) (v128.const i64x2 0 0))
)
;; Check that we can only use shared globals to initialize other shared globals.
(module
(global $a (shared i32) (i32.const 0))
(global $b (shared i32) (global.get $a))
)
(assert_invalid
(module
(global $a i32 (i32.const 0))
(global $b (shared i32) (global.get $a))
)
"invalid type")
(assert_malformed
(module quote "(global (mut shared i64) (i64.const -1))")
"unexpected token")
(assert_invalid
(module (global $a (import "spectest" "global_ref") (shared funcref)))
"shared value type")
;; Check global.atomic.get, global.atomic.set.
(module
(global $a (import "spectest" "global_i32") (shared i32))
(global $b (import "spectest" "global_i64") (shared mut i64))
(global $d (shared i32) (i32.const 0))
(global $e (shared mut i64) (i64.const 1))
(func (export "get-a-seqcst") (result i32) (global.atomic.get seq_cst $a))
(func (export "set-b-seqcst") (global.atomic.set seq_cst $b (i64.const 1)))
(func (export "get-d-acqrel") (result i32) (global.atomic.get acq_rel $d))
(func (export "set-e-acqrel") (global.atomic.set acq_rel $e (i64.const 2)))
)
(assert_invalid
(module
(global $a (shared i32) (i32.const 0))
(func (export "set-shared") (global.atomic.set seq_cst $a (i32.const 1)))
)
"global is immutable")
(assert_invalid
(module
(global $a (shared mut f32) (f32.const 0))
(func (result f32) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f32) (f32.const 0))
(func (global.atomic.set seq_cst $a (f32.const 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f32) (f32.const 0))
(func (result f32) (global.atomic.get acq_rel $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f32) (f32.const 0))
(func (global.atomic.set acq_rel $a (f32.const 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared f32) (f32.const 0))
(func (result f32) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared f32) (f32.const 0))
(func (result f32) (global.atomic.get acq_rel $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f64) (f64.const 0))
(func (result f64) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f64) (f64.const 0))
(func (global.atomic.set seq_cst $a (f64.const 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f64) (f64.const 0))
(func (result f64) (global.atomic.get acq_rel $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut f64) (f64.const 0))
(func (global.atomic.set acq_rel $a (f64.const 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared f64) (f64.const 0))
(func (result f64) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared f64) (f64.const 0))
(func (result f64) (global.atomic.get acq_rel $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut v128) (v128.const i64x2 0 0))
(func (result v128) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut v128) (v128.const i64x2 0 0))
(func (global.atomic.set seq_cst $a (v128.const i64x2 0 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut v128) (v128.const i64x2 0 0))
(func (result v128) (global.atomic.get acq_rel $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared mut v128) (v128.const i64x2 0 0))
(func (global.atomic.set acq_rel $a (v128.const i64x2 0 0)))
)
"invalid type")
(assert_invalid
(module
(global $a (shared v128) (v128.const i64x2 0 0))
(func (result v128) (global.atomic.get seq_cst $a))
)
"invalid type")
(assert_invalid
(module
(global $a (shared v128) (v128.const i64x2 0 0))
(func (result v128) (global.atomic.get acq_rel $a))
)
"invalid type")
;; Check global.atomic.rmw.*.
(module (;i32;)
(global $a (import "spectest" "global_i32") (shared mut i32))
(global $b (shared mut i32) (i32.const 0))
(func (export "rmw-add-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.add seq_cst $a)
(func (export "rmw-add-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.add seq_cst $b)
(func (export "rmw-add-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.add acq_rel $a)
(func (export "rmw-add-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.add acq_rel $b)
(func (export "rmw-sub-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.sub seq_cst $a)
(func (export "rmw-sub-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.sub seq_cst $b)
(func (export "rmw-sub-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.sub acq_rel $a)
(func (export "rmw-sub-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.sub acq_rel $b)
(func (export "rmw-and-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.and seq_cst $a)
(func (export "rmw-and-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.and seq_cst $b)
(func (export "rmw-and-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.and acq_rel $a)
(func (export "rmw-and-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.and acq_rel $b)
(func (export "rmw-or-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.or seq_cst $a)
(func (export "rmw-or-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.or seq_cst $b)
(func (export "rmw-or-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.or acq_rel $a)
(func (export "rmw-or-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.or acq_rel $b)
(func (export "rmw-xor-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xor seq_cst $a)
(func (export "rmw-xor-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xor seq_cst $b)
(func (export "rmw-xor-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xor acq_rel $a)
(func (export "rmw-xor-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xor acq_rel $b)
(func (export "rmw-xchg-i32-seq_cst-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xchg seq_cst $a)
(func (export "rmw-xchg-i32-seq_cst-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xchg seq_cst $b)
(func (export "rmw-xchg-i32-acq_rel-$a") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xchg acq_rel $a)
(func (export "rmw-xchg-i32-acq_rel-$b") (param $x i32) (result i32)
local.get $x
global.atomic.rmw.xchg acq_rel $b)
(func (export "rmw-cmpxchg-i32-seq_cst-$a") (param $x i32) (param $y i32) (result i32)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg seq_cst $a)
(func (export "rmw-cmpxchg-i32-seq_cst-$b") (param $x i32) (param $y i32) (result i32)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg seq_cst $b)
(func (export "rmw-cmpxchg-i32-acq_rel-$a") (param $x i32) (param $y i32) (result i32)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg acq_rel $a)
(func (export "rmw-cmpxchg-i32-acq_rel-$b") (param $x i32) (param $y i32) (result i32)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg acq_rel $b)
)
(module (;i64;)
(global $a (import "spectest" "global_i64") (shared mut i64))
(global $b (shared mut i64) (i64.const 0))
(func (export "rmw-add-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.add seq_cst $a)
(func (export "rmw-add-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.add seq_cst $b)
(func (export "rmw-add-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.add acq_rel $a)
(func (export "rmw-add-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.add acq_rel $b)
(func (export "rmw-sub-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.sub seq_cst $a)
(func (export "rmw-sub-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.sub seq_cst $b)
(func (export "rmw-sub-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.sub acq_rel $a)
(func (export "rmw-sub-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.sub acq_rel $b)
(func (export "rmw-and-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.and seq_cst $a)
(func (export "rmw-and-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.and seq_cst $b)
(func (export "rmw-and-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.and acq_rel $a)
(func (export "rmw-and-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.and acq_rel $b)
(func (export "rmw-or-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.or seq_cst $a)
(func (export "rmw-or-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.or seq_cst $b)
(func (export "rmw-or-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.or acq_rel $a)
(func (export "rmw-or-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.or acq_rel $b)
(func (export "rmw-xor-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xor seq_cst $a)
(func (export "rmw-xor-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xor seq_cst $b)
(func (export "rmw-xor-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xor acq_rel $a)
(func (export "rmw-xor-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xor acq_rel $b)
(func (export "rmw-xchg-i64-seq_cst-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xchg seq_cst $a)
(func (export "rmw-xchg-i64-seq_cst-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xchg seq_cst $b)
(func (export "rmw-xchg-i64-acq_rel-$a") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xchg acq_rel $a)
(func (export "rmw-xchg-i64-acq_rel-$b") (param $x i64) (result i64)
local.get $x
global.atomic.rmw.xchg acq_rel $b)
(func (export "rmw-cmpxchg-i64-seq_cst-$a") (param $x i64) (param $y i64) (result i64)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg seq_cst $a)
(func (export "rmw-cmpxchg-i64-seq_cst-$b") (param $x i64) (param $y i64) (result i64)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg seq_cst $b)
(func (export "rmw-cmpxchg-i64-acq_rel-$a") (param $x i64) (param $y i64) (result i64)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg acq_rel $a)
(func (export "rmw-cmpxchg-i64-acq_rel-$b") (param $x i64) (param $y i64) (result i64)
local.get $x
local.get $y
global.atomic.rmw.cmpxchg acq_rel $b)
)
(assert_invalid
(module
(global $g (mut funcref) (ref.null func))
(func
ref.null func
global.atomic.rmw.xor acq_rel $g
drop
)
)
"invalid type: `global.atomic.rmw.*` only allows `i32` and `i64`")
(assert_invalid
(module
(func
global.atomic.rmw.xor acq_rel 200
)
)
"global index out of bounds")
(assert_invalid
(module
(global $g (mut funcref) (ref.null func))
(func
ref.null func
global.atomic.rmw.xchg acq_rel $g
drop
)
)
"invalid type: `global.atomic.rmw.xchg` only allows `i32`, `i64` and subtypes of `anyref`")
(module
(global $g (mut eqref) (ref.null eq))
(func
ref.null eq
global.atomic.rmw.xchg acq_rel $g
drop
)
)
(assert_invalid
(module
(global $g (mut anyref) (ref.null any))
(func
ref.null any
ref.null any
global.atomic.rmw.cmpxchg acq_rel $g
drop
)
)
"invalid type: `global.atomic.rmw.cmpxchg` only allows `i32`, `i64` and subtypes of `eqref`")
(module
(global $g (mut eqref) (ref.null eq))
(func
ref.null eq
ref.null eq
global.atomic.rmw.cmpxchg acq_rel $g
drop
)
)