v8/test/mjsunit/wasm/liftoff-simd-params.js
Manos Koukoutos 79a1468831 [wasm][wasm-gc][test] Improve and extend Javascript testing API
Changes:
- Add possibility to define and emit all reference types.
- Simplify function locals definition.
- Change 'type' to 'type_index' where appropiate.

Bug: v8:7748
Change-Id: Ie35a6204369e678298ee2ff2ec7c7793c5315c3e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2390144
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: Thibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69814}
2020-09-10 14:32:00 +00:00

78 lines
3.3 KiB
JavaScript

// Copyright 2020 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-simd
load('test/mjsunit/wasm/wasm-module-builder.js');
// This test case tries to exercise SIMD stack to stack movements by creating
// a function that has many parameters.
(function() {
const builder = new WasmModuleBuilder();
// At this point we have limited support for SIMD operations, but we can load
// and store s128 values. So this memory will be used for reading and writing
// s128 values and we will assert expected values from JS.
builder.addImportedMemory('m', 'imported_mem', 1, 2);
builder.addType(makeSig(new Array(18).fill(kWasmS128), []));
builder.addFunction(undefined, makeSig([], []))
.addLocals(kWasmS128, 9)
.addBodyWithEnd([
// These will all be args to the callee.
// Load first arg from memory, this was written with values from JS.
kExprI32Const, 0, // i32.const
kSimdPrefix, kExprS128LoadMem, 0, 0, // s128.load
kExprLocalGet, 0, // local.get
kExprLocalGet, 1, // local.get
kExprLocalGet, 2, // local.get
kExprLocalGet, 3, // local.get
kExprLocalGet, 4, // local.get
kExprLocalGet, 5, // local.get
kExprLocalGet, 6, // local.get
kExprLocalGet, 7, // local.get
kExprLocalGet, 8, // local.get
kExprLocalGet, 0, // local.get
kExprLocalGet, 1, // local.get
kExprLocalGet, 2, // local.get
kExprLocalGet, 3, // local.get
kExprLocalGet, 4, // local.get
kExprLocalGet, 5, // local.get
kExprLocalGet, 6, // local.get
// Load last s128 from memory, this was written with values from JS.
kExprI32Const, 16, // i32.const
kSimdPrefix, kExprS128LoadMem, 0, 0, // s128.load
kExprCallFunction, 0x01, // call
kExprEnd, // end
]);
builder.addFunction(undefined, 0 /* sig */).addBodyWithEnd([
kExprI32Const, 32, // i32.const
kExprLocalGet, 0, // local.get
kSimdPrefix, kExprS128StoreMem, 0, 0, // s128.store
kExprI32Const, 48, // i32.const
kExprLocalGet, 17, // local.get
kSimdPrefix, kExprS128StoreMem, 0, 0, // s128.store
kExprEnd, // end
]);
builder.addExport('main', 0);
var memory = new WebAssembly.Memory({initial: 1, maximum: 2});
const instance = builder.instantiate({m: {imported_mem: memory}});
// We write sentinel values to two s128 values at the start of the memory.
// Function 1 will read these values from memory, and pass them as the first
// and last arg to function 2. Function 2 then write these values to memory
// after these two s128 values.
const arr = new Uint32Array(memory.buffer);
for (let i = 0; i < 8; i++) {
arr[0] = i * 2;
}
instance.exports.main();
for (let i = 0; i < 8; i++) {
assertEquals(arr[i], arr[i + 8]);
}
})();