summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/wasm/loop-unrolling.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/wasm/loop-unrolling.js')
-rw-r--r--deps/v8/test/mjsunit/wasm/loop-unrolling.js146
1 files changed, 146 insertions, 0 deletions
diff --git a/deps/v8/test/mjsunit/wasm/loop-unrolling.js b/deps/v8/test/mjsunit/wasm/loop-unrolling.js
new file mode 100644
index 0000000000..b0e125413f
--- /dev/null
+++ b/deps/v8/test/mjsunit/wasm/loop-unrolling.js
@@ -0,0 +1,146 @@
+// Copyright 2021 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --experimental-wasm-typed-funcref --experimental-wasm-eh
+// Flags: --wasm-loop-unrolling
+// Needed for exceptions-utils.js.
+// Flags: --allow-natives-syntax
+
+load("test/mjsunit/wasm/wasm-module-builder.js");
+load("test/mjsunit/wasm/exceptions-utils.js");
+
+// Test the interaction between multireturn and loop unrolling.
+(function MultiBlockResultTest() {
+ let builder = new WasmModuleBuilder();
+
+ builder.addFunction("main", kSig_i_i)
+ .addBody([
+ ...wasmI32Const(1),
+ kExprLet, kWasmStmt, 1, 1, kWasmI32,
+ kExprLoop, kWasmStmt,
+ ...wasmI32Const(10),
+ kExprLet, kWasmStmt, 1, 1, kWasmI32,
+ kExprLocalGet, 0,
+ kExprLocalGet, 1,
+ kExprI32Sub,
+ kExprLocalGet, 2,
+ kExprI32Add,
+ kExprReturn, // (second let) - (first let) + parameter
+ kExprEnd,
+ kExprEnd,
+ kExprEnd,
+ ...wasmI32Const(0)])
+ .exportAs("main");
+
+ let module = new WebAssembly.Module(builder.toBuffer());
+ let instance = new WebAssembly.Instance(module);
+ assertEquals(instance.exports.main(100), 109);
+})();
+
+// Test the interaction between the eh proposal and loop unrolling.
+
+(function TestRethrowNested() {
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ let except1 = builder.addException(kSig_v_v);
+ let except2 = builder.addException(kSig_v_v);
+ builder.addFunction("rethrow_nested", kSig_i_i)
+ .addBody([
+ kExprLoop, kWasmI32,
+ kExprTry, kWasmI32,
+ kExprLoop, kWasmI32,
+ kExprThrow, except2,
+ kExprEnd,
+ kExprCatch, except2,
+ kExprTry, kWasmI32,
+ kExprThrow, except1,
+ kExprCatch, except1,
+ kExprLocalGet, 0,
+ kExprI32Const, 0,
+ kExprI32Eq,
+ kExprIf, kWasmStmt,
+ kExprLoop, kWasmStmt,
+ kExprRethrow, 2,
+ kExprEnd,
+ kExprEnd,
+ kExprLocalGet, 0,
+ kExprI32Const, 1,
+ kExprI32Eq,
+ kExprIf, kWasmStmt,
+ kExprLoop, kWasmStmt,
+ kExprRethrow, 3,
+ kExprEnd,
+ kExprEnd,
+ kExprI32Const, 23,
+ kExprEnd,
+ kExprEnd,
+ kExprEnd])
+ .exportFunc();
+ let instance = builder.instantiate();
+
+ assertWasmThrows(instance, except1, [],
+ () => instance.exports.rethrow_nested(0));
+ assertWasmThrows(instance, except2, [],
+ () => instance.exports.rethrow_nested(1));
+ assertEquals(23, instance.exports.rethrow_nested(2));
+})();
+
+(function TestThrow() {
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ let except1 = builder.addException(kSig_v_v);
+ builder.addFunction("throw", kSig_i_i)
+ .addBody([
+ kExprLoop, kWasmStmt,
+ kExprLocalGet, 0,
+ kExprI32Const, 10,
+ kExprI32GtS,
+ kExprIf, kWasmStmt,
+ kExprThrow, except1,
+ kExprElse,
+ kExprLocalGet, 0,
+ kExprI32Const, 1,
+ kExprI32Add,
+ kExprLocalSet, 0,
+ kExprBr, 1,
+ kExprEnd,
+ kExprEnd,
+ kExprLocalGet, 0
+ ])
+ .exportFunc();
+
+ let instance = builder.instantiate();
+ assertWasmThrows(instance, except1, [], ()=>instance.exports.throw(0));
+})();
+
+(function TestThrowCatch() {
+ print(arguments.callee.name);
+ let builder = new WasmModuleBuilder();
+ let except1 = builder.addException(kSig_v_v);
+ builder.addFunction("throw_catch", kSig_i_i)
+ .addBody([
+ kExprLoop, kWasmI32,
+ kExprTry, kWasmI32,
+ kExprLocalGet, 0,
+ kExprI32Const, 10,
+ kExprI32GtS,
+ kExprIf, kWasmStmt,
+ kExprThrow, except1,
+ kExprElse,
+ kExprLocalGet, 0,
+ kExprI32Const, 1,
+ kExprI32Add,
+ kExprLocalSet, 0,
+ kExprBr, 2,
+ kExprEnd,
+ kExprLocalGet, 0,
+ kExprCatch, except1,
+ kExprLocalGet, 0,
+ kExprEnd,
+ kExprEnd])
+ .exportFunc();
+
+ let instance = builder.instantiate();
+ assertEquals(11, instance.exports.throw_catch(0));
+})();