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

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

Issue 2264913002: [wasm] asm.js - Remove Wasm.instantiateModuleFromAsm, use asm.js directly. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix Created 4 years, 4 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
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --expose-wasm 5 // Flags: --validate-asm --allow-natives-syntax
6 6
7 function WrapInAsmModule(func) { 7 function WrapInAsmModule(func) {
8 function MODULE_NAME(stdlib) { 8 function MODULE_NAME(stdlib) {
9 "use asm"; 9 "use asm";
10 var imul = stdlib.Math.imul; 10 var imul = stdlib.Math.imul;
11 var Math_max = stdlib.Math.max; 11 var Math_max = stdlib.Math.max;
12 var Math_min = stdlib.Math.min; 12 var Math_min = stdlib.Math.min;
13 var Math_abs = stdlib.Math.abs; 13 var Math_abs = stdlib.Math.abs;
14 14
15 FUNC_BODY 15 FUNC_BODY
16 return {main: FUNC_NAME}; 16 return {main: FUNC_NAME};
17 } 17 }
18 18
19 var source = MODULE_NAME.toString() 19 var source = MODULE_NAME.toString()
20 .replace(/MODULE_NAME/g, func.name + "_module") 20 .replace(/MODULE_NAME/g, func.name + "_module")
21 .replace(/FUNC_BODY/g, func.toString()) 21 .replace(/FUNC_BODY/g, func.toString())
22 .replace(/FUNC_NAME/g, func.name); 22 .replace(/FUNC_NAME/g, func.name);
23 return eval("(" + source + ")"); 23 return eval("(" + source + ")");
24 } 24 }
25 25
26 function RunThreeWayTest(asmfunc, expect) { 26 function RunAsmJsTest(asmfunc, expect) {
27 var asm_source = asmfunc.toString(); 27 var asm_source = asmfunc.toString();
28 var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); 28 var nonasm_source = asm_source.replace(new RegExp("use asm"), "");
29 var stdlib = {Math: Math}; 29 var stdlib = {Math: Math};
30 30
31 print("Testing " + asmfunc.name + " (js)...");
31 var js_module = eval("(" + nonasm_source + ")")(stdlib); 32 var js_module = eval("(" + nonasm_source + ")")(stdlib);
32 print("Testing " + asmfunc.name + " (js)...");
33 expect(js_module); 33 expect(js_module);
34 34
35 print("Testing " + asmfunc.name + " (asm.js)..."); 35 print("Testing " + asmfunc.name + " (asm.js)...");
36 var asm_module = asmfunc(stdlib); 36 var asm_module = asmfunc(stdlib);
37 assertTrue(%IsAsmWasmCode(asmfunc));
37 expect(asm_module); 38 expect(asm_module);
38
39 print("Testing " + asmfunc.name + " (wasm)...");
40 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib);
41 expect(wasm_module);
42 } 39 }
43 40
44 const imul = Math.imul; 41 const imul = Math.imul;
45 const Math_max = Math.max; 42 const Math_max = Math.max;
46 const Math_min = Math.min; 43 const Math_min = Math.min;
47 const Math_abs = Math.abs; 44 const Math_abs = Math.abs;
48 45
49 function i32_add(a, b) { 46 function i32_add(a, b) {
50 a = a | 0; 47 a = a | 0;
51 b = b | 0; 48 b = b | 0;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 i32_lteq, 224 i32_lteq,
228 i32_gt, 225 i32_gt,
229 i32_gteq, 226 i32_gteq,
230 i32_min, 227 i32_min,
231 i32_max, 228 i32_max,
232 i32_abs 229 i32_abs
233 ]; 230 ];
234 231
235 (function () { 232 (function () {
236 for (func of funcs) { 233 for (func of funcs) {
237 RunThreeWayTest(WrapInAsmModule(func), function (module) { 234 RunAsmJsTest(WrapInAsmModule(func), function (module) {
238 if (func.length == 1) { 235 if (func.length == 1) {
239 for (a of inputs) { 236 for (a of inputs) {
240 assertEquals(func(a), module.main(a)); 237 assertEquals(func(a), module.main(a));
241 } 238 }
242 } else { 239 } else {
243 for (a of inputs) { 240 for (a of inputs) {
244 for (b of inputs) { 241 for (b of inputs) {
245 assertEquals(func(a, b), module.main(a, b)); 242 assertEquals(func(a, b), module.main(a, b));
246 } 243 }
247 } 244 }
248 } 245 }
249 }); 246 });
250 } 247 }
251 248
252 })(); 249 })();
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