| 1 |
package testcases |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"math" |
| 6 |
|
| 7 |
"github.com/tetratelabs/wazero/internal/leb128" |
| 8 |
"github.com/tetratelabs/wazero/internal/wasm" |
| 9 |
) |
| 10 |
|
| 11 |
const ExportedFunctionName = "f" |
| 12 |
|
| 13 |
var ( |
| 14 |
Empty = TestCase{Name: "empty", Module: SingleFunctionModule(vv, []byte{wasm.OpcodeEnd}, nil)} |
| 15 |
Constants = TestCase{Name: "consts", Module: SingleFunctionModule(wasm.FunctionType{ |
| 16 |
Results: []wasm.ValueType{i32, i64, f32, f64}, |
| 17 |
}, []byte{ |
| 18 |
wasm.OpcodeI32Const, 1, |
| 19 |
wasm.OpcodeI64Const, 2, |
| 20 |
wasm.OpcodeF32Const, |
| 21 |
byte(math.Float32bits(32.0)), |
| 22 |
byte(math.Float32bits(32.0) >> 8), |
| 23 |
byte(math.Float32bits(32.0) >> 16), |
| 24 |
byte(math.Float32bits(32.0) >> 24), |
| 25 |
wasm.OpcodeF64Const, |
| 26 |
byte(math.Float64bits(64.0)), |
| 27 |
byte(math.Float64bits(64.0) >> 8), |
| 28 |
byte(math.Float64bits(64.0) >> 16), |
| 29 |
byte(math.Float64bits(64.0) >> 24), |
| 30 |
byte(math.Float64bits(64.0) >> 32), |
| 31 |
byte(math.Float64bits(64.0) >> 40), |
| 32 |
byte(math.Float64bits(64.0) >> 48), |
| 33 |
byte(math.Float64bits(64.0) >> 56), |
| 34 |
wasm.OpcodeEnd, |
| 35 |
}, nil)} |
| 36 |
Unreachable = TestCase{Name: "unreachable", Module: SingleFunctionModule(vv, []byte{wasm.OpcodeUnreachable, wasm.OpcodeEnd}, nil)} |
| 37 |
OnlyReturn = TestCase{Name: "only_return", Module: SingleFunctionModule(vv, []byte{wasm.OpcodeReturn, wasm.OpcodeEnd}, nil)} |
| 38 |
Params = TestCase{Name: "params", Module: SingleFunctionModule(i32f32f64_v, []byte{wasm.OpcodeReturn, wasm.OpcodeEnd}, nil)} |
| 39 |
AddSubReturn = TestCase{ |
| 40 |
Name: "add_sub_params_return_const", |
| 41 |
Module: SingleFunctionModule(wasm.FunctionType{Results: []wasm.ValueType{i32, i32, i64, i64}}, []byte{ |
| 42 |
// Small i32 constants should be inlined on arm64, amd64. |
| 43 |
wasm.OpcodeI32Const, 4, |
| 44 |
wasm.OpcodeI32Const, 5, |
| 45 |
wasm.OpcodeI32Add, |
| 46 |
wasm.OpcodeI32Const, 6, |
| 47 |
wasm.OpcodeI32Sub, |
| 48 |
|
| 49 |
// Large i32 constants should be inlined on amd4, load from register on arm64. |
| 50 |
wasm.OpcodeI32Const, 3, |
| 51 |
wasm.OpcodeI32Const, 0xff, 0xff, 0xff, 0xff, 0, |
| 52 |
wasm.OpcodeI32Add, |
| 53 |
wasm.OpcodeI32Const, 0xff, 0xff, 0xff, 0xff, 0, |
| 54 |
wasm.OpcodeI32Sub, |
| 55 |
|
| 56 |
// Small i64 constants should be inlined on arm64, amd64. |
| 57 |
wasm.OpcodeI64Const, 4, |
| 58 |
wasm.OpcodeI64Const, 5, |
| 59 |
wasm.OpcodeI64Add, |
| 60 |
wasm.OpcodeI64Const, 6, |
| 61 |
wasm.OpcodeI64Sub, |
| 62 |
|
| 63 |
// Large i64 constants are loaded from register on arm64, amd64. |
| 64 |
wasm.OpcodeI64Const, 3, |
| 65 |
wasm.OpcodeI64Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0, |
| 66 |
wasm.OpcodeI64Add, |
| 67 |
wasm.OpcodeI64Const, 0xff, 0xff, 0xff, 0xff, 0xff, 0, |
| 68 |
wasm.OpcodeI64Sub, |
| 69 |
|
| 70 |
wasm.OpcodeEnd, |
| 71 |
}, nil), |
| 72 |
} |
| 73 |
AddSubParamsReturn = TestCase{ |
| 74 |
Name: "add_sub_params_return", |
| 75 |
Module: SingleFunctionModule(i32i32_i32, []byte{ |
| 76 |
wasm.OpcodeLocalGet, 0, |
| 77 |
wasm.OpcodeLocalGet, 1, |
| 78 |
wasm.OpcodeI32Add, |
| 79 |
wasm.OpcodeLocalGet, 0, |
| 80 |
wasm.OpcodeI32Sub, |
| 81 |
wasm.OpcodeEnd, |
| 82 |
}, nil), |
| 83 |
} |
| 84 |
ArithmReturn = TestCase{ |
| 85 |
Name: "arithm return", |
| 86 |
Module: SingleFunctionModule( |
| 87 |
wasm.FunctionType{ |
| 88 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64}, |
| 89 |
Results: []wasm.ValueType{ |
| 90 |
i32, i32, i32, i32, |
| 91 |
i32, i32, i32, |
| 92 |
i32, i32, |
| 93 |
|
| 94 |
i64, i64, i64, i64, |
| 95 |
i64, i64, i64, |
| 96 |
i64, i64, |
| 97 |
}, |
| 98 |
}, |
| 99 |
[]byte{ |
| 100 |
wasm.OpcodeLocalGet, 0, |
| 101 |
wasm.OpcodeLocalGet, 1, |
| 102 |
wasm.OpcodeI32Mul, |
| 103 |
wasm.OpcodeLocalGet, 0, |
| 104 |
wasm.OpcodeLocalGet, 1, |
| 105 |
wasm.OpcodeI32And, |
| 106 |
wasm.OpcodeLocalGet, 0, |
| 107 |
wasm.OpcodeLocalGet, 1, |
| 108 |
wasm.OpcodeI32Or, |
| 109 |
wasm.OpcodeLocalGet, 0, |
| 110 |
wasm.OpcodeLocalGet, 1, |
| 111 |
wasm.OpcodeI32Xor, |
| 112 |
|
| 113 |
wasm.OpcodeLocalGet, 0, |
| 114 |
wasm.OpcodeLocalGet, 1, |
| 115 |
wasm.OpcodeI32Shl, |
| 116 |
wasm.OpcodeLocalGet, 0, |
| 117 |
wasm.OpcodeLocalGet, 2, |
| 118 |
wasm.OpcodeI32ShrS, |
| 119 |
wasm.OpcodeLocalGet, 0, |
| 120 |
wasm.OpcodeLocalGet, 1, |
| 121 |
wasm.OpcodeI32ShrU, |
| 122 |
|
| 123 |
wasm.OpcodeLocalGet, 0, |
| 124 |
wasm.OpcodeLocalGet, 1, |
| 125 |
wasm.OpcodeI32Rotr, |
| 126 |
// Exercise the case where the amount is an immediate. |
| 127 |
wasm.OpcodeI32Const, 10, |
| 128 |
wasm.OpcodeLocalGet, 0, |
| 129 |
wasm.OpcodeI32Rotl, |
| 130 |
|
| 131 |
// i64 |
| 132 |
|
| 133 |
wasm.OpcodeLocalGet, 3, |
| 134 |
wasm.OpcodeLocalGet, 4, |
| 135 |
wasm.OpcodeI64Mul, |
| 136 |
wasm.OpcodeLocalGet, 3, |
| 137 |
wasm.OpcodeLocalGet, 4, |
| 138 |
wasm.OpcodeI64And, |
| 139 |
wasm.OpcodeLocalGet, 3, |
| 140 |
wasm.OpcodeLocalGet, 4, |
| 141 |
wasm.OpcodeI64Or, |
| 142 |
wasm.OpcodeLocalGet, 3, |
| 143 |
wasm.OpcodeLocalGet, 4, |
| 144 |
wasm.OpcodeI64Xor, |
| 145 |
|
| 146 |
wasm.OpcodeLocalGet, 3, |
| 147 |
wasm.OpcodeLocalGet, 4, |
| 148 |
wasm.OpcodeI64Shl, |
| 149 |
wasm.OpcodeLocalGet, 5, |
| 150 |
wasm.OpcodeLocalGet, 4, |
| 151 |
wasm.OpcodeI64ShrS, |
| 152 |
wasm.OpcodeLocalGet, 3, |
| 153 |
wasm.OpcodeLocalGet, 4, |
| 154 |
wasm.OpcodeI64ShrU, |
| 155 |
|
| 156 |
wasm.OpcodeLocalGet, 3, |
| 157 |
wasm.OpcodeLocalGet, 4, |
| 158 |
wasm.OpcodeI64Rotr, |
| 159 |
// Exercise the case where the amount is an immediate. |
| 160 |
wasm.OpcodeI64Const, 10, |
| 161 |
wasm.OpcodeLocalGet, 3, |
| 162 |
wasm.OpcodeI64Rotl, |
| 163 |
|
| 164 |
wasm.OpcodeEnd, |
| 165 |
}, nil), |
| 166 |
} |
| 167 |
DivUReturn32 = TestCase{ |
| 168 |
Name: "div return unsigned 32", |
| 169 |
Module: SingleFunctionModule( |
| 170 |
wasm.FunctionType{ |
| 171 |
Params: []wasm.ValueType{i32, i32, i32, i32}, |
| 172 |
Results: []wasm.ValueType{i32, i32}, |
| 173 |
}, |
| 174 |
[]byte{ |
| 175 |
wasm.OpcodeLocalGet, 0, |
| 176 |
wasm.OpcodeLocalGet, 1, |
| 177 |
wasm.OpcodeI32DivU, |
| 178 |
|
| 179 |
wasm.OpcodeLocalGet, 2, |
| 180 |
wasm.OpcodeLocalGet, 3, |
| 181 |
wasm.OpcodeI32RemU, |
| 182 |
|
| 183 |
wasm.OpcodeEnd, |
| 184 |
}, nil), |
| 185 |
} |
| 186 |
DivUReturn64 = TestCase{ |
| 187 |
Name: "div return unsigned 64", |
| 188 |
Module: SingleFunctionModule( |
| 189 |
wasm.FunctionType{ |
| 190 |
Params: []wasm.ValueType{i64, i64, i64, i64}, |
| 191 |
Results: []wasm.ValueType{i64, i64}, |
| 192 |
}, |
| 193 |
[]byte{ |
| 194 |
wasm.OpcodeLocalGet, 0, |
| 195 |
wasm.OpcodeLocalGet, 1, |
| 196 |
wasm.OpcodeI64DivU, |
| 197 |
|
| 198 |
wasm.OpcodeLocalGet, 2, |
| 199 |
wasm.OpcodeLocalGet, 3, |
| 200 |
wasm.OpcodeI64RemU, |
| 201 |
|
| 202 |
wasm.OpcodeEnd, |
| 203 |
}, nil), |
| 204 |
} |
| 205 |
DivSReturn32 = TestCase{ |
| 206 |
Name: "div return signed 32", |
| 207 |
Module: SingleFunctionModule( |
| 208 |
wasm.FunctionType{ |
| 209 |
Params: []wasm.ValueType{i32, i32, i32, i32}, |
| 210 |
Results: []wasm.ValueType{i32, i32}, |
| 211 |
}, |
| 212 |
[]byte{ |
| 213 |
wasm.OpcodeLocalGet, 0, |
| 214 |
wasm.OpcodeLocalGet, 1, |
| 215 |
wasm.OpcodeI32DivS, |
| 216 |
|
| 217 |
wasm.OpcodeLocalGet, 2, |
| 218 |
wasm.OpcodeLocalGet, 3, |
| 219 |
wasm.OpcodeI32RemS, |
| 220 |
|
| 221 |
wasm.OpcodeEnd, |
| 222 |
}, nil), |
| 223 |
} |
| 224 |
DivSReturn32_weird = TestCase{ |
| 225 |
Name: "div return signed 32", |
| 226 |
Module: SingleFunctionModule( |
| 227 |
wasm.FunctionType{ |
| 228 |
Params: []wasm.ValueType{i32, i32, i32, i32}, |
| 229 |
Results: []wasm.ValueType{i32, i32}, |
| 230 |
}, |
| 231 |
[]byte{ |
| 232 |
wasm.OpcodeLocalGet, 2, |
| 233 |
wasm.OpcodeLocalGet, 3, |
| 234 |
wasm.OpcodeI32RemS, |
| 235 |
|
| 236 |
wasm.OpcodeLocalGet, 0, |
| 237 |
wasm.OpcodeLocalGet, 1, |
| 238 |
wasm.OpcodeI32DivS, |
| 239 |
|
| 240 |
wasm.OpcodeEnd, |
| 241 |
}, nil), |
| 242 |
} |
| 243 |
|
| 244 |
DivSReturn64 = TestCase{ |
| 245 |
Name: "div return signed 64", |
| 246 |
Module: SingleFunctionModule( |
| 247 |
wasm.FunctionType{ |
| 248 |
Params: []wasm.ValueType{i64, i64, i64, i64}, |
| 249 |
Results: []wasm.ValueType{i64, i64}, |
| 250 |
}, |
| 251 |
[]byte{ |
| 252 |
wasm.OpcodeLocalGet, 0, |
| 253 |
wasm.OpcodeLocalGet, 1, |
| 254 |
wasm.OpcodeI64DivS, |
| 255 |
|
| 256 |
wasm.OpcodeLocalGet, 2, |
| 257 |
wasm.OpcodeLocalGet, 3, |
| 258 |
wasm.OpcodeI64RemS, |
| 259 |
|
| 260 |
wasm.OpcodeEnd, |
| 261 |
}, nil), |
| 262 |
} |
| 263 |
Locals = TestCase{Name: "locals", Module: SingleFunctionModule(vv, []byte{wasm.OpcodeEnd}, []wasm.ValueType{i32, i64, f32, f64})} |
| 264 |
LocalsParams = TestCase{ |
| 265 |
Name: "locals_params", |
| 266 |
Module: SingleFunctionModule( |
| 267 |
i64f32f64_i64f32f64, |
| 268 |
[]byte{ |
| 269 |
wasm.OpcodeLocalGet, 0, |
| 270 |
wasm.OpcodeLocalGet, 0, |
| 271 |
wasm.OpcodeI64Add, |
| 272 |
wasm.OpcodeLocalGet, 0, |
| 273 |
wasm.OpcodeI64Sub, |
| 274 |
|
| 275 |
wasm.OpcodeLocalGet, 1, |
| 276 |
wasm.OpcodeLocalGet, 1, |
| 277 |
wasm.OpcodeF32Add, |
| 278 |
wasm.OpcodeLocalGet, 1, |
| 279 |
wasm.OpcodeF32Sub, |
| 280 |
wasm.OpcodeLocalGet, 1, |
| 281 |
wasm.OpcodeF32Mul, |
| 282 |
wasm.OpcodeLocalGet, 1, |
| 283 |
wasm.OpcodeF32Div, |
| 284 |
wasm.OpcodeLocalGet, 1, |
| 285 |
wasm.OpcodeF32Max, |
| 286 |
wasm.OpcodeLocalGet, 1, |
| 287 |
wasm.OpcodeF32Min, |
| 288 |
|
| 289 |
wasm.OpcodeLocalGet, 2, |
| 290 |
wasm.OpcodeLocalGet, 2, |
| 291 |
wasm.OpcodeF64Add, |
| 292 |
wasm.OpcodeLocalGet, 2, |
| 293 |
wasm.OpcodeF64Sub, |
| 294 |
wasm.OpcodeLocalGet, 2, |
| 295 |
wasm.OpcodeF64Mul, |
| 296 |
wasm.OpcodeLocalGet, 2, |
| 297 |
wasm.OpcodeF64Div, |
| 298 |
wasm.OpcodeLocalGet, 2, |
| 299 |
wasm.OpcodeF64Max, |
| 300 |
wasm.OpcodeLocalGet, 2, |
| 301 |
wasm.OpcodeF64Min, |
| 302 |
|
| 303 |
wasm.OpcodeEnd, |
| 304 |
}, []wasm.ValueType{i32, i64, f32, f64}, |
| 305 |
), |
| 306 |
} |
| 307 |
LocalParamReturn = TestCase{ |
| 308 |
Name: "local_param_return", |
| 309 |
Module: SingleFunctionModule(i32_i32i32, []byte{ |
| 310 |
wasm.OpcodeLocalGet, 0, |
| 311 |
wasm.OpcodeLocalGet, 1, |
| 312 |
wasm.OpcodeEnd, |
| 313 |
}, []wasm.ValueType{i32}), |
| 314 |
} |
| 315 |
LocalParamTeeReturn = TestCase{ |
| 316 |
Name: "local_param_tee_return", |
| 317 |
Module: SingleFunctionModule(i32_i32i32, []byte{ |
| 318 |
wasm.OpcodeLocalGet, 0, |
| 319 |
wasm.OpcodeLocalTee, 1, |
| 320 |
wasm.OpcodeLocalGet, 1, |
| 321 |
wasm.OpcodeEnd, |
| 322 |
}, []wasm.ValueType{i32}), |
| 323 |
} |
| 324 |
SwapParamAndReturn = TestCase{ |
| 325 |
Name: "swap_param_and_return", |
| 326 |
Module: SingleFunctionModule(i32i32_i32i32, []byte{ |
| 327 |
wasm.OpcodeLocalGet, 1, |
| 328 |
wasm.OpcodeLocalGet, 0, |
| 329 |
wasm.OpcodeEnd, |
| 330 |
}, nil), |
| 331 |
} |
| 332 |
Selects = TestCase{ |
| 333 |
Name: "swap_param_and_return", |
| 334 |
Module: SingleFunctionModule(i32i32i64i64f32f32f64f64_i32i64, []byte{ |
| 335 |
// i32 select. |
| 336 |
wasm.OpcodeLocalGet, 0, // x |
| 337 |
wasm.OpcodeLocalGet, 1, // y |
| 338 |
// cond |
| 339 |
wasm.OpcodeLocalGet, 2, |
| 340 |
wasm.OpcodeLocalGet, 3, |
| 341 |
wasm.OpcodeI64Eq, |
| 342 |
wasm.OpcodeSelect, |
| 343 |
|
| 344 |
// i64 select. |
| 345 |
wasm.OpcodeLocalGet, 2, // x |
| 346 |
wasm.OpcodeLocalGet, 3, // y |
| 347 |
wasm.OpcodeLocalGet, 1, // cond |
| 348 |
wasm.OpcodeTypedSelect, 1, wasm.ValueTypeI64.Kind(), |
| 349 |
|
| 350 |
// f32 select. |
| 351 |
wasm.OpcodeLocalGet, 4, // x |
| 352 |
wasm.OpcodeLocalGet, 5, // y |
| 353 |
// cond |
| 354 |
wasm.OpcodeLocalGet, 6, |
| 355 |
wasm.OpcodeLocalGet, 7, |
| 356 |
wasm.OpcodeF64Gt, |
| 357 |
wasm.OpcodeTypedSelect, 1, wasm.ValueTypeF32.Kind(), |
| 358 |
|
| 359 |
// f64 select. |
| 360 |
wasm.OpcodeLocalGet, 6, // x |
| 361 |
wasm.OpcodeLocalGet, 7, // y |
| 362 |
// cond |
| 363 |
wasm.OpcodeLocalGet, 4, |
| 364 |
wasm.OpcodeLocalGet, 5, |
| 365 |
wasm.OpcodeF32Ne, |
| 366 |
wasm.OpcodeTypedSelect, 1, wasm.ValueTypeF64.Kind(), |
| 367 |
|
| 368 |
wasm.OpcodeEnd, |
| 369 |
}, nil), |
| 370 |
} |
| 371 |
SwapParamsAndReturn = TestCase{ |
| 372 |
Name: "swap_params_and_return", |
| 373 |
Module: SingleFunctionModule(i32i32_i32i32, []byte{ |
| 374 |
wasm.OpcodeLocalGet, 1, |
| 375 |
wasm.OpcodeLocalGet, 0, |
| 376 |
wasm.OpcodeLocalSet, 1, |
| 377 |
wasm.OpcodeLocalSet, 0, |
| 378 |
wasm.OpcodeBlock, blockSignature_vv, |
| 379 |
wasm.OpcodeEnd, |
| 380 |
wasm.OpcodeLocalGet, 0, |
| 381 |
wasm.OpcodeLocalGet, 1, |
| 382 |
wasm.OpcodeEnd, |
| 383 |
}, nil), |
| 384 |
} |
| 385 |
BlockBr = TestCase{ |
| 386 |
Name: "block_br", |
| 387 |
Module: SingleFunctionModule(vv, []byte{ |
| 388 |
wasm.OpcodeBlock, 0, |
| 389 |
wasm.OpcodeBr, 0, |
| 390 |
wasm.OpcodeEnd, |
| 391 |
wasm.OpcodeEnd, |
| 392 |
}, []wasm.ValueType{i32, i64, f32, f64}), |
| 393 |
} |
| 394 |
BlockBrIf = TestCase{ |
| 395 |
Name: "block_br_if", |
| 396 |
Module: SingleFunctionModule(vv, []byte{ |
| 397 |
wasm.OpcodeBlock, 0, |
| 398 |
wasm.OpcodeLocalGet, 0, |
| 399 |
wasm.OpcodeBrIf, 0, |
| 400 |
wasm.OpcodeUnreachable, |
| 401 |
wasm.OpcodeEnd, |
| 402 |
wasm.OpcodeEnd, |
| 403 |
}, []wasm.ValueType{i32}), |
| 404 |
} |
| 405 |
LoopBr = TestCase{ |
| 406 |
Name: "loop_br", |
| 407 |
Module: SingleFunctionModule(vv, []byte{ |
| 408 |
wasm.OpcodeLoop, 0, |
| 409 |
wasm.OpcodeBr, 0, |
| 410 |
wasm.OpcodeEnd, |
| 411 |
wasm.OpcodeEnd, |
| 412 |
}, []wasm.ValueType{}), |
| 413 |
} |
| 414 |
LoopBrWithParamResults = TestCase{ |
| 415 |
Name: "loop_with_param_results", |
| 416 |
Module: SingleFunctionModule(i32i32_i32, []byte{ |
| 417 |
wasm.OpcodeLocalGet, 0, |
| 418 |
wasm.OpcodeLocalGet, 1, |
| 419 |
wasm.OpcodeLoop, 0, |
| 420 |
wasm.OpcodeI32Const, 1, |
| 421 |
wasm.OpcodeBrIf, 0, |
| 422 |
wasm.OpcodeDrop, |
| 423 |
wasm.OpcodeEnd, |
| 424 |
wasm.OpcodeEnd, |
| 425 |
}, []wasm.ValueType{}), |
| 426 |
} |
| 427 |
LoopBrIf = TestCase{ |
| 428 |
Name: "loop_br_if", |
| 429 |
Module: SingleFunctionModule(vv, []byte{ |
| 430 |
wasm.OpcodeLoop, 0, |
| 431 |
wasm.OpcodeI32Const, 1, |
| 432 |
wasm.OpcodeBrIf, 0, |
| 433 |
wasm.OpcodeReturn, |
| 434 |
wasm.OpcodeEnd, |
| 435 |
wasm.OpcodeEnd, |
| 436 |
}, []wasm.ValueType{}), |
| 437 |
} |
| 438 |
BlockBlockBr = TestCase{ |
| 439 |
Name: "block_block_br", |
| 440 |
Module: SingleFunctionModule(vv, []byte{ |
| 441 |
wasm.OpcodeBlock, 0, |
| 442 |
wasm.OpcodeBlock, 0, |
| 443 |
wasm.OpcodeBr, 1, |
| 444 |
wasm.OpcodeEnd, |
| 445 |
wasm.OpcodeEnd, |
| 446 |
wasm.OpcodeEnd, |
| 447 |
}, []wasm.ValueType{i32, i64, f32, f64}), |
| 448 |
} |
| 449 |
IfWithoutElse = TestCase{ |
| 450 |
Name: "if_without_else", |
| 451 |
Module: SingleFunctionModule(vv, []byte{ |
| 452 |
wasm.OpcodeLocalGet, 0, |
| 453 |
wasm.OpcodeIf, 0, |
| 454 |
wasm.OpcodeEnd, |
| 455 |
wasm.OpcodeEnd, |
| 456 |
}, []wasm.ValueType{i32}), |
| 457 |
} |
| 458 |
IfElse = TestCase{ |
| 459 |
Name: "if_else", |
| 460 |
Module: SingleFunctionModule(vv, []byte{ |
| 461 |
wasm.OpcodeLocalGet, 0, |
| 462 |
wasm.OpcodeIf, 0, |
| 463 |
wasm.OpcodeElse, |
| 464 |
wasm.OpcodeBr, 1, |
| 465 |
wasm.OpcodeEnd, |
| 466 |
wasm.OpcodeEnd, |
| 467 |
}, []wasm.ValueType{i32}), |
| 468 |
} |
| 469 |
SinglePredecessorLocalRefs = TestCase{ |
| 470 |
Name: "single_predecessor_local_refs", |
| 471 |
Module: &wasm.Module{ |
| 472 |
TypeSection: []wasm.FunctionType{vv, v_i32}, |
| 473 |
FunctionSection: []wasm.Index{1}, |
| 474 |
CodeSection: []wasm.Code{{ |
| 475 |
LocalTypes: []wasm.ValueType{i32, i32, i32}, |
| 476 |
Body: []byte{ |
| 477 |
wasm.OpcodeLocalGet, 0, |
| 478 |
wasm.OpcodeIf, 0, |
| 479 |
// This is defined in the first block which is the sole predecessor of If. |
| 480 |
wasm.OpcodeLocalGet, 2, |
| 481 |
wasm.OpcodeReturn, |
| 482 |
wasm.OpcodeElse, |
| 483 |
wasm.OpcodeEnd, |
| 484 |
// This is defined in the first block which is the sole predecessor of this block. |
| 485 |
// Note that If block will never reach here because it's returning early. |
| 486 |
wasm.OpcodeLocalGet, 0, |
| 487 |
wasm.OpcodeEnd, |
| 488 |
}, |
| 489 |
}}, |
| 490 |
}, |
| 491 |
} |
| 492 |
MultiPredecessorLocalRef = TestCase{ |
| 493 |
Name: "multi_predecessor_local_ref", |
| 494 |
Module: SingleFunctionModule(i32i32_i32, []byte{ |
| 495 |
wasm.OpcodeLocalGet, 0, |
| 496 |
wasm.OpcodeIf, blockSignature_vv, |
| 497 |
// Set the first param to the local. |
| 498 |
wasm.OpcodeLocalGet, 0, |
| 499 |
wasm.OpcodeLocalSet, 2, |
| 500 |
wasm.OpcodeElse, |
| 501 |
// Set the second param to the local. |
| 502 |
wasm.OpcodeLocalGet, 1, |
| 503 |
wasm.OpcodeLocalSet, 2, |
| 504 |
wasm.OpcodeEnd, |
| 505 |
|
| 506 |
// Return the local as a result which has multiple definitions in predecessors (Then and Else). |
| 507 |
wasm.OpcodeLocalGet, 2, |
| 508 |
wasm.OpcodeEnd, |
| 509 |
}, []wasm.ValueType{i32}), |
| 510 |
} |
| 511 |
ReferenceValueFromUnsealedBlock = TestCase{ |
| 512 |
Name: "reference_value_from_unsealed_block", |
| 513 |
Module: SingleFunctionModule(i32_i32, []byte{ |
| 514 |
wasm.OpcodeLoop, blockSignature_vv, |
| 515 |
// Loop will not be sealed until we reach the end, |
| 516 |
// so this will result in referencing the unsealed definition search. |
| 517 |
wasm.OpcodeLocalGet, 0, |
| 518 |
wasm.OpcodeReturn, |
| 519 |
wasm.OpcodeEnd, |
| 520 |
wasm.OpcodeLocalGet, 0, |
| 521 |
wasm.OpcodeEnd, |
| 522 |
}, []wasm.ValueType{i32}), |
| 523 |
} |
| 524 |
ReferenceValueFromUnsealedBlock2 = TestCase{ |
| 525 |
Name: "reference_value_from_unsealed_block2", |
| 526 |
Module: SingleFunctionModule(i32_i32, []byte{ |
| 527 |
wasm.OpcodeLoop, blockSignature_vv, |
| 528 |
wasm.OpcodeBlock, blockSignature_vv, |
| 529 |
|
| 530 |
wasm.OpcodeLocalGet, 0, |
| 531 |
wasm.OpcodeBrIf, 1, |
| 532 |
wasm.OpcodeEnd, |
| 533 |
|
| 534 |
wasm.OpcodeEnd, |
| 535 |
wasm.OpcodeI32Const, 0, |
| 536 |
wasm.OpcodeEnd, |
| 537 |
}, []wasm.ValueType{}), |
| 538 |
} |
| 539 |
ReferenceValueFromUnsealedBlock3 = TestCase{ |
| 540 |
Name: "reference_value_from_unsealed_block3", |
| 541 |
Module: SingleFunctionModule(i32_v, []byte{ |
| 542 |
wasm.OpcodeLoop, blockSignature_vv, |
| 543 |
wasm.OpcodeBlock, blockSignature_vv, |
| 544 |
wasm.OpcodeLocalGet, 0, |
| 545 |
wasm.OpcodeBrIf, 2, |
| 546 |
wasm.OpcodeEnd, |
| 547 |
wasm.OpcodeI32Const, 1, |
| 548 |
wasm.OpcodeLocalSet, 0, |
| 549 |
wasm.OpcodeBr, 0, |
| 550 |
wasm.OpcodeEnd, |
| 551 |
wasm.OpcodeEnd, |
| 552 |
}, []wasm.ValueType{}), |
| 553 |
} |
| 554 |
CallSimple = TestCase{ |
| 555 |
Name: "call_simple", |
| 556 |
Module: &wasm.Module{ |
| 557 |
TypeSection: []wasm.FunctionType{v_i32, v_i32}, |
| 558 |
FunctionSection: []wasm.Index{0, 1}, |
| 559 |
CodeSection: []wasm.Code{ |
| 560 |
{Body: []byte{ |
| 561 |
// Call v_i32. |
| 562 |
wasm.OpcodeCall, 1, |
| 563 |
wasm.OpcodeEnd, |
| 564 |
}}, |
| 565 |
// v_i32: return 40. |
| 566 |
{Body: []byte{wasm.OpcodeI32Const, 40, wasm.OpcodeEnd}}, |
| 567 |
}, |
| 568 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Index: 0, Type: wasm.ExternTypeFunc}}, |
| 569 |
}, |
| 570 |
} |
| 571 |
Call = TestCase{ |
| 572 |
Name: "call", |
| 573 |
Module: &wasm.Module{ |
| 574 |
TypeSection: []wasm.FunctionType{v_i32i32, v_i32, i32i32_i32, i32_i32i32}, |
| 575 |
FunctionSection: []wasm.Index{0, 1, 2, 3}, |
| 576 |
CodeSection: []wasm.Code{ |
| 577 |
{Body: []byte{ |
| 578 |
// Call v_i32. |
| 579 |
wasm.OpcodeCall, 1, |
| 580 |
// Call i32i32_i32. |
| 581 |
wasm.OpcodeI32Const, 5, |
| 582 |
wasm.OpcodeCall, 2, |
| 583 |
// Call i32_i32i32. |
| 584 |
wasm.OpcodeCall, 3, |
| 585 |
wasm.OpcodeEnd, |
| 586 |
}}, |
| 587 |
// v_i32: return 100. |
| 588 |
{Body: []byte{wasm.OpcodeI32Const, 40, wasm.OpcodeEnd}}, |
| 589 |
// i32i32_i32: adds. |
| 590 |
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeI32Add, wasm.OpcodeEnd}}, |
| 591 |
// i32_i32i32: duplicates. |
| 592 |
{Body: []byte{wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 0, wasm.OpcodeEnd}}, |
| 593 |
}, |
| 594 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Index: 0, Type: wasm.ExternTypeFunc}}, |
| 595 |
}, |
| 596 |
} |
| 597 |
ManyMiddleValues = TestCase{ |
| 598 |
Name: "many_middle_values", |
| 599 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 600 |
Params: []wasm.ValueType{i32, f32}, |
| 601 |
Results: []wasm.ValueType{i32, f32}, |
| 602 |
}, []byte{ |
| 603 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 1, wasm.OpcodeI32Mul, |
| 604 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 2, wasm.OpcodeI32Mul, |
| 605 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 3, wasm.OpcodeI32Mul, |
| 606 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 4, wasm.OpcodeI32Mul, |
| 607 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 5, wasm.OpcodeI32Mul, |
| 608 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 6, wasm.OpcodeI32Mul, |
| 609 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 7, wasm.OpcodeI32Mul, |
| 610 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 8, wasm.OpcodeI32Mul, |
| 611 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 9, wasm.OpcodeI32Mul, |
| 612 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 10, wasm.OpcodeI32Mul, |
| 613 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 11, wasm.OpcodeI32Mul, |
| 614 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 12, wasm.OpcodeI32Mul, |
| 615 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 13, wasm.OpcodeI32Mul, |
| 616 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 14, wasm.OpcodeI32Mul, |
| 617 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 15, wasm.OpcodeI32Mul, |
| 618 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 16, wasm.OpcodeI32Mul, |
| 619 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 17, wasm.OpcodeI32Mul, |
| 620 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 18, wasm.OpcodeI32Mul, |
| 621 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 19, wasm.OpcodeI32Mul, |
| 622 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeI32Const, 20, wasm.OpcodeI32Mul, |
| 623 |
|
| 624 |
wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, |
| 625 |
wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, |
| 626 |
wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, |
| 627 |
wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, wasm.OpcodeI32Add, |
| 628 |
|
| 629 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x80, 0x3f, wasm.OpcodeF32Mul, |
| 630 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0, 0x40, wasm.OpcodeF32Mul, |
| 631 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x40, 0x40, wasm.OpcodeF32Mul, |
| 632 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x80, 0x40, wasm.OpcodeF32Mul, |
| 633 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0xa0, 0x40, wasm.OpcodeF32Mul, |
| 634 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0xc0, 0x40, wasm.OpcodeF32Mul, |
| 635 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0xe0, 0x40, wasm.OpcodeF32Mul, |
| 636 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0, 0x41, wasm.OpcodeF32Mul, |
| 637 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x10, 0x41, wasm.OpcodeF32Mul, |
| 638 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x20, 0x41, wasm.OpcodeF32Mul, |
| 639 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x30, 0x41, wasm.OpcodeF32Mul, |
| 640 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x40, 0x41, wasm.OpcodeF32Mul, |
| 641 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x50, 0x41, wasm.OpcodeF32Mul, |
| 642 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x60, 0x41, wasm.OpcodeF32Mul, |
| 643 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x70, 0x41, wasm.OpcodeF32Mul, |
| 644 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x80, 0x41, wasm.OpcodeF32Mul, |
| 645 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x88, 0x41, wasm.OpcodeF32Mul, |
| 646 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x90, 0x41, wasm.OpcodeF32Mul, |
| 647 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0x98, 0x41, wasm.OpcodeF32Mul, |
| 648 |
wasm.OpcodeLocalGet, 1, wasm.OpcodeF32Const, 0, 0, 0xa0, 0x41, wasm.OpcodeF32Mul, |
| 649 |
|
| 650 |
wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, |
| 651 |
wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, |
| 652 |
wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, |
| 653 |
wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, wasm.OpcodeF32Add, |
| 654 |
|
| 655 |
wasm.OpcodeEnd, |
| 656 |
}, nil), |
| 657 |
} |
| 658 |
CallManyParams = TestCase{ |
| 659 |
Name: "call_many_params", |
| 660 |
Module: &wasm.Module{ |
| 661 |
TypeSection: []wasm.FunctionType{ |
| 662 |
{Params: []wasm.ValueType{i32, i64, f32, f64}}, |
| 663 |
{ |
| 664 |
Params: []wasm.ValueType{ |
| 665 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 666 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 667 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 668 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 669 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 670 |
}, |
| 671 |
}, |
| 672 |
}, |
| 673 |
FunctionSection: []wasm.Index{0, 1}, |
| 674 |
CodeSection: []wasm.Code{ |
| 675 |
{ |
| 676 |
Body: []byte{ |
| 677 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 678 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 679 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 680 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 681 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 682 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 683 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 684 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 685 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 686 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 687 |
wasm.OpcodeCall, 1, |
| 688 |
wasm.OpcodeEnd, |
| 689 |
}, |
| 690 |
}, |
| 691 |
{Body: []byte{wasm.OpcodeEnd}}, |
| 692 |
}, |
| 693 |
}, |
| 694 |
} |
| 695 |
CallManyReturns = TestCase{ |
| 696 |
Name: "call_many_returns", |
| 697 |
Module: &wasm.Module{ |
| 698 |
TypeSection: []wasm.FunctionType{ |
| 699 |
{ |
| 700 |
Params: []wasm.ValueType{i32, i64, f32, f64}, |
| 701 |
Results: []wasm.ValueType{ |
| 702 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 703 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 704 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 705 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 706 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 707 |
}, |
| 708 |
}, |
| 709 |
}, |
| 710 |
FunctionSection: []wasm.Index{0, 0}, |
| 711 |
CodeSection: []wasm.Code{ |
| 712 |
{ |
| 713 |
Body: []byte{ |
| 714 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 715 |
wasm.OpcodeCall, 1, |
| 716 |
wasm.OpcodeEnd, |
| 717 |
}, |
| 718 |
}, |
| 719 |
{Body: []byte{ |
| 720 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 721 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 722 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 723 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 724 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 725 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 726 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 727 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 728 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 729 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 730 |
wasm.OpcodeEnd, |
| 731 |
}}, |
| 732 |
}, |
| 733 |
}, |
| 734 |
} |
| 735 |
ManyParamsSmallResults = TestCase{ |
| 736 |
Name: "many_params_small_results", |
| 737 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 738 |
Params: []wasm.ValueType{ |
| 739 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 740 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 741 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 742 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 743 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 744 |
}, |
| 745 |
Results: []wasm.ValueType{ |
| 746 |
i32, i64, f32, f64, |
| 747 |
}, |
| 748 |
}, []byte{ |
| 749 |
wasm.OpcodeLocalGet, 0, |
| 750 |
wasm.OpcodeLocalGet, 9, |
| 751 |
wasm.OpcodeLocalGet, 18, |
| 752 |
wasm.OpcodeLocalGet, 27, |
| 753 |
wasm.OpcodeEnd, |
| 754 |
}, nil), |
| 755 |
} |
| 756 |
SmallParamsManyResults = TestCase{ |
| 757 |
Name: "small_params_many_results", |
| 758 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 759 |
Params: []wasm.ValueType{i32, i64, f32, f64}, |
| 760 |
Results: []wasm.ValueType{ |
| 761 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 762 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 763 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 764 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 765 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 766 |
}, |
| 767 |
}, []byte{ |
| 768 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 769 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 770 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 771 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 772 |
wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 0, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 3, |
| 773 |
wasm.OpcodeEnd, |
| 774 |
}, nil), |
| 775 |
} |
| 776 |
ManyParamsManyResults = TestCase{ |
| 777 |
Name: "many_params_many_results", |
| 778 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 779 |
Params: []wasm.ValueType{ |
| 780 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 781 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 782 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 783 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 784 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 785 |
}, |
| 786 |
Results: []wasm.ValueType{ |
| 787 |
f64, f32, i64, i32, f64, f32, i64, i32, |
| 788 |
f64, f32, i64, i32, f64, f32, i64, i32, |
| 789 |
f64, f32, i64, i32, f64, f32, i64, i32, |
| 790 |
f64, f32, i64, i32, f64, f32, i64, i32, |
| 791 |
f64, f32, i64, i32, f64, f32, i64, i32, |
| 792 |
}, |
| 793 |
}, []byte{ |
| 794 |
wasm.OpcodeLocalGet, 39, wasm.OpcodeLocalGet, 38, wasm.OpcodeLocalGet, 37, wasm.OpcodeLocalGet, 36, |
| 795 |
wasm.OpcodeLocalGet, 35, wasm.OpcodeLocalGet, 34, wasm.OpcodeLocalGet, 33, wasm.OpcodeLocalGet, 32, |
| 796 |
wasm.OpcodeLocalGet, 31, wasm.OpcodeLocalGet, 30, wasm.OpcodeLocalGet, 29, wasm.OpcodeLocalGet, 28, |
| 797 |
wasm.OpcodeLocalGet, 27, wasm.OpcodeLocalGet, 26, wasm.OpcodeLocalGet, 25, wasm.OpcodeLocalGet, 24, |
| 798 |
wasm.OpcodeLocalGet, 23, wasm.OpcodeLocalGet, 22, wasm.OpcodeLocalGet, 21, wasm.OpcodeLocalGet, 20, |
| 799 |
wasm.OpcodeLocalGet, 19, wasm.OpcodeLocalGet, 18, wasm.OpcodeLocalGet, 17, wasm.OpcodeLocalGet, 16, |
| 800 |
wasm.OpcodeLocalGet, 15, wasm.OpcodeLocalGet, 14, wasm.OpcodeLocalGet, 13, wasm.OpcodeLocalGet, 12, |
| 801 |
wasm.OpcodeLocalGet, 11, wasm.OpcodeLocalGet, 10, wasm.OpcodeLocalGet, 9, wasm.OpcodeLocalGet, 8, |
| 802 |
wasm.OpcodeLocalGet, 7, wasm.OpcodeLocalGet, 6, wasm.OpcodeLocalGet, 5, wasm.OpcodeLocalGet, 4, |
| 803 |
wasm.OpcodeLocalGet, 3, wasm.OpcodeLocalGet, 2, wasm.OpcodeLocalGet, 1, wasm.OpcodeLocalGet, 0, |
| 804 |
wasm.OpcodeEnd, |
| 805 |
}, nil), |
| 806 |
} |
| 807 |
IntegerComparisons = TestCase{ |
| 808 |
Name: "integer_comparisons", |
| 809 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 810 |
Params: []wasm.ValueType{i32, i32, i64, i64}, |
| 811 |
Results: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32}, |
| 812 |
}, []byte{ |
| 813 |
// eq. |
| 814 |
wasm.OpcodeLocalGet, 0, |
| 815 |
wasm.OpcodeLocalGet, 1, |
| 816 |
wasm.OpcodeI32Eq, |
| 817 |
wasm.OpcodeLocalGet, 2, |
| 818 |
wasm.OpcodeLocalGet, 3, |
| 819 |
wasm.OpcodeI64Eq, |
| 820 |
// neq. |
| 821 |
wasm.OpcodeLocalGet, 0, |
| 822 |
wasm.OpcodeLocalGet, 1, |
| 823 |
wasm.OpcodeI32Ne, |
| 824 |
wasm.OpcodeLocalGet, 2, |
| 825 |
wasm.OpcodeLocalGet, 3, |
| 826 |
wasm.OpcodeI64Ne, |
| 827 |
// LtS. |
| 828 |
wasm.OpcodeLocalGet, 0, |
| 829 |
wasm.OpcodeLocalGet, 1, |
| 830 |
wasm.OpcodeI32LtS, |
| 831 |
wasm.OpcodeLocalGet, 2, |
| 832 |
wasm.OpcodeLocalGet, 3, |
| 833 |
wasm.OpcodeI64LtS, |
| 834 |
// LtU. |
| 835 |
wasm.OpcodeLocalGet, 0, |
| 836 |
wasm.OpcodeLocalGet, 1, |
| 837 |
wasm.OpcodeI32LtU, |
| 838 |
wasm.OpcodeLocalGet, 2, |
| 839 |
wasm.OpcodeLocalGet, 3, |
| 840 |
wasm.OpcodeI64LtU, |
| 841 |
// GtS. |
| 842 |
wasm.OpcodeLocalGet, 0, |
| 843 |
wasm.OpcodeLocalGet, 1, |
| 844 |
wasm.OpcodeI32GtS, |
| 845 |
wasm.OpcodeLocalGet, 2, |
| 846 |
wasm.OpcodeLocalGet, 3, |
| 847 |
wasm.OpcodeI64GtS, |
| 848 |
// GtU. |
| 849 |
wasm.OpcodeLocalGet, 0, |
| 850 |
wasm.OpcodeLocalGet, 1, |
| 851 |
wasm.OpcodeI32GtU, |
| 852 |
wasm.OpcodeLocalGet, 2, |
| 853 |
wasm.OpcodeLocalGet, 3, |
| 854 |
wasm.OpcodeI64GtU, |
| 855 |
// LeS. |
| 856 |
wasm.OpcodeLocalGet, 0, |
| 857 |
wasm.OpcodeLocalGet, 1, |
| 858 |
wasm.OpcodeI32LeS, |
| 859 |
wasm.OpcodeLocalGet, 2, |
| 860 |
wasm.OpcodeLocalGet, 3, |
| 861 |
wasm.OpcodeI64LeS, |
| 862 |
// LeU. |
| 863 |
wasm.OpcodeLocalGet, 0, |
| 864 |
wasm.OpcodeLocalGet, 1, |
| 865 |
wasm.OpcodeI32LeU, |
| 866 |
wasm.OpcodeLocalGet, 2, |
| 867 |
wasm.OpcodeLocalGet, 3, |
| 868 |
wasm.OpcodeI64LeU, |
| 869 |
// GeS. |
| 870 |
wasm.OpcodeLocalGet, 0, |
| 871 |
wasm.OpcodeLocalGet, 1, |
| 872 |
wasm.OpcodeI32GeS, |
| 873 |
wasm.OpcodeLocalGet, 2, |
| 874 |
wasm.OpcodeLocalGet, 3, |
| 875 |
wasm.OpcodeI64GeS, |
| 876 |
// GeU. |
| 877 |
wasm.OpcodeLocalGet, 0, |
| 878 |
wasm.OpcodeLocalGet, 1, |
| 879 |
wasm.OpcodeI32GeU, |
| 880 |
wasm.OpcodeLocalGet, 2, |
| 881 |
wasm.OpcodeLocalGet, 3, |
| 882 |
wasm.OpcodeI64GeU, |
| 883 |
wasm.OpcodeEnd, |
| 884 |
}, []wasm.ValueType{}), |
| 885 |
} |
| 886 |
IntegerBitwise = TestCase{ |
| 887 |
Name: "integer_bitwise", |
| 888 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 889 |
Params: []wasm.ValueType{i32, i32, i64, i64}, |
| 890 |
Results: []wasm.ValueType{i32, i32, i32, i32, i64, i64, i64, i64, i64, i64}, |
| 891 |
}, []byte{ |
| 892 |
wasm.OpcodeLocalGet, 0, |
| 893 |
wasm.OpcodeLocalGet, 1, |
| 894 |
wasm.OpcodeI32And, |
| 895 |
|
| 896 |
wasm.OpcodeLocalGet, 0, |
| 897 |
wasm.OpcodeLocalGet, 1, |
| 898 |
wasm.OpcodeI32Or, |
| 899 |
|
| 900 |
wasm.OpcodeLocalGet, 0, |
| 901 |
wasm.OpcodeLocalGet, 1, |
| 902 |
wasm.OpcodeI32Xor, |
| 903 |
|
| 904 |
wasm.OpcodeLocalGet, 0, |
| 905 |
wasm.OpcodeLocalGet, 1, |
| 906 |
wasm.OpcodeI32Rotr, |
| 907 |
|
| 908 |
wasm.OpcodeLocalGet, 2, |
| 909 |
wasm.OpcodeLocalGet, 3, |
| 910 |
wasm.OpcodeI64And, |
| 911 |
|
| 912 |
wasm.OpcodeLocalGet, 2, |
| 913 |
wasm.OpcodeLocalGet, 3, |
| 914 |
wasm.OpcodeI64Or, |
| 915 |
|
| 916 |
wasm.OpcodeLocalGet, 2, |
| 917 |
wasm.OpcodeLocalGet, 3, |
| 918 |
wasm.OpcodeI64Xor, |
| 919 |
|
| 920 |
wasm.OpcodeLocalGet, 2, |
| 921 |
wasm.OpcodeLocalGet, 3, |
| 922 |
wasm.OpcodeI64Const, 8, |
| 923 |
wasm.OpcodeI64Shl, |
| 924 |
wasm.OpcodeI64Xor, |
| 925 |
|
| 926 |
wasm.OpcodeLocalGet, 2, |
| 927 |
wasm.OpcodeLocalGet, 3, |
| 928 |
wasm.OpcodeI64Rotl, |
| 929 |
|
| 930 |
wasm.OpcodeLocalGet, 2, |
| 931 |
wasm.OpcodeLocalGet, 3, |
| 932 |
wasm.OpcodeI64Rotr, |
| 933 |
|
| 934 |
wasm.OpcodeEnd, |
| 935 |
}, []wasm.ValueType{}), |
| 936 |
} |
| 937 |
IntegerShift = TestCase{ |
| 938 |
Name: "integer_shift", |
| 939 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 940 |
Params: []wasm.ValueType{i32, i32, i64, i64}, |
| 941 |
Results: []wasm.ValueType{i32, i32, i64, i64, i32, i32, i64, i64, i32, i32, i64, i64}, |
| 942 |
}, []byte{ |
| 943 |
// logical left. |
| 944 |
wasm.OpcodeLocalGet, 0, |
| 945 |
wasm.OpcodeLocalGet, 1, |
| 946 |
wasm.OpcodeI32Shl, |
| 947 |
wasm.OpcodeLocalGet, 0, |
| 948 |
wasm.OpcodeI32Const, 31, |
| 949 |
wasm.OpcodeI32Shl, |
| 950 |
wasm.OpcodeLocalGet, 2, |
| 951 |
wasm.OpcodeLocalGet, 3, |
| 952 |
wasm.OpcodeI64Shl, |
| 953 |
wasm.OpcodeLocalGet, 2, |
| 954 |
wasm.OpcodeI64Const, 32, |
| 955 |
wasm.OpcodeI64Shl, |
| 956 |
// logical right. |
| 957 |
wasm.OpcodeLocalGet, 0, |
| 958 |
wasm.OpcodeLocalGet, 1, |
| 959 |
wasm.OpcodeI32ShrU, |
| 960 |
wasm.OpcodeLocalGet, 0, |
| 961 |
wasm.OpcodeI32Const, 31, |
| 962 |
wasm.OpcodeI32ShrU, |
| 963 |
wasm.OpcodeLocalGet, 2, |
| 964 |
wasm.OpcodeLocalGet, 3, |
| 965 |
wasm.OpcodeI64ShrU, |
| 966 |
wasm.OpcodeLocalGet, 2, |
| 967 |
wasm.OpcodeI64Const, 32, |
| 968 |
wasm.OpcodeI64ShrU, |
| 969 |
// arithmetic right. |
| 970 |
wasm.OpcodeLocalGet, 0, |
| 971 |
wasm.OpcodeLocalGet, 1, |
| 972 |
wasm.OpcodeI32ShrS, |
| 973 |
wasm.OpcodeLocalGet, 0, |
| 974 |
wasm.OpcodeI32Const, 31, |
| 975 |
wasm.OpcodeI32ShrS, |
| 976 |
wasm.OpcodeLocalGet, 2, |
| 977 |
wasm.OpcodeLocalGet, 3, |
| 978 |
wasm.OpcodeI64ShrS, |
| 979 |
wasm.OpcodeLocalGet, 2, |
| 980 |
wasm.OpcodeI64Const, 32, |
| 981 |
wasm.OpcodeI64ShrS, |
| 982 |
wasm.OpcodeEnd, |
| 983 |
}, []wasm.ValueType{}), |
| 984 |
} |
| 985 |
IntegerExtensions = TestCase{ |
| 986 |
Name: "integer_extensions", |
| 987 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 988 |
Params: []wasm.ValueType{i32, i64}, |
| 989 |
Results: []wasm.ValueType{i64, i64, i64, i64, i64, i32, i32}, |
| 990 |
}, []byte{ |
| 991 |
wasm.OpcodeLocalGet, 0, |
| 992 |
wasm.OpcodeI64ExtendI32S, |
| 993 |
|
| 994 |
wasm.OpcodeLocalGet, 0, |
| 995 |
wasm.OpcodeI64ExtendI32U, |
| 996 |
|
| 997 |
wasm.OpcodeLocalGet, 1, |
| 998 |
wasm.OpcodeI64Extend8S, |
| 999 |
|
| 1000 |
wasm.OpcodeLocalGet, 1, |
| 1001 |
wasm.OpcodeI64Extend16S, |
| 1002 |
|
| 1003 |
wasm.OpcodeLocalGet, 1, |
| 1004 |
wasm.OpcodeI64Extend32S, |
| 1005 |
|
| 1006 |
wasm.OpcodeLocalGet, 0, |
| 1007 |
wasm.OpcodeI32Extend8S, |
| 1008 |
|
| 1009 |
wasm.OpcodeLocalGet, 0, |
| 1010 |
wasm.OpcodeI32Extend16S, |
| 1011 |
|
| 1012 |
wasm.OpcodeEnd, |
| 1013 |
}, []wasm.ValueType{}), |
| 1014 |
} |
| 1015 |
IntegerBitCounts = TestCase{ |
| 1016 |
Name: "integer_bit_counts", |
| 1017 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1018 |
Params: []wasm.ValueType{i32, i64}, |
| 1019 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64}, |
| 1020 |
}, []byte{ |
| 1021 |
wasm.OpcodeLocalGet, 0, |
| 1022 |
wasm.OpcodeI32Clz, |
| 1023 |
|
| 1024 |
wasm.OpcodeLocalGet, 0, |
| 1025 |
wasm.OpcodeI32Ctz, |
| 1026 |
|
| 1027 |
wasm.OpcodeLocalGet, 0, |
| 1028 |
wasm.OpcodeI32Popcnt, |
| 1029 |
|
| 1030 |
wasm.OpcodeLocalGet, 1, |
| 1031 |
wasm.OpcodeI64Clz, |
| 1032 |
|
| 1033 |
wasm.OpcodeLocalGet, 1, |
| 1034 |
wasm.OpcodeI64Ctz, |
| 1035 |
|
| 1036 |
wasm.OpcodeLocalGet, 1, |
| 1037 |
wasm.OpcodeI64Popcnt, |
| 1038 |
|
| 1039 |
wasm.OpcodeEnd, |
| 1040 |
}, []wasm.ValueType{}), |
| 1041 |
} |
| 1042 |
FloatComparisons = TestCase{ |
| 1043 |
Name: "float_comparisons", |
| 1044 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1045 |
Params: []wasm.ValueType{f32, f32, f64, f64}, |
| 1046 |
Results: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32}, |
| 1047 |
}, []byte{ |
| 1048 |
wasm.OpcodeLocalGet, 0, |
| 1049 |
wasm.OpcodeLocalGet, 1, |
| 1050 |
wasm.OpcodeF32Eq, |
| 1051 |
wasm.OpcodeLocalGet, 0, |
| 1052 |
wasm.OpcodeLocalGet, 1, |
| 1053 |
wasm.OpcodeF32Ne, |
| 1054 |
wasm.OpcodeLocalGet, 0, |
| 1055 |
wasm.OpcodeLocalGet, 1, |
| 1056 |
wasm.OpcodeF32Lt, |
| 1057 |
wasm.OpcodeLocalGet, 0, |
| 1058 |
wasm.OpcodeLocalGet, 1, |
| 1059 |
wasm.OpcodeF32Gt, |
| 1060 |
wasm.OpcodeLocalGet, 0, |
| 1061 |
wasm.OpcodeLocalGet, 1, |
| 1062 |
wasm.OpcodeF32Le, |
| 1063 |
wasm.OpcodeLocalGet, 0, |
| 1064 |
wasm.OpcodeLocalGet, 1, |
| 1065 |
wasm.OpcodeF32Ge, |
| 1066 |
|
| 1067 |
wasm.OpcodeLocalGet, 2, |
| 1068 |
wasm.OpcodeLocalGet, 3, |
| 1069 |
wasm.OpcodeF64Eq, |
| 1070 |
wasm.OpcodeLocalGet, 2, |
| 1071 |
wasm.OpcodeLocalGet, 3, |
| 1072 |
wasm.OpcodeF64Ne, |
| 1073 |
wasm.OpcodeLocalGet, 2, |
| 1074 |
wasm.OpcodeLocalGet, 3, |
| 1075 |
wasm.OpcodeF64Lt, |
| 1076 |
wasm.OpcodeLocalGet, 2, |
| 1077 |
wasm.OpcodeLocalGet, 3, |
| 1078 |
wasm.OpcodeF64Gt, |
| 1079 |
wasm.OpcodeLocalGet, 2, |
| 1080 |
wasm.OpcodeLocalGet, 3, |
| 1081 |
wasm.OpcodeF64Le, |
| 1082 |
wasm.OpcodeLocalGet, 2, |
| 1083 |
wasm.OpcodeLocalGet, 3, |
| 1084 |
wasm.OpcodeF64Ge, |
| 1085 |
|
| 1086 |
wasm.OpcodeEnd, |
| 1087 |
}, []wasm.ValueType{}), |
| 1088 |
} |
| 1089 |
FloatArithm = TestCase{ |
| 1090 |
Name: "float_arithm", |
| 1091 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1092 |
Params: []wasm.ValueType{f64, f64, f64, f32, f32, f32}, |
| 1093 |
Results: []wasm.ValueType{ |
| 1094 |
f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, f64, |
| 1095 |
f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, |
| 1096 |
}, |
| 1097 |
}, []byte{ |
| 1098 |
wasm.OpcodeLocalGet, 0, |
| 1099 |
wasm.OpcodeF64Neg, |
| 1100 |
|
| 1101 |
wasm.OpcodeLocalGet, 0, |
| 1102 |
wasm.OpcodeF64Neg, |
| 1103 |
wasm.OpcodeF64Abs, |
| 1104 |
|
| 1105 |
wasm.OpcodeLocalGet, 0, |
| 1106 |
wasm.OpcodeF64Sqrt, |
| 1107 |
|
| 1108 |
wasm.OpcodeLocalGet, 0, |
| 1109 |
wasm.OpcodeLocalGet, 1, |
| 1110 |
wasm.OpcodeF64Add, |
| 1111 |
|
| 1112 |
wasm.OpcodeLocalGet, 0, |
| 1113 |
wasm.OpcodeLocalGet, 1, |
| 1114 |
wasm.OpcodeF64Sub, |
| 1115 |
|
| 1116 |
wasm.OpcodeLocalGet, 0, |
| 1117 |
wasm.OpcodeLocalGet, 1, |
| 1118 |
wasm.OpcodeF64Mul, |
| 1119 |
|
| 1120 |
wasm.OpcodeLocalGet, 0, |
| 1121 |
wasm.OpcodeLocalGet, 1, |
| 1122 |
wasm.OpcodeF64Div, |
| 1123 |
|
| 1124 |
wasm.OpcodeLocalGet, 2, |
| 1125 |
wasm.OpcodeF64Nearest, |
| 1126 |
|
| 1127 |
wasm.OpcodeLocalGet, 2, |
| 1128 |
wasm.OpcodeF64Floor, |
| 1129 |
|
| 1130 |
wasm.OpcodeLocalGet, 2, |
| 1131 |
wasm.OpcodeF64Ceil, |
| 1132 |
|
| 1133 |
wasm.OpcodeLocalGet, 2, |
| 1134 |
wasm.OpcodeF64Trunc, |
| 1135 |
|
| 1136 |
wasm.OpcodeLocalGet, 0, |
| 1137 |
wasm.OpcodeLocalGet, 1, |
| 1138 |
wasm.OpcodeF64Neg, |
| 1139 |
wasm.OpcodeF64Copysign, |
| 1140 |
|
| 1141 |
// 32-bit floats. |
| 1142 |
wasm.OpcodeLocalGet, 3, |
| 1143 |
wasm.OpcodeF32Neg, |
| 1144 |
|
| 1145 |
wasm.OpcodeLocalGet, 3, |
| 1146 |
wasm.OpcodeF32Neg, |
| 1147 |
wasm.OpcodeF32Abs, |
| 1148 |
|
| 1149 |
wasm.OpcodeLocalGet, 3, |
| 1150 |
wasm.OpcodeF32Sqrt, |
| 1151 |
|
| 1152 |
wasm.OpcodeLocalGet, 3, |
| 1153 |
wasm.OpcodeLocalGet, 4, |
| 1154 |
wasm.OpcodeF32Add, |
| 1155 |
|
| 1156 |
wasm.OpcodeLocalGet, 3, |
| 1157 |
wasm.OpcodeLocalGet, 4, |
| 1158 |
wasm.OpcodeF32Sub, |
| 1159 |
|
| 1160 |
wasm.OpcodeLocalGet, 3, |
| 1161 |
wasm.OpcodeLocalGet, 4, |
| 1162 |
wasm.OpcodeF32Mul, |
| 1163 |
|
| 1164 |
wasm.OpcodeLocalGet, 3, |
| 1165 |
wasm.OpcodeLocalGet, 4, |
| 1166 |
wasm.OpcodeF32Div, |
| 1167 |
|
| 1168 |
wasm.OpcodeLocalGet, 5, |
| 1169 |
wasm.OpcodeF32Nearest, |
| 1170 |
|
| 1171 |
wasm.OpcodeLocalGet, 5, |
| 1172 |
wasm.OpcodeF32Floor, |
| 1173 |
|
| 1174 |
wasm.OpcodeLocalGet, 5, |
| 1175 |
wasm.OpcodeF32Ceil, |
| 1176 |
|
| 1177 |
wasm.OpcodeLocalGet, 5, |
| 1178 |
wasm.OpcodeF32Trunc, |
| 1179 |
|
| 1180 |
wasm.OpcodeLocalGet, 3, |
| 1181 |
wasm.OpcodeLocalGet, 4, |
| 1182 |
wasm.OpcodeF32Neg, |
| 1183 |
wasm.OpcodeF32Copysign, |
| 1184 |
|
| 1185 |
wasm.OpcodeEnd, |
| 1186 |
}, []wasm.ValueType{}), |
| 1187 |
} |
| 1188 |
FloatLe = TestCase{ |
| 1189 |
Name: "float_le", |
| 1190 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1191 |
Params: []wasm.ValueType{f64}, |
| 1192 |
Results: []wasm.ValueType{i64, i64}, |
| 1193 |
}, []byte{ |
| 1194 |
wasm.OpcodeLocalGet, 0, |
| 1195 |
wasm.OpcodeF64Const, 0, 0, 0, 0, 0, 0, 240, 63, // 1.0 |
| 1196 |
wasm.OpcodeF64Le, |
| 1197 |
wasm.OpcodeIf, blockSignature_vv, |
| 1198 |
wasm.OpcodeI64Const, 1, |
| 1199 |
wasm.OpcodeLocalGet, 0, |
| 1200 |
wasm.OpcodeF64Const, 0, 0, 0, 0, 0, 0, 240, 63, // 1.0 |
| 1201 |
wasm.OpcodeF64Le, |
| 1202 |
wasm.OpcodeI64ExtendI32U, |
| 1203 |
wasm.OpcodeReturn, |
| 1204 |
wasm.OpcodeElse, |
| 1205 |
wasm.OpcodeI64Const, 0, |
| 1206 |
wasm.OpcodeLocalGet, 0, |
| 1207 |
wasm.OpcodeF64Const, 0, 0, 0, 0, 0, 0, 240, 63, // 1.0 |
| 1208 |
wasm.OpcodeF64Le, |
| 1209 |
wasm.OpcodeI64ExtendI32U, |
| 1210 |
wasm.OpcodeReturn, |
| 1211 |
wasm.OpcodeEnd, |
| 1212 |
wasm.OpcodeUnreachable, |
| 1213 |
wasm.OpcodeEnd, |
| 1214 |
}, []wasm.ValueType{}), |
| 1215 |
} |
| 1216 |
MinMaxFloat = TestCase{ |
| 1217 |
Name: "min_max_float", |
| 1218 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1219 |
Params: []wasm.ValueType{f64, f64, f32, f32}, |
| 1220 |
Results: []wasm.ValueType{ |
| 1221 |
f64, f64, |
| 1222 |
f32, f32, |
| 1223 |
}, |
| 1224 |
}, []byte{ |
| 1225 |
wasm.OpcodeLocalGet, 0, |
| 1226 |
wasm.OpcodeLocalGet, 1, |
| 1227 |
wasm.OpcodeF64Min, |
| 1228 |
|
| 1229 |
wasm.OpcodeLocalGet, 0, |
| 1230 |
wasm.OpcodeLocalGet, 1, |
| 1231 |
wasm.OpcodeF64Max, |
| 1232 |
|
| 1233 |
// 32-bit floats. |
| 1234 |
wasm.OpcodeLocalGet, 2, |
| 1235 |
wasm.OpcodeLocalGet, 3, |
| 1236 |
wasm.OpcodeF32Min, |
| 1237 |
|
| 1238 |
wasm.OpcodeLocalGet, 2, |
| 1239 |
wasm.OpcodeLocalGet, 3, |
| 1240 |
wasm.OpcodeF32Max, |
| 1241 |
|
| 1242 |
wasm.OpcodeEnd, |
| 1243 |
}, []wasm.ValueType{}), |
| 1244 |
} |
| 1245 |
FloatConversions = TestCase{ |
| 1246 |
Name: "float_conversions", |
| 1247 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1248 |
Params: []wasm.ValueType{f64, f32}, |
| 1249 |
Results: []wasm.ValueType{i64, i64, i32, i32, i64, i64, i32, i32, f32, f64}, |
| 1250 |
}, []byte{ |
| 1251 |
wasm.OpcodeLocalGet, 0, |
| 1252 |
wasm.OpcodeI64TruncF64S, |
| 1253 |
|
| 1254 |
wasm.OpcodeLocalGet, 1, |
| 1255 |
wasm.OpcodeI64TruncF32S, |
| 1256 |
|
| 1257 |
wasm.OpcodeLocalGet, 0, |
| 1258 |
wasm.OpcodeI32TruncF64S, |
| 1259 |
|
| 1260 |
wasm.OpcodeLocalGet, 1, |
| 1261 |
wasm.OpcodeI32TruncF32S, |
| 1262 |
|
| 1263 |
wasm.OpcodeLocalGet, 0, |
| 1264 |
wasm.OpcodeI64TruncF64U, |
| 1265 |
|
| 1266 |
wasm.OpcodeLocalGet, 1, |
| 1267 |
wasm.OpcodeI64TruncF32U, |
| 1268 |
|
| 1269 |
wasm.OpcodeLocalGet, 0, |
| 1270 |
wasm.OpcodeI32TruncF64U, |
| 1271 |
|
| 1272 |
wasm.OpcodeLocalGet, 1, |
| 1273 |
wasm.OpcodeI32TruncF32U, |
| 1274 |
|
| 1275 |
wasm.OpcodeLocalGet, 0, |
| 1276 |
wasm.OpcodeF32DemoteF64, |
| 1277 |
|
| 1278 |
wasm.OpcodeLocalGet, 1, |
| 1279 |
wasm.OpcodeF64PromoteF32, |
| 1280 |
|
| 1281 |
wasm.OpcodeEnd, |
| 1282 |
}, []wasm.ValueType{}), |
| 1283 |
} |
| 1284 |
NonTrappingFloatConversions = TestCase{ |
| 1285 |
Name: "float_conversions", |
| 1286 |
Module: SingleFunctionModule(wasm.FunctionType{ |
| 1287 |
Params: []wasm.ValueType{f64, f32}, |
| 1288 |
Results: []wasm.ValueType{i64, i64, i32, i32, i64, i64, i32, i32}, |
| 1289 |
}, []byte{ |
| 1290 |
wasm.OpcodeLocalGet, 0, |
| 1291 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF64S, |
| 1292 |
|
| 1293 |
wasm.OpcodeLocalGet, 1, |
| 1294 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF32S, |
| 1295 |
|
| 1296 |
wasm.OpcodeLocalGet, 0, |
| 1297 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF64S, |
| 1298 |
|
| 1299 |
wasm.OpcodeLocalGet, 1, |
| 1300 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF32S, |
| 1301 |
|
| 1302 |
wasm.OpcodeLocalGet, 0, |
| 1303 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF64U, |
| 1304 |
|
| 1305 |
wasm.OpcodeLocalGet, 1, |
| 1306 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI64TruncSatF32U, |
| 1307 |
|
| 1308 |
wasm.OpcodeLocalGet, 0, |
| 1309 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF64U, |
| 1310 |
|
| 1311 |
wasm.OpcodeLocalGet, 1, |
| 1312 |
wasm.OpcodeMiscPrefix, wasm.OpcodeMiscI32TruncSatF32U, |
| 1313 |
|
| 1314 |
wasm.OpcodeEnd, |
| 1315 |
}, []wasm.ValueType{}), |
| 1316 |
} |
| 1317 |
FibonacciRecursive = TestCase{ |
| 1318 |
Name: "recursive_fibonacci", |
| 1319 |
Module: SingleFunctionModule(i32_i32, []byte{ |
| 1320 |
wasm.OpcodeLocalGet, 0, |
| 1321 |
wasm.OpcodeI32Const, 2, |
| 1322 |
wasm.OpcodeI32LtS, |
| 1323 |
wasm.OpcodeIf, blockSignature_vv, |
| 1324 |
wasm.OpcodeLocalGet, 0, |
| 1325 |
wasm.OpcodeReturn, |
| 1326 |
wasm.OpcodeEnd, |
| 1327 |
wasm.OpcodeLocalGet, 0, |
| 1328 |
wasm.OpcodeI32Const, 1, |
| 1329 |
wasm.OpcodeI32Sub, |
| 1330 |
wasm.OpcodeCall, 0, |
| 1331 |
wasm.OpcodeLocalGet, 0, |
| 1332 |
wasm.OpcodeI32Const, 2, |
| 1333 |
wasm.OpcodeI32Sub, |
| 1334 |
wasm.OpcodeCall, 0, |
| 1335 |
wasm.OpcodeI32Add, |
| 1336 |
wasm.OpcodeEnd, |
| 1337 |
}, nil), |
| 1338 |
} |
| 1339 |
ImportedFunctionCall = TestCase{ |
| 1340 |
Name: "imported_function_call", |
| 1341 |
Imported: &wasm.Module{ |
| 1342 |
ExportSection: []wasm.Export{{Name: "i32_i32", Type: wasm.ExternTypeFunc}}, |
| 1343 |
TypeSection: []wasm.FunctionType{i32i32_i32}, |
| 1344 |
FunctionSection: []wasm.Index{0}, |
| 1345 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1346 |
wasm.OpcodeLocalGet, 0, |
| 1347 |
wasm.OpcodeLocalGet, 1, |
| 1348 |
wasm.OpcodeI32Mul, |
| 1349 |
wasm.OpcodeEnd, |
| 1350 |
}}}, |
| 1351 |
NameSection: &wasm.NameSection{ModuleName: "env"}, |
| 1352 |
}, |
| 1353 |
Module: &wasm.Module{ |
| 1354 |
ImportFunctionCount: 1, |
| 1355 |
TypeSection: []wasm.FunctionType{i32_i32, i32i32_i32}, |
| 1356 |
ImportSection: []wasm.Import{{Type: wasm.ExternTypeFunc, Module: "env", Name: "i32_i32", DescFunc: 1}}, |
| 1357 |
FunctionSection: []wasm.Index{0}, |
| 1358 |
ExportSection: []wasm.Export{ |
| 1359 |
{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 1}, |
| 1360 |
{Name: "imported_exported", Type: wasm.ExternTypeFunc, Index: 0 /* imported */}, |
| 1361 |
}, |
| 1362 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1363 |
wasm.OpcodeLocalGet, 0, |
| 1364 |
wasm.OpcodeLocalGet, 0, |
| 1365 |
wasm.OpcodeCall, 0, |
| 1366 |
wasm.OpcodeEnd, |
| 1367 |
}}}, |
| 1368 |
}, |
| 1369 |
} |
| 1370 |
|
| 1371 |
MemoryStoreBasic = TestCase{ |
| 1372 |
Name: "memory_load_basic", |
| 1373 |
Module: &wasm.Module{ |
| 1374 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}}}, |
| 1375 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1376 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1377 |
FunctionSection: []wasm.Index{0}, |
| 1378 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1379 |
wasm.OpcodeLocalGet, 0, // offset |
| 1380 |
wasm.OpcodeLocalGet, 1, // value |
| 1381 |
wasm.OpcodeI32Store, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1382 |
// Read back. |
| 1383 |
wasm.OpcodeLocalGet, 0, // offset |
| 1384 |
wasm.OpcodeI32Load, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1385 |
wasm.OpcodeEnd, |
| 1386 |
}}}, |
| 1387 |
}, |
| 1388 |
} |
| 1389 |
|
| 1390 |
MemoryStores = TestCase{ |
| 1391 |
Name: "memory_load_basic", |
| 1392 |
Module: &wasm.Module{ |
| 1393 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i64, f32, f64}}}, |
| 1394 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1395 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1396 |
FunctionSection: []wasm.Index{0}, |
| 1397 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1398 |
wasm.OpcodeI32Const, 0, // offset |
| 1399 |
wasm.OpcodeLocalGet, 0, // value |
| 1400 |
wasm.OpcodeI32Store, 0x2, 0x0, |
| 1401 |
|
| 1402 |
wasm.OpcodeI32Const, 8, // offset |
| 1403 |
wasm.OpcodeLocalGet, 1, // value |
| 1404 |
wasm.OpcodeI64Store, 0x3, 0x0, |
| 1405 |
|
| 1406 |
wasm.OpcodeI32Const, 16, // offset |
| 1407 |
wasm.OpcodeLocalGet, 2, // value |
| 1408 |
wasm.OpcodeF32Store, 0x2, 0x0, |
| 1409 |
|
| 1410 |
wasm.OpcodeI32Const, 24, // offset |
| 1411 |
wasm.OpcodeLocalGet, 3, // value |
| 1412 |
wasm.OpcodeF64Store, 0x3, 0x0, |
| 1413 |
|
| 1414 |
wasm.OpcodeI32Const, 32, |
| 1415 |
wasm.OpcodeLocalGet, 0, // value |
| 1416 |
wasm.OpcodeI32Store8, 0x0, 0, |
| 1417 |
|
| 1418 |
wasm.OpcodeI32Const, 40, |
| 1419 |
wasm.OpcodeLocalGet, 0, // value |
| 1420 |
wasm.OpcodeI32Store16, 0x1, 0, |
| 1421 |
|
| 1422 |
wasm.OpcodeI32Const, 48, |
| 1423 |
wasm.OpcodeLocalGet, 1, // value |
| 1424 |
wasm.OpcodeI64Store8, 0x0, 0, |
| 1425 |
|
| 1426 |
wasm.OpcodeI32Const, 56, |
| 1427 |
wasm.OpcodeLocalGet, 1, // value |
| 1428 |
wasm.OpcodeI64Store16, 0x1, 0, |
| 1429 |
|
| 1430 |
wasm.OpcodeI32Const, 0xc0, 0, // 64 in leb128. |
| 1431 |
wasm.OpcodeLocalGet, 1, // value |
| 1432 |
wasm.OpcodeI64Store32, 0x2, 0, |
| 1433 |
|
| 1434 |
wasm.OpcodeEnd, |
| 1435 |
}}}, |
| 1436 |
}, |
| 1437 |
} |
| 1438 |
|
| 1439 |
MemoryLoadBasic = TestCase{ |
| 1440 |
Name: "memory_load_basic", |
| 1441 |
Module: &wasm.Module{ |
| 1442 |
TypeSection: []wasm.FunctionType{{ |
| 1443 |
Params: []wasm.ValueType{i32}, |
| 1444 |
Results: []wasm.ValueType{i32}, |
| 1445 |
}}, |
| 1446 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1447 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1448 |
FunctionSection: []wasm.Index{0}, |
| 1449 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1450 |
wasm.OpcodeLocalGet, 0, |
| 1451 |
wasm.OpcodeI32Load, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1452 |
wasm.OpcodeEnd, |
| 1453 |
}}}, |
| 1454 |
DataSection: []wasm.DataSegment{{OffsetExpression: constExprI32(0), Init: maskedBuf(int(wasm.MemoryPageSize))}}, |
| 1455 |
}, |
| 1456 |
} |
| 1457 |
|
| 1458 |
MemorySizeGrow = TestCase{ |
| 1459 |
Name: "memory_size_grow", |
| 1460 |
Module: &wasm.Module{ |
| 1461 |
TypeSection: []wasm.FunctionType{{Results: []wasm.ValueType{i32, i32, i32}}}, |
| 1462 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1463 |
MemorySection: &wasm.Memory{Min: 1, Max: 2, IsMaxEncoded: true}, |
| 1464 |
FunctionSection: []wasm.Index{0}, |
| 1465 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1466 |
wasm.OpcodeI32Const, 1, |
| 1467 |
wasm.OpcodeMemoryGrow, 0, // return 1. |
| 1468 |
wasm.OpcodeMemorySize, 0, // return 2. |
| 1469 |
wasm.OpcodeI32Const, 1, |
| 1470 |
wasm.OpcodeMemoryGrow, 0, // return -1 since already maximum size. |
| 1471 |
wasm.OpcodeEnd, |
| 1472 |
}}}, |
| 1473 |
}, |
| 1474 |
} |
| 1475 |
|
| 1476 |
MemoryLoadBasic2 = TestCase{ |
| 1477 |
Name: "memory_load_basic2", |
| 1478 |
Module: &wasm.Module{ |
| 1479 |
TypeSection: []wasm.FunctionType{i32_i32, {}}, |
| 1480 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1481 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1482 |
FunctionSection: []wasm.Index{0, 1}, |
| 1483 |
CodeSection: []wasm.Code{ |
| 1484 |
{Body: []byte{ |
| 1485 |
wasm.OpcodeLocalGet, 0, |
| 1486 |
wasm.OpcodeI32Const, 0, |
| 1487 |
wasm.OpcodeI32Eq, |
| 1488 |
wasm.OpcodeIf, blockSignature_vv, |
| 1489 |
wasm.OpcodeCall, 0x1, // After this the memory buf/size pointer reloads. |
| 1490 |
wasm.OpcodeElse, // But in Else block, we do nothing, so not reloaded. |
| 1491 |
wasm.OpcodeEnd, |
| 1492 |
|
| 1493 |
// Therefore, this block should reload the memory buf/size pointer here. |
| 1494 |
wasm.OpcodeLocalGet, 0, |
| 1495 |
wasm.OpcodeI32Load, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1496 |
|
| 1497 |
wasm.OpcodeEnd, |
| 1498 |
}}, |
| 1499 |
{Body: []byte{wasm.OpcodeEnd}}, |
| 1500 |
}, |
| 1501 |
DataSection: []wasm.DataSegment{{OffsetExpression: constExprI32(0), Init: maskedBuf(int(wasm.MemoryPageSize))}}, |
| 1502 |
}, |
| 1503 |
} |
| 1504 |
|
| 1505 |
ImportedMemoryGrow = TestCase{ |
| 1506 |
Name: "imported_memory_grow", |
| 1507 |
Imported: &wasm.Module{ |
| 1508 |
ExportSection: []wasm.Export{ |
| 1509 |
{Name: "mem", Type: wasm.ExternTypeMemory, Index: 0}, |
| 1510 |
{Name: "size", Type: wasm.ExternTypeFunc, Index: 0}, |
| 1511 |
}, |
| 1512 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1513 |
TypeSection: []wasm.FunctionType{v_i32}, |
| 1514 |
FunctionSection: []wasm.Index{0}, |
| 1515 |
CodeSection: []wasm.Code{{Body: []byte{wasm.OpcodeMemorySize, 0, wasm.OpcodeEnd}}}, |
| 1516 |
DataSection: []wasm.DataSegment{{OffsetExpression: constExprI32(0), Init: maskedBuf(int(wasm.MemoryPageSize))}}, |
| 1517 |
NameSection: &wasm.NameSection{ModuleName: "env"}, |
| 1518 |
}, |
| 1519 |
Module: &wasm.Module{ |
| 1520 |
ImportMemoryCount: 1, |
| 1521 |
ImportFunctionCount: 1, |
| 1522 |
ImportSection: []wasm.Import{ |
| 1523 |
{Module: "env", Name: "mem", Type: wasm.ExternTypeMemory, DescMem: &wasm.Memory{Min: 1}}, |
| 1524 |
{Module: "env", Name: "size", Type: wasm.ExternTypeFunc, DescFunc: 0}, |
| 1525 |
}, |
| 1526 |
TypeSection: []wasm.FunctionType{v_i32, {Results: []wasm.ValueType{i32, i32, i32, i32}}}, |
| 1527 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 1}}, |
| 1528 |
FunctionSection: []wasm.Index{1}, |
| 1529 |
CodeSection: []wasm.Code{ |
| 1530 |
{Body: []byte{ |
| 1531 |
wasm.OpcodeCall, 0, // Call imported size function. --> 1 |
| 1532 |
wasm.OpcodeMemorySize, 0, // --> 1. |
| 1533 |
wasm.OpcodeI32Const, 10, |
| 1534 |
wasm.OpcodeMemoryGrow, 0, |
| 1535 |
wasm.OpcodeDrop, |
| 1536 |
wasm.OpcodeCall, 0, // Call imported size function. --> 11. |
| 1537 |
wasm.OpcodeMemorySize, 0, // --> 11. |
| 1538 |
wasm.OpcodeEnd, |
| 1539 |
}}, |
| 1540 |
}, |
| 1541 |
}, |
| 1542 |
} |
| 1543 |
|
| 1544 |
GlobalsGet = TestCase{ |
| 1545 |
Name: "globals_get", |
| 1546 |
Module: &wasm.Module{ |
| 1547 |
TypeSection: []wasm.FunctionType{{Results: []wasm.ValueType{i32, i64, f32, f64, v128}}}, |
| 1548 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1549 |
FunctionSection: []wasm.Index{0}, |
| 1550 |
GlobalSection: []wasm.Global{ |
| 1551 |
{ |
| 1552 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI32, Mutable: false}, |
| 1553 |
Init: constExprI32(math.MinInt32), |
| 1554 |
}, |
| 1555 |
{ |
| 1556 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI64, Mutable: false}, |
| 1557 |
Init: constExprI64(math.MinInt64), |
| 1558 |
}, |
| 1559 |
{ |
| 1560 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF32, Mutable: false}, |
| 1561 |
Init: constExprF32(math.MaxFloat32), |
| 1562 |
}, |
| 1563 |
{ |
| 1564 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF64, Mutable: false}, |
| 1565 |
Init: constExprF64(math.MaxFloat64), |
| 1566 |
}, |
| 1567 |
{ |
| 1568 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeV128, Mutable: false}, |
| 1569 |
Init: constExprV128(1234, 5678), |
| 1570 |
}, |
| 1571 |
}, |
| 1572 |
CodeSection: []wasm.Code{ |
| 1573 |
{Body: []byte{ |
| 1574 |
wasm.OpcodeGlobalGet, 0, |
| 1575 |
wasm.OpcodeGlobalGet, 1, |
| 1576 |
wasm.OpcodeGlobalGet, 2, |
| 1577 |
wasm.OpcodeGlobalGet, 3, |
| 1578 |
wasm.OpcodeGlobalGet, 4, |
| 1579 |
wasm.OpcodeEnd, |
| 1580 |
}}, |
| 1581 |
}, |
| 1582 |
}, |
| 1583 |
} |
| 1584 |
|
| 1585 |
GlobalsSet = TestCase{ |
| 1586 |
Name: "globals_set", |
| 1587 |
Module: &wasm.Module{ |
| 1588 |
TypeSection: []wasm.FunctionType{{Results: []wasm.ValueType{i32, i64, f32, f64, v128}}}, |
| 1589 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1590 |
FunctionSection: []wasm.Index{0}, |
| 1591 |
GlobalSection: []wasm.Global{ |
| 1592 |
{ |
| 1593 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI32, Mutable: true}, |
| 1594 |
Init: constExprI32(0), |
| 1595 |
}, |
| 1596 |
{ |
| 1597 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI64, Mutable: true}, |
| 1598 |
Init: constExprI64(0), |
| 1599 |
}, |
| 1600 |
{ |
| 1601 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF32, Mutable: true}, |
| 1602 |
Init: constExprF32(0), |
| 1603 |
}, |
| 1604 |
{ |
| 1605 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF64, Mutable: true}, |
| 1606 |
Init: constExprF64(0), |
| 1607 |
}, |
| 1608 |
{ |
| 1609 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeV128, Mutable: true}, |
| 1610 |
Init: constExprV128(0, 0), |
| 1611 |
}, |
| 1612 |
}, |
| 1613 |
CodeSection: []wasm.Code{ |
| 1614 |
{Body: []byte{ |
| 1615 |
wasm.OpcodeI32Const, 1, |
| 1616 |
wasm.OpcodeGlobalSet, 0, |
| 1617 |
wasm.OpcodeGlobalGet, 0, |
| 1618 |
wasm.OpcodeI64Const, 2, |
| 1619 |
wasm.OpcodeGlobalSet, 1, |
| 1620 |
wasm.OpcodeGlobalGet, 1, |
| 1621 |
wasm.OpcodeF32Const, 0, 0, 64, 64, // 3.0 |
| 1622 |
wasm.OpcodeGlobalSet, 2, |
| 1623 |
wasm.OpcodeGlobalGet, 2, |
| 1624 |
wasm.OpcodeF64Const, 0, 0, 0, 0, 0, 0, 16, 64, // 4.0 |
| 1625 |
wasm.OpcodeGlobalSet, 3, |
| 1626 |
wasm.OpcodeGlobalGet, 3, |
| 1627 |
wasm.OpcodeVecPrefix, wasm.OpcodeVecV128Const, |
| 1628 |
10, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, |
| 1629 |
wasm.OpcodeGlobalSet, 4, |
| 1630 |
wasm.OpcodeGlobalGet, 4, |
| 1631 |
wasm.OpcodeEnd, |
| 1632 |
}}, |
| 1633 |
}, |
| 1634 |
}, |
| 1635 |
} |
| 1636 |
|
| 1637 |
GlobalsMutable = TestCase{ |
| 1638 |
Module: &wasm.Module{ |
| 1639 |
TypeSection: []wasm.FunctionType{ |
| 1640 |
{Results: []wasm.ValueType{i32, i64, f32, f64, i32, i64, f32, f64}}, |
| 1641 |
{}, |
| 1642 |
}, |
| 1643 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1644 |
FunctionSection: []wasm.Index{0, 1}, |
| 1645 |
GlobalSection: []wasm.Global{ |
| 1646 |
{ |
| 1647 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI32, Mutable: true}, |
| 1648 |
Init: constExprI32(100), |
| 1649 |
}, |
| 1650 |
{ |
| 1651 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeI64, Mutable: true}, |
| 1652 |
Init: constExprI64(200), |
| 1653 |
}, |
| 1654 |
{ |
| 1655 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF32, Mutable: true}, |
| 1656 |
Init: constExprF32(300.0), |
| 1657 |
}, |
| 1658 |
{ |
| 1659 |
Type: wasm.GlobalType{ValType: wasm.ValueTypeF64, Mutable: true}, |
| 1660 |
Init: constExprF64(400.0), |
| 1661 |
}, |
| 1662 |
}, |
| 1663 |
CodeSection: []wasm.Code{ |
| 1664 |
{Body: []byte{ |
| 1665 |
wasm.OpcodeGlobalGet, 0, |
| 1666 |
wasm.OpcodeGlobalGet, 1, |
| 1667 |
wasm.OpcodeGlobalGet, 2, |
| 1668 |
wasm.OpcodeGlobalGet, 3, |
| 1669 |
wasm.OpcodeCall, 1, |
| 1670 |
wasm.OpcodeGlobalGet, 0, |
| 1671 |
wasm.OpcodeGlobalGet, 1, |
| 1672 |
wasm.OpcodeGlobalGet, 2, |
| 1673 |
wasm.OpcodeGlobalGet, 3, |
| 1674 |
wasm.OpcodeEnd, |
| 1675 |
}}, |
| 1676 |
{Body: []byte{ |
| 1677 |
wasm.OpcodeI32Const, 1, |
| 1678 |
wasm.OpcodeGlobalSet, 0, |
| 1679 |
wasm.OpcodeI64Const, 2, |
| 1680 |
wasm.OpcodeGlobalSet, 1, |
| 1681 |
wasm.OpcodeF32Const, 0, 0, 64, 64, // 3.0 |
| 1682 |
wasm.OpcodeGlobalSet, 2, |
| 1683 |
wasm.OpcodeF64Const, 0, 0, 0, 0, 0, 0, 16, 64, // 4.0 |
| 1684 |
wasm.OpcodeGlobalSet, 3, |
| 1685 |
wasm.OpcodeReturn, |
| 1686 |
wasm.OpcodeEnd, |
| 1687 |
}}, |
| 1688 |
}, |
| 1689 |
}, |
| 1690 |
} |
| 1691 |
|
| 1692 |
MemoryLoads = TestCase{ |
| 1693 |
Name: "memory_loads", |
| 1694 |
Module: &wasm.Module{ |
| 1695 |
TypeSection: []wasm.FunctionType{{ |
| 1696 |
Params: []wasm.ValueType{i32}, |
| 1697 |
Results: []wasm.ValueType{ |
| 1698 |
i32, i64, f32, f64, i32, i64, f32, f64, |
| 1699 |
i32, i32, i32, i32, i32, i32, i32, i32, |
| 1700 |
i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, |
| 1701 |
}, |
| 1702 |
}}, |
| 1703 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1704 |
MemorySection: &wasm.Memory{Min: 1}, |
| 1705 |
FunctionSection: []wasm.Index{0}, |
| 1706 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1707 |
// Basic loads (without extensions). |
| 1708 |
wasm.OpcodeLocalGet, 0, // 0 |
| 1709 |
wasm.OpcodeI32Load, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1710 |
wasm.OpcodeLocalGet, 0, // 1 |
| 1711 |
wasm.OpcodeI64Load, 0x3, 0x0, // alignment=3 (natural alignment) staticOffset=0 |
| 1712 |
wasm.OpcodeLocalGet, 0, // 2 |
| 1713 |
wasm.OpcodeF32Load, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1714 |
wasm.OpcodeLocalGet, 0, // 3 |
| 1715 |
wasm.OpcodeF64Load, 0x3, 0x0, // alignment=3 (natural alignment) staticOffset=0 |
| 1716 |
wasm.OpcodeLocalGet, 0, // 4 |
| 1717 |
wasm.OpcodeI32Load, 0x2, 0xf, // alignment=2 (natural alignment) staticOffset=16 |
| 1718 |
wasm.OpcodeLocalGet, 0, // 5 |
| 1719 |
wasm.OpcodeI64Load, 0x3, 0xf, // alignment=3 (natural alignment) staticOffset=16 |
| 1720 |
wasm.OpcodeLocalGet, 0, // 6 |
| 1721 |
wasm.OpcodeF32Load, 0x2, 0xf, // alignment=2 (natural alignment) staticOffset=16 |
| 1722 |
wasm.OpcodeLocalGet, 0, // 7 |
| 1723 |
wasm.OpcodeF64Load, 0x3, 0xf, // alignment=3 (natural alignment) staticOffset=16 |
| 1724 |
|
| 1725 |
// Extension integer loads. |
| 1726 |
wasm.OpcodeLocalGet, 0, // 8 |
| 1727 |
wasm.OpcodeI32Load8S, 0x0, 0x0, // alignment=0 (natural alignment) staticOffset=0 |
| 1728 |
wasm.OpcodeLocalGet, 0, // 9 |
| 1729 |
wasm.OpcodeI32Load8S, 0x0, 0xf, // alignment=0 (natural alignment) staticOffset=16 |
| 1730 |
|
| 1731 |
wasm.OpcodeLocalGet, 0, // 10 |
| 1732 |
wasm.OpcodeI32Load8U, 0x0, 0x0, // alignment=0 (natural alignment) staticOffset=0 |
| 1733 |
wasm.OpcodeLocalGet, 0, // 11 |
| 1734 |
wasm.OpcodeI32Load8U, 0x0, 0xf, // alignment=0 (natural alignment) staticOffset=16 |
| 1735 |
wasm.OpcodeLocalGet, 0, // 12 |
| 1736 |
wasm.OpcodeI32Load16S, 0x1, 0x0, // alignment=1 (natural alignment) staticOffset=0 |
| 1737 |
wasm.OpcodeLocalGet, 0, // 13 |
| 1738 |
wasm.OpcodeI32Load16S, 0x1, 0xf, // alignment=1 (natural alignment) staticOffset=16 |
| 1739 |
wasm.OpcodeLocalGet, 0, // 14 |
| 1740 |
wasm.OpcodeI32Load16U, 0x1, 0x0, // alignment=1 (natural alignment) staticOffset=0 |
| 1741 |
wasm.OpcodeLocalGet, 0, // 15 |
| 1742 |
wasm.OpcodeI32Load16U, 0x1, 0xf, // alignment=1 (natural alignment) staticOffset=16 |
| 1743 |
wasm.OpcodeLocalGet, 0, // 16 |
| 1744 |
wasm.OpcodeI64Load8S, 0x0, 0x0, // alignment=0 (natural alignment) staticOffset=0 |
| 1745 |
wasm.OpcodeLocalGet, 0, // 17 |
| 1746 |
wasm.OpcodeI64Load8S, 0x0, 0xf, // alignment=0 (natural alignment) staticOffset=16 |
| 1747 |
wasm.OpcodeLocalGet, 0, // 18 |
| 1748 |
wasm.OpcodeI64Load8U, 0x0, 0x0, // alignment=0 (natural alignment) staticOffset=0 |
| 1749 |
wasm.OpcodeLocalGet, 0, // 19 |
| 1750 |
|
| 1751 |
wasm.OpcodeI64Load8U, 0x0, 0xf, // alignment=0 (natural alignment) staticOffset=16 |
| 1752 |
wasm.OpcodeLocalGet, 0, // 20 |
| 1753 |
wasm.OpcodeI64Load16S, 0x1, 0x0, // alignment=1 (natural alignment) staticOffset=0 |
| 1754 |
wasm.OpcodeLocalGet, 0, // 21 |
| 1755 |
wasm.OpcodeI64Load16S, 0x1, 0xf, // alignment=1 (natural alignment) staticOffset=16 |
| 1756 |
wasm.OpcodeLocalGet, 0, // 22 |
| 1757 |
wasm.OpcodeI64Load16U, 0x1, 0x0, // alignment=1 (natural alignment) staticOffset=0 |
| 1758 |
wasm.OpcodeLocalGet, 0, // 23 |
| 1759 |
wasm.OpcodeI64Load16U, 0x1, 0xf, // alignment=1 (natural alignment) staticOffset=16 |
| 1760 |
wasm.OpcodeLocalGet, 0, // 24 |
| 1761 |
wasm.OpcodeI64Load32S, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1762 |
wasm.OpcodeLocalGet, 0, // 25 |
| 1763 |
wasm.OpcodeI64Load32S, 0x2, 0xf, // alignment=2 (natural alignment) staticOffset=16 |
| 1764 |
wasm.OpcodeLocalGet, 0, // 26 |
| 1765 |
wasm.OpcodeI64Load32U, 0x2, 0x0, // alignment=2 (natural alignment) staticOffset=0 |
| 1766 |
wasm.OpcodeLocalGet, 0, // 27 |
| 1767 |
wasm.OpcodeI64Load32U, 0x2, 0xf, // alignment=2 (natural alignment) staticOffset=16 |
| 1768 |
|
| 1769 |
wasm.OpcodeEnd, |
| 1770 |
}}}, |
| 1771 |
DataSection: []wasm.DataSegment{{OffsetExpression: constExprI32(0), Init: maskedBuf(int(wasm.MemoryPageSize))}}, |
| 1772 |
}, |
| 1773 |
} |
| 1774 |
|
| 1775 |
CallIndirect = TestCase{ |
| 1776 |
Module: &wasm.Module{ |
| 1777 |
TypeSection: []wasm.FunctionType{i32_i32, {}, v_i32, v_i32i32}, |
| 1778 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1779 |
FunctionSection: []wasm.Index{0, 1, 2, 3}, |
| 1780 |
TableSection: []wasm.Table{{Type: wasm.RefTypeFuncref, Min: 1000}}, |
| 1781 |
ElementSection: []wasm.ElementSegment{ |
| 1782 |
{ |
| 1783 |
OffsetExpr: constExprI32(0), TableIndex: 0, Type: wasm.RefTypeFuncref, Mode: wasm.ElementModeActive, |
| 1784 |
// Set the function 1, 2, 3 at the beginning of the table. |
| 1785 |
Init: []wasm.ConstantExpression{ |
| 1786 |
wasm.NewConstantExpressionFromOpcode(wasm.OpcodeRefFunc, []byte{1}), |
| 1787 |
wasm.NewConstantExpressionFromOpcode(wasm.OpcodeRefFunc, []byte{2}), |
| 1788 |
wasm.NewConstantExpressionFromOpcode(wasm.OpcodeRefFunc, []byte{3}), |
| 1789 |
}, |
| 1790 |
}, |
| 1791 |
}, |
| 1792 |
CodeSection: []wasm.Code{ |
| 1793 |
{Body: []byte{ |
| 1794 |
wasm.OpcodeLocalGet, 0, |
| 1795 |
wasm.OpcodeCallIndirect, 2, 0, // Expecting type 2 (v_i32), in tables[0] |
| 1796 |
wasm.OpcodeEnd, |
| 1797 |
}}, |
| 1798 |
{Body: []byte{wasm.OpcodeEnd}}, |
| 1799 |
{Body: []byte{wasm.OpcodeI32Const, 10, wasm.OpcodeEnd}}, |
| 1800 |
{Body: []byte{wasm.OpcodeI32Const, 1, wasm.OpcodeI32Const, 1, wasm.OpcodeEnd}}, |
| 1801 |
}, |
| 1802 |
}, |
| 1803 |
} |
| 1804 |
|
| 1805 |
BrTable = TestCase{ |
| 1806 |
Module: &wasm.Module{ |
| 1807 |
TypeSection: []wasm.FunctionType{i32_i32, {}}, |
| 1808 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1809 |
FunctionSection: []wasm.Index{0}, |
| 1810 |
CodeSection: []wasm.Code{ |
| 1811 |
{Body: []byte{ |
| 1812 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1813 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1814 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1815 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1816 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1817 |
wasm.OpcodeBlock, 1, // Signature v_v, |
| 1818 |
wasm.OpcodeLocalGet, 0, |
| 1819 |
wasm.OpcodeBrTable, |
| 1820 |
6, // size of label vector |
| 1821 |
0, 1, 2, 3, 4, 5, // labels. |
| 1822 |
0, // default label |
| 1823 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 11, wasm.OpcodeReturn, |
| 1824 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 12, wasm.OpcodeReturn, |
| 1825 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 13, wasm.OpcodeReturn, |
| 1826 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 14, wasm.OpcodeReturn, |
| 1827 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 15, wasm.OpcodeReturn, |
| 1828 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 16, wasm.OpcodeReturn, |
| 1829 |
wasm.OpcodeEnd, |
| 1830 |
}}, |
| 1831 |
}, |
| 1832 |
}, |
| 1833 |
} |
| 1834 |
|
| 1835 |
BrTableWithArg = TestCase{ |
| 1836 |
Name: "br_table_with_arg", |
| 1837 |
Module: &wasm.Module{ |
| 1838 |
TypeSection: []wasm.FunctionType{i32i32_i32, v_i32}, |
| 1839 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1840 |
FunctionSection: []wasm.Index{0}, |
| 1841 |
CodeSection: []wasm.Code{ |
| 1842 |
{Body: []byte{ |
| 1843 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1844 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1845 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1846 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1847 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1848 |
wasm.OpcodeBlock, 1, // Signature v_i32, |
| 1849 |
wasm.OpcodeLocalGet, 1, // Argument to each destination. |
| 1850 |
wasm.OpcodeLocalGet, 0, |
| 1851 |
wasm.OpcodeBrTable, |
| 1852 |
6, // size of label vector |
| 1853 |
0, 1, 2, 3, 4, 5, // labels. |
| 1854 |
0, // default label |
| 1855 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 11, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1856 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 12, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1857 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 13, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1858 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 14, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1859 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 15, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1860 |
wasm.OpcodeEnd, wasm.OpcodeI32Const, 16, wasm.OpcodeI32Add, wasm.OpcodeReturn, |
| 1861 |
wasm.OpcodeUnreachable, |
| 1862 |
wasm.OpcodeEnd, |
| 1863 |
}}, |
| 1864 |
}, |
| 1865 |
}, |
| 1866 |
} |
| 1867 |
|
| 1868 |
IfThenEndNestingUnreachableIfThenElseEnd = TestCase{ |
| 1869 |
// This has been detected by fuzzing. This should belong to internal/integration_test/fuzzcases eventually, |
| 1870 |
// but for now, wazevo should have its own cases under engine/wazevo. |
| 1871 |
Name: "if_then_end_nesting_unreachable_if_then_else_end", |
| 1872 |
// (module |
| 1873 |
// (type (;0;) (func (param f64 f64 f64))) |
| 1874 |
// (func (;0;) (type 0) (param f64 f64 f64) |
| 1875 |
// block (result i64) ;; label = @1 |
| 1876 |
// memory.size |
| 1877 |
// if ;; label = @2 |
| 1878 |
// memory.size |
| 1879 |
// br 0 (;@2;) |
| 1880 |
// if ;; label = @3 |
| 1881 |
// else |
| 1882 |
// end |
| 1883 |
// drop |
| 1884 |
// end |
| 1885 |
// i64.const 0 |
| 1886 |
// end |
| 1887 |
// drop |
| 1888 |
// ) |
| 1889 |
// (memory (;0;) 4554) |
| 1890 |
//) |
| 1891 |
Module: &wasm.Module{ |
| 1892 |
TypeSection: []wasm.FunctionType{ |
| 1893 |
{Params: []wasm.ValueType{f64, f64, f64}}, |
| 1894 |
{Results: []wasm.ValueType{i64}}, |
| 1895 |
}, |
| 1896 |
|
| 1897 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1898 |
MemorySection: &wasm.Memory{Min: 4554}, |
| 1899 |
FunctionSection: []wasm.Index{0}, |
| 1900 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1901 |
wasm.OpcodeBlock, 1, // Signature v_i64, |
| 1902 |
wasm.OpcodeMemorySize, 0, |
| 1903 |
wasm.OpcodeIf, blockSignature_vv, |
| 1904 |
wasm.OpcodeMemorySize, 0, |
| 1905 |
wasm.OpcodeBr, 0x0, // label=0 |
| 1906 |
wasm.OpcodeIf, blockSignature_vv, |
| 1907 |
wasm.OpcodeElse, |
| 1908 |
wasm.OpcodeEnd, |
| 1909 |
wasm.OpcodeDrop, |
| 1910 |
wasm.OpcodeEnd, |
| 1911 |
wasm.OpcodeI64Const, 0, |
| 1912 |
wasm.OpcodeEnd, |
| 1913 |
wasm.OpcodeDrop, |
| 1914 |
wasm.OpcodeEnd, |
| 1915 |
}}}, |
| 1916 |
}, |
| 1917 |
} |
| 1918 |
|
| 1919 |
VecBitSelect = TestCase{ |
| 1920 |
Name: "vector_bit_select", |
| 1921 |
Module: &wasm.Module{ |
| 1922 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{v128, v128, v128}, Results: []wasm.ValueType{v128, v128}}}, |
| 1923 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1924 |
FunctionSection: []wasm.Index{0}, |
| 1925 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1926 |
// In arm64, the "C" of BSL instruction is overwritten by the result, |
| 1927 |
// so this case can be used to ensure that it is still alive if 'c' is used somewhere else, |
| 1928 |
// which in this case is as a return value. |
| 1929 |
wasm.OpcodeLocalGet, 0, |
| 1930 |
wasm.OpcodeLocalGet, 1, |
| 1931 |
wasm.OpcodeLocalGet, 2, |
| 1932 |
wasm.OpcodeVecPrefix, wasm.OpcodeVecV128Bitselect, |
| 1933 |
wasm.OpcodeLocalGet, 2, // Returns the 'c' as-is. |
| 1934 |
wasm.OpcodeEnd, |
| 1935 |
}}}, |
| 1936 |
}, |
| 1937 |
} |
| 1938 |
|
| 1939 |
VecShuffle = TestCase{ |
| 1940 |
Name: "shuffle", |
| 1941 |
Module: VecShuffleWithLane(0, 1, 2, 3, 4, 5, 6, 7, 24, 25, 26, 27, 28, 29, 30, 31), |
| 1942 |
} |
| 1943 |
|
| 1944 |
MemoryWait32 = TestCase{ |
| 1945 |
Name: "memory_wait32", |
| 1946 |
Module: &wasm.Module{ |
| 1947 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i32, i64}, Results: []wasm.ValueType{i32}}}, |
| 1948 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1949 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 1950 |
FunctionSection: []wasm.Index{0}, |
| 1951 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1952 |
wasm.OpcodeLocalGet, 0, |
| 1953 |
wasm.OpcodeLocalGet, 1, |
| 1954 |
wasm.OpcodeLocalGet, 2, |
| 1955 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicMemoryWait32, 0x1, 8, |
| 1956 |
wasm.OpcodeEnd, |
| 1957 |
}}}, |
| 1958 |
}, |
| 1959 |
} |
| 1960 |
|
| 1961 |
MemoryWait64 = TestCase{ |
| 1962 |
Name: "memory_wait64", |
| 1963 |
Module: &wasm.Module{ |
| 1964 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i64, i64}, Results: []wasm.ValueType{i32}}}, |
| 1965 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1966 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 1967 |
FunctionSection: []wasm.Index{0}, |
| 1968 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1969 |
wasm.OpcodeLocalGet, 0, |
| 1970 |
wasm.OpcodeLocalGet, 1, |
| 1971 |
wasm.OpcodeLocalGet, 2, |
| 1972 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicMemoryWait64, 0x2, 8, |
| 1973 |
wasm.OpcodeEnd, |
| 1974 |
}}}, |
| 1975 |
}, |
| 1976 |
} |
| 1977 |
|
| 1978 |
MemoryNotify = TestCase{ |
| 1979 |
Name: "memory_notify", |
| 1980 |
Module: &wasm.Module{ |
| 1981 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}}}, |
| 1982 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 1983 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 1984 |
FunctionSection: []wasm.Index{0}, |
| 1985 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 1986 |
wasm.OpcodeLocalGet, 0, |
| 1987 |
wasm.OpcodeLocalGet, 1, |
| 1988 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicMemoryNotify, 0x1, 8, |
| 1989 |
wasm.OpcodeEnd, |
| 1990 |
}}}, |
| 1991 |
}, |
| 1992 |
} |
| 1993 |
|
| 1994 |
AtomicRmwAdd = TestCase{ |
| 1995 |
Name: "atomic_rmw_add", |
| 1996 |
Module: &wasm.Module{ |
| 1997 |
TypeSection: []wasm.FunctionType{{ |
| 1998 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 1999 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2000 |
}}, |
| 2001 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2002 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2003 |
FunctionSection: []wasm.Index{0}, |
| 2004 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2005 |
wasm.OpcodeI32Const, 0, |
| 2006 |
wasm.OpcodeLocalGet, 0, |
| 2007 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8AddU, 0x0, 0, |
| 2008 |
wasm.OpcodeI32Const, 8, |
| 2009 |
wasm.OpcodeLocalGet, 1, |
| 2010 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16AddU, 0x1, 0, |
| 2011 |
wasm.OpcodeI32Const, 16, |
| 2012 |
wasm.OpcodeLocalGet, 2, |
| 2013 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwAdd, 0x2, 0, |
| 2014 |
wasm.OpcodeI32Const, 24, |
| 2015 |
wasm.OpcodeLocalGet, 3, |
| 2016 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8AddU, 0x0, 0, |
| 2017 |
wasm.OpcodeI32Const, 32, |
| 2018 |
wasm.OpcodeLocalGet, 4, |
| 2019 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16AddU, 0x1, 0, |
| 2020 |
wasm.OpcodeI32Const, 40, |
| 2021 |
wasm.OpcodeLocalGet, 5, |
| 2022 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32AddU, 0x2, 0, |
| 2023 |
wasm.OpcodeI32Const, 48, |
| 2024 |
wasm.OpcodeLocalGet, 6, |
| 2025 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwAdd, 0x3, 0, |
| 2026 |
wasm.OpcodeEnd, |
| 2027 |
}}}, |
| 2028 |
}, |
| 2029 |
} |
| 2030 |
|
| 2031 |
AtomicRmwSub = TestCase{ |
| 2032 |
Name: "atomic_rmw_sub", |
| 2033 |
Module: &wasm.Module{ |
| 2034 |
TypeSection: []wasm.FunctionType{{ |
| 2035 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2036 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2037 |
}}, |
| 2038 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2039 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2040 |
FunctionSection: []wasm.Index{0}, |
| 2041 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2042 |
wasm.OpcodeI32Const, 0, |
| 2043 |
wasm.OpcodeLocalGet, 0, |
| 2044 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8SubU, 0x0, 0, |
| 2045 |
wasm.OpcodeI32Const, 8, |
| 2046 |
wasm.OpcodeLocalGet, 1, |
| 2047 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16SubU, 0x1, 0, |
| 2048 |
wasm.OpcodeI32Const, 16, |
| 2049 |
wasm.OpcodeLocalGet, 2, |
| 2050 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwSub, 0x2, 0, |
| 2051 |
wasm.OpcodeI32Const, 24, |
| 2052 |
wasm.OpcodeLocalGet, 3, |
| 2053 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8SubU, 0x0, 0, |
| 2054 |
wasm.OpcodeI32Const, 32, |
| 2055 |
wasm.OpcodeLocalGet, 4, |
| 2056 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16SubU, 0x1, 0, |
| 2057 |
wasm.OpcodeI32Const, 40, |
| 2058 |
wasm.OpcodeLocalGet, 5, |
| 2059 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32SubU, 0x2, 0, |
| 2060 |
wasm.OpcodeI32Const, 48, |
| 2061 |
wasm.OpcodeLocalGet, 6, |
| 2062 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwSub, 0x3, 0, |
| 2063 |
wasm.OpcodeEnd, |
| 2064 |
}}}, |
| 2065 |
}, |
| 2066 |
} |
| 2067 |
|
| 2068 |
AtomicRmwAnd = TestCase{ |
| 2069 |
Name: "atomic_rmw_and", |
| 2070 |
Module: &wasm.Module{ |
| 2071 |
TypeSection: []wasm.FunctionType{{ |
| 2072 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2073 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2074 |
}}, |
| 2075 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2076 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2077 |
FunctionSection: []wasm.Index{0}, |
| 2078 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2079 |
wasm.OpcodeI32Const, 0, |
| 2080 |
wasm.OpcodeLocalGet, 0, |
| 2081 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8AndU, 0x0, 0, |
| 2082 |
wasm.OpcodeI32Const, 0, |
| 2083 |
wasm.OpcodeLocalGet, 1, |
| 2084 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16AndU, 0x1, 8, |
| 2085 |
wasm.OpcodeI32Const, 0, |
| 2086 |
wasm.OpcodeLocalGet, 2, |
| 2087 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwAnd, 0x2, 16, |
| 2088 |
wasm.OpcodeI32Const, 0, |
| 2089 |
wasm.OpcodeLocalGet, 3, |
| 2090 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8AndU, 0x0, 24, |
| 2091 |
wasm.OpcodeI32Const, 0, |
| 2092 |
wasm.OpcodeLocalGet, 4, |
| 2093 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16AndU, 0x1, 32, |
| 2094 |
wasm.OpcodeI32Const, 0, |
| 2095 |
wasm.OpcodeLocalGet, 5, |
| 2096 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32AndU, 0x2, 40, |
| 2097 |
wasm.OpcodeI32Const, 0, |
| 2098 |
wasm.OpcodeLocalGet, 6, |
| 2099 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwAnd, 0x3, 48, |
| 2100 |
wasm.OpcodeEnd, |
| 2101 |
}}}, |
| 2102 |
}, |
| 2103 |
} |
| 2104 |
|
| 2105 |
AtomicRmwOr = TestCase{ |
| 2106 |
Name: "atomic_rmw_or", |
| 2107 |
Module: &wasm.Module{ |
| 2108 |
TypeSection: []wasm.FunctionType{{ |
| 2109 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2110 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2111 |
}}, |
| 2112 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2113 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2114 |
FunctionSection: []wasm.Index{0}, |
| 2115 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2116 |
wasm.OpcodeI32Const, 0, |
| 2117 |
wasm.OpcodeLocalGet, 0, |
| 2118 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8OrU, 0x0, 0, |
| 2119 |
wasm.OpcodeI32Const, 0, |
| 2120 |
wasm.OpcodeLocalGet, 1, |
| 2121 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16OrU, 0x1, 8, |
| 2122 |
wasm.OpcodeI32Const, 0, |
| 2123 |
wasm.OpcodeLocalGet, 2, |
| 2124 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwOr, 0x2, 16, |
| 2125 |
wasm.OpcodeI32Const, 0, |
| 2126 |
wasm.OpcodeLocalGet, 3, |
| 2127 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8OrU, 0x0, 24, |
| 2128 |
wasm.OpcodeI32Const, 0, |
| 2129 |
wasm.OpcodeLocalGet, 4, |
| 2130 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16OrU, 0x1, 32, |
| 2131 |
wasm.OpcodeI32Const, 0, |
| 2132 |
wasm.OpcodeLocalGet, 5, |
| 2133 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32OrU, 0x2, 40, |
| 2134 |
wasm.OpcodeI32Const, 0, |
| 2135 |
wasm.OpcodeLocalGet, 6, |
| 2136 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwOr, 0x3, 48, |
| 2137 |
wasm.OpcodeEnd, |
| 2138 |
}}}, |
| 2139 |
}, |
| 2140 |
} |
| 2141 |
|
| 2142 |
AtomicRmwXor = TestCase{ |
| 2143 |
Name: "atomic_rmw_xor", |
| 2144 |
Module: &wasm.Module{ |
| 2145 |
TypeSection: []wasm.FunctionType{{ |
| 2146 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2147 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2148 |
}}, |
| 2149 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2150 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2151 |
FunctionSection: []wasm.Index{0}, |
| 2152 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2153 |
wasm.OpcodeI32Const, 0, |
| 2154 |
wasm.OpcodeLocalGet, 0, |
| 2155 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8XorU, 0x0, 0, |
| 2156 |
wasm.OpcodeI32Const, 0, |
| 2157 |
wasm.OpcodeLocalGet, 1, |
| 2158 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16XorU, 0x1, 8, |
| 2159 |
wasm.OpcodeI32Const, 0, |
| 2160 |
wasm.OpcodeLocalGet, 2, |
| 2161 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwXor, 0x2, 16, |
| 2162 |
wasm.OpcodeI32Const, 0, |
| 2163 |
wasm.OpcodeLocalGet, 3, |
| 2164 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8XorU, 0x0, 24, |
| 2165 |
wasm.OpcodeI32Const, 0, |
| 2166 |
wasm.OpcodeLocalGet, 4, |
| 2167 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16XorU, 0x1, 32, |
| 2168 |
wasm.OpcodeI32Const, 0, |
| 2169 |
wasm.OpcodeLocalGet, 5, |
| 2170 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32XorU, 0x2, 40, |
| 2171 |
wasm.OpcodeI32Const, 0, |
| 2172 |
wasm.OpcodeLocalGet, 6, |
| 2173 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwXor, 0x3, 48, |
| 2174 |
wasm.OpcodeEnd, |
| 2175 |
}}}, |
| 2176 |
}, |
| 2177 |
} |
| 2178 |
|
| 2179 |
AtomicRmwXchg = TestCase{ |
| 2180 |
Name: "atomic_rmw_xchg", |
| 2181 |
Module: &wasm.Module{ |
| 2182 |
TypeSection: []wasm.FunctionType{{ |
| 2183 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2184 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2185 |
}}, |
| 2186 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2187 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2188 |
FunctionSection: []wasm.Index{0}, |
| 2189 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2190 |
wasm.OpcodeI32Const, 0, |
| 2191 |
wasm.OpcodeLocalGet, 0, |
| 2192 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8XchgU, 0x0, 0, |
| 2193 |
wasm.OpcodeI32Const, 0, |
| 2194 |
wasm.OpcodeLocalGet, 1, |
| 2195 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16XchgU, 0x1, 8, |
| 2196 |
wasm.OpcodeI32Const, 0, |
| 2197 |
wasm.OpcodeLocalGet, 2, |
| 2198 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwXchg, 0x2, 16, |
| 2199 |
wasm.OpcodeI32Const, 0, |
| 2200 |
wasm.OpcodeLocalGet, 3, |
| 2201 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8XchgU, 0x0, 24, |
| 2202 |
wasm.OpcodeI32Const, 0, |
| 2203 |
wasm.OpcodeLocalGet, 4, |
| 2204 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16XchgU, 0x1, 32, |
| 2205 |
wasm.OpcodeI32Const, 0, |
| 2206 |
wasm.OpcodeLocalGet, 5, |
| 2207 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32XchgU, 0x2, 40, |
| 2208 |
wasm.OpcodeI32Const, 0, |
| 2209 |
wasm.OpcodeLocalGet, 6, |
| 2210 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwXchg, 0x3, 48, |
| 2211 |
wasm.OpcodeEnd, |
| 2212 |
}}}, |
| 2213 |
}, |
| 2214 |
} |
| 2215 |
|
| 2216 |
AtomicStoreLoad = TestCase{ |
| 2217 |
Name: "atomic_store_load", |
| 2218 |
Module: &wasm.Module{ |
| 2219 |
TypeSection: []wasm.FunctionType{{ |
| 2220 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2221 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2222 |
}}, |
| 2223 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2224 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2225 |
FunctionSection: []wasm.Index{0}, |
| 2226 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2227 |
wasm.OpcodeI32Const, 0, |
| 2228 |
wasm.OpcodeLocalGet, 0, |
| 2229 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Store8, 0x0, 0, |
| 2230 |
wasm.OpcodeI32Const, 0, |
| 2231 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Load8U, 0x0, 0, |
| 2232 |
wasm.OpcodeI32Const, 0, |
| 2233 |
wasm.OpcodeLocalGet, 1, |
| 2234 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Store16, 0x1, 8, |
| 2235 |
wasm.OpcodeI32Const, 0, |
| 2236 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Load16U, 0x1, 8, |
| 2237 |
wasm.OpcodeI32Const, 0, |
| 2238 |
wasm.OpcodeLocalGet, 2, |
| 2239 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Store, 0x2, 16, |
| 2240 |
wasm.OpcodeI32Const, 0, |
| 2241 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Load, 0x2, 16, |
| 2242 |
wasm.OpcodeI32Const, 0, |
| 2243 |
wasm.OpcodeLocalGet, 3, |
| 2244 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Store8, 0x0, 24, |
| 2245 |
wasm.OpcodeI32Const, 0, |
| 2246 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Load8U, 0x0, 24, |
| 2247 |
wasm.OpcodeI32Const, 0, |
| 2248 |
wasm.OpcodeLocalGet, 4, |
| 2249 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Store16, 0x1, 32, |
| 2250 |
wasm.OpcodeI32Const, 0, |
| 2251 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Load16U, 0x1, 32, |
| 2252 |
wasm.OpcodeI32Const, 0, |
| 2253 |
wasm.OpcodeLocalGet, 5, |
| 2254 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Store32, 0x2, 40, |
| 2255 |
wasm.OpcodeI32Const, 0, |
| 2256 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Load32U, 0x2, 40, |
| 2257 |
wasm.OpcodeI32Const, 0, |
| 2258 |
wasm.OpcodeLocalGet, 6, |
| 2259 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Store, 0x3, 48, |
| 2260 |
wasm.OpcodeI32Const, 0, |
| 2261 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Load, 0x3, 48, |
| 2262 |
wasm.OpcodeEnd, |
| 2263 |
}}}, |
| 2264 |
}, |
| 2265 |
} |
| 2266 |
|
| 2267 |
AtomicCas = TestCase{ |
| 2268 |
Name: "atomic_cas", |
| 2269 |
Module: &wasm.Module{ |
| 2270 |
TypeSection: []wasm.FunctionType{{ |
| 2271 |
Params: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i64, i64}, |
| 2272 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2273 |
}}, |
| 2274 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2275 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2276 |
FunctionSection: []wasm.Index{0}, |
| 2277 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2278 |
wasm.OpcodeI32Const, 0, |
| 2279 |
wasm.OpcodeLocalGet, 0, |
| 2280 |
wasm.OpcodeLocalGet, 1, |
| 2281 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8CmpxchgU, 0x0, 0, |
| 2282 |
wasm.OpcodeI32Const, 0, |
| 2283 |
wasm.OpcodeLocalGet, 2, |
| 2284 |
wasm.OpcodeLocalGet, 3, |
| 2285 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16CmpxchgU, 0x1, 8, |
| 2286 |
wasm.OpcodeI32Const, 0, |
| 2287 |
wasm.OpcodeLocalGet, 4, |
| 2288 |
wasm.OpcodeLocalGet, 5, |
| 2289 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwCmpxchg, 0x2, 16, |
| 2290 |
wasm.OpcodeI32Const, 0, |
| 2291 |
wasm.OpcodeLocalGet, 6, |
| 2292 |
wasm.OpcodeLocalGet, 7, |
| 2293 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8CmpxchgU, 0x0, 24, |
| 2294 |
wasm.OpcodeI32Const, 0, |
| 2295 |
wasm.OpcodeLocalGet, 8, |
| 2296 |
wasm.OpcodeLocalGet, 9, |
| 2297 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16CmpxchgU, 0x1, 32, |
| 2298 |
wasm.OpcodeI32Const, 0, |
| 2299 |
wasm.OpcodeLocalGet, 10, |
| 2300 |
wasm.OpcodeLocalGet, 11, |
| 2301 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32CmpxchgU, 0x2, 40, |
| 2302 |
wasm.OpcodeI32Const, 0, |
| 2303 |
wasm.OpcodeLocalGet, 12, |
| 2304 |
wasm.OpcodeLocalGet, 13, |
| 2305 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwCmpxchg, 0x3, 48, |
| 2306 |
wasm.OpcodeEnd, |
| 2307 |
}}}, |
| 2308 |
}, |
| 2309 |
} |
| 2310 |
|
| 2311 |
AtomicCasConst0 = TestCase{ |
| 2312 |
Name: "atomic_cas_const0", |
| 2313 |
Module: &wasm.Module{ |
| 2314 |
TypeSection: []wasm.FunctionType{{ |
| 2315 |
Params: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2316 |
Results: []wasm.ValueType{i32, i32, i32, i64, i64, i64, i64}, |
| 2317 |
}}, |
| 2318 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2319 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2320 |
FunctionSection: []wasm.Index{0}, |
| 2321 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2322 |
wasm.OpcodeI32Const, 0, |
| 2323 |
wasm.OpcodeI32Const, 0, |
| 2324 |
wasm.OpcodeLocalGet, 0, |
| 2325 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw8CmpxchgU, 0x0, 0, |
| 2326 |
wasm.OpcodeI32Const, 8, |
| 2327 |
wasm.OpcodeI32Const, 0, |
| 2328 |
wasm.OpcodeLocalGet, 1, |
| 2329 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32Rmw16CmpxchgU, 0x1, 0, |
| 2330 |
wasm.OpcodeI32Const, 16, |
| 2331 |
wasm.OpcodeI32Const, 0, |
| 2332 |
wasm.OpcodeLocalGet, 2, |
| 2333 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI32RmwCmpxchg, 0x2, 0, |
| 2334 |
wasm.OpcodeI32Const, 24, |
| 2335 |
wasm.OpcodeI64Const, 0, |
| 2336 |
wasm.OpcodeLocalGet, 3, |
| 2337 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw8CmpxchgU, 0x0, 0, |
| 2338 |
wasm.OpcodeI32Const, 32, |
| 2339 |
wasm.OpcodeI64Const, 0, |
| 2340 |
wasm.OpcodeLocalGet, 4, |
| 2341 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw16CmpxchgU, 0x1, 0, |
| 2342 |
wasm.OpcodeI32Const, 40, |
| 2343 |
wasm.OpcodeI64Const, 0, |
| 2344 |
wasm.OpcodeLocalGet, 5, |
| 2345 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64Rmw32CmpxchgU, 0x2, 0, |
| 2346 |
wasm.OpcodeI32Const, 48, |
| 2347 |
wasm.OpcodeI64Const, 0, |
| 2348 |
wasm.OpcodeLocalGet, 6, |
| 2349 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicI64RmwCmpxchg, 0x3, 0, |
| 2350 |
wasm.OpcodeEnd, |
| 2351 |
}}}, |
| 2352 |
}, |
| 2353 |
} |
| 2354 |
|
| 2355 |
AtomicFence = TestCase{ |
| 2356 |
Name: "atomic_fence", |
| 2357 |
Module: &wasm.Module{ |
| 2358 |
TypeSection: []wasm.FunctionType{{ |
| 2359 |
Params: []wasm.ValueType{}, |
| 2360 |
Results: []wasm.ValueType{}, |
| 2361 |
}}, |
| 2362 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2363 |
MemorySection: &wasm.Memory{Min: 1, Max: 1, IsMaxEncoded: true, IsShared: true}, |
| 2364 |
FunctionSection: []wasm.Index{0}, |
| 2365 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2366 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicFence, 0, |
| 2367 |
wasm.OpcodeEnd, |
| 2368 |
}}}, |
| 2369 |
}, |
| 2370 |
} |
| 2371 |
|
| 2372 |
AtomicFenceNoMemory = TestCase{ |
| 2373 |
Name: "atomic_fence", |
| 2374 |
Module: &wasm.Module{ |
| 2375 |
TypeSection: []wasm.FunctionType{{ |
| 2376 |
Params: []wasm.ValueType{}, |
| 2377 |
Results: []wasm.ValueType{}, |
| 2378 |
}}, |
| 2379 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2380 |
FunctionSection: []wasm.Index{0}, |
| 2381 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2382 |
wasm.OpcodeAtomicPrefix, wasm.OpcodeAtomicFence, 0, |
| 2383 |
wasm.OpcodeEnd, |
| 2384 |
}}}, |
| 2385 |
}, |
| 2386 |
} |
| 2387 |
|
| 2388 |
IcmpAndZero = TestCase{ |
| 2389 |
Name: "icmp_and_zero", |
| 2390 |
Module: &wasm.Module{ |
| 2391 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}}}, |
| 2392 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2393 |
FunctionSection: []wasm.Index{0}, |
| 2394 |
CodeSection: []wasm.Code{{Body: []byte{ |
| 2395 |
wasm.OpcodeLocalGet, 0, |
| 2396 |
wasm.OpcodeLocalGet, 1, |
| 2397 |
wasm.OpcodeI32And, |
| 2398 |
wasm.OpcodeI32Eqz, |
| 2399 |
wasm.OpcodeIf, blockSignature_vv, |
| 2400 |
wasm.OpcodeI32Const, 1, |
| 2401 |
wasm.OpcodeReturn, |
| 2402 |
wasm.OpcodeElse, |
| 2403 |
wasm.OpcodeI32Const, 0, |
| 2404 |
wasm.OpcodeReturn, |
| 2405 |
wasm.OpcodeEnd, |
| 2406 |
wasm.OpcodeUnreachable, |
| 2407 |
wasm.OpcodeEnd, |
| 2408 |
}}}, |
| 2409 |
}, |
| 2410 |
} |
| 2411 |
FibonacciTailRecursive = TestCase{ |
| 2412 |
Name: "tail_recursive_fibonacci", |
| 2413 |
Module: SingleFunctionModule( |
| 2414 |
wasm.FunctionType{Params: []wasm.ValueType{wasm.ValueTypeI32, wasm.ValueTypeI32, wasm.ValueTypeI32}, Results: []wasm.ValueType{wasm.ValueTypeI32}}, |
| 2415 |
[]byte{ |
| 2416 |
wasm.OpcodeLocalGet, 0, // n |
| 2417 |
wasm.OpcodeI32Eqz, |
| 2418 |
wasm.OpcodeIf, 0x7f, // if (n == 0) -> i32 |
| 2419 |
wasm.OpcodeLocalGet, 1, // then: return a |
| 2420 |
wasm.OpcodeElse, |
| 2421 |
wasm.OpcodeLocalGet, 0, // n |
| 2422 |
wasm.OpcodeI32Const, 1, |
| 2423 |
wasm.OpcodeI32Eq, |
| 2424 |
wasm.OpcodeIf, 0x7f, // if (n == 1) -> i32 |
| 2425 |
wasm.OpcodeLocalGet, 2, // then: return b |
| 2426 |
wasm.OpcodeElse, |
| 2427 |
wasm.OpcodeLocalGet, 0, |
| 2428 |
wasm.OpcodeI32Const, 1, |
| 2429 |
wasm.OpcodeI32Sub, |
| 2430 |
wasm.OpcodeLocalGet, 2, |
| 2431 |
wasm.OpcodeLocalGet, 1, |
| 2432 |
wasm.OpcodeLocalGet, 2, |
| 2433 |
wasm.OpcodeI32Add, |
| 2434 |
wasm.OpcodeTailCallReturnCall, 0, |
| 2435 |
wasm.OpcodeEnd, |
| 2436 |
wasm.OpcodeEnd, |
| 2437 |
wasm.OpcodeEnd, |
| 2438 |
}, |
| 2439 |
nil, |
| 2440 |
), |
| 2441 |
} |
| 2442 |
CountTailRecursive = TestCase{ |
| 2443 |
Name: "tail_recursive_count", |
| 2444 |
Module: SingleFunctionModule( |
| 2445 |
wasm.FunctionType{ |
| 2446 |
Params: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI64}, |
| 2447 |
Results: []wasm.ValueType{wasm.ValueTypeI64}, |
| 2448 |
}, |
| 2449 |
[]byte{ |
| 2450 |
wasm.OpcodeLocalGet, 0, // n |
| 2451 |
wasm.OpcodeI64Eqz, // n == 0 |
| 2452 |
wasm.OpcodeIf, 0x7e, // if (result i64) |
| 2453 |
wasm.OpcodeLocalGet, 1, // return acc |
| 2454 |
wasm.OpcodeElse, |
| 2455 |
wasm.OpcodeLocalGet, 0, // n |
| 2456 |
wasm.OpcodeI64Const, 1, |
| 2457 |
wasm.OpcodeI64Sub, // n-1 |
| 2458 |
wasm.OpcodeLocalGet, 1, // acc |
| 2459 |
wasm.OpcodeI64Const, 1, |
| 2460 |
wasm.OpcodeI64Add, // acc+1 |
| 2461 |
wasm.OpcodeTailCallReturnCall, 0, |
| 2462 |
wasm.OpcodeEnd, |
| 2463 |
wasm.OpcodeEnd, |
| 2464 |
}, |
| 2465 |
nil, |
| 2466 |
), |
| 2467 |
} |
| 2468 |
// CountTailRecursiveTwoResults is a tail recursive function returning two arguments: (n, acc) |
| 2469 |
CountTailRecursiveTwoResults = TestCase{ |
| 2470 |
Name: "tail_recursive_count_two_results", |
| 2471 |
Module: &wasm.Module{ |
| 2472 |
TypeSection: []wasm.FunctionType{ |
| 2473 |
{ |
| 2474 |
Params: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI64}, |
| 2475 |
Results: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI64}, |
| 2476 |
}, |
| 2477 |
{ |
| 2478 |
Params: []wasm.ValueType{}, |
| 2479 |
Results: []wasm.ValueType{wasm.ValueTypeI64, wasm.ValueTypeI64}, |
| 2480 |
}, |
| 2481 |
}, |
| 2482 |
FunctionSection: []wasm.Index{0}, |
| 2483 |
CodeSection: []wasm.Code{{ |
| 2484 |
LocalTypes: nil, |
| 2485 |
Body: []byte{ |
| 2486 |
wasm.OpcodeLocalGet, 0, // n |
| 2487 |
wasm.OpcodeI64Eqz, // n == 0 |
| 2488 |
wasm.OpcodeIf, 1, // if (blockSignature_vv) |
| 2489 |
wasm.OpcodeLocalGet, 0, // return n |
| 2490 |
wasm.OpcodeLocalGet, 1, // return acc |
| 2491 |
wasm.OpcodeReturn, |
| 2492 |
wasm.OpcodeElse, |
| 2493 |
wasm.OpcodeLocalGet, 0, // n |
| 2494 |
wasm.OpcodeI64Const, 1, |
| 2495 |
wasm.OpcodeI64Sub, // n-1 |
| 2496 |
wasm.OpcodeLocalGet, 1, // acc |
| 2497 |
wasm.OpcodeI64Const, 1, |
| 2498 |
wasm.OpcodeI64Add, // acc+1 |
| 2499 |
wasm.OpcodeTailCallReturnCall, 0, |
| 2500 |
wasm.OpcodeEnd, |
| 2501 |
wasm.OpcodeEnd, |
| 2502 |
}, |
| 2503 |
}}, |
| 2504 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2505 |
}, |
| 2506 |
} |
| 2507 |
|
| 2508 |
// TailCallCompatibleSignatures tests a tail call between functions with compatible but different signatures. |
| 2509 |
// - entry: (a, b, c, d) -> calls tail_caller(a, b, c + d) with a normal call |
| 2510 |
// - tail_caller: (a, b, c) -> tail calls tail_callee(a + c, b) |
| 2511 |
// - tail_callee: (x, y) -> calls helper(x, y) and returns its result |
| 2512 |
// - helper: (x, y) -> returns x * y |
| 2513 |
TailCallCompatibleSignatures = TestCase{ |
| 2514 |
Name: "tail_call_compatible_signatures", |
| 2515 |
Module: &wasm.Module{ |
| 2516 |
TypeSection: []wasm.FunctionType{ |
| 2517 |
{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}}, // helper: (i32, i32) -> i32 |
| 2518 |
{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}}, // tail_callee: (i32, i32) -> i32 |
| 2519 |
{Params: []wasm.ValueType{i32, i32, i32}, Results: []wasm.ValueType{i32}}, // tail_caller: (i32, i32, i32) -> i32 |
| 2520 |
{Params: []wasm.ValueType{i32, i32, i32, i32}, Results: []wasm.ValueType{i32}}, // entry: (i32, i32, i32, i32) -> i32 |
| 2521 |
}, |
| 2522 |
FunctionSection: []wasm.Index{3, 2, 1, 0}, // entry is index 0, tail_caller is 1, tail_callee is 2, helper is 3 |
| 2523 |
CodeSection: []wasm.Code{ |
| 2524 |
{ // entry(a, b, c, d) -> tail_caller(a, b, c + d) |
| 2525 |
Body: []byte{ |
| 2526 |
wasm.OpcodeLocalGet, 0, // a |
| 2527 |
wasm.OpcodeLocalGet, 1, // b |
| 2528 |
wasm.OpcodeLocalGet, 2, // c |
| 2529 |
wasm.OpcodeLocalGet, 3, // d |
| 2530 |
wasm.OpcodeI32Add, // c + d |
| 2531 |
wasm.OpcodeCall, 1, // call tail_caller(a, b, c + d) |
| 2532 |
wasm.OpcodeEnd, |
| 2533 |
}, |
| 2534 |
}, |
| 2535 |
{ // tail_caller(a, b, c) -> tail tail_callee(a + c, b) |
| 2536 |
Body: []byte{ |
| 2537 |
wasm.OpcodeLocalGet, 0, // a |
| 2538 |
wasm.OpcodeLocalGet, 2, // c |
| 2539 |
wasm.OpcodeI32Add, // a + c |
| 2540 |
wasm.OpcodeLocalGet, 1, // b |
| 2541 |
wasm.OpcodeTailCallReturnCall, 2, // tail call tail_callee |
| 2542 |
wasm.OpcodeEnd, |
| 2543 |
}, |
| 2544 |
}, |
| 2545 |
{ // tail_callee(x, y) -> helper(x, y) |
| 2546 |
Body: []byte{ |
| 2547 |
wasm.OpcodeLocalGet, 0, // x |
| 2548 |
wasm.OpcodeLocalGet, 1, // y |
| 2549 |
wasm.OpcodeCall, 3, // call helper(x, y) |
| 2550 |
wasm.OpcodeEnd, |
| 2551 |
}, |
| 2552 |
}, |
| 2553 |
{ // helper(x, y) -> x * y |
| 2554 |
Body: []byte{ |
| 2555 |
wasm.OpcodeLocalGet, 0, |
| 2556 |
wasm.OpcodeLocalGet, 1, |
| 2557 |
wasm.OpcodeI32Mul, |
| 2558 |
wasm.OpcodeEnd, |
| 2559 |
}, |
| 2560 |
}, |
| 2561 |
}, |
| 2562 |
ExportSection: []wasm.Export{{ |
| 2563 |
Name: ExportedFunctionName, |
| 2564 |
Type: wasm.ExternTypeFunc, |
| 2565 |
Index: 0, // Export entry |
| 2566 |
}}, |
| 2567 |
}, |
| 2568 |
} |
| 2569 |
|
| 2570 |
// TailCallMoreParams tests tail calls where the callee has more parameters than the caller. |
| 2571 |
// This reproduces the ARM64 bug where current=0, callee=16 stack slot sizes cause return value corruption |
| 2572 |
// - entry: () -> calls tail_caller() with no parameters |
| 2573 |
// - tail_caller: () -> tail calls tail_callee(1, 2, 3, 4, 5, 6, 7, 8, 9) with many stack args |
| 2574 |
// - tail_callee: returns multiple values that should be (10, 26) but get corrupted on ARM64 |
| 2575 |
TailCallMoreParams = TestCase{ |
| 2576 |
Name: "tail_call_more_params", |
| 2577 |
Module: &wasm.Module{ |
| 2578 |
TypeSection: []wasm.FunctionType{ |
| 2579 |
{Params: []wasm.ValueType{}, Results: []wasm.ValueType{i64, i64}}, // type 0: () -> (i64, i64) |
| 2580 |
{Params: []wasm.ValueType{i64, i64, i64, i64, i64, i64, i64, i64, i64}, Results: []wasm.ValueType{i64, i64}}, // type 1: (i64 x 9) -> (i64, i64) |
| 2581 |
}, |
| 2582 |
FunctionSection: []wasm.Index{0, 0, 1}, // entry (type 0), tail_caller (type 0), tail_callee (type 1) |
| 2583 |
CodeSection: []wasm.Code{ |
| 2584 |
{ // entry() -> tail_caller() |
| 2585 |
Body: []byte{ |
| 2586 |
wasm.OpcodeCall, 1, // call tail_caller() |
| 2587 |
wasm.OpcodeEnd, |
| 2588 |
}, |
| 2589 |
}, |
| 2590 |
{ // tail_caller() -> tail call tail_callee(1,2,3,4,5,6,7,8,9) |
| 2591 |
Body: []byte{ |
| 2592 |
wasm.OpcodeI64Const, 1, |
| 2593 |
wasm.OpcodeI64Const, 2, |
| 2594 |
wasm.OpcodeI64Const, 3, |
| 2595 |
wasm.OpcodeI64Const, 4, |
| 2596 |
wasm.OpcodeI64Const, 5, |
| 2597 |
wasm.OpcodeI64Const, 6, |
| 2598 |
wasm.OpcodeI64Const, 7, |
| 2599 |
wasm.OpcodeI64Const, 8, |
| 2600 |
wasm.OpcodeI64Const, 9, |
| 2601 |
wasm.OpcodeTailCallReturnCall, 2, // tail call tail_callee(1,2,3,4,5,6,7,8,9) |
| 2602 |
wasm.OpcodeEnd, |
| 2603 |
}, |
| 2604 |
}, |
| 2605 |
{ // tail_callee(a,b,c,d,e,f,g,h,i) -> returns (a+b+c+d, e+f+g+h+i) |
| 2606 |
Body: []byte{ |
| 2607 |
// First return value: a+b+c+d = 1+2+3+4 = 10 |
| 2608 |
wasm.OpcodeLocalGet, 0, // a=1 |
| 2609 |
wasm.OpcodeLocalGet, 1, // b=2 |
| 2610 |
wasm.OpcodeI64Add, // a+b=3 |
| 2611 |
wasm.OpcodeLocalGet, 2, // c=3 |
| 2612 |
wasm.OpcodeI64Add, // a+b+c=6 |
| 2613 |
wasm.OpcodeLocalGet, 3, // d=4 |
| 2614 |
wasm.OpcodeI64Add, // a+b+c+d=10 |
| 2615 |
|
| 2616 |
// Second return value: e+f+g+h+i = 5+6+7+8+9 = 35 |
| 2617 |
wasm.OpcodeLocalGet, 4, // e=5 |
| 2618 |
wasm.OpcodeLocalGet, 5, // f=6 |
| 2619 |
wasm.OpcodeI64Add, // e+f=11 |
| 2620 |
wasm.OpcodeLocalGet, 6, // g=7 |
| 2621 |
wasm.OpcodeI64Add, // e+f+g=18 |
| 2622 |
wasm.OpcodeLocalGet, 7, // h=8 |
| 2623 |
wasm.OpcodeI64Add, // e+f+g+h=26 |
| 2624 |
wasm.OpcodeLocalGet, 8, // i=9 |
| 2625 |
wasm.OpcodeI64Add, // e+f+g+h+i=35 |
| 2626 |
wasm.OpcodeEnd, |
| 2627 |
}, |
| 2628 |
}, |
| 2629 |
}, |
| 2630 |
ExportSection: []wasm.Export{{ |
| 2631 |
Name: ExportedFunctionName, |
| 2632 |
Type: wasm.ExternTypeFunc, |
| 2633 |
Index: 0, // entry function |
| 2634 |
}}, |
| 2635 |
}, |
| 2636 |
} |
| 2637 |
|
| 2638 |
// TailCallManyParams is a tail call that uses stack space as well as registers on both |
| 2639 |
// the amd64 and the arm64 ABIs to use. In these cases we fall back to a plain function call. |
| 2640 |
TailCallManyParams = TestCase{ |
| 2641 |
Name: "tail_call_sqlite_pattern", |
| 2642 |
Module: &wasm.Module{ |
| 2643 |
TypeSection: []wasm.FunctionType{ |
| 2644 |
{Params: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i32}, Results: []wasm.ValueType{i32}}, // type 0: (i32 x 7) -> i32 |
| 2645 |
{Params: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i32, i32}, Results: []wasm.ValueType{i32}}, // type 1: (i32 x 8) -> i32 |
| 2646 |
}, |
| 2647 |
FunctionSection: []wasm.Index{0, 0, 1}, // entry (type 0), caller (type 0), callee (type 1) |
| 2648 |
CodeSection: []wasm.Code{ |
| 2649 |
{ // entry(a,b,c,d,e,f,g) -> caller(a,b,c,d,e,f,g) |
| 2650 |
Body: []byte{ |
| 2651 |
wasm.OpcodeLocalGet, 0, // a |
| 2652 |
wasm.OpcodeLocalGet, 1, // b |
| 2653 |
wasm.OpcodeLocalGet, 2, // c |
| 2654 |
wasm.OpcodeLocalGet, 3, // d |
| 2655 |
wasm.OpcodeLocalGet, 4, // e |
| 2656 |
wasm.OpcodeLocalGet, 5, // f |
| 2657 |
wasm.OpcodeLocalGet, 6, // g |
| 2658 |
wasm.OpcodeCall, 1, // call caller(a,b,c,d,e,f,g) |
| 2659 |
wasm.OpcodeEnd, |
| 2660 |
}, |
| 2661 |
}, |
| 2662 |
// The following reproduces a similar case found in the SQLite codebase |
| 2663 |
{ // caller(a,b,c,d,e,f,g) -> tail call callee(a,b,c,d|128,0,e,f,g) - mimics SQLite's pattern |
| 2664 |
Body: []byte{ |
| 2665 |
wasm.OpcodeLocalGet, 0, // a |
| 2666 |
wasm.OpcodeLocalGet, 1, // b |
| 2667 |
wasm.OpcodeLocalGet, 2, // c |
| 2668 |
wasm.OpcodeLocalGet, 3, // d |
| 2669 |
wasm.OpcodeI32Const, 31, // const 31 (like SQLite) |
| 2670 |
wasm.OpcodeI32And, // d & 31 |
| 2671 |
wasm.OpcodeI32Const, 0x80, 1, // const 128 (like SQLite) |
| 2672 |
wasm.OpcodeI32Or, // (d & 31) | 128 |
| 2673 |
wasm.OpcodeI32Const, 0, // const 0 (like SQLite) |
| 2674 |
wasm.OpcodeLocalGet, 4, // e |
| 2675 |
wasm.OpcodeLocalGet, 5, // f |
| 2676 |
wasm.OpcodeLocalGet, 6, // g |
| 2677 |
wasm.OpcodeTailCallReturnCall, 2, // tail call callee(a,b,c,(d&31)|128,0,e,f,g) |
| 2678 |
wasm.OpcodeEnd, |
| 2679 |
}, |
| 2680 |
}, |
| 2681 |
{ // callee(a,b,c,d,e,f,g,h) -> returns a+b+c+d+e+f+g+h |
| 2682 |
Body: []byte{ |
| 2683 |
wasm.OpcodeLocalGet, 0, |
| 2684 |
wasm.OpcodeLocalGet, 1, |
| 2685 |
wasm.OpcodeI32Add, |
| 2686 |
wasm.OpcodeLocalGet, 2, |
| 2687 |
wasm.OpcodeI32Add, |
| 2688 |
wasm.OpcodeLocalGet, 3, |
| 2689 |
wasm.OpcodeI32Add, |
| 2690 |
wasm.OpcodeLocalGet, 4, |
| 2691 |
wasm.OpcodeI32Add, |
| 2692 |
wasm.OpcodeLocalGet, 5, |
| 2693 |
wasm.OpcodeI32Add, |
| 2694 |
wasm.OpcodeLocalGet, 6, |
| 2695 |
wasm.OpcodeI32Add, |
| 2696 |
wasm.OpcodeLocalGet, 7, |
| 2697 |
wasm.OpcodeI32Add, |
| 2698 |
wasm.OpcodeEnd, |
| 2699 |
}, |
| 2700 |
}, |
| 2701 |
}, |
| 2702 |
ExportSection: []wasm.Export{{ |
| 2703 |
Name: ExportedFunctionName, |
| 2704 |
Type: wasm.ExternTypeFunc, |
| 2705 |
Index: 0, // entry function |
| 2706 |
}}, |
| 2707 |
}, |
| 2708 |
} |
| 2709 |
) |
| 2710 |
|
| 2711 |
// VecShuffleWithLane returns a VecShuffle test with a custom 16-bytes immediate (lane indexes). |
| 2712 |
func VecShuffleWithLane(lane ...byte) *wasm.Module { |
| 2713 |
return &wasm.Module{ |
| 2714 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{v128, v128}, Results: []wasm.ValueType{v128}}}, |
| 2715 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2716 |
FunctionSection: []wasm.Index{0}, |
| 2717 |
CodeSection: []wasm.Code{{ |
| 2718 |
Body: append(append([]byte{ |
| 2719 |
wasm.OpcodeLocalGet, 0, |
| 2720 |
wasm.OpcodeLocalGet, 1, |
| 2721 |
wasm.OpcodeVecPrefix, wasm.OpcodeVecV128i8x16Shuffle, |
| 2722 |
}, lane...), |
| 2723 |
wasm.OpcodeEnd), |
| 2724 |
}}, |
| 2725 |
} |
| 2726 |
} |
| 2727 |
|
| 2728 |
// Exception Handling test cases. |
| 2729 |
|
| 2730 |
// ThrowOnly: a function that always throws tag 0 (no params). |
| 2731 |
// Expected: uncaught exception trap. |
| 2732 |
// |
| 2733 |
// (module |
| 2734 |
// (tag $e) |
| 2735 |
// (func (export "f") (throw $e)) |
| 2736 |
// ) |
| 2737 |
var ThrowOnly = TestCase{ |
| 2738 |
Name: "throw_only", |
| 2739 |
Module: &wasm.Module{ |
| 2740 |
TypeSection: []wasm.FunctionType{vv}, |
| 2741 |
FunctionSection: []wasm.Index{0}, |
| 2742 |
TagSection: []wasm.Tag{{Type: 0}}, |
| 2743 |
CodeSection: []wasm.Code{{ |
| 2744 |
Body: []byte{ |
| 2745 |
wasm.OpcodeThrow, 0, // throw $e (tag index 0) |
| 2746 |
wasm.OpcodeEnd, |
| 2747 |
}, |
| 2748 |
}}, |
| 2749 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2750 |
}, |
| 2751 |
} |
| 2752 |
|
| 2753 |
// ThrowWithParam: throws tag 0 (i32 param) with the function's i32 parameter. |
| 2754 |
// Expected: uncaught exception trap. |
| 2755 |
// |
| 2756 |
// (module |
| 2757 |
// (tag $e (param i32)) |
| 2758 |
// (func (export "f") (param i32) (local.get 0) (throw $e)) |
| 2759 |
// ) |
| 2760 |
var ThrowWithParam = TestCase{ |
| 2761 |
Name: "throw_with_param", |
| 2762 |
Module: &wasm.Module{ |
| 2763 |
TypeSection: []wasm.FunctionType{ |
| 2764 |
{Params: []wasm.ValueType{i32}}, // type 0: tag type (i32) -> () |
| 2765 |
{Params: []wasm.ValueType{i32}}, // type 1: func type (i32) -> () |
| 2766 |
}, |
| 2767 |
FunctionSection: []wasm.Index{1}, |
| 2768 |
TagSection: []wasm.Tag{{Type: 0}}, |
| 2769 |
CodeSection: []wasm.Code{{ |
| 2770 |
Body: []byte{ |
| 2771 |
wasm.OpcodeLocalGet, 0, |
| 2772 |
wasm.OpcodeThrow, 0, // throw $e (tag index 0) |
| 2773 |
wasm.OpcodeEnd, |
| 2774 |
}, |
| 2775 |
}}, |
| 2776 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2777 |
}, |
| 2778 |
} |
| 2779 |
|
| 2780 |
// TryTableCatchAllEmpty: try_table with catch_all where the body does not throw. |
| 2781 |
// The try_table body pushes 42 and returns. catch_all is never triggered. |
| 2782 |
// |
| 2783 |
// (module |
| 2784 |
// (func (export "f") (result i32) |
| 2785 |
// (block $caught ;; catch_all target, expects 0 values |
| 2786 |
// (try_table (catch_all $caught) |
| 2787 |
// (i32.const 42) |
| 2788 |
// (return) |
| 2789 |
// ) |
| 2790 |
// (i32.const 99) |
| 2791 |
// (return) |
| 2792 |
// ) |
| 2793 |
// (i32.const 0) |
| 2794 |
// ) |
| 2795 |
// ) |
| 2796 |
var TryTableCatchAllEmpty = TestCase{ |
| 2797 |
Name: "try_table_catch_all_empty", |
| 2798 |
Module: &wasm.Module{ |
| 2799 |
TypeSection: []wasm.FunctionType{{Results: []wasm.ValueType{i32}}}, |
| 2800 |
FunctionSection: []wasm.Index{0}, |
| 2801 |
CodeSection: []wasm.Code{{ |
| 2802 |
Body: []byte{ |
| 2803 |
// block $caught -- void block (catch_all delivers 0 values) |
| 2804 |
wasm.OpcodeBlock, blockSignature_vv, |
| 2805 |
// try_table (catch_all $caught) -- void block |
| 2806 |
wasm.OpcodeTryTable, blockSignature_vv, |
| 2807 |
1, // catch clause count = 1 |
| 2808 |
wasm.CatchKindCatchAll, // catch_all |
| 2809 |
0, // label index 0 = $caught (try_table not yet on stack) |
| 2810 |
// body: return 42 directly |
| 2811 |
wasm.OpcodeI32Const, 42, |
| 2812 |
wasm.OpcodeReturn, |
| 2813 |
wasm.OpcodeEnd, // end try_table |
| 2814 |
// After try_table (catch_all path): return 99 |
| 2815 |
wasm.OpcodeI32Const, 0xe3, 0x00, // 99 in signed LEB128 |
| 2816 |
wasm.OpcodeReturn, |
| 2817 |
wasm.OpcodeEnd, // end block $caught |
| 2818 |
// Should not reach here. |
| 2819 |
wasm.OpcodeI32Const, 0, |
| 2820 |
wasm.OpcodeEnd, // end function |
| 2821 |
}, |
| 2822 |
}}, |
| 2823 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2824 |
}, |
| 2825 |
} |
| 2826 |
|
| 2827 |
// TryTableCatchAllThrow: try_table with catch_all where the body throws. |
| 2828 |
// The catch_all catches the exception, falls through, and returns 42. |
| 2829 |
// |
| 2830 |
// (module |
| 2831 |
// (tag $e) |
| 2832 |
// (func (export "f") (result i32) |
| 2833 |
// (block $caught |
| 2834 |
// (try_table (catch_all $caught) |
| 2835 |
// (throw $e) |
| 2836 |
// ) |
| 2837 |
// (unreachable) |
| 2838 |
// ) |
| 2839 |
// (i32.const 42) |
| 2840 |
// ) |
| 2841 |
// ) |
| 2842 |
var TryTableCatchAllThrow = TestCase{ |
| 2843 |
Name: "try_table_catch_all_throw", |
| 2844 |
Module: &wasm.Module{ |
| 2845 |
TypeSection: []wasm.FunctionType{vv, {Results: []wasm.ValueType{i32}}}, |
| 2846 |
FunctionSection: []wasm.Index{1}, // func type 1: () -> i32 |
| 2847 |
TagSection: []wasm.Tag{{Type: 0}}, // tag type 0: () -> () |
| 2848 |
CodeSection: []wasm.Code{{ |
| 2849 |
Body: []byte{ |
| 2850 |
wasm.OpcodeBlock, blockSignature_vv, // block $caught |
| 2851 |
wasm.OpcodeTryTable, blockSignature_vv, // try_table |
| 2852 |
1, // 1 catch clause |
| 2853 |
wasm.CatchKindCatchAll, // catch_all |
| 2854 |
0, // label 0 = $caught |
| 2855 |
wasm.OpcodeThrow, 0, // throw tag 0 |
| 2856 |
wasm.OpcodeEnd, // end try_table |
| 2857 |
wasm.OpcodeUnreachable, // after try_table (unreachable) |
| 2858 |
wasm.OpcodeEnd, // end block $caught |
| 2859 |
wasm.OpcodeI32Const, 42, |
| 2860 |
wasm.OpcodeEnd, // end func |
| 2861 |
}, |
| 2862 |
}}, |
| 2863 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2864 |
}, |
| 2865 |
} |
| 2866 |
|
| 2867 |
// TryTableCatchThrow: try_table with catch $e0 (specific tag, no params) where |
| 2868 |
// the body throws. The catch dispatches to the enclosing block. |
| 2869 |
// |
| 2870 |
// (module |
| 2871 |
// (tag $e0) |
| 2872 |
// (func (export "f") (result i32) |
| 2873 |
// (block $h ;; label 0 |
| 2874 |
// (try_table (result i32) (catch $e0 $h) |
| 2875 |
// (throw $e0) |
| 2876 |
// (i32.const 42) |
| 2877 |
// ) |
| 2878 |
// (return) |
| 2879 |
// ) |
| 2880 |
// (i32.const 23) |
| 2881 |
// ) |
| 2882 |
// ) |
| 2883 |
var TryTableCatchThrow = TestCase{ |
| 2884 |
Name: "try_table_catch_throw", |
| 2885 |
Module: &wasm.Module{ |
| 2886 |
TypeSection: []wasm.FunctionType{vv, {Results: []wasm.ValueType{i32}}}, |
| 2887 |
FunctionSection: []wasm.Index{1}, // func type 1: () -> i32 |
| 2888 |
TagSection: []wasm.Tag{{Type: 0}}, // tag type 0: () -> () |
| 2889 |
CodeSection: []wasm.Code{{ |
| 2890 |
Body: []byte{ |
| 2891 |
wasm.OpcodeBlock, blockSignature_vv, // block $h (label 0) |
| 2892 |
wasm.OpcodeTryTable, 0x7F, // try_table (result i32) |
| 2893 |
1, // 1 catch clause |
| 2894 |
wasm.CatchKindCatch, // catch |
| 2895 |
0, // tag index 0 ($e0) |
| 2896 |
0, // label 0 ($h) |
| 2897 |
wasm.OpcodeThrow, 0, // throw tag 0 |
| 2898 |
wasm.OpcodeI32Const, 42, // (unreachable but needed for type) |
| 2899 |
wasm.OpcodeEnd, // end try_table |
| 2900 |
wasm.OpcodeReturn, // return try_table result |
| 2901 |
wasm.OpcodeEnd, // end block $h |
| 2902 |
wasm.OpcodeI32Const, 23, |
| 2903 |
wasm.OpcodeEnd, // end func |
| 2904 |
}, |
| 2905 |
}}, |
| 2906 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2907 |
}, |
| 2908 |
} |
| 2909 |
|
| 2910 |
// TryTableCatchParamThrow: try_table with catch $e-i32 where the tag has an i32 parameter. |
| 2911 |
// The exception parameter is forwarded to the catch target block. |
| 2912 |
// |
| 2913 |
// (module |
| 2914 |
// (tag $e-i32 (param i32)) |
| 2915 |
// (func (export "f") (param i32) (result i32) |
| 2916 |
// (block $h (result i32) |
| 2917 |
// (try_table (result i32) (catch $e-i32 $h) |
| 2918 |
// (throw $e-i32 (local.get 0)) |
| 2919 |
// (i32.const 2) |
| 2920 |
// ) |
| 2921 |
// (return) |
| 2922 |
// ) |
| 2923 |
// (return) |
| 2924 |
// ) |
| 2925 |
// ) |
| 2926 |
var TryTableCatchParamThrow = TestCase{ |
| 2927 |
Name: "try_table_catch_param_throw", |
| 2928 |
Module: &wasm.Module{ |
| 2929 |
TypeSection: []wasm.FunctionType{ |
| 2930 |
{Params: []wasm.ValueType{i32}}, // type 0: (i32) -> () for tag |
| 2931 |
{Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}}, // type 1: (i32) -> (i32) for func |
| 2932 |
}, |
| 2933 |
FunctionSection: []wasm.Index{1}, // func type 1 |
| 2934 |
TagSection: []wasm.Tag{{Type: 0}}, // tag type 0: (i32) -> () |
| 2935 |
CodeSection: []wasm.Code{{ |
| 2936 |
Body: []byte{ |
| 2937 |
wasm.OpcodeBlock, 0x7F, // block $h (result i32) -- label 0 |
| 2938 |
wasm.OpcodeTryTable, 0x7F, // try_table (result i32) |
| 2939 |
1, // 1 catch clause |
| 2940 |
wasm.CatchKindCatch, // catch |
| 2941 |
0, // tag index 0 ($e-i32) |
| 2942 |
0, // label 0 ($h) |
| 2943 |
wasm.OpcodeLocalGet, 0, // local.get 0 |
| 2944 |
wasm.OpcodeThrow, 0, // throw tag 0 |
| 2945 |
wasm.OpcodeI32Const, 2, // (unreachable but needed for type) |
| 2946 |
wasm.OpcodeEnd, // end try_table |
| 2947 |
wasm.OpcodeReturn, // return try_table result |
| 2948 |
wasm.OpcodeEnd, // end block $h |
| 2949 |
wasm.OpcodeReturn, // return |
| 2950 |
wasm.OpcodeEnd, // end func |
| 2951 |
}, |
| 2952 |
}}, |
| 2953 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 2954 |
}, |
| 2955 |
} |
| 2956 |
|
| 2957 |
// TryTableCatchManyParamThrow: try_table with catch $e where the tag has 5 i32 parameters. |
| 2958 |
// This exercises tags with more than 4 parameters, exposing the hardcoded 4-param limit in |
| 2959 |
// caughtExceptionParams [4]uint64. The 5th (and beyond) parameter will be silently dropped |
| 2960 |
// under the current implementation. |
| 2961 |
// |
| 2962 |
// (module |
| 2963 |
// (tag $e (param i32 i32 i32 i32 i32)) |
| 2964 |
// (func (export "f") (param i32 i32 i32 i32 i32) (result i32 i32 i32 i32 i32) |
| 2965 |
// (block $h (result i32 i32 i32 i32 i32) |
| 2966 |
// (try_table (result i32 i32 i32 i32 i32) (catch $e $h) |
| 2967 |
// (local.get 0) |
| 2968 |
// (local.get 1) |
| 2969 |
// (local.get 2) |
| 2970 |
// (local.get 3) |
| 2971 |
// (local.get 4) |
| 2972 |
// (throw $e) |
| 2973 |
// (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) (i32.const 0) |
| 2974 |
// ) |
| 2975 |
// (return) |
| 2976 |
// ) |
| 2977 |
// (return) |
| 2978 |
// ) |
| 2979 |
// ) |
| 2980 |
var TryTableCatchManyParamThrow = TestCase{ |
| 2981 |
Name: "try_table_catch_many_param_throw", |
| 2982 |
Module: &wasm.Module{ |
| 2983 |
TypeSection: []wasm.FunctionType{ |
| 2984 |
{Params: []wasm.ValueType{i32, i32, i32, i32, i32}}, // type 0: (i32x5) -> () for tag |
| 2985 |
{Params: []wasm.ValueType{i32, i32, i32, i32, i32}, Results: []wasm.ValueType{i32, i32, i32, i32, i32}}, // type 1: (i32x5) -> (i32x5) for func |
| 2986 |
{Results: []wasm.ValueType{i32, i32, i32, i32, i32}}, // type 2: () -> (i32x5) for block/try_table |
| 2987 |
}, |
| 2988 |
FunctionSection: []wasm.Index{1}, // func type 1 |
| 2989 |
TagSection: []wasm.Tag{{Type: 0}}, // tag type 0: (i32x5) -> () |
| 2990 |
CodeSection: []wasm.Code{{ |
| 2991 |
Body: []byte{ |
| 2992 |
wasm.OpcodeBlock, 0x02, // block $h (result i32 i32 i32 i32 i32) -- type index 2 |
| 2993 |
wasm.OpcodeTryTable, 0x02, // try_table (result i32 i32 i32 i32 i32) -- type index 2 |
| 2994 |
1, // 1 catch clause |
| 2995 |
wasm.CatchKindCatch, // catch |
| 2996 |
0, // tag index 0 ($e) |
| 2997 |
0, // label 0 ($h) |
| 2998 |
wasm.OpcodeLocalGet, 0, // local.get 0 |
| 2999 |
wasm.OpcodeLocalGet, 1, // local.get 1 |
| 3000 |
wasm.OpcodeLocalGet, 2, // local.get 2 |
| 3001 |
wasm.OpcodeLocalGet, 3, // local.get 3 |
| 3002 |
wasm.OpcodeLocalGet, 4, // local.get 4 |
| 3003 |
wasm.OpcodeThrow, 0, // throw tag 0 |
| 3004 |
wasm.OpcodeI32Const, 0, // unreachable dummy results |
| 3005 |
wasm.OpcodeI32Const, 0, |
| 3006 |
wasm.OpcodeI32Const, 0, |
| 3007 |
wasm.OpcodeI32Const, 0, |
| 3008 |
wasm.OpcodeI32Const, 0, |
| 3009 |
wasm.OpcodeEnd, // end try_table |
| 3010 |
wasm.OpcodeReturn, // return try_table result |
| 3011 |
wasm.OpcodeEnd, // end block $h |
| 3012 |
wasm.OpcodeReturn, // return |
| 3013 |
wasm.OpcodeEnd, // end func |
| 3014 |
}, |
| 3015 |
}}, |
| 3016 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 3017 |
}, |
| 3018 |
} |
| 3019 |
|
| 3020 |
// TryTableCatchWithReturnCall exercises the interaction between try_table and tail calls. |
| 3021 |
// The try_table body performs a conditional: |
| 3022 |
// - param=1: TryTableLeave (pops handler) + return_call $target → returns 99 |
| 3023 |
// - param=0: throw $e (caught by the catch clause) → catch handler returns 42 |
| 3024 |
// |
| 3025 |
// This verifies two things: |
| 3026 |
// |
| 3027 |
// 1. removeUntilRet does not accidentally remove the catch handler block that follows |
| 3028 |
// the tail-call path in the instruction stream. |
| 3029 |
// |
| 3030 |
// 2. TryTableLeave + return_call correctly pass control to the tail callee. |
| 3031 |
// |
| 3032 |
// (module |
| 3033 |
// (tag $e) |
| 3034 |
// (func $target (result i32) (i32.const 99)) |
| 3035 |
// (func (export "f") (param i32) (result i32) |
| 3036 |
// (block $h |
| 3037 |
// (try_table (catch $e $h) |
| 3038 |
// (if (local.get 0) |
| 3039 |
// (then (return_call $target)) |
| 3040 |
// (else (throw $e)) |
| 3041 |
// ) |
| 3042 |
// (unreachable) |
| 3043 |
// ) |
| 3044 |
// (return) |
| 3045 |
// ) |
| 3046 |
// (i32.const 42) |
| 3047 |
// ) |
| 3048 |
// ) |
| 3049 |
var TryTableCatchWithReturnCall = TestCase{ |
| 3050 |
Name: "try_table_catch_with_return_call", |
| 3051 |
Module: &wasm.Module{ |
| 3052 |
TypeSection: []wasm.FunctionType{ |
| 3053 |
vv, // type 0: () -> () for tag $e |
| 3054 |
{Results: []wasm.ValueType{i32}}, // type 1: () -> i32 for $target |
| 3055 |
{Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}}, // type 2: (i32) -> i32 for $f |
| 3056 |
}, |
| 3057 |
FunctionSection: []wasm.Index{1, 2}, // $target = func 0 (type 1), $f = func 1 (type 2) |
| 3058 |
TagSection: []wasm.Tag{{Type: 0}}, |
| 3059 |
CodeSection: []wasm.Code{ |
| 3060 |
{Body: []byte{wasm.OpcodeI32Const, 0xe3, 0x00, wasm.OpcodeEnd}}, // $target: () -> i32 (99 in signed LEB128) |
| 3061 |
{Body: []byte{ |
| 3062 |
// block $h (void) = label 0; catch $e delivers 0 values to label 0. |
| 3063 |
wasm.OpcodeBlock, blockSignature_vv, |
| 3064 |
// try_table (result i32): type is declared even though the body is unreachable |
| 3065 |
// (both if-branches diverge). The result is consumed by the return on the normal |
| 3066 |
// path (which is also unreachable), satisfying the validator. |
| 3067 |
wasm.OpcodeTryTable, 0x7F, |
| 3068 |
1, // 1 catch clause |
| 3069 |
wasm.CatchKindCatch, // catch $e (no params) → label 0 ($h) |
| 3070 |
0, // tag index 0 |
| 3071 |
0, // label 0 ($h) |
| 3072 |
// body: conditional — both branches diverge. |
| 3073 |
wasm.OpcodeLocalGet, 0, |
| 3074 |
wasm.OpcodeIf, blockSignature_vv, // void if — both branches diverge |
| 3075 |
// then: TryTableLeave (pops handler) + return_call $target (tail call) |
| 3076 |
wasm.OpcodeTailCallReturnCall, 0, |
| 3077 |
wasm.OpcodeElse, |
| 3078 |
// else: throw $e → caught by try_table → branches to end of block $h |
| 3079 |
wasm.OpcodeThrow, 0, |
| 3080 |
wasm.OpcodeEnd, // end if |
| 3081 |
wasm.OpcodeUnreachable, // unreachable |
| 3082 |
wasm.OpcodeEnd, // end try_table |
| 3083 |
wasm.OpcodeReturn, // unreachable (never reached) |
| 3084 |
wasm.OpcodeEnd, // end block $h |
| 3085 |
// catch handler: reached when $e is caught (jumped to end of block $h) |
| 3086 |
wasm.OpcodeI32Const, 42, |
| 3087 |
wasm.OpcodeEnd, // end func |
| 3088 |
}}, |
| 3089 |
}, |
| 3090 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 1}}, |
| 3091 |
}, |
| 3092 |
} |
| 3093 |
|
| 3094 |
var LargeMethodBodyWithManyArgs = TestCase{ |
| 3095 |
Name: "large_method_body_with_many_args", |
| 3096 |
Module: &wasm.Module{ |
| 3097 |
TypeSection: []wasm.FunctionType{{Params: []wasm.ValueType{i32, i32, i32, i32, i32, i32, i32, i32, i32}, Results: []wasm.ValueType{i32}}}, |
| 3098 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 3099 |
MemorySection: &wasm.Memory{Min: 1}, |
| 3100 |
FunctionSection: []wasm.Index{0}, |
| 3101 |
CodeSection: []wasm.Code{{ |
| 3102 |
Body: func() []byte { |
| 3103 |
var body bytes.Buffer |
| 3104 |
body.WriteByte(wasm.OpcodeLocalGet) |
| 3105 |
body.Write(leb128.EncodeUint32(8)) |
| 3106 |
body.WriteByte(wasm.OpcodeIf) |
| 3107 |
body.WriteByte(blockSignature_vv) |
| 3108 |
|
| 3109 |
for i := 0; i < 14000; i++ { // 14000 is an arbitrary number large enough to ensure that arm64 needs to introduce conditional branch trampolines |
| 3110 |
body.WriteByte(wasm.OpcodeI32Const) |
| 3111 |
body.Write(leb128.EncodeInt32(int32((i * 4) & 0xfffc))) // arbitrary constant that depends on the loop index |
| 3112 |
body.WriteByte(wasm.OpcodeLocalGet) |
| 3113 |
body.Write(leb128.EncodeUint32(8)) |
| 3114 |
body.WriteByte(wasm.OpcodeI32Store) |
| 3115 |
body.WriteByte(2) // align (log2) |
| 3116 |
body.WriteByte(0) // offset |
| 3117 |
} |
| 3118 |
body.WriteByte(wasm.OpcodeEnd) // end if |
| 3119 |
body.WriteByte(wasm.OpcodeLocalGet) |
| 3120 |
body.Write(leb128.EncodeUint32(8)) |
| 3121 |
body.WriteByte(wasm.OpcodeEnd) // end function |
| 3122 |
|
| 3123 |
return body.Bytes() |
| 3124 |
}(), |
| 3125 |
}}, |
| 3126 |
}, |
| 3127 |
} |
| 3128 |
|
| 3129 |
type TestCase struct { |
| 3130 |
Name string |
| 3131 |
Imported, Module *wasm.Module |
| 3132 |
} |
| 3133 |
|
| 3134 |
func SingleFunctionModule(typ wasm.FunctionType, body []byte, localTypes []wasm.ValueType) *wasm.Module { |
| 3135 |
return &wasm.Module{ |
| 3136 |
TypeSection: []wasm.FunctionType{typ}, |
| 3137 |
FunctionSection: []wasm.Index{0}, |
| 3138 |
CodeSection: []wasm.Code{{ |
| 3139 |
LocalTypes: localTypes, |
| 3140 |
Body: body, |
| 3141 |
}}, |
| 3142 |
ExportSection: []wasm.Export{{Name: ExportedFunctionName, Type: wasm.ExternTypeFunc, Index: 0}}, |
| 3143 |
} |
| 3144 |
} |
| 3145 |
|
| 3146 |
var ( |
| 3147 |
vv = wasm.FunctionType{} |
| 3148 |
v_i32 = wasm.FunctionType{Results: []wasm.ValueType{i32}} |
| 3149 |
v_i32i32 = wasm.FunctionType{Results: []wasm.ValueType{i32, i32}} |
| 3150 |
i32_v = wasm.FunctionType{Params: []wasm.ValueType{i32}} |
| 3151 |
i32_i32 = wasm.FunctionType{Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32}} |
| 3152 |
i32i32_i32 = wasm.FunctionType{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32}} |
| 3153 |
i32i32_i32i32 = wasm.FunctionType{Params: []wasm.ValueType{i32, i32}, Results: []wasm.ValueType{i32, i32}} |
| 3154 |
i32i32i64i64f32f32f64f64_i32i64 = wasm.FunctionType{Params: []wasm.ValueType{i32, i32, i64, i64, f32, f32, f64, f64}, Results: []wasm.ValueType{i32, i64, f32, f64}} |
| 3155 |
i32_i32i32 = wasm.FunctionType{Params: []wasm.ValueType{i32}, Results: []wasm.ValueType{i32, i32}} |
| 3156 |
i32f32f64_v = wasm.FunctionType{Params: []wasm.ValueType{i32, f32, f64}, Results: nil} |
| 3157 |
i64f32f64_i64f32f64 = wasm.FunctionType{Params: []wasm.ValueType{i64, f32, f64}, Results: []wasm.ValueType{i64, f32, f64}} |
| 3158 |
) |
| 3159 |
|
| 3160 |
const ( |
| 3161 |
i32 = wasm.ValueTypeI32 |
| 3162 |
i64 = wasm.ValueTypeI64 |
| 3163 |
f32 = wasm.ValueTypeF32 |
| 3164 |
f64 = wasm.ValueTypeF64 |
| 3165 |
v128 = wasm.ValueTypeV128 |
| 3166 |
|
| 3167 |
blockSignature_vv = 0x40 // 0x40 is the v_v signature in 33-bit signed. See wasm.DecodeBlockType. |
| 3168 |
) |
| 3169 |
|
| 3170 |
func maskedBuf(size int) []byte { |
| 3171 |
ret := make([]byte, size) |
| 3172 |
for i := range ret { |
| 3173 |
ret[i] = byte(i) |
| 3174 |
} |
| 3175 |
return ret |
| 3176 |
} |
| 3177 |
|
| 3178 |
func constExprI32(i int32) wasm.ConstantExpression { |
| 3179 |
return wasm.NewConstantExpressionFromI32(i) |
| 3180 |
} |
| 3181 |
|
| 3182 |
func constExprI64(i int64) wasm.ConstantExpression { |
| 3183 |
return wasm.NewConstantExpressionFromI64(i) |
| 3184 |
} |
| 3185 |
|
| 3186 |
func constExprF32(i float32) wasm.ConstantExpression { |
| 3187 |
b := math.Float32bits(i) |
| 3188 |
return wasm.NewConstantExpressionFromOpcode( |
| 3189 |
wasm.OpcodeF32Const, []byte{ |
| 3190 |
byte(b), byte(b >> 8), byte(b >> 16), byte(b >> 24), |
| 3191 |
}, |
| 3192 |
) |
| 3193 |
} |
| 3194 |
|
| 3195 |
func constExprF64(i float64) wasm.ConstantExpression { |
| 3196 |
b := math.Float64bits(i) |
| 3197 |
return wasm.NewConstantExpressionFromOpcode( |
| 3198 |
wasm.OpcodeF64Const, []byte{ |
| 3199 |
byte(b), byte(b >> 8), byte(b >> 16), byte(b >> 24), |
| 3200 |
byte(b >> 32), byte(b >> 40), byte(b >> 48), byte(b >> 56), |
| 3201 |
}, |
| 3202 |
) |
| 3203 |
} |
| 3204 |
|
| 3205 |
func constExprV128(lo, hi uint64) wasm.ConstantExpression { |
| 3206 |
return wasm.NewConstantExpressionFromOpcode( |
| 3207 |
wasm.OpcodeVecV128Const, |
| 3208 |
[]byte{ |
| 3209 |
byte(lo), byte(lo >> 8), byte(lo >> 16), byte(lo >> 24), |
| 3210 |
byte(lo >> 32), byte(lo >> 40), byte(lo >> 48), byte(lo >> 56), |
| 3211 |
byte(hi), byte(hi >> 8), byte(hi >> 16), byte(hi >> 24), |
| 3212 |
byte(hi >> 32), byte(hi >> 40), byte(hi >> 48), byte(hi >> 56), |
| 3213 |
}, |
| 3214 |
) |
| 3215 |
} |