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 assertWasm(expected, func, ffi) { | 7 function assertWasm(expected, func, ffi) { |
8 print("Testing " + func.name + "..."); | 8 print("Testing " + func.name + "..."); |
9 assertEquals(expected, Wasm.instantiateModuleFromAsm( | 9 assertEquals(expected, Wasm.instantiateModuleFromAsm( |
10 func.toString(), ffi).caller()); | 10 func.toString(), ffi).caller()); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 "use asm"; | 452 "use asm"; |
453 | 453 |
454 var f32 = new stdlib.Float32Array(buffer); | 454 var f32 = new stdlib.Float32Array(buffer); |
455 var f64 = new stdlib.Float64Array(buffer); | 455 var f64 = new stdlib.Float64Array(buffer); |
456 var fround = stdlib.Math.fround; | 456 var fround = stdlib.Math.fround; |
457 function caller() { | 457 function caller() { |
458 var i = 8; | 458 var i = 8; |
459 var j = 8; | 459 var j = 8; |
460 var v = 6.0; | 460 var v = 6.0; |
461 | 461 |
462 // TODO(bradnelson): Add float32 when asm-wasm supports it. | |
463 f64[2] = v + 1.0; | 462 f64[2] = v + 1.0; |
464 f64[i >> 3] = +f64[2] + 1.0; | 463 f64[i >> 3] = +f64[2] + 1.0; |
465 f64[j >> 3] = +f64[j >> 3] + 1.0; | 464 f64[j >> 3] = +f64[j >> 3] + 1.0; |
466 i = +f64[i >> 3] == 9.0; | 465 i = +f64[i >> 3] == 9.0; |
467 return i|0; | 466 return i|0; |
468 } | 467 } |
469 | 468 |
470 return {caller: caller}; | 469 return {caller: caller}; |
471 } | 470 } |
472 | 471 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 579 } |
581 return 0; | 580 return 0; |
582 } | 581 } |
583 | 582 |
584 return {caller:caller}; | 583 return {caller:caller}; |
585 } | 584 } |
586 | 585 |
587 assertWasm(28, TestModDouble); | 586 assertWasm(28, TestModDouble); |
588 | 587 |
589 | 588 |
590 /* | |
591 TODO: Fix parsing of negative doubles | |
592 Fix code to use trunc instead of casts | |
593 function TestModDoubleNegative() { | 589 function TestModDoubleNegative() { |
594 "use asm"; | 590 "use asm"; |
595 | 591 |
596 function caller() { | 592 function caller() { |
597 var a = -34359738368.25; | 593 var a = -34359738368.25; |
598 var b = 2.5; | 594 var b = 2.5; |
599 if (a%b == -0.75) { | 595 if (a%b == -0.75) { |
600 return 28; | 596 return 28; |
601 } | 597 } |
602 return 0; | 598 return 0; |
603 } | 599 } |
604 | 600 |
605 return {caller:caller}; | 601 return {caller:caller}; |
606 } | 602 } |
607 | 603 |
608 assertWasm(28, TestModDoubleNegative); | 604 assertWasm(28, TestModDoubleNegative); |
609 */ | |
610 | |
611 | 605 |
612 (function () { | 606 (function () { |
613 function TestNamedFunctions() { | 607 function TestNamedFunctions() { |
614 "use asm"; | 608 "use asm"; |
615 | 609 |
616 var a = 0.0; | 610 var a = 0.0; |
617 var b = 0.0; | 611 var b = 0.0; |
618 | 612 |
619 function add() { | 613 function add() { |
620 return +(a + b); | 614 return +(a + b); |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 var a = fround(1.0); | 1312 var a = fround(1.0); |
1319 var b = fround(2.0); | 1313 var b = fround(2.0); |
1320 HEAPF32[0] = a + b; | 1314 HEAPF32[0] = a + b; |
1321 return +HEAPF32[0]; | 1315 return +HEAPF32[0]; |
1322 } | 1316 } |
1323 return {func: func}; | 1317 return {func: func}; |
1324 } | 1318 } |
1325 | 1319 |
1326 var m = Wasm.instantiateModuleFromAsm(Module.toString()); | 1320 var m = Wasm.instantiateModuleFromAsm(Module.toString()); |
1327 assertEquals(3, m.func()); | 1321 assertEquals(3, m.func()); |
1328 }); // TODO(bradnelson): Enable when Math.fround implementation lands. | 1322 })(); |
1329 | 1323 |
1330 | 1324 |
1331 (function TestDoubleToFloatAssignment() { | 1325 (function TestDoubleToFloatAssignment() { |
1332 function Module(stdlib, foreign, heap) { | 1326 function Module(stdlib, foreign, heap) { |
1333 "use asm"; | 1327 "use asm"; |
1334 var HEAPF32 = new stdlib.Float32Array(heap); | 1328 var HEAPF32 = new stdlib.Float32Array(heap); |
1335 var fround = stdlib.Math.fround; | 1329 var fround = stdlib.Math.fround; |
1336 function func() { | 1330 function func() { |
1337 var a = 1.23; | 1331 var a = 1.23; |
1338 HEAPF32[0] = a; | 1332 HEAPF32[0] = a; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 u0xffffffff: u0xffffffff, | 1486 u0xffffffff: u0xffffffff, |
1493 u0x80000000: u0x80000000, | 1487 u0x80000000: u0x80000000, |
1494 u0x87654321: u0x87654321, | 1488 u0x87654321: u0x87654321, |
1495 }; | 1489 }; |
1496 } | 1490 } |
1497 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); | 1491 var wasm = Wasm.instantiateModuleFromAsm(asmModule.toString()); |
1498 assertEquals(0xffffffff, wasm.u0xffffffff()); | 1492 assertEquals(0xffffffff, wasm.u0xffffffff()); |
1499 assertEquals(0x80000000, wasm.u0x80000000()); | 1493 assertEquals(0x80000000, wasm.u0x80000000()); |
1500 assertEquals(0x87654321, wasm.u0x87654321()); | 1494 assertEquals(0x87654321, wasm.u0x87654321()); |
1501 })(); | 1495 })(); |
OLD | NEW |