OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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: --expose-wasm |
6 | 6 |
7 function EmptyTest() { | 7 function EmptyTest() { |
8 "use asm"; | 8 "use asm"; |
9 function caller() { | 9 function caller() { |
10 empty(); | 10 empty(); |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 | 1260 |
1261 return {ifunc: ifunc, dfunc: dfunc}; | 1261 return {ifunc: ifunc, dfunc: dfunc}; |
1262 } | 1262 } |
1263 | 1263 |
1264 var m = _WASMEXP_.instantiateModuleFromAsm(CommaModule.toString()); | 1264 var m = _WASMEXP_.instantiateModuleFromAsm(CommaModule.toString()); |
1265 assertEquals(123, m.ifunc(456.7, 123)); | 1265 assertEquals(123, m.ifunc(456.7, 123)); |
1266 assertEquals(123.4, m.dfunc(456, 123.4)); | 1266 assertEquals(123.4, m.dfunc(456, 123.4)); |
1267 })(); | 1267 })(); |
1268 | 1268 |
1269 | 1269 |
| 1270 (function TestStdlibConstants() { |
| 1271 function Module(stdlib) { |
| 1272 "use asm"; |
| 1273 |
| 1274 var StdlibInfinity = stdlib.Infinity; |
| 1275 var StdlibNaN = stdlib.NaN; |
| 1276 var StdlibMathE = stdlib.Math.E; |
| 1277 var StdlibMathLN10 = stdlib.Math.LN10; |
| 1278 var StdlibMathLN2 = stdlib.Math.LN2; |
| 1279 var StdlibMathLOG2E = stdlib.Math.LOG2E; |
| 1280 var StdlibMathLOG10E = stdlib.Math.LOG10E; |
| 1281 var StdlibMathPI = stdlib.Math.PI; |
| 1282 var StdlibMathSQRT1_2 = stdlib.Math.SQRT1_2; |
| 1283 var StdlibMathSQRT2 = stdlib.Math.SQRT2; |
| 1284 |
| 1285 function caller() { |
| 1286 if (StdlibInfinity != 1.0 / 0.0) return 0; |
| 1287 if (StdlibMathE != 2.718281828459045) return 0; |
| 1288 if (StdlibMathLN10 != 2.302585092994046) return 0; |
| 1289 if (StdlibMathLN2 != 0.6931471805599453) return 0; |
| 1290 if (StdlibMathLOG2E != 1.4426950408889634) return 0; |
| 1291 if (StdlibMathLOG10E != 0.4342944819032518) return 0; |
| 1292 if (StdlibMathPI != 3.141592653589793) return 0; |
| 1293 if (StdlibMathSQRT1_2 != 0.7071067811865476) return 0; |
| 1294 if (StdlibMathSQRT2 != 1.4142135623730951) return 0; |
| 1295 return 1; |
| 1296 } |
| 1297 |
| 1298 function nanCheck() { |
| 1299 return +StdlibNaN; |
| 1300 } |
| 1301 |
| 1302 return {caller:caller, nanCheck:nanCheck}; |
| 1303 } |
| 1304 |
| 1305 var m =_WASMEXP_.instantiateModuleFromAsm(Module.toString()); |
| 1306 assertEquals(1, m.caller()); |
| 1307 assertTrue(isNaN(m.nanCheck())); |
| 1308 })(); |
| 1309 |
| 1310 |
| 1311 (function TestStdlibFunctions() { |
| 1312 function Module(stdlib) { |
| 1313 "use asm"; |
| 1314 |
| 1315 var StdlibMathAcos = stdlib.Math.acos; |
| 1316 var StdlibMathAsin = stdlib.Math.asin; |
| 1317 var StdlibMathAtan = stdlib.Math.atan; |
| 1318 var StdlibMathCos = stdlib.Math.cos; |
| 1319 var StdlibMathSin = stdlib.Math.sin; |
| 1320 var StdlibMathTan = stdlib.Math.tan; |
| 1321 var StdlibMathExp = stdlib.Math.exp; |
| 1322 var StdlibMathLog = stdlib.Math.log; |
| 1323 var StdlibMathCeil = stdlib.Math.ceil; |
| 1324 var StdlibMathFloor = stdlib.Math.floor; |
| 1325 var StdlibMathSqrt = stdlib.Math.sqrt; |
| 1326 var StdlibMathAbs = stdlib.Math.abs; |
| 1327 var StdlibMathMin = stdlib.Math.min; |
| 1328 var StdlibMathMax = stdlib.Math.max; |
| 1329 var StdlibMathAtan2 = stdlib.Math.atan2; |
| 1330 var StdlibMathPow = stdlib.Math.pow; |
| 1331 var StdlibMathImul = stdlib.Math.imul; |
| 1332 var fround = stdlib.Math.fround; |
| 1333 |
| 1334 function caller() { |
| 1335 // TODO(bradnelson): Test transendentals when implemented. |
| 1336 if (StdlibMathSqrt(123.0) != 11.090536506409418) return 0; |
| 1337 if (StdlibMathSqrt(fround(256.0)) != fround(16.0)) return 0; |
| 1338 if (StdlibMathCeil(123.7) != 124.0) return 0; |
| 1339 if (StdlibMathCeil(fround(123.7)) != fround(124.0)) return 0; |
| 1340 if (StdlibMathFloor(123.7) != 123.0) return 0; |
| 1341 if (StdlibMathFloor(fround(123.7)) != fround(123.0)) return 0; |
| 1342 if (StdlibMathAbs(-123.0) != 123.0) return 0; |
| 1343 if (StdlibMathAbs(fround(-123.0)) != fround(123.0)) return 0; |
| 1344 if (StdlibMathMin(123.4, 1236.4) != 123.4) return 0; |
| 1345 if (StdlibMathMin(fround(123.4), |
| 1346 fround(1236.4)) != fround(123.4)) return 0; |
| 1347 if (StdlibMathMax(123.4, 1236.4) != 1236.4) return 0; |
| 1348 if (StdlibMathMax(fround(123.4), fround(1236.4)) |
| 1349 != fround(1236.4)) return 0; |
| 1350 if (StdlibMathImul(6, 7) != 42) return 0; |
| 1351 return 1; |
| 1352 } |
| 1353 |
| 1354 return {caller:caller}; |
| 1355 } |
| 1356 |
| 1357 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); |
| 1358 assertEquals(1, m.caller()); |
| 1359 })(); |
| 1360 |
| 1361 |
1270 (function TestOr() { | 1362 (function TestOr() { |
1271 function Module() { | 1363 function Module() { |
1272 "use asm"; | 1364 "use asm"; |
1273 function func() { | 1365 function func() { |
1274 var x = 1; | 1366 var x = 1; |
1275 var y = 2; | 1367 var y = 2; |
1276 return (x | y) | 0; | 1368 return (x | y) | 0; |
1277 } | 1369 } |
1278 return {func: func}; | 1370 return {func: func}; |
1279 } | 1371 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 var b = fround(2.0); | 1435 var b = fround(2.0); |
1344 HEAPF32[0] = a + b; | 1436 HEAPF32[0] = a + b; |
1345 return +HEAPF32[0]; | 1437 return +HEAPF32[0]; |
1346 } | 1438 } |
1347 return {func: func}; | 1439 return {func: func}; |
1348 } | 1440 } |
1349 | 1441 |
1350 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); | 1442 var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString()); |
1351 assertEquals(3, m.func()); | 1443 assertEquals(3, m.func()); |
1352 }) // TODO(bradnelson): Enable when Math.fround implementation lands. | 1444 }) // TODO(bradnelson): Enable when Math.fround implementation lands. |
OLD | NEW |