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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --expose-wasm
6
7 function RunThreeWayTest(asmfunc, expect) {
8 var asm_source = asmfunc.toString();
9 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
10
11 var js_module = eval("(" + nonasm_source + ")")();
12 print("Testing " + asmfunc.name + " (js)...");
13 expect(js_module);
14
15 print("Testing " + asmfunc.name + " (asm.js)...");
16 var asm_module = asmfunc();
17 expect(asm_module);
18
19 print("Testing " + asmfunc.name + " (wasm)...");
20 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source);
21 expect(wasm_module);
22 }
23
24 function PositiveIntLiterals() {
25 "use asm";
26 function f0() { return 0; }
27 function f1() { return 1; }
28 function f4() { return 4; }
29 function f64() { return 64; }
30 function f127() { return 127; }
31 function f128() { return 128; }
32 function f256() { return 256; }
33 function f1000() { return 1000; }
34 function f2000000() { return 2000000; }
35 function fmax() { return 2147483647; }
36 return {f0: f0, f1: f1, f4: f4, f64: f64, f127: f127, f128: f128,
37 f256: f256, f1000: f1000, f2000000, fmax: fmax};
38 }
39
40 RunThreeWayTest(PositiveIntLiterals, function(module) {
41 assertEquals(0, module.f0());
42 assertEquals(1, module.f1());
43 assertEquals(4, module.f4());
44 assertEquals(64, module.f64());
45 assertEquals(128, module.f128());
46 assertEquals(256, module.f256());
47 assertEquals(1000, module.f1000());
48 assertEquals(2000000, module.f2000000());
49 assertEquals(2147483647, module.fmax());
50 });
51
52 function NegativeIntLiterals() {
53 "use asm";
54 function f1() { return -1; }
55 function f4() { return -4; }
56 function f64() { return -64; }
57 function f127() { return -127; }
58 function f128() { return -128; }
59 function f256() { return -256; }
60 function f1000() { return -1000; }
61 function f2000000() { return -2000000; }
62 function fmin() { return -2147483648; }
63 return {f1: f1, f4: f4, f64: f64, f127: f127, f128: f128,
64 f256: f256, f1000: f1000, f2000000, fmin: fmin};
65 }
66
67 RunThreeWayTest(NegativeIntLiterals, function (module) {
68 assertEquals(-1, module.f1());
69 assertEquals(-4, module.f4());
70 assertEquals(-64, module.f64());
71 assertEquals(-127, module.f127());
72 assertEquals(-128, module.f128());
73 assertEquals(-256, module.f256());
74 assertEquals(-1000, module.f1000());
75 assertEquals(-2000000, module.f2000000());
76 assertEquals(-2147483648, module.fmin());
77 });
78
79 function PositiveUnsignedLiterals() {
80 "use asm";
81 function f0() { return 0 >>> 0; }
82 function f1() { return 1 >>> 0; }
83 function f4() { return 4 >>> 0; }
84 function f64() { return 64 >>> 0; }
85 function f127() { return 127 >>> 0; }
86 function f128() { return 128 >>> 0; }
87 function f256() { return 256 >>> 0; }
88 function f1000() { return 1000 >>> 0; }
89 function f2000000() { return 2000000 >>> 0; }
90 function fmax() { return 2147483647 >>> 0; }
91 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
92 }
93
94 RunThreeWayTest(PositiveUnsignedLiterals, function (module) {
95 assertEquals(0, module.f0());
96 assertEquals(1, module.f1());
97 assertEquals(4, module.f4());
98 assertEquals(64, module.f64());
99 assertEquals(128, module.f128());
100 assertEquals(256, module.f256());
101 assertEquals(1000, module.f1000());
102 assertEquals(2000000, module.f2000000());
103 assertEquals(2147483647, module.fmax());
104 });
105
106 function LargeUnsignedLiterals() {
107 "use asm";
108 function a() {
109 var x = 2147483648;
110 return +x;
111 }
112 function b() {
113 var x = 2147483649;
114 return +x;
115 }
116 function c() {
117 var x = 0x80000000;
118 return +x;
119 }
120 function d() {
121 var x = 0x80000001;
122 return +x;
123 }
124 function e() {
125 var x = 0xffffffff;
126 return +x;
127 }
128 return {a: a, b: b, c: c, d: d, e: e};
129 }
130
131 RunThreeWayTest(LargeUnsignedLiterals, function(module) {
132 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.
133 assertEquals(2147483648, module.a());
134 assertEquals(2147483649, module.b());
135 assertEquals(0x80000000, module.c());
136 assertEquals(0x80000001, module.d());
137 assertEquals(0xffffffff, module.e());
138 });
139
140 function ManyI32() {
141 "use asm";
142 function main() {
143 var a = 1 + -2 + 3 + -4 | 0;
144 var b = 11 + -22 + 33 + -44 | 0;
145 var c = 111 + -222 + 333 + -444 | 0;
146 var d = 1111 + -2222 + 3333 + -4444 | 0;
147 var e = 11111 + -22222 + 33333 + -44444 | 0;
148 var f = 155555 + -266666 + 377777 + -488888 | 0;
149 var g = 1155555 + -2266666 + 3377777 + -4488888 | 0;
150 var h = 11155555 + -22266666 + 33377777 + -44488888 | 0;
151 var i = 111155555 + -222266666 + 333377777 + -444488888 | 0;
152 var j = (
153 0x1 + 0x2 + 0x4 + 0x8 +
154 0x10 + 0x20 + 0x40 + 0x80 +
155 0x10F + 0x200 + 0x400 + 0x800 +
156 0x10E0 + 0x20F0 + 0x4000 + 0x8000 +
157 0x10D00 + 0x20E00 + 0x400F0 + 0x80002 +
158 0x10C000 + 0x20D000 + 0x400E00 + 0x800030 +
159 0x10B0000 + 0x20C0000 + 0x400D000 + 0x8000400 +
160 0x10A00000 + 0x20B00000 + 0x400C0000 + 0x80005000
161 ) | 0;
162 return (a + b + c + d + e + f + g + h + i + j) | 0;
163 }
164 return {main: main};
165 }
166
167 RunThreeWayTest(ManyI32, function(module) {
168 assertEquals(-222411306, module.main());
169 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698