Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: test/mjsunit/wasm/asm-wasm-literals.js

Issue 1830663002: [wasm] Binary 11: AST changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/wasm/asm-wasm-literals.js
diff --git a/test/mjsunit/wasm/asm-wasm-literals.js b/test/mjsunit/wasm/asm-wasm-literals.js
new file mode 100644
index 0000000000000000000000000000000000000000..bf6f5f8022fddf2ae27f06170b0d4da26453e565
--- /dev/null
+++ b/test/mjsunit/wasm/asm-wasm-literals.js
@@ -0,0 +1,169 @@
+// Copyright 2016 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: --expose-wasm
+
+function RunThreeWayTest(asmfunc, expect) {
+ var asm_source = asmfunc.toString();
+ var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
+
+ var js_module = eval("(" + nonasm_source + ")")();
+ print("Testing " + asmfunc.name + " (js)...");
+ expect(js_module);
+
+ print("Testing " + asmfunc.name + " (asm.js)...");
+ var asm_module = asmfunc();
+ expect(asm_module);
+
+ print("Testing " + asmfunc.name + " (wasm)...");
+ var wasm_module = Wasm.instantiateModuleFromAsm(asm_source);
+ expect(wasm_module);
+}
+
+function PositiveIntLiterals() {
+ "use asm";
+ function f0() { return 0; }
+ function f1() { return 1; }
+ function f4() { return 4; }
+ function f64() { return 64; }
+ function f127() { return 127; }
+ function f128() { return 128; }
+ function f256() { return 256; }
+ function f1000() { return 1000; }
+ function f2000000() { return 2000000; }
+ function fmax() { return 2147483647; }
+ return {f0: f0, f1: f1, f4: f4, f64: f64, f127: f127, f128: f128,
+ f256: f256, f1000: f1000, f2000000, fmax: fmax};
+}
+
+RunThreeWayTest(PositiveIntLiterals, function(module) {
+ assertEquals(0, module.f0());
+ assertEquals(1, module.f1());
+ assertEquals(4, module.f4());
+ assertEquals(64, module.f64());
+ assertEquals(128, module.f128());
+ assertEquals(256, module.f256());
+ assertEquals(1000, module.f1000());
+ assertEquals(2000000, module.f2000000());
+ assertEquals(2147483647, module.fmax());
+});
+
+function NegativeIntLiterals() {
+ "use asm";
+ function f1() { return -1; }
+ function f4() { return -4; }
+ function f64() { return -64; }
+ function f127() { return -127; }
+ function f128() { return -128; }
+ function f256() { return -256; }
+ function f1000() { return -1000; }
+ function f2000000() { return -2000000; }
+ function fmin() { return -2147483648; }
+ return {f1: f1, f4: f4, f64: f64, f127: f127, f128: f128,
+ f256: f256, f1000: f1000, f2000000, fmin: fmin};
+}
+
+RunThreeWayTest(NegativeIntLiterals, function (module) {
+ assertEquals(-1, module.f1());
+ assertEquals(-4, module.f4());
+ assertEquals(-64, module.f64());
+ assertEquals(-127, module.f127());
+ assertEquals(-128, module.f128());
+ assertEquals(-256, module.f256());
+ assertEquals(-1000, module.f1000());
+ assertEquals(-2000000, module.f2000000());
+ assertEquals(-2147483648, module.fmin());
+});
+
+function PositiveUnsignedLiterals() {
+ "use asm";
+ function f0() { return 0 >>> 0; }
+ function f1() { return 1 >>> 0; }
+ function f4() { return 4 >>> 0; }
+ function f64() { return 64 >>> 0; }
+ function f127() { return 127 >>> 0; }
+ function f128() { return 128 >>> 0; }
+ function f256() { return 256 >>> 0; }
+ function f1000() { return 1000 >>> 0; }
+ function f2000000() { return 2000000 >>> 0; }
+ function fmax() { return 2147483647 >>> 0; }
+ return {f0: f0, f1: f1, f4: f4, f64: f64, f127: f127, f128: f128, f256: f256, f1000: f1000, f2000000, fmax: fmax};
bradnelson 2016/03/23 19:14:25 wrap?
titzer 2016/03/23 19:53:05 I'll split these tests out into a different CL and
+}
+
+RunThreeWayTest(PositiveUnsignedLiterals, function (module) {
+ assertEquals(0, module.f0());
+ assertEquals(1, module.f1());
+ assertEquals(4, module.f4());
+ assertEquals(64, module.f64());
+ assertEquals(128, module.f128());
+ assertEquals(256, module.f256());
+ assertEquals(1000, module.f1000());
+ assertEquals(2000000, module.f2000000());
+ assertEquals(2147483647, module.fmax());
+});
+
+function LargeUnsignedLiterals() {
+ "use asm";
+ function a() {
+ var x = 2147483648;
+ return +x;
+ }
+ function b() {
+ var x = 2147483649;
+ return +x;
+ }
+ function c() {
+ var x = 0x80000000;
+ return +x;
+ }
+ function d() {
+ var x = 0x80000001;
+ return +x;
+ }
+ function e() {
+ var x = 0xffffffff;
+ return +x;
+ }
+ return {a: a, b: b, c: c, d: d, e: e};
+}
+
+RunThreeWayTest(LargeUnsignedLiterals, function(module) {
+ return; // TODO(bradnelson): unsigned literals are broken!
bradnelson 2016/03/23 19:14:25 Have a fix, but might wait until this lands.
titzer 2016/03/23 19:53:05 Acknowledged.
+ assertEquals(2147483648, module.a());
+ assertEquals(2147483649, module.b());
+ assertEquals(0x80000000, module.c());
+ assertEquals(0x80000001, module.d());
+ assertEquals(0xffffffff, module.e());
+});
+
+function ManyI32() {
+ "use asm";
+ function main() {
+ var a = 1 + -2 + 3 + -4 | 0;
+ var b = 11 + -22 + 33 + -44 | 0;
+ var c = 111 + -222 + 333 + -444 | 0;
+ var d = 1111 + -2222 + 3333 + -4444 | 0;
+ var e = 11111 + -22222 + 33333 + -44444 | 0;
+ var f = 155555 + -266666 + 377777 + -488888 | 0;
+ var g = 1155555 + -2266666 + 3377777 + -4488888 | 0;
+ var h = 11155555 + -22266666 + 33377777 + -44488888 | 0;
+ var i = 111155555 + -222266666 + 333377777 + -444488888 | 0;
+ var j = (
+ 0x1 + 0x2 + 0x4 + 0x8 +
+ 0x10 + 0x20 + 0x40 + 0x80 +
+ 0x10F + 0x200 + 0x400 + 0x800 +
+ 0x10E0 + 0x20F0 + 0x4000 + 0x8000 +
+ 0x10D00 + 0x20E00 + 0x400F0 + 0x80002 +
+ 0x10C000 + 0x20D000 + 0x400E00 + 0x800030 +
+ 0x10B0000 + 0x20C0000 + 0x400D000 + 0x8000400 +
+ 0x10A00000 + 0x20B00000 + 0x400C0000 + 0x80005000
+ ) | 0;
+ return (a + b + c + d + e + f + g + h + i + j) | 0;
+ }
+ return {main: main};
+}
+
+RunThreeWayTest(ManyI32, function(module) {
+ assertEquals(-222411306, module.main());
+});

Powered by Google App Engine
This is Rietveld 408576698