зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1770688 - Move common testing functions to lib/wasm.js. r=jseward
Move a number of Array-oriented testing functions to lib/wasm.js, as we keep copying them from file to file, with variations. The main sticking point here was actually that the simd tests include a common testing file using an include: directive, but this directive is processed before the common include: directive that loads wasm.js. Unfortunately the present patch creates a dependency wherein the simd common testing file will depend on wasm.js being loaded first. To fix the dependency order the simd tests were updated to load the common testing file explicitly, and this load will happen after wasm.js is loaded. Differential Revision: https://phabricator.services.mozilla.com/D147053
This commit is contained in:
Родитель
179572cc9c
Коммит
1730bd17ff
|
@ -462,3 +462,76 @@ let WasmNonNullExternrefValues = [
|
|||
...WasmNonNullEqrefValues
|
||||
];
|
||||
let WasmExternrefValues = [null, ...WasmNonNullExternrefValues];
|
||||
|
||||
// Common array utilities
|
||||
|
||||
// iota(n) creates an Array of length n with values 0..n-1
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
// cross(A) where A is an array of length n creates an Array length n*n of
|
||||
// two-element Arrays representing all pairs of elements of A.
|
||||
function cross(xs) {
|
||||
let results = [];
|
||||
for ( let x of xs )
|
||||
for ( let y of xs )
|
||||
results.push([x,y]);
|
||||
return results;
|
||||
}
|
||||
|
||||
// Remove all values equal to v from an array xs, comparing equal for NaN.
|
||||
function remove(v, xs) {
|
||||
let result = [];
|
||||
for ( let w of xs ) {
|
||||
if (v === w || isNaN(v) && isNaN(w))
|
||||
continue;
|
||||
result.push(w);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// permute(A) where A is an Array returns an Array of Arrays, each inner Array a
|
||||
// distinct permutation of the elements of A. A is assumed not to have any
|
||||
// elements that are pairwise equal in the sense of remove().
|
||||
function permute(xs) {
|
||||
if (xs.length == 1)
|
||||
return [xs];
|
||||
let results = [];
|
||||
for (let v of xs)
|
||||
for (let tail of permute(remove(v, xs)))
|
||||
results.push([v, ...tail]);
|
||||
return results;
|
||||
}
|
||||
|
||||
// interleave([a,b,c,...],[0,1,2,...]) => [a,0,b,1,c,2,...]
|
||||
function interleave(xs, ys) {
|
||||
assertEq(xs.length, ys.length);
|
||||
let res = [];
|
||||
for ( let i=0 ; i < xs.length; i++ ) {
|
||||
res.push(xs[i]);
|
||||
res.push(ys[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// assertSame([a,...],[b,...]) asserts that the two arrays have the same length
|
||||
// and that they element-wise assertEq IGNORING Number/BigInt differences. This
|
||||
// predicate is in this file because it is wasm-specific.
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
let g = got[i];
|
||||
let e = expected[i];
|
||||
if (typeof g != typeof e) {
|
||||
if (typeof g == "bigint")
|
||||
e = BigInt(e);
|
||||
else if (typeof e == "bigint")
|
||||
g = BigInt(g);
|
||||
}
|
||||
assertEq(g, e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,3 @@ function getFuncBody(dis) {
|
|||
const parts = dis.split(/mov %rsp, %rbp\n|^[0-9A-Fa-f ]+pop %rbp/gm);
|
||||
return parts.at(-2).replace(/[0-9A-F]{8} (?: [0-9a-f]{2})+[\s\n]+/g, "");
|
||||
}
|
||||
function iota(len) {
|
||||
return Array(len).fill(null).map((_, i) => i);
|
||||
}
|
||||
|
|
|
@ -72,10 +72,3 @@ for (let v of WasmExternrefValues)
|
|||
assertEq(typeof x[9], "object");
|
||||
assertEq(x[9].x, 9);
|
||||
}
|
||||
|
||||
function iota(k) {
|
||||
let a = new Array(k);
|
||||
for ( let i=0 ; i < k; i++ )
|
||||
a[i] = i;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1573,27 +1573,3 @@ if (getBuildConfiguration()["pointer-byte-size"] == 8) {
|
|||
assertEq(mem[Number(oobTarget-1n)], 0);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
let g = got[i];
|
||||
let e = expected[i];
|
||||
if (typeof g != typeof e) {
|
||||
if (typeof g == "bigint")
|
||||
e = BigInt(e);
|
||||
else if (typeof e == "bigint")
|
||||
g = BigInt(g);
|
||||
}
|
||||
assertEq(g, e);
|
||||
}
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
// Testing runtime execution of select + comparison operations.
|
||||
// Normally they are folded into shorter/faster sequence than select alone.
|
||||
|
||||
function cross(xs) {
|
||||
let results = [];
|
||||
for ( let x of xs )
|
||||
for ( let y of xs )
|
||||
results.push([x,y]);
|
||||
return results;
|
||||
}
|
||||
|
||||
const floatOps = {
|
||||
lt(a, b) { return a < b ? 0 : 1; },
|
||||
le(a, b) { return a <= b ? 0 : 1; },
|
||||
|
@ -85,12 +77,3 @@ for (let [ty, signed] of [['i32', true], ['i32', false], ['i64', true], ['i64',
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function cross(xs) {
|
||||
let results = [];
|
||||
for ( let x of xs )
|
||||
for ( let y of xs )
|
||||
results.push([x,y]);
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled() || wasmCompileMode().indexOf("cranelift") >= 0; include:../tests/wasm/simd/ad-hack-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled() || wasmCompileMode().indexOf("cranelift") >= 0
|
||||
|
||||
// Do not include this in the preamble, it must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
|
||||
// New instructions, not yet supported by cranelift
|
||||
|
||||
|
|
|
@ -45,61 +45,10 @@ function setUnaligned(arr, width, loc, vals) {
|
|||
}
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
let g = got[i];
|
||||
let e = expected[i];
|
||||
if (typeof g != typeof e) {
|
||||
if (typeof g == "bigint")
|
||||
e = BigInt(e);
|
||||
else if (typeof e == "bigint")
|
||||
g = BigInt(g);
|
||||
}
|
||||
assertEq(g, e);
|
||||
}
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
function cross(xs) {
|
||||
let results = [];
|
||||
for ( let x of xs )
|
||||
for ( let y of xs )
|
||||
results.push([x,y]);
|
||||
return results;
|
||||
}
|
||||
|
||||
function equal(a, b) {
|
||||
return a === b || isNaN(a) && isNaN(b);
|
||||
}
|
||||
|
||||
// Remove a value v from an array xs, comparing equal for NaN.
|
||||
function remove(v, xs) {
|
||||
let result = [];
|
||||
for ( let w of xs ) {
|
||||
if (equal(v, w))
|
||||
continue;
|
||||
result.push(w);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function permute(xs) {
|
||||
if (xs.length == 1)
|
||||
return [xs];
|
||||
let results = [];
|
||||
for (let v of xs)
|
||||
for (let tail of permute(remove(v, xs)))
|
||||
results.push([v, ...tail]);
|
||||
return results;
|
||||
}
|
||||
|
||||
function upd(xs, at, val) {
|
||||
let ys = Array.from(xs);
|
||||
ys[at] = val;
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled(); include:../tests/wasm/simd/ad-hack-preamble.js; include:../tests/wasm/simd/ad-hack-binop-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled()
|
||||
|
||||
// Do not include these in the preamble, they must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
load(scriptdir + "ad-hack-binop-preamble.js")
|
||||
|
||||
runSimpleBinopTest(0, 3);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled(); include:../tests/wasm/simd/ad-hack-preamble.js; include:../tests/wasm/simd/ad-hack-binop-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled()
|
||||
|
||||
// Do not include these in the preamble, they must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
load(scriptdir + "ad-hack-binop-preamble.js")
|
||||
|
||||
runSimpleBinopTest(1, 3);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled(); include:../tests/wasm/simd/ad-hack-preamble.js; include:../tests/wasm/simd/ad-hack-binop-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled()
|
||||
|
||||
// Do not include these in the preamble, they must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
load(scriptdir + "ad-hack-binop-preamble.js")
|
||||
|
||||
runSimpleBinopTest(2, 3);
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled(); include:../tests/wasm/simd/ad-hack-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled()
|
||||
|
||||
// Do not include this in the preamble, it must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
|
||||
// Simple unary operators. Place parameter in memory at offset 16,
|
||||
// read the result at offset 0.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// |jit-test| skip-if: !wasmSimdEnabled(); include:../tests/wasm/simd/ad-hack-preamble.js
|
||||
// |jit-test| skip-if: !wasmSimdEnabled()
|
||||
|
||||
// Ad-hoc test cases used during development. Generally these are ordered from
|
||||
// easier toward harder.
|
||||
|
@ -7,6 +7,9 @@
|
|||
// Simple binary operators (v128 x v128 -> v128) and unary operators (v128 ->
|
||||
// v128) are tested in ad-hack-simple-binops*.js and ad-hack-simple-unops.js.
|
||||
|
||||
// Do not include this in the preamble, it must be loaded after lib/wasm.js
|
||||
load(scriptdir + "ad-hack-preamble.js")
|
||||
|
||||
// v128.store
|
||||
// oob store
|
||||
// v128.const
|
||||
|
|
|
@ -94,20 +94,6 @@ ${suffix}
|
|||
assertSame(get(mem, 0, 16), values);
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
assertEq(got[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function get(arr, loc, len) {
|
||||
let res = [];
|
||||
for ( let i=0; i < len; i++ ) {
|
||||
|
|
|
@ -33,28 +33,6 @@ function set(arr, loc, vals) {
|
|||
}
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
let g = got[i];
|
||||
let e = expected[i];
|
||||
if (typeof g != typeof e) {
|
||||
if (typeof g == "bigint")
|
||||
e = BigInt(e);
|
||||
else if (typeof e == "bigint")
|
||||
g = BigInt(g);
|
||||
}
|
||||
assertEq(g, e);
|
||||
}
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
const v2vSig = {args:[], ret:VoidCode};
|
||||
|
||||
function V128Load(addr) {
|
||||
|
@ -431,12 +409,3 @@ for (let ai = 0; ai < testNeg.length - 15; ai++)
|
|||
assertEq(expected, result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Misc utils.
|
||||
function cross(xs) {
|
||||
let results = [];
|
||||
for ( let x of xs )
|
||||
for ( let y of xs )
|
||||
results.push([x,y]);
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -872,28 +872,6 @@ function set(arr, loc, vals) {
|
|||
}
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
assertEq(got[i], expected[i]);
|
||||
}
|
||||
}
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
function interleave(xs, ys) {
|
||||
let res = [];
|
||||
for ( let i=0 ; i < xs.length; i++ ) {
|
||||
res.push(xs[i]);
|
||||
res.push(ys[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function i32ToI8(xs) {
|
||||
return xs.map(x => [x*4, x*4+1, x*4+2, x*4+3]).flat();
|
||||
}
|
||||
|
|
|
@ -153,11 +153,3 @@ if (hasDisassembler() && isX64) {
|
|||
// No leftover PMULL, PSLLW, or PSRAW.
|
||||
assertEq(/pmullw|psllw|psraw/.test(output), false);
|
||||
}
|
||||
|
||||
// Misc utils.
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
assertEq(got[i], expected[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,22 +18,6 @@ function get(arr, loc, len) {
|
|||
return res;
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
for ( let i=0; i < got.length; i++ ) {
|
||||
let g = got[i];
|
||||
let e = expected[i];
|
||||
assertEq(g, e);
|
||||
}
|
||||
}
|
||||
|
||||
for ( let offset of iota(16) ) {
|
||||
var ins = wasmEvalText(`
|
||||
(module
|
||||
|
|
|
@ -63,15 +63,3 @@ function get(arr, loc, len) {
|
|||
function set(arr, loc, vals) {
|
||||
iota(vals.length).map(i => arr[loc+i] = vals[i]);
|
||||
}
|
||||
|
||||
function assertSame(got, expected) {
|
||||
assertEq(got.length, expected.length);
|
||||
iota(got.length).map(i => assertEq(got[i], expected[i]));
|
||||
}
|
||||
|
||||
function iota(len) {
|
||||
let xs = [];
|
||||
for ( let i=0 ; i < len ; i++ )
|
||||
xs.push(i);
|
||||
return xs;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче