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

Side by Side Diff: test/mjsunit/wasm/asm-wasm-i32.js

Issue 1825333004: [wasm] Add more extensive tests for asm->wasm translation. (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
« no previous file with comments | « test/mjsunit/wasm/asm-wasm-heap.js ('k') | test/mjsunit/wasm/asm-wasm-literals.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 WrapInAsmModule(func) {
8 function MODULE_NAME(stdlib) {
9 "use asm";
10 var imul = stdlib.Math.imul;
11
12 FUNC_BODY
13 return {main: FUNC_NAME};
14 }
15
16 var source = MODULE_NAME.toString()
17 .replace(/MODULE_NAME/g, func.name + "_module")
18 .replace(/FUNC_BODY/g, func.toString())
19 .replace(/FUNC_NAME/g, func.name);
20 return eval("(" + source + ")");
21 }
22
23 function RunThreeWayTest(asmfunc, expect) {
24 var asm_source = asmfunc.toString();
25 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
26 var stdlib = {Math: Math};
27
28 var js_module = eval("(" + nonasm_source + ")")(stdlib);
29 print("Testing " + asmfunc.name + " (js)...");
30 expect(js_module);
31
32 print("Testing " + asmfunc.name + " (asm.js)...");
33 var asm_module = asmfunc(stdlib);
34 expect(asm_module);
35
36 print("Testing " + asmfunc.name + " (wasm)...");
37 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib);
38 expect(wasm_module);
39 }
40
41 const imul = Math.imul;
42
43 function i32_add(a, b) {
44 a = a | 0;
45 b = b | 0;
46 return (a + b) | 0;
47 }
48
49 function i32_sub(a, b) {
50 a = a | 0;
51 b = b | 0;
52 return (a - b) | 0;
53 }
54
55 function i32_mul(a, b) {
56 a = a | 0;
57 b = b | 0;
58 return imul(a, b) | 0;
59 }
60
61 function i32_div(a, b) {
62 a = a | 0;
63 b = b | 0;
64 return (a / b) | 0;
65 }
66
67 function i32_mod(a, b) {
68 a = a | 0;
69 b = b | 0;
70 return (a % b) | 0;
71 }
72
73 function i32_and(a, b) {
74 a = a | 0;
75 b = b | 0;
76 return (a & b) | 0;
77 }
78
79 function i32_or(a, b) {
80 a = a | 0;
81 b = b | 0;
82 return (a | b) | 0;
83 }
84
85 function i32_xor(a, b) {
86 a = a | 0;
87 b = b | 0;
88 return (a ^ b) | 0;
89 }
90
91 function i32_shl(a, b) {
92 a = a | 0;
93 b = b | 0;
94 return (a << b) | 0;
95 }
96
97 function i32_shr(a, b) {
98 a = a | 0;
99 b = b | 0;
100 return (a >> b) | 0;
101 }
102
103 function i32_sar(a, b) {
104 a = a | 0;
105 b = b | 0;
106 return (a >>> b) | 0;
107 }
108
109 function i32_eq(a, b) {
110 a = a | 0;
111 b = b | 0;
112 if ((a | 0) == (b | 0)) {
113 return 1;
114 }
115 return 0;
116 }
117
118 function i32_ne(a, b) {
119 a = a | 0;
120 b = b | 0;
121 if ((a | 0) < (b | 0)) {
122 return 1;
123 }
124 return 0;
125 }
126
127 function i32_lt(a, b) {
128 a = a | 0;
129 b = b | 0;
130 if ((a | 0) < (b | 0)) {
131 return 1;
132 }
133 return 0;
134 }
135
136 function i32_lteq(a, b) {
137 a = a | 0;
138 b = b | 0;
139 if ((a | 0) <= (b | 0)) {
140 return 1;
141 }
142 return 0;
143 }
144
145 function i32_gt(a, b) {
146 a = a | 0;
147 b = b | 0;
148 if ((a | 0) > (b | 0)) {
149 return 1;
150 }
151 return 0;
152 }
153
154 function i32_gteq(a, b) {
155 a = a | 0;
156 b = b | 0;
157 if ((a | 0) >= (b | 0)) {
158 return 1;
159 }
160 return 0;
161 }
162
163 var inputs = [
164 0, 1, 2, 3, 4,
165 10, 20, 30, 31, 32, 33, 100, 2000,
166 30000, 400000, 5000000,
167 100000000, 2000000000,
168 2147483646,
169 2147483647,
170 2147483648,
171 2147483649,
172 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
173 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
174 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
175 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
176 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
177 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
178 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
179 -1, -2, -3, -4,
180 -10, -20, -30, -31, -32, -33, -100, -2000,
181 -30000, -400000, -5000000,
182 -100000000, -2000000000,
183 -2147483646,
184 -2147483647,
185 -2147483648,
186 -2147483649,
187 ];
188
189 var funcs = [
190 i32_add,
191 i32_sub,
192 i32_mul,
193 // TODO(titzer): i32_mul requires Math.imul
194 // TODO(titzer): i32_div divide by zero is incorrect
195 // TODO(titzer): i32_mod by zero is incorrect
196 i32_and,
197 i32_or,
198 i32_xor,
199 // TODO(titzer): i32_shl on arm
200 // TODO(titzer): i32_shr on arm
201 // TODO(titzer): i32_sar on arm
202 i32_eq,
203 i32_ne,
204 i32_lt,
205 i32_lteq,
206 i32_gt,
207 i32_gteq,
208 // TODO(titzer): i32_min
209 // TODO(titzer): i32_max
210 // TODO(titzer): i32_abs
211 ];
212
213 (function () {
214 for (func of funcs) {
215 RunThreeWayTest(WrapInAsmModule(func), function (module) {
216 for (a of inputs) {
217 for (b of inputs) {
218 var expected = func(a, b);
219 assertEquals(expected, module.main(a, b));
220 }
221 }
222 });
223 }
224
225 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/asm-wasm-heap.js ('k') | test/mjsunit/wasm/asm-wasm-literals.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698