Commit 46a49fdf authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Split large asm.js test into parts.

R=sigurds@chromium.org
TEST=mjsunit/wasm/asm-wasm
BUG=v8:8038

NOTREECHECKS=true

Change-Id: Id12226116aae1b12c8cc948b28097c1dc126f17c
Reviewed-on: https://chromium-review.googlesource.com/1169046
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55023}
parent 3c1f40de
// Copyright 2018 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: --validate-asm --allow-natives-syntax
var stdlib = this;
function assertValidAsm(func) {
assertTrue(%IsAsmWasmCode(func), "must be valid asm code");
}
function assertWasm(expected, func, ffi) {
print("Testing " + func.name + "...");
assertEquals(
expected, func(stdlib, ffi, new ArrayBuffer(1024)).caller());
assertValidAsm(func);
}
function TestForeignFunctions() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var setVal = foreign.setVal;
var getVal = foreign.getVal;
function caller(initial_value, new_value) {
initial_value = initial_value|0;
new_value = new_value|0;
if ((getVal()|0) == (initial_value|0)) {
setVal(new_value|0);
return getVal()|0;
}
return 0;
}
return {caller:caller};
}
function ffi(initial_val) {
var val = initial_val;
function getVal() {
return val;
}
function setVal(new_val) {
val = new_val;
}
return {getVal:getVal, setVal:setVal};
}
var foreign = new ffi(23);
var module = AsmModule({Math: Math}, foreign, null);
assertValidAsm(AsmModule);
assertEquals(103, module.caller(23, 103));
}
print("TestForeignFunctions...");
TestForeignFunctions();
function TestForeignFunctionMultipleUse() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var getVal = foreign.getVal;
function caller(int_val, double_val) {
int_val = int_val|0;
double_val = +double_val;
if ((getVal()|0) == (int_val|0)) {
if ((+getVal()) == (+double_val)) {
return 89;
}
}
return 0;
}
return {caller:caller};
}
function ffi() {
function getVal() {
return 83.25;
}
return {getVal:getVal};
}
var foreign = new ffi();
var module_decl = eval('(' + AsmModule.toString() + ')');
var module = module_decl(stdlib, foreign, null);
assertValidAsm(module_decl);
assertEquals(89, module.caller(83, 83.25));
}
print("TestForeignFunctionMultipleUse...");
TestForeignFunctionMultipleUse();
function TestForeignVariables() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var i1 = foreign.foo | 0;
var f1 = +foreign.bar;
var i2 = foreign.baz | 0;
var f2 = +foreign.baz;
function geti1() {
return i1|0;
}
function getf1() {
return +f1;
}
function geti2() {
return i2|0;
}
function getf2() {
return +f2;
}
return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2};
}
function TestCase(env, i1, f1, i2, f2) {
print("Testing foreign variables...");
var module_decl = eval('(' + AsmModule.toString() + ')');
var module = module_decl(stdlib, env);
assertValidAsm(module_decl);
assertEquals(i1, module.geti1());
assertEquals(f1, module.getf1());
assertEquals(i2, module.geti2());
assertEquals(f2, module.getf2());
}
// Check normal operation.
TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7);
// Check partial operation.
TestCase({baz: 345.7}, 0, NaN, 345, 345.7);
// Check that undefined values are converted to proper defaults.
TestCase({qux: 999}, 0, NaN, 0, NaN);
// Check that true values are converted properly.
TestCase({foo: true, bar: true, baz: true}, 1, 1.0, 1, 1.0);
// Check that false values are converted properly.
TestCase({foo: false, bar: false, baz: false}, 0, 0, 0, 0);
// Check that null values are converted properly.
TestCase({foo: null, bar: null, baz: null}, 0, 0, 0, 0);
// Check that string values are converted properly.
TestCase({foo: 'hi', bar: 'there', baz: 'dude'}, 0, NaN, 0, NaN);
TestCase({foo: '0xff', bar: '234', baz: '456.1'}, 255, 234, 456, 456.1);
// Check that function values are converted properly.
TestCase({foo: TestCase, bar: TestCase, qux: TestCase}, 0, NaN, 0, NaN);
}
print("TestForeignVariables...");
TestForeignVariables();
function TestGlobalBlock(stdlib, foreign, buffer) {
"use asm";
var x = foreign.x | 0, y = foreign.y | 0;
function test() {
return (x + y) | 0;
}
return {caller: test};
}
assertWasm(15, TestGlobalBlock, { x: 4, y: 11 });
// Copyright 2018 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: --validate-asm --allow-natives-syntax
var stdlib = this;
function assertValidAsm(func) {
assertTrue(%IsAsmWasmCode(func), "must be valid asm code");
}
function assertWasm(expected, func, ffi) {
print("Testing " + func.name + "...");
assertEquals(
expected, func(stdlib, ffi, new ArrayBuffer(1024)).caller());
assertValidAsm(func);
}
function TestInt32HeapAccess(stdlib, foreign, buffer) {
"use asm";
var m = new stdlib.Int32Array(buffer);
function caller() {
var i = 4;
m[0] = (i + 1) | 0;
m[i >> 2] = ((m[0]|0) + 1) | 0;
m[2] = ((m[i >> 2]|0) + 1) | 0;
return m[2] | 0;
}
return {caller: caller};
}
assertWasm(7, TestInt32HeapAccess);
function TestInt32HeapAccessExternal() {
var memory = new ArrayBuffer(1024);
var memory_int32 = new Int32Array(memory);
var module_decl = eval('(' + TestInt32HeapAccess.toString() + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(7, module.caller());
assertEquals(7, memory_int32[2]);
}
TestInt32HeapAccessExternal();
function TestHeapAccessIntTypes() {
var types = [
[Int8Array, 'Int8Array', '>> 0'],
[Uint8Array, 'Uint8Array', '>> 0'],
[Int16Array, 'Int16Array', '>> 1'],
[Uint16Array, 'Uint16Array', '>> 1'],
[Int32Array, 'Int32Array', '>> 2'],
[Uint32Array, 'Uint32Array', '>> 2'],
];
for (var i = 0; i < types.length; i++) {
var code = TestInt32HeapAccess.toString();
code = code.replace('Int32Array', types[i][1]);
code = code.replace(/>> 2/g, types[i][2]);
var memory = new ArrayBuffer(1024);
var memory_view = new types[i][0](memory);
var module_decl = eval('(' + code + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(7, module.caller());
assertEquals(7, memory_view[2]);
assertValidAsm(module_decl);
}
}
TestHeapAccessIntTypes();
function TestFloatHeapAccess(stdlib, foreign, buffer) {
"use asm";
var f32 = new stdlib.Float32Array(buffer);
var f64 = new stdlib.Float64Array(buffer);
var fround = stdlib.Math.fround;
function caller() {
var i = 8;
var j = 8;
var v = 6.0;
f64[2] = v + 1.0;
f64[i >> 3] = +f64[2] + 1.0;
f64[j >> 3] = +f64[j >> 3] + 1.0;
i = +f64[i >> 3] == 9.0;
return i|0;
}
return {caller: caller};
}
assertWasm(1, TestFloatHeapAccess);
function TestFloatHeapAccessExternal() {
var memory = new ArrayBuffer(1024);
var memory_float64 = new Float64Array(memory);
var module_decl = eval('(' + TestFloatHeapAccess.toString() + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(1, module.caller());
assertEquals(9.0, memory_float64[1]);
}
TestFloatHeapAccessExternal();
(function() {
function TestByteHeapAccessCompat(stdlib, foreign, buffer) {
"use asm";
var HEAP8 = new stdlib.Uint8Array(buffer);
var HEAP32 = new stdlib.Int32Array(buffer);
function store(i, v) {
i = i | 0;
v = v | 0;
HEAP32[i >> 2] = v;
}
function storeb(i, v) {
i = i | 0;
v = v | 0;
HEAP8[i | 0] = v;
}
function load(i) {
i = i | 0;
return HEAP8[i] | 0;
}
function iload(i) {
i = i | 0;
return HEAP8[HEAP32[i >> 2] | 0] | 0;
}
return {load: load, iload: iload, store: store, storeb: storeb};
}
var memory = new ArrayBuffer(1024);
var module_decl = eval('(' + TestByteHeapAccessCompat.toString() + ')');
var m = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
m.store(0, 20);
m.store(4, 21);
m.store(8, 22);
m.storeb(20, 123);
m.storeb(21, 42);
m.storeb(22, 77);
assertEquals(123, m.load(20));
assertEquals(42, m.load(21));
assertEquals(77, m.load(22));
assertEquals(123, m.iload(0));
assertEquals(42, m.iload(4));
assertEquals(77, m.iload(8));
})();
function TestIntishAssignment(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function func() {
var a = 1;
var b = 2;
HEAP32[0] = a + b;
return HEAP32[0] | 0;
}
return {caller: func};
}
assertWasm(3, TestIntishAssignment);
function TestFloatishAssignment(stdlib, foreign, heap) {
"use asm";
var HEAPF32 = new stdlib.Float32Array(heap);
var fround = stdlib.Math.fround;
function func() {
var a = fround(1.0);
var b = fround(2.0);
HEAPF32[0] = a + b;
return +HEAPF32[0];
}
return {caller: func};
}
assertWasm(3, TestFloatishAssignment);
function TestDoubleToFloatAssignment(stdlib, foreign, heap) {
"use asm";
var HEAPF32 = new stdlib.Float32Array(heap);
var fround = stdlib.Math.fround;
function func() {
var a = 1.23;
HEAPF32[0] = a;
return +HEAPF32[0];
}
return {caller: func};
}
assertWasm(Math.fround(1.23), TestDoubleToFloatAssignment);
...@@ -514,100 +514,6 @@ function TestMixedAdd() { ...@@ -514,100 +514,6 @@ function TestMixedAdd() {
assertWasm(23, TestMixedAdd); assertWasm(23, TestMixedAdd);
function TestInt32HeapAccess(stdlib, foreign, buffer) {
"use asm";
var m = new stdlib.Int32Array(buffer);
function caller() {
var i = 4;
m[0] = (i + 1) | 0;
m[i >> 2] = ((m[0]|0) + 1) | 0;
m[2] = ((m[i >> 2]|0) + 1) | 0;
return m[2] | 0;
}
return {caller: caller};
}
assertWasm(7, TestInt32HeapAccess);
function TestInt32HeapAccessExternal() {
var memory = new ArrayBuffer(1024);
var memory_int32 = new Int32Array(memory);
var module_decl = eval('(' + TestInt32HeapAccess.toString() + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(7, module.caller());
assertEquals(7, memory_int32[2]);
}
TestInt32HeapAccessExternal();
function TestHeapAccessIntTypes() {
var types = [
[Int8Array, 'Int8Array', '>> 0'],
[Uint8Array, 'Uint8Array', '>> 0'],
[Int16Array, 'Int16Array', '>> 1'],
[Uint16Array, 'Uint16Array', '>> 1'],
[Int32Array, 'Int32Array', '>> 2'],
[Uint32Array, 'Uint32Array', '>> 2'],
];
for (var i = 0; i < types.length; i++) {
var code = TestInt32HeapAccess.toString();
code = code.replace('Int32Array', types[i][1]);
code = code.replace(/>> 2/g, types[i][2]);
var memory = new ArrayBuffer(1024);
var memory_view = new types[i][0](memory);
var module_decl = eval('(' + code + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(7, module.caller());
assertEquals(7, memory_view[2]);
assertValidAsm(module_decl);
}
}
TestHeapAccessIntTypes();
function TestFloatHeapAccess(stdlib, foreign, buffer) {
"use asm";
var f32 = new stdlib.Float32Array(buffer);
var f64 = new stdlib.Float64Array(buffer);
var fround = stdlib.Math.fround;
function caller() {
var i = 8;
var j = 8;
var v = 6.0;
f64[2] = v + 1.0;
f64[i >> 3] = +f64[2] + 1.0;
f64[j >> 3] = +f64[j >> 3] + 1.0;
i = +f64[i >> 3] == 9.0;
return i|0;
}
return {caller: caller};
}
assertWasm(1, TestFloatHeapAccess);
function TestFloatHeapAccessExternal() {
var memory = new ArrayBuffer(1024);
var memory_float64 = new Float64Array(memory);
var module_decl = eval('(' + TestFloatHeapAccess.toString() + ')');
var module = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
assertEquals(1, module.caller());
assertEquals(9.0, memory_float64[1]);
}
TestFloatHeapAccessExternal();
function TestConvertI32() { function TestConvertI32() {
...@@ -1031,219 +937,6 @@ assertEquals(31, module.caller(1, 0, 30, 11)); ...@@ -1031,219 +937,6 @@ assertEquals(31, module.caller(1, 0, 30, 11));
})(); })();
function TestForeignFunctions() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var setVal = foreign.setVal;
var getVal = foreign.getVal;
function caller(initial_value, new_value) {
initial_value = initial_value|0;
new_value = new_value|0;
if ((getVal()|0) == (initial_value|0)) {
setVal(new_value|0);
return getVal()|0;
}
return 0;
}
return {caller:caller};
}
function ffi(initial_val) {
var val = initial_val;
function getVal() {
return val;
}
function setVal(new_val) {
val = new_val;
}
return {getVal:getVal, setVal:setVal};
}
var foreign = new ffi(23);
var module = AsmModule({Math: Math}, foreign, null);
assertValidAsm(AsmModule);
assertEquals(103, module.caller(23, 103));
}
print("TestForeignFunctions...");
TestForeignFunctions();
function TestForeignFunctionMultipleUse() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var getVal = foreign.getVal;
function caller(int_val, double_val) {
int_val = int_val|0;
double_val = +double_val;
if ((getVal()|0) == (int_val|0)) {
if ((+getVal()) == (+double_val)) {
return 89;
}
}
return 0;
}
return {caller:caller};
}
function ffi() {
function getVal() {
return 83.25;
}
return {getVal:getVal};
}
var foreign = new ffi();
var module_decl = eval('(' + AsmModule.toString() + ')');
var module = module_decl(stdlib, foreign, null);
assertValidAsm(module_decl);
assertEquals(89, module.caller(83, 83.25));
}
print("TestForeignFunctionMultipleUse...");
TestForeignFunctionMultipleUse();
function TestForeignVariables() {
function AsmModule(stdlib, foreign, buffer) {
"use asm";
var i1 = foreign.foo | 0;
var f1 = +foreign.bar;
var i2 = foreign.baz | 0;
var f2 = +foreign.baz;
function geti1() {
return i1|0;
}
function getf1() {
return +f1;
}
function geti2() {
return i2|0;
}
function getf2() {
return +f2;
}
return {geti1:geti1, getf1:getf1, geti2:geti2, getf2:getf2};
}
function TestCase(env, i1, f1, i2, f2) {
print("Testing foreign variables...");
var module_decl = eval('(' + AsmModule.toString() + ')');
var module = module_decl(stdlib, env);
assertValidAsm(module_decl);
assertEquals(i1, module.geti1());
assertEquals(f1, module.getf1());
assertEquals(i2, module.geti2());
assertEquals(f2, module.getf2());
}
// Check normal operation.
TestCase({foo: 123, bar: 234.5, baz: 345.7}, 123, 234.5, 345, 345.7);
// Check partial operation.
TestCase({baz: 345.7}, 0, NaN, 345, 345.7);
// Check that undefined values are converted to proper defaults.
TestCase({qux: 999}, 0, NaN, 0, NaN);
// Check that true values are converted properly.
TestCase({foo: true, bar: true, baz: true}, 1, 1.0, 1, 1.0);
// Check that false values are converted properly.
TestCase({foo: false, bar: false, baz: false}, 0, 0, 0, 0);
// Check that null values are converted properly.
TestCase({foo: null, bar: null, baz: null}, 0, 0, 0, 0);
// Check that string values are converted properly.
TestCase({foo: 'hi', bar: 'there', baz: 'dude'}, 0, NaN, 0, NaN);
TestCase({foo: '0xff', bar: '234', baz: '456.1'}, 255, 234, 456, 456.1);
// Check that function values are converted properly.
TestCase({foo: TestCase, bar: TestCase, qux: TestCase}, 0, NaN, 0, NaN);
}
print("TestForeignVariables...");
TestForeignVariables();
(function() {
function TestByteHeapAccessCompat(stdlib, foreign, buffer) {
"use asm";
var HEAP8 = new stdlib.Uint8Array(buffer);
var HEAP32 = new stdlib.Int32Array(buffer);
function store(i, v) {
i = i | 0;
v = v | 0;
HEAP32[i >> 2] = v;
}
function storeb(i, v) {
i = i | 0;
v = v | 0;
HEAP8[i | 0] = v;
}
function load(i) {
i = i | 0;
return HEAP8[i] | 0;
}
function iload(i) {
i = i | 0;
return HEAP8[HEAP32[i >> 2] | 0] | 0;
}
return {load: load, iload: iload, store: store, storeb: storeb};
}
var memory = new ArrayBuffer(1024);
var module_decl = eval('(' + TestByteHeapAccessCompat.toString() + ')');
var m = module_decl(stdlib, null, memory);
assertValidAsm(module_decl);
m.store(0, 20);
m.store(4, 21);
m.store(8, 22);
m.storeb(20, 123);
m.storeb(21, 42);
m.storeb(22, 77);
assertEquals(123, m.load(20));
assertEquals(42, m.load(21));
assertEquals(77, m.load(22));
assertEquals(123, m.iload(0));
assertEquals(42, m.iload(4));
assertEquals(77, m.iload(8));
})();
function TestGlobalBlock(stdlib, foreign, buffer) {
"use asm";
var x = foreign.x | 0, y = foreign.y | 0;
function test() {
return (x + y) | 0;
}
return {caller: test};
}
assertWasm(15, TestGlobalBlock, { x: 4, y: 11 });
(function TestComma() { (function TestComma() {
function CommaModule() { function CommaModule() {
"use asm"; "use asm";
...@@ -1322,52 +1015,6 @@ function TestXor() { ...@@ -1322,52 +1015,6 @@ function TestXor() {
assertWasm(1, TestXor); assertWasm(1, TestXor);
function TestIntishAssignment(stdlib, foreign, heap) {
"use asm";
var HEAP32 = new stdlib.Int32Array(heap);
function func() {
var a = 1;
var b = 2;
HEAP32[0] = a + b;
return HEAP32[0] | 0;
}
return {caller: func};
}
assertWasm(3, TestIntishAssignment);
function TestFloatishAssignment(stdlib, foreign, heap) {
"use asm";
var HEAPF32 = new stdlib.Float32Array(heap);
var fround = stdlib.Math.fround;
function func() {
var a = fround(1.0);
var b = fround(2.0);
HEAPF32[0] = a + b;
return +HEAPF32[0];
}
return {caller: func};
}
assertWasm(3, TestFloatishAssignment);
function TestDoubleToFloatAssignment(stdlib, foreign, heap) {
"use asm";
var HEAPF32 = new stdlib.Float32Array(heap);
var fround = stdlib.Math.fround;
function func() {
var a = 1.23;
HEAPF32[0] = a;
return +HEAPF32[0];
}
return {caller: func};
}
assertWasm(Math.fround(1.23), TestDoubleToFloatAssignment);
function TestIntegerMultiplyBothWays(stdlib, foreign, heap) { function TestIntegerMultiplyBothWays(stdlib, foreign, heap) {
"use asm"; "use asm";
function func() { function func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment