OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm --wasm-num-compilation-tasks=10 |
| 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 |
| 10 (function CompileFunctionsTest() { |
| 11 |
| 12 var builder = new WasmModuleBuilder(); |
| 13 |
| 14 builder.addMemory(1, 1, true); |
| 15 for (i = 0; i < 1000; i++) { |
| 16 builder.addFunction("sub" + i, kSig_i_i) |
| 17 .addBody([ // -- |
| 18 kExprGetLocal, 0, // -- |
| 19 kExprI32Const, i % 61, // -- |
| 20 kExprI32Sub]) // -- |
| 21 .exportFunc() |
| 22 } |
| 23 |
| 24 var module = builder.instantiate(); |
| 25 assertModule(module, kPageSize); |
| 26 |
| 27 // Check the properties of the functions. |
| 28 for (i = 0; i < 1000; i++) { |
| 29 var sub = assertFunction(module, "sub" + i); |
| 30 assertEquals(33 - (i % 61), sub(33)); |
| 31 } |
| 32 })(); |
| 33 |
| 34 (function CallFunctionsTest() { |
| 35 |
| 36 var builder = new WasmModuleBuilder(); |
| 37 |
| 38 var f = [] |
| 39 |
| 40 f[0] = builder.addFunction("add0", kSig_i_ii) |
| 41 .addBody([ |
| 42 kExprGetLocal, 0, // -- |
| 43 kExprGetLocal, 1, // -- |
| 44 kExprI32Add, // -- |
| 45 ]) |
| 46 .exportFunc() |
| 47 |
| 48 builder.addMemory(1, 1, true); |
| 49 for (i = 1; i < 256; i++) { |
| 50 f[i] = builder.addFunction("add" + i, kSig_i_ii) |
| 51 .addBody([ // -- |
| 52 kExprGetLocal, 0, // -- |
| 53 kExprGetLocal, 1, // -- |
| 54 kExprCallFunction, kArity2, f[i >>> 1].index]) // -- |
| 55 .exportFunc() |
| 56 } |
| 57 var module = builder.instantiate(); |
| 58 assertModule(module, kPageSize); |
| 59 |
| 60 // Check the properties of the functions. |
| 61 for (i = 0; i < 256; i++) { |
| 62 var add = assertFunction(module, "add" + i); |
| 63 assertEquals(88, add(33, 55)); |
| 64 assertEquals(88888, add(33333, 55555)); |
| 65 assertEquals(8888888, add(3333333, 5555555)); |
| 66 } |
| 67 })(); |
OLD | NEW |