<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[183963] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183963">183963</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-07 17:23:32 -0700 (Thu, 07 May 2015)</dd>
</dl>

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

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; 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&lt;AbstractStateType&gt;::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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerMacroAssemblerX86Commonh">trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreassemblerX86Assemblerh">trunk/Source/JavaScriptCore/assembler/X86Assembler.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeSpeculatedTypecpp">trunk/Source/JavaScriptCore/bytecode/SpeculatedType.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodeSpeculatedTypeh">trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGAbstractInterpreterInlinesh">trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGArithModeh">trunk/Source/JavaScriptCore/dfg/DFGArithMode.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGByteCodeParsercpp">trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGClobberizeh">trunk/Source/JavaScriptCore/dfg/DFGClobberize.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGDoesGCcpp">trunk/Source/JavaScriptCore/dfg/DFGDoesGC.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGFixupPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGGraphh">trunk/Source/JavaScriptCore/dfg/DFGGraph.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGNodeh">trunk/Source/JavaScriptCore/dfg/DFGNode.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGNodeTypeh">trunk/Source/JavaScriptCore/dfg/DFGNodeType.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSafeToExecuteh">trunk/Source/JavaScriptCore/dfg/DFGSafeToExecute.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJITh">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJIT32_64cpp">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSpeculativeJIT64cpp">trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLCapabilitiescpp">trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh">trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOutputh">trunk/Source/JavaScriptCore/ftl/FTLOutput.h</a></li>
<li><a href="#trunkSourceJavaScriptCorejitThunkGeneratorscpp">trunk/Source/JavaScriptCore/jit/ThunkGenerators.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeMathCommoncpp">trunk/Source/JavaScriptCore/runtime/MathCommon.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeMathCommonh">trunk/Source/JavaScriptCore/runtime/MathCommon.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeMathObjectcpp">trunk/Source/JavaScriptCore/runtime/MathObject.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressmathroundbasicsjs">trunk/Source/JavaScriptCore/tests/stress/math-round-basics.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -1,3 +1,95 @@
</span><ins>+2015-05-07  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [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&lt;AbstractStateType&gt;::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):
+
</ins><span class="cx"> 2015-05-07  Saam Barati  &lt;saambarati1@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         exceptionFuzz tests should explicitly initialize the exceptionFuzz boolean in JavaScript code through a function in jsc.cpp
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerMacroAssemblerX86Commonh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -921,8 +921,17 @@
</span><span class="cx">         m_assembler.cvttsd2si_rr(src, dest);
</span><span class="cx"> 
</span><span class="cx">         // If the result is zero, it might have been -0.0, and the double comparison won't catch this!
</span><ins>+#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
</ins><span class="cx">         if (negZeroCheck)
</span><span class="cx">             failureCases.append(branchTest32(Zero, dest));
</span><ins>+#endif
</ins><span class="cx"> 
</span><span class="cx">         // Convert the integer result back to float &amp; compare to the original value - if not equal or unordered (NaN) then jump.
</span><span class="cx">         convertInt32ToDouble(dest, fpTemp);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreassemblerX86Assemblerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/assembler/X86Assembler.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/assembler/X86Assembler.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/assembler/X86Assembler.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -253,6 +253,7 @@
</span><span class="cx">         OP2_CVTSS2SD_VsdWsd = 0x5A,
</span><span class="cx">         OP2_SUBSD_VsdWsd    = 0x5C,
</span><span class="cx">         OP2_DIVSD_VsdWsd    = 0x5E,
</span><ins>+        OP2_MOVMSKPD_VdEd   = 0x50,
</ins><span class="cx">         OP2_SQRTSD_VsdWsd   = 0x51,
</span><span class="cx">         OP2_ANDNPD_VpdWpd   = 0x55,
</span><span class="cx">         OP2_XORPD_VpdWpd    = 0x57,
</span><span class="lines">@@ -1804,6 +1805,12 @@
</span><span class="cx">         m_formatter.twoByteOp(OP2_MOVD_VdEd, (RegisterID)dst, src);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void movmskpd_rr(XMMRegisterID src, RegisterID dst)
+    {
+        m_formatter.prefix(PRE_SSE_66);
+        m_formatter.twoByteOp64(OP2_MOVMSKPD_VdEd, dst, (RegisterID)src);
+    }
+
</ins><span class="cx"> #if CPU(X86_64)
</span><span class="cx">     void movq_rr(XMMRegisterID src, RegisterID dst)
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeSpeculatedTypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/SpeculatedType.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/SpeculatedType.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/bytecode/SpeculatedType.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -507,7 +507,7 @@
</span><span class="cx">     return typeOfDoubleNegation(value);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SpeculatedType typeOfDoubleFRound(SpeculatedType value)
</del><ins>+SpeculatedType typeOfDoubleRounding(SpeculatedType value)
</ins><span class="cx"> {
</span><span class="cx">     // We might lose bits, which leads to a NaN being purified.
</span><span class="cx">     if (value &amp; SpecDoubleImpureNaN)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodeSpeculatedTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -422,7 +422,7 @@
</span><span class="cx"> SpeculatedType typeOfDoubleMinMax(SpeculatedType, SpeculatedType);
</span><span class="cx"> SpeculatedType typeOfDoubleNegation(SpeculatedType);
</span><span class="cx"> SpeculatedType typeOfDoubleAbs(SpeculatedType);
</span><del>-SpeculatedType typeOfDoubleFRound(SpeculatedType);
</del><ins>+SpeculatedType typeOfDoubleRounding(SpeculatedType);
</ins><span class="cx"> SpeculatedType typeOfDoublePow(SpeculatedType, SpeculatedType);
</span><span class="cx"> 
</span><span class="cx"> // This conservatively models the behavior of arbitrary double operations.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGAbstractInterpreterInlinesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -761,6 +761,36 @@
</span><span class="cx">         forNode(node).setType(typeOfDoublePow(forNode(node-&gt;child1()).m_type, forNode(node-&gt;child2()).m_type));
</span><span class="cx">         break;
</span><span class="cx">     }
</span><ins>+
+    case ArithRound: {
+        JSValue operand = forNode(node-&gt;child1()).value();
+        if (operand &amp;&amp; operand.isNumber()) {
+            double roundedValue = jsRound(operand.asNumber());
+
+            if (producesInteger(node-&gt;arithRoundingMode())) {
+                int32_t roundedValueAsInt32 = static_cast&lt;int32_t&gt;(roundedValue);
+                if (roundedValueAsInt32 == roundedValue) {
+                    if (shouldCheckNegativeZero(node-&gt;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-&gt;arithRoundingMode()))
+            forNode(node).setType(SpecInt32);
+        else
+            forNode(node).setType(typeOfDoubleRounding(forNode(node-&gt;child1()).m_type));
+        break;
+    }
</ins><span class="cx">             
</span><span class="cx">     case ArithSqrt: {
</span><span class="cx">         JSValue child = forNode(node-&gt;child1()).value();
</span><span class="lines">@@ -778,7 +808,7 @@
</span><span class="cx">             setConstant(node, jsDoubleNumber(static_cast&lt;float&gt;(child.asNumber())));
</span><span class="cx">             break;
</span><span class="cx">         }
</span><del>-        forNode(node).setType(typeOfDoubleFRound(forNode(node-&gt;child1()).m_type));
</del><ins>+        forNode(node).setType(typeOfDoubleRounding(forNode(node-&gt;child1()).m_type));
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGArithModeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGArithMode.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGArithMode.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGArithMode.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -40,6 +40,14 @@
</span><span class="cx">     CheckOverflowAndNegativeZero, // Check for both overflow and negative zero.
</span><span class="cx">     DoOverflow // Up-convert to the smallest type that soundly represents all possible results after input type speculation.
</span><span class="cx"> };
</span><ins>+
+// 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.
+};
+
</ins><span class="cx"> } // namespace Arith
</span><span class="cx"> 
</span><span class="cx"> inline bool doesOverflow(Arith::Mode mode)
</span><span class="lines">@@ -122,6 +130,16 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+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;
+}
+
</ins><span class="cx"> } } // namespace JSC::DFG
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGByteCodeParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -2044,7 +2044,21 @@
</span><span class="cx">         
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><del>-
</del><ins>+    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;
+    }
</ins><span class="cx">     case IMulIntrinsic: {
</span><span class="cx">         if (argumentCountIncludingThis != 3)
</span><span class="cx">             return false;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGClobberizeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGClobberize.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGClobberize.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGClobberize.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -134,6 +134,7 @@
</span><span class="cx">     case ArithPow:
</span><span class="cx">     case ArithSqrt:
</span><span class="cx">     case ArithFRound:
</span><ins>+    case ArithRound:
</ins><span class="cx">     case ArithSin:
</span><span class="cx">     case ArithCos:
</span><span class="cx">     case ArithLog:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGDoesGCcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGDoesGC.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGDoesGC.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGDoesGC.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -83,6 +83,7 @@
</span><span class="cx">     case ArithMax:
</span><span class="cx">     case ArithPow:
</span><span class="cx">     case ArithSqrt:
</span><ins>+    case ArithRound:
</ins><span class="cx">     case ArithFRound:
</span><span class="cx">     case ArithSin:
</span><span class="cx">     case ArithCos:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGFixupPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -322,6 +322,28 @@
</span><span class="cx">             fixDoubleOrBooleanEdge(node-&gt;child2());
</span><span class="cx">             break;
</span><span class="cx">         }
</span><ins>+
+        case ArithRound: {
+            if (node-&gt;child1()-&gt;shouldSpeculateInt32OrBooleanForArithmetic() &amp;&amp; node-&gt;canSpeculateInt32(FixupPass)) {
+                fixIntOrBooleanEdge(node-&gt;child1());
+                insertCheck&lt;Int32Use&gt;(m_indexInBlock, node-&gt;child1().node());
+                node-&gt;convertToIdentity();
+                break;
+            }
+            fixDoubleOrBooleanEdge(node-&gt;child1());
+
+            if (isInt32OrBooleanSpeculation(node-&gt;getHeapPrediction()) &amp;&amp; m_graph.roundShouldSpeculateInt32(node, FixupPass)) {
+                node-&gt;setResult(NodeResultInt32);
+                if (bytecodeCanIgnoreNegativeZero(node-&gt;arithNodeFlags()))
+                    node-&gt;setArithRoundingMode(Arith::RoundingMode::Int32);
+                else
+                    node-&gt;setArithRoundingMode(Arith::RoundingMode::Int32WithNegativeZeroCheck);
+            } else {
+                node-&gt;setResult(NodeResultDouble);
+                node-&gt;setArithRoundingMode(Arith::RoundingMode::Double);
+            }
+            break;
+        }
</ins><span class="cx">             
</span><span class="cx">         case ArithSqrt:
</span><span class="cx">         case ArithFRound:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGGraphh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGGraph.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGGraph.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGGraph.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -314,6 +314,12 @@
</span><span class="cx">             &amp;&amp; !hasExitSite(negate, Int52Overflow)
</span><span class="cx">             &amp;&amp; negate-&gt;canSpeculateInt52(pass);
</span><span class="cx">     }
</span><ins>+
+    bool roundShouldSpeculateInt32(Node* arithRound, PredictionPass pass)
+    {
+        ASSERT(arithRound-&gt;op() == ArithRound);
+        return arithRound-&gt;canSpeculateInt32(pass) &amp;&amp; !hasExitSite(arithRound-&gt;origin.semantic, Overflow) &amp;&amp; !hasExitSite(arithRound-&gt;origin.semantic, NegativeZero);
+    }
</ins><span class="cx">     
</span><span class="cx">     static const char *opName(NodeType);
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGNode.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGNode.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGNode.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -872,7 +872,7 @@
</span><span class="cx">     NodeFlags arithNodeFlags()
</span><span class="cx">     {
</span><span class="cx">         NodeFlags result = m_flags &amp; NodeArithFlagsMask;
</span><del>-        if (op() == ArithMul || op() == ArithDiv || op() == ArithMod || op() == ArithNegate || op() == ArithPow || op() == DoubleAsInt32)
</del><ins>+        if (op() == ArithMul || op() == ArithDiv || op() == ArithMod || op() == ArithNegate || op() == ArithPow || op() == ArithRound || op() == DoubleAsInt32)
</ins><span class="cx">             return result;
</span><span class="cx">         return result &amp; ~NodeBytecodeNeedsNegZero;
</span><span class="cx">     }
</span><span class="lines">@@ -1242,6 +1242,7 @@
</span><span class="cx">     bool hasHeapPrediction()
</span><span class="cx">     {
</span><span class="cx">         switch (op()) {
</span><ins>+        case ArithRound:
</ins><span class="cx">         case GetDirectPname:
</span><span class="cx">         case GetById:
</span><span class="cx">         case GetByIdFlush:
</span><span class="lines">@@ -1563,6 +1564,23 @@
</span><span class="cx">     {
</span><span class="cx">         m_opInfo = mode;
</span><span class="cx">     }
</span><ins>+
+    bool hasArithRoundingMode()
+    {
+        return op() == ArithRound;
+    }
+
+    Arith::RoundingMode arithRoundingMode()
+    {
+        ASSERT(hasArithRoundingMode());
+        return static_cast&lt;Arith::RoundingMode&gt;(m_opInfo);
+    }
+
+    void setArithRoundingMode(Arith::RoundingMode mode)
+    {
+        ASSERT(hasArithRoundingMode());
+        m_opInfo = static_cast&lt;uintptr_t&gt;(mode);
+    }
</ins><span class="cx">     
</span><span class="cx">     bool hasVirtualRegister()
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGNodeTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGNodeType.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGNodeType.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGNodeType.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -150,6 +150,7 @@
</span><span class="cx">     macro(ArithMax, NodeResultNumber) \
</span><span class="cx">     macro(ArithFRound, NodeResultNumber) \
</span><span class="cx">     macro(ArithPow, NodeResultNumber) \
</span><ins>+    macro(ArithRound, NodeResultNumber) \
</ins><span class="cx">     macro(ArithSqrt, NodeResultNumber) \
</span><span class="cx">     macro(ArithSin, NodeResultNumber) \
</span><span class="cx">     macro(ArithCos, NodeResultNumber) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -347,7 +347,15 @@
</span><span class="cx">             changed |= setPrediction(SpecBytecodeDouble);
</span><span class="cx">             break;
</span><span class="cx">         }
</span><del>-            
</del><ins>+
+        case ArithRound: {
+            if (isInt32OrBooleanSpeculation(node-&gt;getHeapPrediction()) &amp;&amp; m_graph.roundShouldSpeculateInt32(node, m_pass))
+                changed |= setPrediction(SpecInt32);
+            else
+                changed |= setPrediction(SpecBytecodeDouble);
+            break;
+        }
+
</ins><span class="cx">         case ArithAbs: {
</span><span class="cx">             SpeculatedType child = node-&gt;child1()-&gt;prediction();
</span><span class="cx">             if (isInt32OrBooleanSpeculationForArithmetic(child)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSafeToExecuteh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSafeToExecute.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSafeToExecute.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGSafeToExecute.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -154,6 +154,7 @@
</span><span class="cx">     case ArithPow:
</span><span class="cx">     case ArithSqrt:
</span><span class="cx">     case ArithFRound:
</span><ins>+    case ArithRound:
</ins><span class="cx">     case ArithSin:
</span><span class="cx">     case ArithCos:
</span><span class="cx">     case ArithLog:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -3544,6 +3544,31 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SpeculativeJIT::compileArithRound(Node* node)
+{
+    ASSERT(node-&gt;child1().useKind() == DoubleRepUse);
+
+    SpeculateDoubleOperand value(this, node-&gt;child1());
+    FPRReg valueFPR = value.fpr();
+    flushRegisters();
+    FPRResult roundedResultAsDouble(this);
+    FPRReg resultFPR = roundedResultAsDouble.fpr();
+    callOperation(jsRound, resultFPR, valueFPR);
+
+    if (producesInteger(node-&gt;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-&gt;arithRoundingMode()));
+        speculationCheck(Overflow, JSValueRegs(), node, failureCases);
+
+        int32Result(resultGPR, node);
+    } else
+        doubleResult(resultFPR, node);
+}
+
</ins><span class="cx"> void SpeculativeJIT::compileArithSqrt(Node* node)
</span><span class="cx"> {
</span><span class="cx">     SpeculateDoubleOperand op1(this, node-&gt;child1());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJITh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -2199,6 +2199,7 @@
</span><span class="cx">     void compileArithDiv(Node*);
</span><span class="cx">     void compileArithMod(Node*);
</span><span class="cx">     void compileArithPow(Node*);
</span><ins>+    void compileArithRound(Node*);
</ins><span class="cx">     void compileArithSqrt(Node*);
</span><span class="cx">     void compileArithLog(Node*);
</span><span class="cx">     void compileConstantStoragePointer(Node*);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJIT32_64cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -2170,6 +2170,10 @@
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    case ArithRound:
+        compileArithRound(node);
+        break;
+
</ins><span class="cx">     case ArithSin: {
</span><span class="cx">         SpeculateDoubleOperand op1(this, node-&gt;child1());
</span><span class="cx">         FPRReg op1FPR = op1.fpr();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSpeculativeJIT64cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -2313,6 +2313,10 @@
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    case ArithRound:
+        compileArithRound(node);
+        break;
+
</ins><span class="cx">     case ArithSin: {
</span><span class="cx">         SpeculateDoubleOperand op1(this, node-&gt;child1());
</span><span class="cx">         FPRReg op1FPR = op1.fpr();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLCapabilitiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -63,6 +63,7 @@
</span><span class="cx">     case BitLShift:
</span><span class="cx">     case BitURShift:
</span><span class="cx">     case CheckStructure:
</span><ins>+    case DoubleAsInt32:
</ins><span class="cx">     case ArrayifyToStructure:
</span><span class="cx">     case PutStructure:
</span><span class="cx">     case GetButterfly:
</span><span class="lines">@@ -89,6 +90,7 @@
</span><span class="cx">     case ArithSin:
</span><span class="cx">     case ArithCos:
</span><span class="cx">     case ArithPow:
</span><ins>+    case ArithRound:
</ins><span class="cx">     case ArithSqrt:
</span><span class="cx">     case ArithLog:
</span><span class="cx">     case ArithFRound:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> namespace JSC { namespace FTL {
</span><span class="cx"> 
</span><span class="cx"> #define FOR_EACH_FTL_INTRINSIC(macro) \
</span><ins>+    macro(ceil64, &quot;llvm.ceil.f64&quot;, functionType(doubleType, doubleType)) \
</ins><span class="cx">     macro(ctlz32, &quot;llvm.ctlz.i32&quot;, functionType(int32, int32, boolean)) \
</span><span class="cx">     macro(addWithOverflow32, &quot;llvm.sadd.with.overflow.i32&quot;, functionType(structType(m_context, int32, boolean), int32, int32)) \
</span><span class="cx">     macro(addWithOverflow64, &quot;llvm.sadd.with.overflow.i64&quot;, functionType(structType(m_context, int64, boolean), int64, int64)) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -443,6 +443,9 @@
</span><span class="cx">         case DoubleRep:
</span><span class="cx">             compileDoubleRep();
</span><span class="cx">             break;
</span><ins>+        case DoubleAsInt32:
+            compileDoubleAsInt32();
+            break;
</ins><span class="cx">         case ValueRep:
</span><span class="cx">             compileValueRep();
</span><span class="cx">             break;
</span><span class="lines">@@ -505,6 +508,9 @@
</span><span class="cx">         case ArithPow:
</span><span class="cx">             compileArithPow();
</span><span class="cx">             break;
</span><ins>+        case ArithRound:
+            compileArithRound();
+            break;
</ins><span class="cx">         case ArithSqrt:
</span><span class="cx">             compileArithSqrt();
</span><span class="cx">             break;
</span><span class="lines">@@ -970,7 +976,13 @@
</span><span class="cx">             DFG_CRASH(m_graph, m_node, &quot;Bad use kind&quot;);
</span><span class="cx">         }
</span><span class="cx">     }
</span><del>-    
</del><ins>+
+    void compileDoubleAsInt32()
+    {
+        LValue integerValue = convertDoubleToInt32(lowDouble(m_node-&gt;child1()), shouldCheckNegativeZero(m_node-&gt;arithMode()));
+        setInt32(integerValue);
+    }
+
</ins><span class="cx">     void compileValueRep()
</span><span class="cx">     {
</span><span class="cx">         switch (m_node-&gt;child1().useKind()) {
</span><span class="lines">@@ -1761,6 +1773,34 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void compileArithRound()
+    {
+        LBasicBlock realPartIsMoreThanHalf = FTL_NEW_BLOCK(m_out, (&quot;ArithRound should round down&quot;));
+        LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArithRound continuation&quot;));
+
+        LValue value = lowDouble(m_node-&gt;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-&gt;arithRoundingMode())) {
+            LValue integerValue = convertDoubleToInt32(result, shouldCheckNegativeZero(m_node-&gt;arithRoundingMode()));
+            setInt32(integerValue);
+        } else
+            setDouble(result);
+    }
+
</ins><span class="cx">     void compileArithSqrt() { setDouble(m_out.doubleSqrt(lowDouble(m_node-&gt;child1()))); }
</span><span class="cx"> 
</span><span class="cx">     void compileArithLog() { setDouble(m_out.doubleLog(lowDouble(m_node-&gt;child1()))); }
</span><span class="lines">@@ -7235,7 +7275,31 @@
</span><span class="cx">         
</span><span class="cx">         return possibleResult;
</span><span class="cx">     }
</span><del>-    
</del><ins>+
+    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, (&quot;ConvertDoubleToInt32 on zero&quot;));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ConvertDoubleToInt32 continuation&quot;));
+            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;
+    }
+
</ins><span class="cx">     LValue isNumber(LValue jsValue, SpeculatedType type = SpecFullTop)
</span><span class="cx">     {
</span><span class="cx">         if (LValue proven = isProvenValue(type, SpecFullNumber))
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOutputh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOutput.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/ftl/FTLOutput.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -139,6 +139,10 @@
</span><span class="cx">     
</span><span class="cx">     LValue insertElement(LValue vector, LValue element, LValue index) { return buildInsertElement(m_builder, vector, element, index); }
</span><span class="cx"> 
</span><ins>+    LValue ceil64(LValue operand)
+    {
+        return call(ceil64Intrinsic(), operand);
+    }
</ins><span class="cx">     LValue ctlz32(LValue xOperand, LValue yOperand)
</span><span class="cx">     {
</span><span class="cx">         return call(ctlz32Intrinsic(), xOperand, yOperand);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejitThunkGeneratorscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jit/ThunkGenerators.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jit/ThunkGenerators.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/jit/ThunkGenerators.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;JSArray.h&quot;
</span><span class="cx"> #include &quot;JSArrayIterator.h&quot;
</span><span class="cx"> #include &quot;JSStack.h&quot;
</span><ins>+#include &quot;MathCommon.h&quot;
</ins><span class="cx"> #include &quot;MaxFrameExtentForSlowPathCall.h&quot;
</span><span class="cx"> #include &quot;JSCInlines.h&quot;
</span><span class="cx"> #include &quot;SpecializedThunkJIT.h&quot;
</span><span class="lines">@@ -683,17 +684,7 @@
</span><span class="cx"> #define UnaryDoubleOpWrapper(function) function##Wrapper
</span><span class="cx"> enum MathThunkCallingConvention { };
</span><span class="cx"> typedef MathThunkCallingConvention(*MathThunk)(MathThunkCallingConvention);
</span><del>-extern &quot;C&quot; {
</del><span class="cx"> 
</span><del>-double jsRound(double) REFERENCED_FROM_ASM;
-double jsRound(double d)
-{
-    double integer = ceil(d);
-    return integer - (integer - d &gt; 0.5);
-}
-
-}
-
</del><span class="cx"> #if CPU(X86_64) &amp;&amp; COMPILER(GCC) &amp;&amp; (OS(DARWIN) || OS(LINUX))
</span><span class="cx"> 
</span><span class="cx"> #define defineUnaryDoubleOpWrapper(function) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeMathCommoncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/MathCommon.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/MathCommon.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/runtime/MathCommon.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -420,4 +420,12 @@
</span><span class="cx">     return mathPowInternal(x, y);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+extern &quot;C&quot; {
+double jsRound(double value)
+{
+    double integer = ceil(value);
+    return integer - (integer - value &gt; 0.5);
+}
+}
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeMathCommonh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/MathCommon.h (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/MathCommon.h        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/runtime/MathCommon.h        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -54,6 +54,10 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+extern &quot;C&quot; {
+double JIT_OPERATION jsRound(double value) REFERENCED_FROM_ASM WTF_INTERNAL;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+}
+
</ins><span class="cx"> #endif // MathCommon_h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeMathObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/MathObject.cpp (183962 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/MathObject.cpp        2015-05-08 00:20:58 UTC (rev 183962)
+++ trunk/Source/JavaScriptCore/runtime/MathObject.cpp        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -268,9 +268,7 @@
</span><span class="cx"> 
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL mathProtoFuncRound(ExecState* exec)
</span><span class="cx"> {
</span><del>-    double arg = exec-&gt;argument(0).toNumber(exec);
-    double integer = ceil(arg);
-    return JSValue::encode(jsNumber(integer - (integer - arg &gt; 0.5)));
</del><ins>+    return JSValue::encode(jsNumber(jsRound(exec-&gt;argument(0).toNumber(exec))));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL mathProtoFuncSign(ExecState* exec)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressmathroundbasicsjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/math-round-basics.js (0 => 183963)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/math-round-basics.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/math-round-basics.js        2015-05-08 00:23:32 UTC (rev 183963)
</span><span class="lines">@@ -0,0 +1,257 @@
</span><ins>+
+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 &lt; 1e4; ++i) {
+    var roundedValue = mathRoundOnIntegers(i);
+    if (roundedValue !== i)
+        throw &quot;mathRoundOnIntegers(&quot; + i + &quot;) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnIntegers(-i);
+    if (roundedValue !== -i)
+        throw &quot;mathRoundOnIntegers(&quot; + -i + &quot;) = &quot; + roundedValue;
+
+    var doubleLow = i + 0.4;
+    var roundedValue = mathRoundOnDoubles(doubleLow);
+    if (roundedValue !== i)
+        throw &quot;mathRoundOnDoubles(&quot; + doubleLow + &quot;) = &quot; + roundedValue;
+
+    var doubleHigh = i + 0.6;
+    var roundedValue = mathRoundOnDoubles(doubleHigh);
+    if (roundedValue !== i + 1)
+        throw &quot;mathRoundOnDoubles(&quot; + doubleHigh + &quot;) = &quot; + roundedValue;
+
+    var doubleMid = i + 0.5;
+    var roundedValue = mathRoundOnDoubles(doubleMid);
+    if (roundedValue !== i + 1)
+        throw &quot;mathRoundOnDoubles(&quot; + doubleMid + &quot;) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.6);
+    if (roundedValue !== -1)
+        throw &quot;mathRoundOnDoubles(-0.6) = &quot; + roundedValue;
+}
+
+// Some more interesting cases, some of them well OSR exit when the return value is zero.
+for (var i = 0; i &lt; 1e4; ++i) {
+    var roundedValue = mathRoundOnIntegers(i);
+    if (roundedValue !== i)
+        throw &quot;mathRoundOnIntegers(&quot; + i + &quot;) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnIntegers(-i);
+    if (roundedValue !== -i)
+        throw &quot;mathRoundOnIntegers(-&quot; + i + &quot;) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.4);
+    if (roundedValue !== 0)
+        throw &quot;mathRoundOnDoubles(-0.4) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0.5);
+    if (roundedValue !== 0)
+        throw &quot;mathRoundOnDoubles(-0.5) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(-0);
+    if (!(roundedValue === 0 &amp;&amp; (1/roundedValue) === -Infinity))
+        throw &quot;mathRoundOnDoubles(-0) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(NaN);
+    if (roundedValue === roundedValue)
+        throw &quot;mathRoundOnDoubles(NaN) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(Number.POSITIVE_INFINITY);
+    if (roundedValue !== Number.POSITIVE_INFINITY)
+        throw &quot;mathRoundOnDoubles(Number.POSITIVE_INFINITY) = &quot; + roundedValue;
+
+    var roundedValue = mathRoundOnDoubles(Number.NEGATIVE_INFINITY);
+    if (roundedValue !== Number.NEGATIVE_INFINITY)
+        throw &quot;mathRoundOnDoubles(Number.NEGATIVE_INFINITY) = &quot; + roundedValue;
+
+    var boolean = !!(i % 2);
+    var roundedBoolean = mathRoundOnBooleans(boolean);
+    if (roundedBoolean != boolean)
+        throw &quot;mathRoundOnDoubles(&quot; + boolean + &quot;) = &quot; + roundedBoolean;
+}
+
+function uselessMathRound(value)
+{
+    return Math.round(value|0);
+}
+noInline(uselessMathRound);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    var roundedValue = uselessMathRound(i);
+    if (roundedValue !== i)
+        throw &quot;uselessMathRound(&quot; + i + &quot;) = &quot; + roundedValue;
+
+    var doubleLow = i + 0.4;
+    var roundedValue = uselessMathRound(doubleLow);
+    if (roundedValue !== i)
+        throw &quot;uselessMathRound(&quot; + doubleLow + &quot;) = &quot; + roundedValue;
+
+    var doubleHigh = i + 0.6;
+    var roundedValue = uselessMathRound(doubleHigh);
+    if (roundedValue !== i)
+        throw &quot;uselessMathRound(&quot; + doubleHigh + &quot;) = &quot; + roundedValue;
+
+    var doubleMid = i + 0.5;
+    var roundedValue = uselessMathRound(doubleMid);
+    if (roundedValue !== i)
+        throw &quot;uselessMathRound(&quot; + doubleMid + &quot;) = &quot; + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.4);
+    if (roundedValue !== 0)
+        throw &quot;uselessMathRound(-0.4) = &quot; + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.5);
+    if (roundedValue !== 0)
+        throw &quot;uselessMathRound(-0.5) = &quot; + roundedValue;
+
+    var roundedValue = uselessMathRound(-0.6);
+    if (roundedValue !== 0)
+        throw &quot;uselessMathRound(-0.6) = &quot; + roundedValue;
+}
+
+function mathRoundWithOverflow(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundWithOverflow);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    var bigValue = 1000000000000;
+    var roundedValue = mathRoundWithOverflow(bigValue);
+    if (roundedValue !== bigValue)
+        throw &quot;mathRoundWithOverflow(&quot; + bigValue + &quot;) = &quot; + roundedValue;
+}
+
+function mathRoundConsumedAsDouble(value)
+{
+    return Math.round(value) * 0.5;
+}
+noInline(mathRoundConsumedAsDouble);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    var doubleValue = i + 0.1;
+    var roundedValue = mathRoundConsumedAsDouble(doubleValue);
+    if (roundedValue !== (i * 0.5))
+        throw &quot;mathRoundConsumedAsDouble(&quot; + doubleValue + &quot;) = &quot; + roundedValue;
+
+    var doubleValue = i + 0.6;
+    var roundedValue = mathRoundConsumedAsDouble(doubleValue);
+    if (roundedValue !== ((i + 1) * 0.5))
+        throw &quot;mathRoundConsumedAsDouble(&quot; + doubleValue + &quot;) = &quot; + roundedValue;
+
+}
+
+function mathRoundDoesNotCareAboutMinusZero(value)
+{
+    return Math.round(value)|0;
+}
+noInline(mathRoundDoesNotCareAboutMinusZero);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    var doubleMid = i + 0.5;
+    var roundedValue = mathRoundDoesNotCareAboutMinusZero(doubleMid);
+    if (roundedValue !== i + 1)
+        throw &quot;mathRoundDoesNotCareAboutMinusZero(&quot; + doubleMid + &quot;) = &quot; + 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 &lt; 1e4; ++i) {
+    var value = mathRoundNoArguments();
+    if (value === value)
+        throw &quot;mathRoundNoArguments() = &quot; + value;
+
+    var value = mathRoundTooManyArguments(2.1, 3, 5);
+    if (value !== 2)
+        throw &quot;mathRoundTooManyArguments() = &quot; + value;
+}
+
+
+// *** Constant as arguments. ***
+function testMathRoundOnConstants()
+{
+    var value = Math.round(0);
+    if (value !== 0)
+        throw &quot;Math.round(0) = &quot; + value;
+    var value = Math.round(-0);
+    if (!(value === 0 &amp;&amp; (1/value) === -Infinity))
+        throw &quot;Math.round(-0) = &quot; + value;
+    var value = Math.round(1);
+    if (value !== 1)
+        throw &quot;Math.round(1) = &quot; + value;
+    var value = Math.round(-1);
+    if (value !== -1)
+        throw &quot;Math.round(-1) = &quot; + value;
+    var value = Math.round(42);
+    if (value !== 42)
+        throw &quot;Math.round(42) = &quot; + value;
+    var value = Math.round(-42.2);
+    if (value !== -42)
+        throw &quot;Math.round(-42.2) = &quot; + value;
+    var value = Math.round(NaN);
+    if (value === value)
+        throw &quot;Math.round(NaN) = &quot; + value;
+    var value = Math.round(Number.POSITIVE_INFINITI);
+    if (value === value)
+        throw &quot;Math.round(Number.POSITIVE_INFINITI) = &quot; + value;
+    var value = Math.round(Number.NEGATIVE_INFINITI);
+    if (value === value)
+        throw &quot;Math.round(Number.NEGATIVE_INFINITI) = &quot; + value;
+    var value = Math.round(Math.E);
+    if (value !== 3)
+        throw &quot;Math.round(Math.E) = &quot; + value;
+}
+noInline(testMathRoundOnConstants);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    testMathRoundOnConstants();
+}
+
+
+// *** Struct transition. ***
+function mathRoundStructTransition(value)
+{
+    return Math.round(value);
+}
+noInline(mathRoundStructTransition);
+
+for (var i = 0; i &lt; 1e4; ++i) {
+    var value = mathRoundStructTransition(42.5);
+    if (value !== 43)
+        throw &quot;mathRoundStructTransition(42.5) = &quot; + value;
+}
+
+Math.round = function() { return arguments[0] + 5; }
+
+var value = mathRoundStructTransition(42);
+if (value !== 47)
+    throw &quot;mathRoundStructTransition(42) after transition = &quot; + value;
</ins></span></pre>
</div>
</div>

</body>
</html>