OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // Test usage of static type information for loads that would otherwise | |
31 // turn into polymorphic or generic loads. | |
32 | 30 |
33 // Prepare a highly polymorphic load to be used by all tests. | 31 // Test that both kinds of NaNs (signaling or quiet) do not signal |
34 Object.prototype.load = function() { return this.property; }; | |
35 Object.prototype.load.call({ A:0, property:10 }); | |
36 Object.prototype.load.call({ A:0, B:0, property:11 }); | |
37 Object.prototype.load.call({ A:0, B:0, C:0, property:12 }); | |
38 Object.prototype.load.call({ A:0, B:0, C:0, D:0, property:13 }); | |
39 Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, property:14 }); | |
40 Object.prototype.load.call({ A:0, B:0, C:0, D:0, E:0, F:0, property:15 }); | |
41 | 32 |
42 // Test for object literals. | 33 function TestAllModes(f) { |
43 (function() { | 34 f(); // Runtime |
44 function f(x) { | 35 f(); // IC |
45 var object = { property:x }; | 36 f(); // IC second time |
46 return object.load(); | 37 %OptimizeFunctionOnNextCall(f); |
| 38 f(); // hydrogen |
| 39 } |
| 40 |
| 41 function TestDoubleSignalingNan() { |
| 42 // NaN with signal bit set |
| 43 function f() { |
| 44 var bytes = new Uint32Array([1, 0x7FF00000]); |
| 45 var doubles = new Float64Array(bytes.buffer); |
| 46 assertTrue(isNaN(doubles[0])); |
| 47 assertTrue(isNaN(doubles[0]*2.0)); |
| 48 assertTrue(isNaN(doubles[0] + 0.5)); |
47 } | 49 } |
48 | 50 |
49 assertSame(1, f(1)); | 51 TestAllModes(f); |
50 assertSame(2, f(2)); | 52 } |
51 %OptimizeFunctionOnNextCall(f); | |
52 assertSame(3, f(3)); | |
53 })(); | |
54 | 53 |
55 // Test for inlined constructors. | 54 TestDoubleSignalingNan(); |
56 (function() { | 55 |
57 function c(x) { | 56 function TestDoubleQuietNan() { |
58 this.property = x; | 57 // NaN with signal bit cleared |
59 } | 58 function f() { |
60 function f(x) { | 59 var bytes = new Uint32Array([0, 0x7FF80000]); |
61 var object = new c(x); | 60 var doubles = new Float64Array(bytes.buffer); |
62 return object.load(); | 61 assertTrue(isNaN(doubles[0])); |
| 62 assertTrue(isNaN(doubles[0]*2.0)); |
| 63 assertTrue(isNaN(doubles[0] + 0.5)); |
63 } | 64 } |
64 | 65 |
65 assertSame(1, f(1)); | 66 TestAllModes(f); |
66 assertSame(2, f(2)); | 67 } |
67 %OptimizeFunctionOnNextCall(f); | 68 |
68 assertSame(3, f(3)); | 69 TestDoubleQuietNan(); |
69 })(); | 70 |
| 71 function TestFloatSignalingNan() { |
| 72 // NaN with signal bit set |
| 73 function f() { |
| 74 var bytes = new Uint32Array([0x7F800001]); |
| 75 var floats = new Float32Array(bytes.buffer); |
| 76 assertTrue(isNaN(floats[0])); |
| 77 assertTrue(isNaN(floats[0]*2.0)); |
| 78 assertTrue(isNaN(floats[0] + 0.5)); |
| 79 } |
| 80 |
| 81 TestAllModes(f); |
| 82 } |
| 83 |
| 84 TestFloatSignalingNan(); |
| 85 |
| 86 function TestFloatQuietNan() { |
| 87 // NaN with signal bit cleared |
| 88 function f() { |
| 89 var bytes = new Uint32Array([0x7FC00000]); |
| 90 var floats = new Float32Array(bytes.buffer); |
| 91 assertTrue(isNaN(floats[0])); |
| 92 assertTrue(isNaN(floats[0]*2.0)); |
| 93 assertTrue(isNaN(floats[0] + 0.5)); |
| 94 } |
| 95 |
| 96 TestAllModes(f); |
| 97 } |
| 98 |
| 99 TestFloatQuietNan(); |
| 100 |
| 101 |
| 102 |
| 103 |
OLD | NEW |