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

Side by Side Diff: test/mjsunit/wasm/asm-wasm-f32.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.js ('k') | test/mjsunit/wasm/asm-wasm-f64.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 fround = stdlib.Math.fround;
11 var Math_ceil = stdlib.Math.ceil;
12 var Math_floor = stdlib.Math.floor;
13 var Math_sqrt = stdlib.Math.sqrt;
14 var Math_abs = stdlib.Math.abs;
15 var Math_min = stdlib.Math.min;
16 var Math_max = stdlib.Math.max;
17
18 FUNC_BODY
19 return {main: FUNC_NAME};
20 }
21
22 var source = MODULE_NAME.toString()
23 .replace(/MODULE_NAME/g, func.name + "_module")
24 .replace(/FUNC_BODY/g, func.toString())
25 .replace(/FUNC_NAME/g, func.name);
26 return eval("(" + source + ")");
27 }
28
29 function RunThreeWayTest(asmfunc, expect) {
30 var asm_source = asmfunc.toString();
31 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
32 var stdlib = {Math: Math};
33
34 var js_module = eval("(" + nonasm_source + ")")(stdlib);
35 print("Testing " + asmfunc.name + " (js)...");
36 expect(js_module);
37
38 print("Testing " + asmfunc.name + " (asm.js)...");
39 var asm_module = asmfunc(stdlib);
40 expect(asm_module);
41
42 print("Testing " + asmfunc.name + " (wasm)...");
43 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib);
44 expect(wasm_module);
45 }
46
47 const fround = Math.fround;
48 const Math_ceil = Math.ceil;
49 const Math_floor = Math.floor;
50 const Math_sqrt = Math.sqrt;
51 const Math_abs = Math.abs;
52 const Math_min = Math.min;
53 const Math_max = Math.max;
54
55 function f32_add(a, b) {
56 a = fround(a);
57 b = fround(b);
58 return fround(fround(a) + fround(b));
59 }
60
61 function f32_sub(a, b) {
62 a = fround(a);
63 b = fround(b);
64 return fround(fround(a) - fround(b));
65 }
66
67 function f32_mul(a, b) {
68 a = fround(a);
69 b = fround(b);
70 return fround(fround(a) * fround(b));
71 }
72
73 function f32_div(a, b) {
74 a = fround(a);
75 b = fround(b);
76 return fround(fround(a) / fround(b));
77 }
78
79 function f32_ceil(a) {
80 a = fround(a);
81 return fround(Math_ceil(fround(a)));
82 }
83
84 function f32_floor(a) {
85 a = fround(a);
86 return fround(Math_floor(fround(a)));
87 }
88
89 function f32_sqrt(a) {
90 a = fround(a);
91 return fround(Math_sqrt(fround(a)));
92 }
93
94 function f32_abs(a) {
95 a = fround(a);
96 return fround(Math_abs(fround(a)));
97 }
98
99 function f32_min(a, b) {
100 a = fround(a);
101 b = fround(b);
102 return fround(Math_min(fround(a), fround(b)));
103 }
104
105 function f32_max(a, b) {
106 a = fround(a);
107 b = fround(b);
108 return fround(Math_max(fround(a), fround(b)));
109 }
110
111 function f32_eq(a, b) {
112 a = fround(a);
113 b = fround(b);
114 if (fround(a) == fround(b)) {
115 return 1;
116 }
117 return 0;
118 }
119
120 function f32_ne(a, b) {
121 a = fround(a);
122 b = fround(b);
123 if (fround(a) != fround(b)) {
124 return 1;
125 }
126 return 0;
127 }
128
129 function f32_lt(a, b) {
130 a = fround(a);
131 b = fround(b);
132 if (fround(a) < fround(b)) {
133 return 1;
134 }
135 return 0;
136 }
137
138 function f32_lteq(a, b) {
139 a = fround(a);
140 b = fround(b);
141 if (fround(a) <= fround(b)) {
142 return 1;
143 }
144 return 0;
145 }
146
147 function f32_gt(a, b) {
148 a = fround(a);
149 b = fround(b);
150 if (fround(a) > fround(b)) {
151 return 1;
152 }
153 return 0;
154 }
155
156 function f32_gteq(a, b) {
157 a = fround(a);
158 b = fround(b);
159 if (fround(a) >= fround(b)) {
160 return 1;
161 }
162 return 0;
163 }
164
165
166 var inputs = [
167 0, 1, 2, 3, 4,
168 10, 20, 30, 31, 32, 33, 100, 2000,
169 30000, 400000, 5000000,
170 100000000, 2000000000,
171 2147483646,
172 2147483647,
173 2147483648,
174 2147483649,
175 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
176 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
177 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
178 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
179 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
180 -0,
181 -1, -2, -3, -4,
182 -10, -20, -30, -31, -32, -33, -100, -2000,
183 -30000, -400000, -5000000,
184 -100000000, -2000000000,
185 -2147483646,
186 -2147483647,
187 -2147483648,
188 -2147483649,
189 0.1,
190 1.1e-2,
191 1.2e-4,
192 1.3e-8,
193 1.4e-11,
194 1.5e-12,
195 1.6e-13
196 ];
197
198 var funcs = [
199 f32_add,
200 f32_sub,
201 f32_mul,
202 f32_div,
203 // TODO(bradnelson) f32_ceil,
204 // TODO(bradnelson) f32_floor,
205 // TODO(bradnelson) f32_sqrt,
206 // TODO(bradnelson) f32_abs,
207 // TODO(bradnelson) f32_min is wrong for -0
208 // TODO(bradnelson) f32_max is wrong for -0
209 f32_eq,
210 f32_ne,
211 f32_lt,
212 f32_lteq,
213 f32_gt,
214 f32_gteq,
215 ];
216
217 (function () {
218 for (func of funcs) {
219 RunThreeWayTest(WrapInAsmModule(func), function (module) {
220 for (a of inputs) {
221 for (b of inputs) {
222 assertEquals(func(a, b), module.main(a, b));
223 assertEquals(func(a / 10, b), module.main(a / 10, b));
224 assertEquals(func(a, b / 440.9), module.main(a, b / 440.9));
225 assertEquals(func(a / -33.1, b), module.main(a / -33.1, b));
226 }
227 }
228 });
229 }
230
231 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/asm-wasm.js ('k') | test/mjsunit/wasm/asm-wasm-f64.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698