| 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 | 48 // Ensure that a negative zero coming from Math.floor is properly handled |
| 56 // by other operations. | 49 // by other operations. |
| 57 function ifloor(x) { | 50 function ifloor(x) { |
| 58 return 1 / Math.floor(x); | 51 return 1 / Math.floor(x); |
| 59 } | 52 } |
| 60 assertEquals(-Infinity, ifloor(-0)); | 53 assertEquals(-Infinity, ifloor(-0)); |
| 61 assertEquals(-Infinity, ifloor(-0)); | 54 assertEquals(-Infinity, ifloor(-0)); |
| 62 assertEquals(-Infinity, ifloor(-0)); | 55 assertEquals(-Infinity, ifloor(-0)); |
| 63 %OptimizeFunctionOnNextCall(ifloor); | 56 %OptimizeFunctionOnNextCall(ifloor); |
| 64 assertEquals(-Infinity, ifloor(-0)); | 57 assertEquals(-Infinity, ifloor(-0)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 testFloor(-2, -1.1); | 72 testFloor(-2, -1.1); |
| 80 testFloor(-2, -1.5); | 73 testFloor(-2, -1.5); |
| 81 testFloor(-2, -1.7); | 74 testFloor(-2, -1.7); |
| 82 | 75 |
| 83 testFloor(0, Number.MIN_VALUE); | 76 testFloor(0, Number.MIN_VALUE); |
| 84 testFloor(-1, -Number.MIN_VALUE); | 77 testFloor(-1, -Number.MIN_VALUE); |
| 85 testFloor(Number.MAX_VALUE, Number.MAX_VALUE); | 78 testFloor(Number.MAX_VALUE, Number.MAX_VALUE); |
| 86 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE); | 79 testFloor(-Number.MAX_VALUE, -Number.MAX_VALUE); |
| 87 testFloor(Infinity, Infinity); | 80 testFloor(Infinity, Infinity); |
| 88 testFloor(-Infinity, -Infinity); | 81 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. | |
| 114 var two_52 = (1 << 30) * (1 << 22); | |
| 115 | |
| 116 testFloor(two_52, two_52); | |
| 117 testFloor(two_52, two_52 + 0.1); | |
| 118 assertEquals(two_52, two_52 + 0.5); | |
| 119 testFloor(two_52, two_52 + 0.5); | |
| 120 assertEquals(two_52 + 1, two_52 + 0.7); | |
| 121 testFloor(two_52 + 1, two_52 + 0.7); | |
| 122 | |
| 123 testFloor(two_52 - 1, two_52 - 1); | |
| 124 testFloor(two_52 - 1, two_52 - 1 + 0.1); | |
| 125 testFloor(two_52 - 1, two_52 - 1 + 0.5); | |
| 126 testFloor(two_52 - 1, two_52 - 1 + 0.7); | |
| 127 | |
| 128 testFloor(-two_52, -two_52); | |
| 129 testFloor(-two_52, -two_52 + 0.1); | |
| 130 testFloor(-two_52, -two_52 + 0.5); | |
| 131 testFloor(-two_52, -two_52 + 0.7); | |
| 132 | |
| 133 testFloor(-two_52 + 1, -two_52 + 1); | |
| 134 testFloor(-two_52 + 1, -two_52 + 1 + 0.1); | |
| 135 testFloor(-two_52 + 1, -two_52 + 1 + 0.5); | |
| 136 testFloor(-two_52 + 1, -two_52 + 1 + 0.7); | |
| 137 } | 82 } |
| 138 | 83 |
| 139 | 84 |
| 140 // Test in a loop to cover the custom IC and GC-related issues. | 85 // Test in a loop to cover the custom IC and GC-related issues. |
| 141 for (var i = 0; i < 500; i++) { | 86 for (var i = 0; i < 100; i++) { |
| 142 test(); | 87 test(); |
| 143 } | 88 } |
| 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 |