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

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

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: [wasm] Master CL for Binary 0xC changes. Created 4 years, 2 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: --validate-asm --allow-natives-syntax
6
7 var selectedTest = undefined;
8 //selectedTest = 16;
bradnelson 2016/09/23 11:36:01 Leftover?
titzer 2016/09/23 12:07:30 Left it there intentionally so that you can select
9
10 function skip(a) {
11 return selectedTest != undefined ? a != selectedTest : false;
12 }
13
14 const assign_in_stmt = [
15 "if (E) =",
bradnelson 2016/09/23 11:36:01 Indented oddly.
titzer 2016/09/23 12:07:30 Done.
16 "if (=) E",
17 "if (E) E; else =",
18 "for (=; E; S) S",
19 "for (E; =; S) S",
20 "for (E; E; =) E",
21 "for (E; E; E) =",
22 "do { = } while(E)",
23 "do { S } while (=)",
24 ];
25 const assign_in_expr = [
26 "i32_func(=)",
27 "(=) ? E : E",
28 "E ? (=) : E",
29 "E ? E : (=)",
30 "(=) + E",
31 "E + (=)",
32 "imul(=, E)",
33 "imul(E, =)",
34 "~(=)",
35 "(=) | 0",
36 "(=), E",
37 "E, (=)",
38 "E, E, (=)",
39 "E, (=), E",
40 "(=), E, E",
41 ];
42
43 const stdlib = {
44 Math: Math,
45 Int8Array: Int8Array,
46 Int16Array: Int16Array,
47 Int32Array: Int32Array,
48 Uint8Array: Uint8Array,
49 Uint16Array: Uint16Array,
50 Uint32Array: Uint32Array,
51 Float32Array: Float32Array,
52 Float64Array: Float64Array,
53 };
54
55 const buffer = new ArrayBuffer(65536);
56
57 // Template for a module.
58 function MODULE_TEMPLATE(stdlib, foreign, buffer) {
59 "use asm";
60 var imul = stdlib.Math.imul;
61 var fround = stdlib.Math.fround;
62 var M = new stdlib.Int32Array(buffer);
63 var G = 0;
64
65 function void_func() {}
66 function i32_func(a) {
67 a = a | 0;
68 return a | 0;
69 }
70
71 FUNC_DECL
72 return {main: main};
73 }
74
75 // Template for main function.
76 {
77 function main(i32, f32, f64) {
78 i32 = i32 | 0;
79 f32 = fround(f32);
80 f64 = +f64;
81 FUNC_BODY
82 }
83 }
84
85 function RunAsmJsTest(asmfunc, expect) {
86 var asm_source = asmfunc.toString();
87 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
88
89 print("Testing " + asmfunc.name + " (js)...");
90 var js_module = eval("(" + nonasm_source + ")")(stdlib, {}, buffer);
91 expect(js_module);
92
93 print("Testing " + asmfunc.name + " (asm.js)...");
94 var asm_module = asmfunc(stdlib, {}, buffer);
95 assertTrue(%IsAsmWasmCode(asmfunc));
96 expect(asm_module);
97 }
98
99 var test = 0;
100
101 function DoTheTests(expr, assign, stmt) {
102 // ==== Expression assignment tests ========================================
103 for (let e of assign_in_expr) {
104 if (skip(++test)) continue;
105 var orig = e;
106 e = e.replace(/=/g, assign);
107 e = e.replace(/E/g, expr);
108 e = e.replace(/S/g, stmt);
109 var str = main.toString().replace("FUNC_BODY", "return (" + e + ") | 0;");
110 var asm_source = MODULE_TEMPLATE.toString().replace("FUNC_DECL", str);
111 // TODO(titzer): a verbosity API for these kinds of tests?
112 // print(asm_source);
113
114 doTest(asm_source, "(" + test + ") " + e);
115 }
116
117 // ==== Statement assignment tests =========================================
118 for (let e of assign_in_stmt) {
119 if (skip(++test)) continue;
120 var orig = e;
121 e = e.replace(/=/g, assign);
122 e = e.replace(/E/g, expr);
123 e = e.replace(/S/g, stmt);
124 var str = main.toString().replace("FUNC_BODY", e + "; return 0;");
125 var asm_source = MODULE_TEMPLATE.toString().replace("FUNC_DECL", str);
126 // print(asm_source);
bradnelson 2016/09/23 11:36:01 leftover
titzer 2016/09/23 12:07:30 Mircea asked about the same thing. I left it for e
127
128 doTest(asm_source, "(" + test + ") " + e);
129 }
130
131 function doTest(asm_source, orig) {
132
bradnelson 2016/09/23 11:36:01 Drop line
titzer 2016/09/23 12:07:30 Done.
133 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
134 print("Testing JS: " + orig);
135 var js_module = eval("(" + nonasm_source + ")")(stdlib, {}, buffer);
136 expect(js_module);
137
138 var asmfunc = eval("(" + asm_source + ")");
139
140 print("Testing ASMJS: " + orig);
141 var asm_module = asmfunc(stdlib, {}, buffer);
142 assertTrue(%IsAsmWasmCode(asmfunc));
143 expect(asm_module);
144 }
145
146 function expect(module) { module.main(0, 0, 0); print(" ok"); return true; }
147 }
148
149 DoTheTests("(i32 | 0)", "i32 = 0", "void_func()");
bradnelson 2016/09/23 11:36:01 Good to have more coverage. Interested what you hi
titzer 2016/09/23 12:07:31 I hit a few cases of missing or extra kDrop instru
150 DoTheTests("G", "G = 0", "void_func()");
151 DoTheTests("G", "G = 0", "G");
152 DoTheTests("(M[0] | 0)", "M[0] = 0", "void_func()");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698