Commit af903021 authored by bradnelson's avatar bradnelson Committed by Commit bot

Add asm.js stdlib portion implementable as wasm opcodes.

Lost in the repo shuffle:
https://github.com/WebAssembly/v8-native-prototype/pull/102

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=mjsunit/asm-wasm
R=aseemgarg@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1702293002

Cr-Commit-Position: refs/heads/master@{#34218}
parent fe2ed566
This diff is collapsed.
......@@ -7,6 +7,7 @@
#include "src/allocation.h"
#include "src/objects.h"
#include "src/typing-asm.h"
#include "src/wasm/encoder.h"
#include "src/zone.h"
......@@ -20,7 +21,7 @@ namespace wasm {
class AsmWasmBuilder {
public:
explicit AsmWasmBuilder(Isolate* isolate, Zone* zone, FunctionLiteral* root,
Handle<Object> foreign);
Handle<Object> foreign, AsmTyper* typer);
WasmModuleIndex* Run();
private:
......@@ -28,6 +29,7 @@ class AsmWasmBuilder {
Zone* zone_;
FunctionLiteral* literal_;
Handle<Object> foreign_;
AsmTyper* typer_;
};
} // namespace wasm
} // namespace internal
......
......@@ -123,8 +123,9 @@ v8::internal::wasm::WasmModuleIndex* TranslateAsmModule(
return nullptr;
}
auto module = v8::internal::wasm::AsmWasmBuilder(
info->isolate(), info->zone(), info->literal(), foreign)
auto module =
v8::internal::wasm::AsmWasmBuilder(info->isolate(), info->zone(),
info->literal(), foreign, &typer)
.Run();
if (i::FLAG_dump_asmjs_wasm) {
......
......@@ -1267,6 +1267,98 @@ TestForeignVariables();
})();
(function TestStdlibConstants() {
function Module(stdlib) {
"use asm";
var StdlibInfinity = stdlib.Infinity;
var StdlibNaN = stdlib.NaN;
var StdlibMathE = stdlib.Math.E;
var StdlibMathLN10 = stdlib.Math.LN10;
var StdlibMathLN2 = stdlib.Math.LN2;
var StdlibMathLOG2E = stdlib.Math.LOG2E;
var StdlibMathLOG10E = stdlib.Math.LOG10E;
var StdlibMathPI = stdlib.Math.PI;
var StdlibMathSQRT1_2 = stdlib.Math.SQRT1_2;
var StdlibMathSQRT2 = stdlib.Math.SQRT2;
function caller() {
if (StdlibInfinity != 1.0 / 0.0) return 0;
if (StdlibMathE != 2.718281828459045) return 0;
if (StdlibMathLN10 != 2.302585092994046) return 0;
if (StdlibMathLN2 != 0.6931471805599453) return 0;
if (StdlibMathLOG2E != 1.4426950408889634) return 0;
if (StdlibMathLOG10E != 0.4342944819032518) return 0;
if (StdlibMathPI != 3.141592653589793) return 0;
if (StdlibMathSQRT1_2 != 0.7071067811865476) return 0;
if (StdlibMathSQRT2 != 1.4142135623730951) return 0;
return 1;
}
function nanCheck() {
return +StdlibNaN;
}
return {caller:caller, nanCheck:nanCheck};
}
var m =_WASMEXP_.instantiateModuleFromAsm(Module.toString());
assertEquals(1, m.caller());
assertTrue(isNaN(m.nanCheck()));
})();
(function TestStdlibFunctions() {
function Module(stdlib) {
"use asm";
var StdlibMathAcos = stdlib.Math.acos;
var StdlibMathAsin = stdlib.Math.asin;
var StdlibMathAtan = stdlib.Math.atan;
var StdlibMathCos = stdlib.Math.cos;
var StdlibMathSin = stdlib.Math.sin;
var StdlibMathTan = stdlib.Math.tan;
var StdlibMathExp = stdlib.Math.exp;
var StdlibMathLog = stdlib.Math.log;
var StdlibMathCeil = stdlib.Math.ceil;
var StdlibMathFloor = stdlib.Math.floor;
var StdlibMathSqrt = stdlib.Math.sqrt;
var StdlibMathAbs = stdlib.Math.abs;
var StdlibMathMin = stdlib.Math.min;
var StdlibMathMax = stdlib.Math.max;
var StdlibMathAtan2 = stdlib.Math.atan2;
var StdlibMathPow = stdlib.Math.pow;
var StdlibMathImul = stdlib.Math.imul;
var fround = stdlib.Math.fround;
function caller() {
// TODO(bradnelson): Test transendentals when implemented.
if (StdlibMathSqrt(123.0) != 11.090536506409418) return 0;
if (StdlibMathSqrt(fround(256.0)) != fround(16.0)) return 0;
if (StdlibMathCeil(123.7) != 124.0) return 0;
if (StdlibMathCeil(fround(123.7)) != fround(124.0)) return 0;
if (StdlibMathFloor(123.7) != 123.0) return 0;
if (StdlibMathFloor(fround(123.7)) != fround(123.0)) return 0;
if (StdlibMathAbs(-123.0) != 123.0) return 0;
if (StdlibMathAbs(fround(-123.0)) != fround(123.0)) return 0;
if (StdlibMathMin(123.4, 1236.4) != 123.4) return 0;
if (StdlibMathMin(fround(123.4),
fround(1236.4)) != fround(123.4)) return 0;
if (StdlibMathMax(123.4, 1236.4) != 1236.4) return 0;
if (StdlibMathMax(fround(123.4), fround(1236.4))
!= fround(1236.4)) return 0;
if (StdlibMathImul(6, 7) != 42) return 0;
return 1;
}
return {caller:caller};
}
var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString());
assertEquals(1, m.caller());
})();
(function TestOr() {
function Module() {
"use asm";
......
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