Title: [183963] trunk/Source/_javascript_Core
Revision
183963
Author
benja...@webkit.org
Date
2015-05-07 17:23:32 -0700 (Thu, 07 May 2015)

Log Message

[JSC] Add basic DFG/FTL support for Math.round
https://bugs.webkit.org/show_bug.cgi?id=144725

Patch by Benjamin Poulain <bpoul...@apple.com> on 2015-05-07
Reviewed by Filip Pizlo.

This patch adds two optimizations targeting Math.round():
-Add a DFGNode ArithRound corresponding to the intrinsic RoundIntrinsic.
-Change the MacroAssembler to be stricter on how we fail to convert a double
 to ingeter. Previously, any number valued zero would fail, now we only
 fail for -0.

Since ArithRound speculate it produces int32, the MacroAssembler assembler
part became necessary because zero is a pretty common output of Math.round()
and we would OSR exit a lot (and eventually recompile for doubles).

The implementation itself of the inline Math.round() is exactly the same
as the C function that exists for Math.round(). We can very likely do better
but it is a good start known to be valid and inlining alone alread provides
significant speedups.

* assembler/X86Assembler.h:
(JSC::X86Assembler::movmskpd_rr):
* assembler/MacroAssemblerX86Common.h:
(JSC::MacroAssemblerX86Common::branchConvertDoubleToInt32):
When we have a zero, get the sign bit out of the double and check if is one.

I'll look into doing the same improvement for ARM.

* bytecode/SpeculatedType.cpp:
(JSC::typeOfDoubleRounding):
(JSC::typeOfDoubleFRound): Deleted.
* bytecode/SpeculatedType.h:
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsic):
* dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* dfg/DFGDoesGC.cpp:
(JSC::DFG::doesGC):
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::roundShouldSpeculateInt32):
(JSC::DFG::Graph::negateShouldSpeculateMachineInt): Deleted.
* dfg/DFGNode.h:
(JSC::DFG::Node::arithNodeFlags):
(JSC::DFG::Node::hasHeapPrediction):
(JSC::DFG::Node::hasArithMode):
* dfg/DFGNodeType.h:
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):
* dfg/DFGSafeToExecute.h:
(JSC::DFG::safeToExecute):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileArithRound):
* dfg/DFGSpeculativeJIT.h:
* dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLIntrinsicRepository.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::convertDoubleToInt32):
(JSC::FTL::LowerDFGToLLVM::compileDoubleAsInt32):
(JSC::FTL::LowerDFGToLLVM::compileArithRound):
* ftl/FTLOutput.h:
(JSC::FTL::Output::ceil64):
* jit/ThunkGenerators.cpp:
* runtime/MathCommon.cpp:
* runtime/MathCommon.h:
* runtime/MathObject.cpp:
(JSC::mathProtoFuncRound):
* tests/stress/math-round-basics.js: Added.
(mathRoundOnIntegers):
(mathRoundOnDoubles):
(mathRoundOnBooleans):
(uselessMathRound):
(mathRoundWithOverflow):
(mathRoundConsumedAsDouble):
(mathRoundDoesNotCareAboutMinusZero):
(mathRoundNoArguments):
(mathRoundTooManyArguments):
(testMathRoundOnConstants):
(mathRoundStructTransition):
(Math.round):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (183962 => 183963)


--- trunk/Source/_javascript_Core/ChangeLog	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-05-08 00:23:32 UTC (rev 183963)
@@ -1,3 +1,95 @@
+2015-05-07  Benjamin Poulain  <bpoul...@apple.com>
+
+        [JSC] Add basic DFG/FTL support for Math.round
+        https://bugs.webkit.org/show_bug.cgi?id=144725
+
+        Reviewed by Filip Pizlo.
+
+        This patch adds two optimizations targeting Math.round():
+        -Add a DFGNode ArithRound corresponding to the intrinsic RoundIntrinsic.
+        -Change the MacroAssembler to be stricter on how we fail to convert a double
+         to ingeter. Previously, any number valued zero would fail, now we only
+         fail for -0.
+
+        Since ArithRound speculate it produces int32, the MacroAssembler assembler
+        part became necessary because zero is a pretty common output of Math.round()
+        and we would OSR exit a lot (and eventually recompile for doubles).
+
+        The implementation itself of the inline Math.round() is exactly the same
+        as the C function that exists for Math.round(). We can very likely do better
+        but it is a good start known to be valid and inlining alone alread provides
+        significant speedups.
+
+        * assembler/X86Assembler.h:
+        (JSC::X86Assembler::movmskpd_rr):
+        * assembler/MacroAssemblerX86Common.h:
+        (JSC::MacroAssemblerX86Common::branchConvertDoubleToInt32):
+        When we have a zero, get the sign bit out of the double and check if is one.
+
+        I'll look into doing the same improvement for ARM.
+
+        * bytecode/SpeculatedType.cpp:
+        (JSC::typeOfDoubleRounding):
+        (JSC::typeOfDoubleFRound): Deleted.
+        * bytecode/SpeculatedType.h:
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::handleIntrinsic):
+        * dfg/DFGClobberize.h:
+        (JSC::DFG::clobberize):
+        * dfg/DFGDoesGC.cpp:
+        (JSC::DFG::doesGC):
+        * dfg/DFGFixupPhase.cpp:
+        (JSC::DFG::FixupPhase::fixupNode):
+        * dfg/DFGGraph.h:
+        (JSC::DFG::Graph::roundShouldSpeculateInt32):
+        (JSC::DFG::Graph::negateShouldSpeculateMachineInt): Deleted.
+        * dfg/DFGNode.h:
+        (JSC::DFG::Node::arithNodeFlags):
+        (JSC::DFG::Node::hasHeapPrediction):
+        (JSC::DFG::Node::hasArithMode):
+        * dfg/DFGNodeType.h:
+        * dfg/DFGPredictionPropagationPhase.cpp:
+        (JSC::DFG::PredictionPropagationPhase::propagate):
+        * dfg/DFGSafeToExecute.h:
+        (JSC::DFG::safeToExecute):
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileArithRound):
+        * dfg/DFGSpeculativeJIT.h:
+        * dfg/DFGSpeculativeJIT32_64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * dfg/DFGSpeculativeJIT64.cpp:
+        (JSC::DFG::SpeculativeJIT::compile):
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLIntrinsicRepository.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileNode):
+        (JSC::FTL::LowerDFGToLLVM::convertDoubleToInt32):
+        (JSC::FTL::LowerDFGToLLVM::compileDoubleAsInt32):
+        (JSC::FTL::LowerDFGToLLVM::compileArithRound):
+        * ftl/FTLOutput.h:
+        (JSC::FTL::Output::ceil64):
+        * jit/ThunkGenerators.cpp:
+        * runtime/MathCommon.cpp:
+        * runtime/MathCommon.h:
+        * runtime/MathObject.cpp:
+        (JSC::mathProtoFuncRound):
+        * tests/stress/math-round-basics.js: Added.
+        (mathRoundOnIntegers):
+        (mathRoundOnDoubles):
+        (mathRoundOnBooleans):
+        (uselessMathRound):
+        (mathRoundWithOverflow):
+        (mathRoundConsumedAsDouble):
+        (mathRoundDoesNotCareAboutMinusZero):
+        (mathRoundNoArguments):
+        (mathRoundTooManyArguments):
+        (testMathRoundOnConstants):
+        (mathRoundStructTransition):
+        (Math.round):
+
 2015-05-07  Saam Barati  <saambara...@gmail.com>
 
         exceptionFuzz tests should explicitly initialize the exceptionFuzz boolean in _javascript_ code through a function in jsc.cpp

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h (183962 => 183963)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -921,8 +921,17 @@
         m_assembler.cvttsd2si_rr(src, dest);
 
         // If the result is zero, it might have been -0.0, and the double comparison won't catch this!
+#if CPU(X86_64)
+        if (negZeroCheck) {
+            Jump valueIsNonZero = branchTest32(NonZero, dest);
+            m_assembler.movmskpd_rr(src, scratchRegister);
+            failureCases.append(branchTest32(NonZero, scratchRegister, TrustedImm32(1)));
+            valueIsNonZero.link(this);
+        }
+#else
         if (negZeroCheck)
             failureCases.append(branchTest32(Zero, dest));
+#endif
 
         // Convert the integer result back to float & compare to the original value - if not equal or unordered (NaN) then jump.
         convertInt32ToDouble(dest, fpTemp);

Modified: trunk/Source/_javascript_Core/assembler/X86Assembler.h (183962 => 183963)


--- trunk/Source/_javascript_Core/assembler/X86Assembler.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/assembler/X86Assembler.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -253,6 +253,7 @@
         OP2_CVTSS2SD_VsdWsd = 0x5A,
         OP2_SUBSD_VsdWsd    = 0x5C,
         OP2_DIVSD_VsdWsd    = 0x5E,
+        OP2_MOVMSKPD_VdEd   = 0x50,
         OP2_SQRTSD_VsdWsd   = 0x51,
         OP2_ANDNPD_VpdWpd   = 0x55,
         OP2_XORPD_VpdWpd    = 0x57,
@@ -1804,6 +1805,12 @@
         m_formatter.twoByteOp(OP2_MOVD_VdEd, (RegisterID)dst, src);
     }
 
+    void movmskpd_rr(XMMRegisterID src, RegisterID dst)
+    {
+        m_formatter.prefix(PRE_SSE_66);
+        m_formatter.twoByteOp64(OP2_MOVMSKPD_VdEd, dst, (RegisterID)src);
+    }
+
 #if CPU(X86_64)
     void movq_rr(XMMRegisterID src, RegisterID dst)
     {

Modified: trunk/Source/_javascript_Core/bytecode/SpeculatedType.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/bytecode/SpeculatedType.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/bytecode/SpeculatedType.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -507,7 +507,7 @@
     return typeOfDoubleNegation(value);
 }
 
-SpeculatedType typeOfDoubleFRound(SpeculatedType value)
+SpeculatedType typeOfDoubleRounding(SpeculatedType value)
 {
     // We might lose bits, which leads to a NaN being purified.
     if (value & SpecDoubleImpureNaN)

Modified: trunk/Source/_javascript_Core/bytecode/SpeculatedType.h (183962 => 183963)


--- trunk/Source/_javascript_Core/bytecode/SpeculatedType.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/bytecode/SpeculatedType.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -422,7 +422,7 @@
 SpeculatedType typeOfDoubleMinMax(SpeculatedType, SpeculatedType);
 SpeculatedType typeOfDoubleNegation(SpeculatedType);
 SpeculatedType typeOfDoubleAbs(SpeculatedType);
-SpeculatedType typeOfDoubleFRound(SpeculatedType);
+SpeculatedType typeOfDoubleRounding(SpeculatedType);
 SpeculatedType typeOfDoublePow(SpeculatedType, SpeculatedType);
 
 // This conservatively models the behavior of arbitrary double operations.

Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -761,6 +761,36 @@
         forNode(node).setType(typeOfDoublePow(forNode(node->child1()).m_type, forNode(node->child2()).m_type));
         break;
     }
+
+    case ArithRound: {
+        JSValue operand = forNode(node->child1()).value();
+        if (operand && operand.isNumber()) {
+            double roundedValue = jsRound(operand.asNumber());
+
+            if (producesInteger(node->arithRoundingMode())) {
+                int32_t roundedValueAsInt32 = static_cast<int32_t>(roundedValue);
+                if (roundedValueAsInt32 == roundedValue) {
+                    if (shouldCheckNegativeZero(node->arithRoundingMode())) {
+                        if (roundedValueAsInt32 || !std::signbit(roundedValue)) {
+                            setConstant(node, jsNumber(roundedValueAsInt32));
+                            break;
+                        }
+                    } else {
+                        setConstant(node, jsNumber(roundedValueAsInt32));
+                        break;
+                    }
+                }
+            } else {
+                setConstant(node, jsDoubleNumber(roundedValue));
+                break;
+            }
+        }
+        if (producesInteger(node->arithRoundingMode()))
+            forNode(node).setType(SpecInt32);
+        else
+            forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
+        break;
+    }
             
     case ArithSqrt: {
         JSValue child = forNode(node->child1()).value();
@@ -778,7 +808,7 @@
             setConstant(node, jsDoubleNumber(static_cast<float>(child.asNumber())));
             break;
         }
-        forNode(node).setType(typeOfDoubleFRound(forNode(node->child1()).m_type));
+        forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
         break;
     }
         

Modified: trunk/Source/_javascript_Core/dfg/DFGArithMode.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGArithMode.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGArithMode.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -40,6 +40,14 @@
     CheckOverflowAndNegativeZero, // Check for both overflow and negative zero.
     DoOverflow // Up-convert to the smallest type that soundly represents all possible results after input type speculation.
 };
+
+// Define the type of operation the rounding operation will perform.
+enum class RoundingMode {
+    Int32, // The round operation produces a integer and -0 is considered as 0.
+    Int32WithNegativeZeroCheck, // The round operation produces a integer and checks for -0.
+    Double // The round operation produce a double. The result can be -0, NaN or (+/-)Infinity.
+};
+
 } // namespace Arith
 
 inline bool doesOverflow(Arith::Mode mode)
@@ -122,6 +130,16 @@
     }
 }
 
+inline bool producesInteger(Arith::RoundingMode mode)
+{
+    return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck || mode == Arith::RoundingMode::Int32;
+}
+
+inline bool shouldCheckNegativeZero(Arith::RoundingMode mode)
+{
+    return mode == Arith::RoundingMode::Int32WithNegativeZeroCheck;
+}
+
 } } // namespace JSC::DFG
 
 namespace WTF {

Modified: trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGByteCodeParser.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -2044,7 +2044,21 @@
         
         return true;
     }
-
+    case RoundIntrinsic: {
+        if (argumentCountIncludingThis == 1) {
+            insertChecks();
+            set(VirtualRegister(resultOperand), addToGraph(JSConstant, OpInfo(m_constantNaN)));
+            return true;
+        }
+        if (argumentCountIncludingThis == 2) {
+            insertChecks();
+            Node* operand = get(virtualRegisterForArgument(1, registerOffset));
+            Node* roundNode = addToGraph(ArithRound, OpInfo(0), OpInfo(prediction), operand);
+            set(VirtualRegister(resultOperand), roundNode);
+            return true;
+        }
+        return false;
+    }
     case IMulIntrinsic: {
         if (argumentCountIncludingThis != 3)
             return false;

Modified: trunk/Source/_javascript_Core/dfg/DFGClobberize.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -134,6 +134,7 @@
     case ArithPow:
     case ArithSqrt:
     case ArithFRound:
+    case ArithRound:
     case ArithSin:
     case ArithCos:
     case ArithLog:

Modified: trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGDoesGC.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -83,6 +83,7 @@
     case ArithMax:
     case ArithPow:
     case ArithSqrt:
+    case ArithRound:
     case ArithFRound:
     case ArithSin:
     case ArithCos:

Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -322,6 +322,28 @@
             fixDoubleOrBooleanEdge(node->child2());
             break;
         }
+
+        case ArithRound: {
+            if (node->child1()->shouldSpeculateInt32OrBooleanForArithmetic() && node->canSpeculateInt32(FixupPass)) {
+                fixIntOrBooleanEdge(node->child1());
+                insertCheck<Int32Use>(m_indexInBlock, node->child1().node());
+                node->convertToIdentity();
+                break;
+            }
+            fixDoubleOrBooleanEdge(node->child1());
+
+            if (isInt32OrBooleanSpeculation(node->getHeapPrediction()) && m_graph.roundShouldSpeculateInt32(node, FixupPass)) {
+                node->setResult(NodeResultInt32);
+                if (bytecodeCanIgnoreNegativeZero(node->arithNodeFlags()))
+                    node->setArithRoundingMode(Arith::RoundingMode::Int32);
+                else
+                    node->setArithRoundingMode(Arith::RoundingMode::Int32WithNegativeZeroCheck);
+            } else {
+                node->setResult(NodeResultDouble);
+                node->setArithRoundingMode(Arith::RoundingMode::Double);
+            }
+            break;
+        }
             
         case ArithSqrt:
         case ArithFRound:

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -314,6 +314,12 @@
             && !hasExitSite(negate, Int52Overflow)
             && negate->canSpeculateInt52(pass);
     }
+
+    bool roundShouldSpeculateInt32(Node* arithRound, PredictionPass pass)
+    {
+        ASSERT(arithRound->op() == ArithRound);
+        return arithRound->canSpeculateInt32(pass) && !hasExitSite(arithRound->origin.semantic, Overflow) && !hasExitSite(arithRound->origin.semantic, NegativeZero);
+    }
     
     static const char *opName(NodeType);
     

Modified: trunk/Source/_javascript_Core/dfg/DFGNode.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGNode.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGNode.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -872,7 +872,7 @@
     NodeFlags arithNodeFlags()
     {
         NodeFlags result = m_flags & NodeArithFlagsMask;
-        if (op() == ArithMul || op() == ArithDiv || op() == ArithMod || op() == ArithNegate || op() == ArithPow || op() == DoubleAsInt32)
+        if (op() == ArithMul || op() == ArithDiv || op() == ArithMod || op() == ArithNegate || op() == ArithPow || op() == ArithRound || op() == DoubleAsInt32)
             return result;
         return result & ~NodeBytecodeNeedsNegZero;
     }
@@ -1242,6 +1242,7 @@
     bool hasHeapPrediction()
     {
         switch (op()) {
+        case ArithRound:
         case GetDirectPname:
         case GetById:
         case GetByIdFlush:
@@ -1563,6 +1564,23 @@
     {
         m_opInfo = mode;
     }
+
+    bool hasArithRoundingMode()
+    {
+        return op() == ArithRound;
+    }
+
+    Arith::RoundingMode arithRoundingMode()
+    {
+        ASSERT(hasArithRoundingMode());
+        return static_cast<Arith::RoundingMode>(m_opInfo);
+    }
+
+    void setArithRoundingMode(Arith::RoundingMode mode)
+    {
+        ASSERT(hasArithRoundingMode());
+        m_opInfo = static_cast<uintptr_t>(mode);
+    }
     
     bool hasVirtualRegister()
     {

Modified: trunk/Source/_javascript_Core/dfg/DFGNodeType.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -150,6 +150,7 @@
     macro(ArithMax, NodeResultNumber) \
     macro(ArithFRound, NodeResultNumber) \
     macro(ArithPow, NodeResultNumber) \
+    macro(ArithRound, NodeResultNumber) \
     macro(ArithSqrt, NodeResultNumber) \
     macro(ArithSin, NodeResultNumber) \
     macro(ArithCos, NodeResultNumber) \

Modified: trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGPredictionPropagationPhase.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -347,7 +347,15 @@
             changed |= setPrediction(SpecBytecodeDouble);
             break;
         }
-            
+
+        case ArithRound: {
+            if (isInt32OrBooleanSpeculation(node->getHeapPrediction()) && m_graph.roundShouldSpeculateInt32(node, m_pass))
+                changed |= setPrediction(SpecInt32);
+            else
+                changed |= setPrediction(SpecBytecodeDouble);
+            break;
+        }
+
         case ArithAbs: {
             SpeculatedType child = node->child1()->prediction();
             if (isInt32OrBooleanSpeculationForArithmetic(child)

Modified: trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGSafeToExecute.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -154,6 +154,7 @@
     case ArithPow:
     case ArithSqrt:
     case ArithFRound:
+    case ArithRound:
     case ArithSin:
     case ArithCos:
     case ArithLog:

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -3544,6 +3544,31 @@
     }
 }
 
+void SpeculativeJIT::compileArithRound(Node* node)
+{
+    ASSERT(node->child1().useKind() == DoubleRepUse);
+
+    SpeculateDoubleOperand value(this, node->child1());
+    FPRReg valueFPR = value.fpr();
+    flushRegisters();
+    FPRResult roundedResultAsDouble(this);
+    FPRReg resultFPR = roundedResultAsDouble.fpr();
+    callOperation(jsRound, resultFPR, valueFPR);
+
+    if (producesInteger(node->arithRoundingMode())) {
+        GPRTemporary roundedResultAsInt32(this);
+        FPRTemporary scratch(this);
+        FPRReg scratchFPR = scratch.fpr();
+        GPRReg resultGPR = roundedResultAsInt32.gpr();
+        JITCompiler::JumpList failureCases;
+        m_jit.branchConvertDoubleToInt32(resultFPR, resultGPR, failureCases, scratchFPR, shouldCheckNegativeZero(node->arithRoundingMode()));
+        speculationCheck(Overflow, JSValueRegs(), node, failureCases);
+
+        int32Result(resultGPR, node);
+    } else
+        doubleResult(resultFPR, node);
+}
+
 void SpeculativeJIT::compileArithSqrt(Node* node)
 {
     SpeculateDoubleOperand op1(this, node->child1());

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -2199,6 +2199,7 @@
     void compileArithDiv(Node*);
     void compileArithMod(Node*);
     void compileArithPow(Node*);
+    void compileArithRound(Node*);
     void compileArithSqrt(Node*);
     void compileArithLog(Node*);
     void compileConstantStoragePointer(Node*);

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -2170,6 +2170,10 @@
         break;
     }
 
+    case ArithRound:
+        compileArithRound(node);
+        break;
+
     case ArithSin: {
         SpeculateDoubleOperand op1(this, node->child1());
         FPRReg op1FPR = op1.fpr();

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -2313,6 +2313,10 @@
         break;
     }
 
+    case ArithRound:
+        compileArithRound(node);
+        break;
+
     case ArithSin: {
         SpeculateDoubleOperand op1(this, node->child1());
         FPRReg op1FPR = op1.fpr();

Modified: trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/ftl/FTLCapabilities.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -63,6 +63,7 @@
     case BitLShift:
     case BitURShift:
     case CheckStructure:
+    case DoubleAsInt32:
     case ArrayifyToStructure:
     case PutStructure:
     case GetButterfly:
@@ -89,6 +90,7 @@
     case ArithSin:
     case ArithCos:
     case ArithPow:
+    case ArithRound:
     case ArithSqrt:
     case ArithLog:
     case ArithFRound:

Modified: trunk/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h (183962 => 183963)


--- trunk/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/ftl/FTLIntrinsicRepository.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -35,6 +35,7 @@
 namespace JSC { namespace FTL {
 
 #define FOR_EACH_FTL_INTRINSIC(macro) \
+    macro(ceil64, "llvm.ceil.f64", functionType(doubleType, doubleType)) \
     macro(ctlz32, "llvm.ctlz.i32", functionType(int32, int32, boolean)) \
     macro(addWithOverflow32, "llvm.sadd.with.overflow.i32", functionType(structType(m_context, int32, boolean), int32, int32)) \
     macro(addWithOverflow64, "llvm.sadd.with.overflow.i64", functionType(structType(m_context, int64, boolean), int64, int64)) \

Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToLLVM.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -443,6 +443,9 @@
         case DoubleRep:
             compileDoubleRep();
             break;
+        case DoubleAsInt32:
+            compileDoubleAsInt32();
+            break;
         case ValueRep:
             compileValueRep();
             break;
@@ -505,6 +508,9 @@
         case ArithPow:
             compileArithPow();
             break;
+        case ArithRound:
+            compileArithRound();
+            break;
         case ArithSqrt:
             compileArithSqrt();
             break;
@@ -970,7 +976,13 @@
             DFG_CRASH(m_graph, m_node, "Bad use kind");
         }
     }
-    
+
+    void compileDoubleAsInt32()
+    {
+        LValue integerValue = convertDoubleToInt32(lowDouble(m_node->child1()), shouldCheckNegativeZero(m_node->arithMode()));
+        setInt32(integerValue);
+    }
+
     void compileValueRep()
     {
         switch (m_node->child1().useKind()) {
@@ -1761,6 +1773,34 @@
         }
     }
 
+    void compileArithRound()
+    {
+        LBasicBlock realPartIsMoreThanHalf = FTL_NEW_BLOCK(m_out, ("ArithRound should round down"));
+        LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithRound continuation"));
+
+        LValue value = lowDouble(m_node->child1());
+        LValue integerValue = m_out.ceil64(value);
+        ValueFromBlock integerValueResult = m_out.anchor(integerValue);
+
+        LValue realPart = m_out.doubleSub(integerValue, value);
+
+        m_out.branch(m_out.doubleGreaterThanOrUnordered(realPart, m_out.constDouble(0.5)), unsure(realPartIsMoreThanHalf), unsure(continuation));
+
+        LBasicBlock lastNext = m_out.appendTo(realPartIsMoreThanHalf, continuation);
+        LValue integerValueRoundedDown = m_out.doubleSub(integerValue, m_out.constDouble(1));
+        ValueFromBlock integerValueRoundedDownResult = m_out.anchor(integerValueRoundedDown);
+        m_out.jump(continuation);
+        m_out.appendTo(continuation, lastNext);
+
+        LValue result = m_out.phi(m_out.doubleType, integerValueResult, integerValueRoundedDownResult);
+
+        if (producesInteger(m_node->arithRoundingMode())) {
+            LValue integerValue = convertDoubleToInt32(result, shouldCheckNegativeZero(m_node->arithRoundingMode()));
+            setInt32(integerValue);
+        } else
+            setDouble(result);
+    }
+
     void compileArithSqrt() { setDouble(m_out.doubleSqrt(lowDouble(m_node->child1()))); }
 
     void compileArithLog() { setDouble(m_out.doubleLog(lowDouble(m_node->child1()))); }
@@ -7235,7 +7275,31 @@
         
         return possibleResult;
     }
-    
+
+    LValue convertDoubleToInt32(LValue value, bool shouldCheckNegativeZero)
+    {
+        LValue integerValue = m_out.fpToInt32(value);
+        LValue integerValueConvertedToDouble = m_out.intToDouble(integerValue);
+        LValue valueNotConvertibleToInteger = m_out.doubleNotEqualOrUnordered(value, integerValueConvertedToDouble);
+        speculate(Overflow, FormattedValue(ValueFormatDouble, value), m_node, valueNotConvertibleToInteger);
+
+        if (shouldCheckNegativeZero) {
+            LBasicBlock valueIsZero = FTL_NEW_BLOCK(m_out, ("ConvertDoubleToInt32 on zero"));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ConvertDoubleToInt32 continuation"));
+            m_out.branch(m_out.isZero32(integerValue), unsure(valueIsZero), unsure(continuation));
+
+            LBasicBlock lastNext = m_out.appendTo(valueIsZero, continuation);
+
+            LValue doubleBitcastToInt64 = m_out.bitCast(value, m_out.int64);
+            LValue signBitSet = m_out.lessThan(doubleBitcastToInt64, m_out.constInt64(0));
+
+            speculate(NegativeZero, FormattedValue(ValueFormatDouble, value), m_node, signBitSet);
+            m_out.jump(continuation);
+            m_out.appendTo(continuation, lastNext);
+        }
+        return integerValue;
+    }
+
     LValue isNumber(LValue jsValue, SpeculatedType type = SpecFullTop)
     {
         if (LValue proven = isProvenValue(type, SpecFullNumber))

Modified: trunk/Source/_javascript_Core/ftl/FTLOutput.h (183962 => 183963)


--- trunk/Source/_javascript_Core/ftl/FTLOutput.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/ftl/FTLOutput.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -139,6 +139,10 @@
     
     LValue insertElement(LValue vector, LValue element, LValue index) { return buildInsertElement(m_builder, vector, element, index); }
 
+    LValue ceil64(LValue operand)
+    {
+        return call(ceil64Intrinsic(), operand);
+    }
     LValue ctlz32(LValue xOperand, LValue yOperand)
     {
         return call(ctlz32Intrinsic(), xOperand, yOperand);

Modified: trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/jit/ThunkGenerators.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -32,6 +32,7 @@
 #include "JSArray.h"
 #include "JSArrayIterator.h"
 #include "JSStack.h"
+#include "MathCommon.h"
 #include "MaxFrameExtentForSlowPathCall.h"
 #include "JSCInlines.h"
 #include "SpecializedThunkJIT.h"
@@ -683,17 +684,7 @@
 #define UnaryDoubleOpWrapper(function) function##Wrapper
 enum MathThunkCallingConvention { };
 typedef MathThunkCallingConvention(*MathThunk)(MathThunkCallingConvention);
-extern "C" {
 
-double jsRound(double) REFERENCED_FROM_ASM;
-double jsRound(double d)
-{
-    double integer = ceil(d);
-    return integer - (integer - d > 0.5);
-}
-
-}
-
 #if CPU(X86_64) && COMPILER(GCC) && (OS(DARWIN) || OS(LINUX))
 
 #define defineUnaryDoubleOpWrapper(function) \

Modified: trunk/Source/_javascript_Core/runtime/MathCommon.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/runtime/MathCommon.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/runtime/MathCommon.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -420,4 +420,12 @@
     return mathPowInternal(x, y);
 }
 
+extern "C" {
+double jsRound(double value)
+{
+    double integer = ceil(value);
+    return integer - (integer - value > 0.5);
+}
+}
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/MathCommon.h (183962 => 183963)


--- trunk/Source/_javascript_Core/runtime/MathCommon.h	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/runtime/MathCommon.h	2015-05-08 00:23:32 UTC (rev 183963)
@@ -54,6 +54,10 @@
 #endif
 }
 
+extern "C" {
+double JIT_OPERATION jsRound(double value) REFERENCED_FROM_ASM WTF_INTERNAL;
 }
 
+}
+
 #endif // MathCommon_h

Modified: trunk/Source/_javascript_Core/runtime/MathObject.cpp (183962 => 183963)


--- trunk/Source/_javascript_Core/runtime/MathObject.cpp	2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/_javascript_Core/runtime/MathObject.cpp	2015-05-08 00:23:32 UTC (rev 183963)
@@ -268,9 +268,7 @@
 
 EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState* exec)
 {
-    double arg = exec->argument(0).toNumber(exec);
-    double integer = ceil(arg);
-    return JSValue::encode(jsNumber(integer - (integer - arg > 0.5)));
+    return JSValue::encode(jsNumber(jsRound(exec->argument(0).toNumber(exec))));
 }
 
 EncodedJSValue JSC_HOST_CALL mathProtoFuncSign(ExecState* exec)

Added: trunk/Source/_javascript_Core/tests/stress/math-round-basics.js (0 => 183963)


--- trunk/Source/_javascript_Core/tests/stress/math-round-basics.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/tests/stress/math-round-basics.js	2015-05-08 00:23:32 UTC (rev 183963)
@@ -0,0 +1,257 @@
+
+function mathRoundOnIntegers(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundOnIntegers);
+
+function mathRoundOnDoubles(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundOnDoubles);
+
+function mathRoundOnBooleans(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundOnBooleans);
+
+// The trivial cases first.
+for (var i = 1; i < 1e4; ++i) {
+    var roundedValue = mathRoundOnIntegers(i);
+    if (roundedValue !== i)
+        throw "mathRoundOnIntegers(" + i + ") = " + roundedValue;
+
+    var roundedValue = mathRoundOnIntegers(-i);
+    if (roundedValue !== -i)
+        throw "mathRoundOnIntegers(" + -i + ") = " + roundedValue;
+
+    var doubleLow = i + 0.4;
+    var roundedValue = mathRoundOnDoubles(doubleLow);
+    if (roundedValue !== i)
+        throw "mathRoundOnDoubles(" + doubleLow + ") = " + roundedValue;
+
+    var doubleHigh = i + 0.6;
+    var roundedValue = mathRoundOnDoubles(doubleHigh);
+    if (roundedValue !== i + 1)
+        throw "mathRoundOnDoubles(" + doubleHigh + ") = " + roundedValue;
+
+    var doubleMid = i + 0.5;
+    var roundedValue = mathRoundOnDoubles(doubleMid);
+    if (roundedValue !== i + 1)
+        throw "mathRoundOnDoubles(" + doubleMid + ") = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.6);
+    if (roundedValue !== -1)
+        throw "mathRoundOnDoubles(-0.6) = " + roundedValue;
+}
+
+// Some more interesting cases, some of them well OSR exit when the return value is zero.
+for (var i = 0; i < 1e4; ++i) {
+    var roundedValue = mathRoundOnIntegers(i);
+    if (roundedValue !== i)
+        throw "mathRoundOnIntegers(" + i + ") = " + roundedValue;
+
+    var roundedValue = mathRoundOnIntegers(-i);
+    if (roundedValue !== -i)
+        throw "mathRoundOnIntegers(-" + i + ") = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.4);
+    if (roundedValue !== 0)
+        throw "mathRoundOnDoubles(-0.4) = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.5);
+    if (roundedValue !== 0)
+        throw "mathRoundOnDoubles(-0.5) = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0);
+    if (!(roundedValue === 0 && (1/roundedValue) === -Infinity))
+        throw "mathRoundOnDoubles(-0) = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(NaN);
+    if (roundedValue === roundedValue)
+        throw "mathRoundOnDoubles(NaN) = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(Number.POSITIVE_INFINITY);
+    if (roundedValue !== Number.POSITIVE_INFINITY)
+        throw "mathRoundOnDoubles(Number.POSITIVE_INFINITY) = " + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(Number.NEGATIVE_INFINITY);
+    if (roundedValue !== Number.NEGATIVE_INFINITY)
+        throw "mathRoundOnDoubles(Number.NEGATIVE_INFINITY) = " + roundedValue;
+
+    var boolean = !!(i % 2);
+    var roundedBoolean = mathRoundOnBooleans(boolean);
+    if (roundedBoolean != boolean)
+        throw "mathRoundOnDoubles(" + boolean + ") = " + roundedBoolean;
+}
+
+function uselessMathRound(value)
+{
+    return Math.round(value|0);
+}
+noInline(uselessMathRound);
+
+for (var i = 0; i < 1e4; ++i) {
+    var roundedValue = uselessMathRound(i);
+    if (roundedValue !== i)
+        throw "uselessMathRound(" + i + ") = " + roundedValue;
+
+    var doubleLow = i + 0.4;
+    var roundedValue = uselessMathRound(doubleLow);
+    if (roundedValue !== i)
+        throw "uselessMathRound(" + doubleLow + ") = " + roundedValue;
+
+    var doubleHigh = i + 0.6;
+    var roundedValue = uselessMathRound(doubleHigh);
+    if (roundedValue !== i)
+        throw "uselessMathRound(" + doubleHigh + ") = " + roundedValue;
+
+    var doubleMid = i + 0.5;
+    var roundedValue = uselessMathRound(doubleMid);
+    if (roundedValue !== i)
+        throw "uselessMathRound(" + doubleMid + ") = " + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.4);
+    if (roundedValue !== 0)
+        throw "uselessMathRound(-0.4) = " + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.5);
+    if (roundedValue !== 0)
+        throw "uselessMathRound(-0.5) = " + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.6);
+    if (roundedValue !== 0)
+        throw "uselessMathRound(-0.6) = " + roundedValue;
+}
+
+function mathRoundWithOverflow(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundWithOverflow);
+
+for (var i = 0; i < 1e4; ++i) {
+    var bigValue = 1000000000000;
+    var roundedValue = mathRoundWithOverflow(bigValue);
+    if (roundedValue !== bigValue)
+        throw "mathRoundWithOverflow(" + bigValue + ") = " + roundedValue;
+}
+
+function mathRoundConsumedAsDouble(value)
+{
+    return Math.round(value) * 0.5;
+}
+noInline(mathRoundConsumedAsDouble);
+
+for (var i = 0; i < 1e4; ++i) {
+    var doubleValue = i + 0.1;
+    var roundedValue = mathRoundConsumedAsDouble(doubleValue);
+    if (roundedValue !== (i * 0.5))
+        throw "mathRoundConsumedAsDouble(" + doubleValue + ") = " + roundedValue;
+
+    var doubleValue = i + 0.6;
+    var roundedValue = mathRoundConsumedAsDouble(doubleValue);
+    if (roundedValue !== ((i + 1) * 0.5))
+        throw "mathRoundConsumedAsDouble(" + doubleValue + ") = " + roundedValue;
+
+}
+
+function mathRoundDoesNotCareAboutMinusZero(value)
+{
+    return Math.round(value)|0;
+}
+noInline(mathRoundDoesNotCareAboutMinusZero);
+
+for (var i = 0; i < 1e4; ++i) {
+    var doubleMid = i + 0.5;
+    var roundedValue = mathRoundDoesNotCareAboutMinusZero(doubleMid);
+    if (roundedValue !== i + 1)
+        throw "mathRoundDoesNotCareAboutMinusZero(" + doubleMid + ") = " + roundedValue;
+}
+
+
+// *** Function arguments. ***
+function mathRoundNoArguments()
+{
+    return Math.round();
+}
+noInline(mathRoundNoArguments);
+
+function mathRoundTooManyArguments(a, b, c)
+{
+    return Math.round(a, b, c);
+}
+noInline(mathRoundTooManyArguments);
+
+for (var i = 0; i < 1e4; ++i) {
+    var value = mathRoundNoArguments();
+    if (value === value)
+        throw "mathRoundNoArguments() = " + value;
+
+    var value = mathRoundTooManyArguments(2.1, 3, 5);
+    if (value !== 2)
+        throw "mathRoundTooManyArguments() = " + value;
+}
+
+
+// *** Constant as arguments. ***
+function testMathRoundOnConstants()
+{
+    var value = Math.round(0);
+    if (value !== 0)
+        throw "Math.round(0) = " + value;
+    var value = Math.round(-0);
+    if (!(value === 0 && (1/value) === -Infinity))
+        throw "Math.round(-0) = " + value;
+    var value = Math.round(1);
+    if (value !== 1)
+        throw "Math.round(1) = " + value;
+    var value = Math.round(-1);
+    if (value !== -1)
+        throw "Math.round(-1) = " + value;
+    var value = Math.round(42);
+    if (value !== 42)
+        throw "Math.round(42) = " + value;
+    var value = Math.round(-42.2);
+    if (value !== -42)
+        throw "Math.round(-42.2) = " + value;
+    var value = Math.round(NaN);
+    if (value === value)
+        throw "Math.round(NaN) = " + value;
+    var value = Math.round(Number.POSITIVE_INFINITI);
+    if (value === value)
+        throw "Math.round(Number.POSITIVE_INFINITI) = " + value;
+    var value = Math.round(Number.NEGATIVE_INFINITI);
+    if (value === value)
+        throw "Math.round(Number.NEGATIVE_INFINITI) = " + value;
+    var value = Math.round(Math.E);
+    if (value !== 3)
+        throw "Math.round(Math.E) = " + value;
+}
+noInline(testMathRoundOnConstants);
+
+for (var i = 0; i < 1e4; ++i) {
+    testMathRoundOnConstants();
+}
+
+
+// *** Struct transition. ***
+function mathRoundStructTransition(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundStructTransition);
+
+for (var i = 0; i < 1e4; ++i) {
+    var value = mathRoundStructTransition(42.5);
+    if (value !== 43)
+        throw "mathRoundStructTransition(42.5) = " + value;
+}
+
+Math.round = function() { return arguments[0] + 5; }
+
+var value = mathRoundStructTransition(42);
+if (value !== 47)
+    throw "mathRoundStructTransition(42) after transition = " + value;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to