OLD | NEW |
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 fround = stdlib.Math.fround; | 10 var fround = stdlib.Math.fround; |
11 var Math_ceil = stdlib.Math.ceil; | 11 var Math_ceil = stdlib.Math.ceil; |
12 var Math_floor = stdlib.Math.floor; | 12 var Math_floor = stdlib.Math.floor; |
13 var Math_sqrt = stdlib.Math.sqrt; | 13 var Math_sqrt = stdlib.Math.sqrt; |
14 var Math_abs = stdlib.Math.abs; | 14 var Math_abs = stdlib.Math.abs; |
15 var Math_min = stdlib.Math.min; | 15 var Math_min = stdlib.Math.min; |
16 var Math_max = stdlib.Math.max; | 16 var Math_max = stdlib.Math.max; |
17 | 17 |
18 FUNC_BODY | 18 FUNC_BODY |
19 return {main: FUNC_NAME}; | 19 return {main: FUNC_NAME}; |
20 } | 20 } |
21 | 21 |
22 var source = MODULE_NAME.toString() | 22 var source = MODULE_NAME.toString() |
23 .replace(/MODULE_NAME/g, func.name + "_module") | 23 .replace(/MODULE_NAME/g, func.name + "_module") |
24 .replace(/FUNC_BODY/g, func.toString()) | 24 .replace(/FUNC_BODY/g, func.toString()) |
25 .replace(/FUNC_NAME/g, func.name); | 25 .replace(/FUNC_NAME/g, func.name); |
26 return eval("(" + source + ")"); | 26 return eval("(" + source + ")"); |
27 } | 27 } |
28 | 28 |
29 function RunThreeWayTest(asmfunc, expect) { | 29 function RunAsmJsTest(asmfunc, expect) { |
30 var asm_source = asmfunc.toString(); | 30 var asm_source = asmfunc.toString(); |
31 var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); | 31 var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); |
32 var stdlib = {Math: Math}; | 32 var stdlib = {Math: Math}; |
33 | 33 |
| 34 print("Testing " + asmfunc.name + " (js)..."); |
34 var js_module = eval("(" + nonasm_source + ")")(stdlib); | 35 var js_module = eval("(" + nonasm_source + ")")(stdlib); |
35 print("Testing " + asmfunc.name + " (js)..."); | |
36 expect(js_module); | 36 expect(js_module); |
37 | 37 |
38 print("Testing " + asmfunc.name + " (asm.js)..."); | 38 print("Testing " + asmfunc.name + " (asm.js)..."); |
39 var asm_module = asmfunc(stdlib); | 39 var asm_module = asmfunc(stdlib); |
| 40 assertTrue(%IsAsmWasmCode(asmfunc) || |
| 41 %GetOptimizationStatus(asmfunc) === 3); |
40 expect(asm_module); | 42 expect(asm_module); |
41 | |
42 print("Testing " + asmfunc.name + " (wasm)..."); | |
43 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); | |
44 expect(wasm_module); | |
45 } | 43 } |
46 | 44 |
47 const fround = Math.fround; | 45 const fround = Math.fround; |
48 const Math_ceil = Math.ceil; | 46 const Math_ceil = Math.ceil; |
49 const Math_floor = Math.floor; | 47 const Math_floor = Math.floor; |
50 const Math_sqrt = Math.sqrt; | 48 const Math_sqrt = Math.sqrt; |
51 const Math_abs = Math.abs; | 49 const Math_abs = Math.abs; |
52 const Math_min = Math.min; | 50 const Math_min = Math.min; |
53 const Math_max = Math.max; | 51 const Math_max = Math.max; |
54 | 52 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 f32_eq, | 209 f32_eq, |
212 f32_ne, | 210 f32_ne, |
213 f32_lt, | 211 f32_lt, |
214 f32_lteq, | 212 f32_lteq, |
215 f32_gt, | 213 f32_gt, |
216 f32_gteq, | 214 f32_gteq, |
217 ]; | 215 ]; |
218 | 216 |
219 (function () { | 217 (function () { |
220 for (func of funcs) { | 218 for (func of funcs) { |
221 RunThreeWayTest(WrapInAsmModule(func), function (module) { | 219 RunAsmJsTest(WrapInAsmModule(func), function (module) { |
222 if (func.length == 1) { | 220 if (func.length == 1) { |
223 for (a of inputs) { | 221 for (a of inputs) { |
224 assertEquals(func(a), module.main(a)); | 222 assertEquals(func(a), module.main(a)); |
225 assertEquals(func(a / 11), module.main(a / 11)); | 223 assertEquals(func(a / 11), module.main(a / 11)); |
226 assertEquals(func(a / 430.9), module.main(a / 430.9)); | 224 assertEquals(func(a / 430.9), module.main(a / 430.9)); |
227 assertEquals(func(a / -31.1), module.main(a / -31.1)); | 225 assertEquals(func(a / -31.1), module.main(a / -31.1)); |
228 } | 226 } |
229 } else { | 227 } else { |
230 for (a of inputs) { | 228 for (a of inputs) { |
231 for (b of inputs) { | 229 for (b of inputs) { |
232 assertEquals(func(a, b), module.main(a, b)); | 230 assertEquals(func(a, b), module.main(a, b)); |
233 assertEquals(func(a / 11, b), module.main(a / 11, b)); | 231 assertEquals(func(a / 11, b), module.main(a / 11, b)); |
234 assertEquals(func(a, b / 420.9), module.main(a, b / 420.9)); | 232 assertEquals(func(a, b / 420.9), module.main(a, b / 420.9)); |
235 assertEquals(func(a / -31.1, b), module.main(a / -31.1, b)); | 233 assertEquals(func(a / -31.1, b), module.main(a / -31.1, b)); |
236 } | 234 } |
237 } | 235 } |
238 } | 236 } |
239 }); | 237 }); |
240 } | 238 } |
241 | 239 |
242 })(); | 240 })(); |
OLD | NEW |