Index: test/mjsunit/math-floor-minus-zero.js |
diff --git a/test/mjsunit/regress/regress-3976.js b/test/mjsunit/math-floor-minus-zero.js |
similarity index 50% |
copy from test/mjsunit/regress/regress-3976.js |
copy to test/mjsunit/math-floor-minus-zero.js |
index efa3ac03bc05a5b1018eb1bdd0db761154f2b664..5488f80a2611f7254a918cff48112e2da2c05f8b 100644 |
--- a/test/mjsunit/regress/regress-3976.js |
+++ b/test/mjsunit/math-floor-minus-zero.js |
@@ -25,56 +25,51 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// Flags: --max-old-space-size=60 --check-handle-count |
+// Flags: --allow-natives-syntax --noalways-opt |
-table = []; |
- |
-for (var i = 0; i < 32; i++) { |
- table[i] = String.fromCharCode(i + 0x410); |
+// Test that a -0 result doesn't cause deopt loops |
+function noDeoptLoop(x) { |
+ return Math.floor(x); |
} |
- |
- |
-var random = (function() { |
- var seed = 10; |
- return function() { |
- seed = (seed * 1009) % 8831; |
- return seed; |
- }; |
-})(); |
- |
- |
-function key(length) { |
- var s = ""; |
- for (var i = 0; i < length; i++) { |
- s += table[random() % 32]; |
- } |
- return '"' + s + '"'; |
+assertEquals(0, noDeoptLoop(0.4)); |
+assertEquals(0, noDeoptLoop(0.4)); |
+assertEquals(0, noDeoptLoop(0.4)); |
+%OptimizeFunctionOnNextCall(noDeoptLoop); |
+assertEquals(0, noDeoptLoop(0.4)); |
+assertEquals(0, noDeoptLoop(0.4)); |
+assertEquals(-Infinity, 1/noDeoptLoop(-0.0)); |
+assertUnoptimized(noDeoptLoop); |
+assertEquals(-1, 1/noDeoptLoop(-1.0)); |
+assertEquals(-1, 1/noDeoptLoop(-0.9)); |
+assertEquals(-1, 1/noDeoptLoop(-0.4)); |
+assertEquals(-1, 1/noDeoptLoop(-0.5)); |
+assertEquals(-Infinity, 1/noDeoptLoop(-0.0)); |
+%OptimizeFunctionOnNextCall(noDeoptLoop); |
+assertEquals(-Infinity, 1/noDeoptLoop(-0.0)); |
+assertOptimized(noDeoptLoop); |
+%ClearFunctionTypeFeedback(noDeoptLoop); |
+%DeoptimizeFunction(noDeoptLoop); |
+ |
+// Test that floor that goes megamorphic is handled correctly. |
+function notFloor(x) { |
+ return -x; |
} |
- |
- |
-function value() { |
- return '[{' + '"field1" : ' + random() + ', "field2" : ' + random() + '}]'; |
+function testMega(f, x) { |
+ return f(x); |
} |
- |
- |
-function generate(n) { |
- var s = '{'; |
- for (var i = 0; i < n; i++) { |
- if (i > 0) s += ', '; |
- s += key(random() % 10 + 7); |
- s += ':'; |
- s += value(); |
- } |
- s += '}'; |
- return s; |
+assertEquals(7, testMega(Math.floor, 7.4)); |
+assertEquals(7, testMega(Math.floor, 7.4)); |
+assertEquals(7, testMega(Math.floor, 7.4)); |
+assertEquals(-7.4, testMega(notFloor, 7.4)); |
+ |
+// Make sure that we can learn about floor specialization from Cranskhaft, which |
+// doesn't insert soft deopts for CallICs. |
+function crankFloorLearn(x) { |
+ return Math.floor(x); |
} |
- |
- |
-print("generating"); |
- |
-var str = generate(50000); |
- |
-print("parsing " + str.length); |
-JSON.parse(str); |
- |
-print("done"); |
+%OptimizeFunctionOnNextCall(crankFloorLearn); |
+assertEquals(12, crankFloorLearn(12.3)); |
+assertOptimized(crankFloorLearn); |
+assertEquals(-Infinity, 1/crankFloorLearn(-0.0)); |
+assertOptimized(crankFloorLearn); |
+assertEquals(-Infinity, 1/crankFloorLearn(-0.0)); |