OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 27 matching lines...) Expand all Loading... |
38 %OptimizeFunctionOnNextCall(test); | 38 %OptimizeFunctionOnNextCall(test); |
39 assertEquals(expect, test(input)); | 39 assertEquals(expect, test(input)); |
40 } | 40 } |
41 | 41 |
42 function zero() { | 42 function zero() { |
43 var x = 0.5; | 43 var x = 0.5; |
44 return (function() { return x - 0.5; })(); | 44 return (function() { return x - 0.5; })(); |
45 } | 45 } |
46 | 46 |
47 function test() { | 47 function test() { |
48 testFloor(0, 0); | |
49 testFloor(0, zero()); | |
50 testFloor(-0, -0); | |
51 testFloor(Infinity, Infinity); | |
52 testFloor(-Infinity, -Infinity); | |
53 testFloor(NaN, NaN); | |
54 | |
55 // Ensure that a negative zero coming from Math.floor is properly handled | |
56 // by other operations. | |
57 function ifloor(x) { | |
58 return 1 / Math.floor(x); | |
59 } | |
60 assertEquals(-Infinity, ifloor(-0)); | |
61 assertEquals(-Infinity, ifloor(-0)); | |
62 assertEquals(-Infinity, ifloor(-0)); | |
63 %OptimizeFunctionOnNextCall(ifloor); | |
64 assertEquals(-Infinity, ifloor(-0)); | |
65 | |
66 testFloor(0, 0.1); | |
67 testFloor(0, 0.49999999999999994); | |
68 testFloor(0, 0.5); | |
69 testFloor(0, 0.7); | |
70 testFloor(-1, -0.1); | |
71 testFloor(-1, -0.49999999999999994); | |
72 testFloor(-1, -0.5); | |
73 testFloor(-1, -0.7); | |
74 testFloor(1, 1); | |
75 testFloor(1, 1.1); | |
76 testFloor(1, 1.5); | |
77 testFloor(1, 1.7); | |
78 testFloor(-1, -1); | |
79 testFloor(-2, -1.1); | |
80 testFloor(-2, -1.5); | |
81 testFloor(-2, -1.7); | |
82 | |
83 testFloor(0, Number.MIN_VALUE); | |
84 testFloor(-1, -Number.MIN_VALUE); | |
85 testFloor(Number.MAX_VALUE, Number.MAX_VALUE); | |
86 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE); | |
87 testFloor(Infinity, Infinity); | |
88 testFloor(-Infinity, -Infinity); | |
89 | |
90 // 2^30 is a smi boundary. | |
91 var two_30 = 1 << 30; | |
92 | |
93 testFloor(two_30, two_30); | |
94 testFloor(two_30, two_30 + 0.1); | |
95 testFloor(two_30, two_30 + 0.5); | |
96 testFloor(two_30, two_30 + 0.7); | |
97 | |
98 testFloor(two_30 - 1, two_30 - 1); | |
99 testFloor(two_30 - 1, two_30 - 1 + 0.1); | |
100 testFloor(two_30 - 1, two_30 - 1 + 0.5); | |
101 testFloor(two_30 - 1, two_30 - 1 + 0.7); | |
102 | |
103 testFloor(-two_30, -two_30); | |
104 testFloor(-two_30, -two_30 + 0.1); | |
105 testFloor(-two_30, -two_30 + 0.5); | |
106 testFloor(-two_30, -two_30 + 0.7); | |
107 | |
108 testFloor(-two_30 + 1, -two_30 + 1); | |
109 testFloor(-two_30 + 1, -two_30 + 1 + 0.1); | |
110 testFloor(-two_30 + 1, -two_30 + 1 + 0.5); | |
111 testFloor(-two_30 + 1, -two_30 + 1 + 0.7); | |
112 | |
113 // 2^52 is a precision boundary. | 48 // 2^52 is a precision boundary. |
114 var two_52 = (1 << 30) * (1 << 22); | 49 var two_52 = (1 << 30) * (1 << 22); |
115 | 50 |
116 testFloor(two_52, two_52); | 51 testFloor(two_52, two_52); |
117 testFloor(two_52, two_52 + 0.1); | 52 testFloor(two_52, two_52 + 0.1); |
118 assertEquals(two_52, two_52 + 0.5); | 53 assertEquals(two_52, two_52 + 0.5); |
119 testFloor(two_52, two_52 + 0.5); | 54 testFloor(two_52, two_52 + 0.5); |
120 assertEquals(two_52 + 1, two_52 + 0.7); | 55 assertEquals(two_52 + 1, two_52 + 0.7); |
121 testFloor(two_52 + 1, two_52 + 0.7); | 56 testFloor(two_52 + 1, two_52 + 0.7); |
122 | 57 |
123 testFloor(two_52 - 1, two_52 - 1); | 58 testFloor(two_52 - 1, two_52 - 1); |
124 testFloor(two_52 - 1, two_52 - 1 + 0.1); | 59 testFloor(two_52 - 1, two_52 - 1 + 0.1); |
125 testFloor(two_52 - 1, two_52 - 1 + 0.5); | 60 testFloor(two_52 - 1, two_52 - 1 + 0.5); |
126 testFloor(two_52 - 1, two_52 - 1 + 0.7); | 61 testFloor(two_52 - 1, two_52 - 1 + 0.7); |
127 | 62 |
128 testFloor(-two_52, -two_52); | 63 testFloor(-two_52, -two_52); |
129 testFloor(-two_52, -two_52 + 0.1); | 64 testFloor(-two_52, -two_52 + 0.1); |
130 testFloor(-two_52, -two_52 + 0.5); | 65 testFloor(-two_52, -two_52 + 0.5); |
131 testFloor(-two_52, -two_52 + 0.7); | 66 testFloor(-two_52, -two_52 + 0.7); |
132 | 67 |
133 testFloor(-two_52 + 1, -two_52 + 1); | 68 testFloor(-two_52 + 1, -two_52 + 1); |
134 testFloor(-two_52 + 1, -two_52 + 1 + 0.1); | 69 testFloor(-two_52 + 1, -two_52 + 1 + 0.1); |
135 testFloor(-two_52 + 1, -two_52 + 1 + 0.5); | 70 testFloor(-two_52 + 1, -two_52 + 1 + 0.5); |
136 testFloor(-two_52 + 1, -two_52 + 1 + 0.7); | 71 testFloor(-two_52 + 1, -two_52 + 1 + 0.7); |
137 } | 72 } |
138 | 73 |
139 | 74 |
140 // Test in a loop to cover the custom IC and GC-related issues. | 75 // Test in a loop to cover the custom IC and GC-related issues. |
141 for (var i = 0; i < 500; i++) { | 76 for (var i = 0; i < 100; i++) { |
142 test(); | 77 test(); |
143 } | 78 } |
144 | |
145 | |
146 // Regression test for a bug where a negative zero coming from Math.floor | |
147 // was not properly handled by other operations. | |
148 function floorsum(i, n) { | |
149 var ret = Math.floor(n); | |
150 while (--i > 0) { | |
151 ret += Math.floor(n); | |
152 } | |
153 return ret; | |
154 } | |
155 assertEquals(-0, floorsum(1, -0)); | |
156 %OptimizeFunctionOnNextCall(floorsum); | |
157 // The optimized function will deopt. Run it with enough iterations to try | |
158 // to optimize via OSR (triggering the bug). | |
159 assertEquals(-0, floorsum(100000, -0)); | |
OLD | NEW |