| 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 Math_ceil = stdlib.Math.ceil; | 10 var Math_ceil = stdlib.Math.ceil; |
| 11 var Math_floor = stdlib.Math.floor; | 11 var Math_floor = stdlib.Math.floor; |
| 12 var Math_sqrt = stdlib.Math.sqrt; | 12 var Math_sqrt = stdlib.Math.sqrt; |
| 13 var Math_abs = stdlib.Math.abs; | 13 var Math_abs = stdlib.Math.abs; |
| 14 var Math_min = stdlib.Math.min; | 14 var Math_min = stdlib.Math.min; |
| 15 var Math_max = stdlib.Math.max; | 15 var Math_max = stdlib.Math.max; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 return {main: FUNC_NAME}; | 27 return {main: FUNC_NAME}; |
| 28 } | 28 } |
| 29 | 29 |
| 30 var source = MODULE_NAME.toString() | 30 var source = MODULE_NAME.toString() |
| 31 .replace(/MODULE_NAME/g, func.name + "_module") | 31 .replace(/MODULE_NAME/g, func.name + "_module") |
| 32 .replace(/FUNC_BODY/g, func.toString()) | 32 .replace(/FUNC_BODY/g, func.toString()) |
| 33 .replace(/FUNC_NAME/g, func.name); | 33 .replace(/FUNC_NAME/g, func.name); |
| 34 return eval("(" + source + ")"); | 34 return eval("(" + source + ")"); |
| 35 } | 35 } |
| 36 | 36 |
| 37 function RunThreeWayTest(asmfunc, expect) { | 37 function RunAsmJsTest(asmfunc, expect) { |
| 38 var asm_source = asmfunc.toString(); | 38 var asm_source = asmfunc.toString(); |
| 39 var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); | 39 var nonasm_source = asm_source.replace(new RegExp("use asm"), ""); |
| 40 var stdlib = {Math: Math}; | 40 var stdlib = {Math: Math}; |
| 41 | 41 |
| 42 print("Testing " + asmfunc.name + " (js)..."); |
| 42 var js_module = eval("(" + nonasm_source + ")")(stdlib); | 43 var js_module = eval("(" + nonasm_source + ")")(stdlib); |
| 43 print("Testing " + asmfunc.name + " (js)..."); | |
| 44 expect(js_module); | 44 expect(js_module); |
| 45 | 45 |
| 46 print("Testing " + asmfunc.name + " (asm.js)..."); | 46 print("Testing " + asmfunc.name + " (asm.js)..."); |
| 47 var asm_module = asmfunc(stdlib); | 47 var asm_module = asmfunc(stdlib); |
| 48 assertTrue(%IsAsmWasmCode(asmfunc)); |
| 48 expect(asm_module); | 49 expect(asm_module); |
| 49 | |
| 50 print("Testing " + asmfunc.name + " (wasm)..."); | |
| 51 var wasm_module = Wasm.instantiateModuleFromAsm(asm_source, stdlib); | |
| 52 expect(wasm_module); | |
| 53 } | 50 } |
| 54 | 51 |
| 55 const Math_ceil = Math.ceil; | 52 const Math_ceil = Math.ceil; |
| 56 const Math_floor = Math.floor; | 53 const Math_floor = Math.floor; |
| 57 const Math_sqrt = Math.sqrt; | 54 const Math_sqrt = Math.sqrt; |
| 58 const Math_abs = Math.abs; | 55 const Math_abs = Math.abs; |
| 59 const Math_min = Math.min; | 56 const Math_min = Math.min; |
| 60 const Math_max = Math.max; | 57 const Math_max = Math.max; |
| 61 const Math_acos = Math.acos; | 58 const Math_acos = Math.acos; |
| 62 const Math_asin = Math.asin; | 59 const Math_asin = Math.asin; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // TODO(bradnelson) f64_cos, | 280 // TODO(bradnelson) f64_cos, |
| 284 // TODO(bradnelson) f64_sin, | 281 // TODO(bradnelson) f64_sin, |
| 285 // TODO(bradnelson) f64_tan, | 282 // TODO(bradnelson) f64_tan, |
| 286 // TODO(bradnelson) f64_exp, | 283 // TODO(bradnelson) f64_exp, |
| 287 // TODO(bradnelson) f64_log, | 284 // TODO(bradnelson) f64_log, |
| 288 // TODO(bradnelson) f64_atan2, | 285 // TODO(bradnelson) f64_atan2, |
| 289 ]; | 286 ]; |
| 290 | 287 |
| 291 (function () { | 288 (function () { |
| 292 for (func of funcs) { | 289 for (func of funcs) { |
| 293 RunThreeWayTest(WrapInAsmModule(func), function (module) { | 290 RunAsmJsTest(WrapInAsmModule(func), function (module) { |
| 294 if (func.length == 1) { | 291 if (func.length == 1) { |
| 295 for (a of inputs) { | 292 for (a of inputs) { |
| 296 assertEquals(func(a), module.main(a)); | 293 assertEquals(func(a), module.main(a)); |
| 297 assertEquals(func(a / 10), module.main(a / 10)); | 294 assertEquals(func(a / 10), module.main(a / 10)); |
| 298 assertEquals(func(a / 440.9), module.main(a / 440.9)); | 295 assertEquals(func(a / 440.9), module.main(a / 440.9)); |
| 299 assertEquals(func(a / -33.1), module.main(a / -33.1)); | 296 assertEquals(func(a / -33.1), module.main(a / -33.1)); |
| 300 } | 297 } |
| 301 } else { | 298 } else { |
| 302 for (a of inputs) { | 299 for (a of inputs) { |
| 303 for (b of inputs) { | 300 for (b of inputs) { |
| 304 assertEquals(func(a, b), module.main(a, b)); | 301 assertEquals(func(a, b), module.main(a, b)); |
| 305 assertEquals(func(a / 10, b), module.main(a / 10, b)); | 302 assertEquals(func(a / 10, b), module.main(a / 10, b)); |
| 306 assertEquals(func(a, b / 440.9), module.main(a, b / 440.9)); | 303 assertEquals(func(a, b / 440.9), module.main(a, b / 440.9)); |
| 307 assertEquals(func(a / -33.1, b), module.main(a / -33.1, b)); | 304 assertEquals(func(a / -33.1, b), module.main(a / -33.1, b)); |
| 308 } | 305 } |
| 309 } | 306 } |
| 310 } | 307 } |
| 311 }); | 308 }); |
| 312 } | 309 } |
| 313 })(); | 310 })(); |
| OLD | NEW |