node/deps/v8/test/mjsunit/wasm/deopt/deopt-many-params.js
Michaël Zasso 9d7cd9b864
deps: update V8 to 12.8.374.13
PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:03:01 +02:00

65 lines
2.1 KiB
JavaScript

// Copyright 2024 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: --wasm-deopt --allow-natives-syntax --turboshaft-wasm
// Flags: --experimental-wasm-inlining --liftoff
// Flags: --turboshaft-wasm-instruction-selection-staged
// Flags: --wasm-inlining-ignore-call-counts --no-jit-fuzzing
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
(function TestManyParams() {
let paramCount = 12;
let builder = new WasmModuleBuilder();
let calleeParams = new Array(paramCount).fill(kWasmI32);
let funcRefT = builder.addType(makeSig(calleeParams, [kWasmI32]));
builder.addFunction("add", funcRefT)
.addBody(generateCalleeBody(kExprI32Add)).exportFunc();
builder.addFunction("sub", funcRefT)
.addBody(generateCalleeBody(kExprI32Sub)).exportFunc();
let mainParams = [...calleeParams, wasmRefType(funcRefT)];
builder.addFunction("main", makeSig(mainParams, [kWasmI32]))
.addBody([
...pushArgs(paramCount + 1),
kExprCallRef, funcRefT,
]).exportFunc();
// [0, 1, ..., paramCount - 1]
let values = [...Array(paramCount).keys()];
let expectedSum = values.reduce((a, b) => a + b);
let expectedDiff = values.reduce((a, b) => a - b);
assertEquals(expectedSum, -expectedDiff);
let wasm = builder.instantiate().exports;
assertEquals(expectedSum, wasm.main(...values, wasm.add));
%WasmTierUpFunction(wasm.main);
assertEquals(expectedSum, wasm.main(...values, wasm.add));
if (%IsolateCountForTesting() == 1) {
assertTrue(%IsTurboFanFunction(wasm.main));
}
assertEquals(expectedDiff, wasm.main(...values, wasm.sub));
if (%IsolateCountForTesting() == 1) {
assertFalse(%IsTurboFanFunction(wasm.main));
}
function generateCalleeBody(binop) {
let result = [kExprLocalGet, 0];
for (let i = 1; i < paramCount; ++i) {
result.push(kExprLocalGet, i, binop);
}
return result;
}
function pushArgs(paramCount) {
let result = [];
for (let i = 0; i < paramCount; ++i) {
result.push(kExprLocalGet, i);
}
return result;
}
})();