<!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>[163004] branches/jsCStack/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/163004">163004</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-01-28 22:29:22 -0800 (Tue, 28 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>FTL should support ArrayPop
https://bugs.webkit.org/show_bug.cgi?id=127749

Reviewed by Geoffrey Garen.

* ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* ftl/FTLIntrinsicRepository.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileArrayPush):
(JSC::FTL::LowerDFGToLLVM::compileArrayPop):
* tests/stress/array-pop-contiguous.js: Added.
(foo):
* tests/stress/array-pop-double.js: Added.
(foo):
* tests/stress/array-pop-int32.js: Added.
(foo):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoreChangeLog">branches/jsCStack/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreftlFTLCapabilitiescpp">branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreftlFTLIntrinsicRepositoryh">branches/jsCStack/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressarraypopcontiguousjs">branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-contiguous.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressarraypopdoublejs">branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-double.js</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoretestsstressarraypopint32js">branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-int32.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjsCStackSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ChangeLog (163003 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-29 06:12:19 UTC (rev 163003)
+++ branches/jsCStack/Source/JavaScriptCore/ChangeLog        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2014-01-28  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        FTL should support ArrayPop
+        https://bugs.webkit.org/show_bug.cgi?id=127749
+
+        Reviewed by Geoffrey Garen.
+
+        * ftl/FTLCapabilities.cpp:
+        (JSC::FTL::canCompile):
+        * ftl/FTLIntrinsicRepository.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileNode):
+        (JSC::FTL::LowerDFGToLLVM::compileArrayPush):
+        (JSC::FTL::LowerDFGToLLVM::compileArrayPop):
+        * tests/stress/array-pop-contiguous.js: Added.
+        (foo):
+        * tests/stress/array-pop-double.js: Added.
+        (foo):
+        * tests/stress/array-pop-int32.js: Added.
+        (foo):
+
+2014-01-28  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
</ins><span class="cx">         DFG ArrayPop double array mishandles the NaN hole installation
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=127813
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreftlFTLCapabilitiescpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp (163003 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2014-01-29 06:12:19 UTC (rev 163003)
+++ branches/jsCStack/Source/JavaScriptCore/ftl/FTLCapabilities.cpp        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -202,6 +202,7 @@
</span><span class="cx">         }
</span><span class="cx">         break;
</span><span class="cx">     case ArrayPush:
</span><ins>+    case ArrayPop:
</ins><span class="cx">         switch (node-&gt;arrayMode().type()) {
</span><span class="cx">         case Array::Int32:
</span><span class="cx">         case Array::Contiguous:
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreftlFTLIntrinsicRepositoryh"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h (163003 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2014-01-29 06:12:19 UTC (rev 163003)
+++ branches/jsCStack/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx">     macro(C_JITOperation_ESt, functionType(intPtr, intPtr, intPtr)) \
</span><span class="cx">     macro(I_JITOperation_EJss, functionType(intPtr, intPtr, intPtr)) \
</span><span class="cx">     macro(J_JITOperation_E, functionType(int64, intPtr)) \
</span><ins>+    macro(J_JITOperation_EA, functionType(int64, intPtr, intPtr)) \
</ins><span class="cx">     macro(J_JITOperation_EAZ, functionType(int64, intPtr, intPtr, int32)) \
</span><span class="cx">     macro(J_JITOperation_EDA, functionType(int64, intPtr, doubleType, intPtr)) \
</span><span class="cx">     macro(J_JITOperation_EJA, functionType(int64, intPtr, int64, intPtr)) \
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (163003 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-01-29 06:12:19 UTC (rev 163003)
+++ branches/jsCStack/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -419,6 +419,9 @@
</span><span class="cx">         case ArrayPush:
</span><span class="cx">             compileArrayPush();
</span><span class="cx">             break;
</span><ins>+        case ArrayPop:
+            compileArrayPop();
+            break;
</ins><span class="cx">         case NewObject:
</span><span class="cx">             compileNewObject();
</span><span class="cx">             break;
</span><span class="lines">@@ -2215,9 +2218,9 @@
</span><span class="cx"> 
</span><span class="cx">             LValue prevLength = m_out.load32(storage, m_heaps.Butterfly_publicLength);
</span><span class="cx">             
</span><del>-            LBasicBlock fastPath = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush int32/contiguous fast path&quot;));
-            LBasicBlock slowPath = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush int32/contiguous slow path&quot;));
-            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush int32/contiguous continuation&quot;));
</del><ins>+            LBasicBlock fastPath = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush fast path&quot;));
+            LBasicBlock slowPath = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush slow path&quot;));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArrayPush continuation&quot;));
</ins><span class="cx">             
</span><span class="cx">             m_out.branch(
</span><span class="cx">                 m_out.aboveOrEqual(
</span><span class="lines">@@ -2256,6 +2259,60 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void compileArrayPop()
+    {
+        LValue base = lowCell(m_node-&gt;child1());
+        LValue storage = lowStorage(m_node-&gt;child2());
+        
+        switch (m_node-&gt;arrayMode().type()) {
+        case Array::Int32:
+        case Array::Double:
+        case Array::Contiguous: {
+            IndexedAbstractHeap&amp; heap = m_heaps.forArrayType(m_node-&gt;arrayMode().type());
+            
+            LBasicBlock fastCase = FTL_NEW_BLOCK(m_out, (&quot;ArrayPop fast case&quot;));
+            LBasicBlock slowCase = FTL_NEW_BLOCK(m_out, (&quot;ArrayPop slow case&quot;));
+            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, (&quot;ArrayPop continuation&quot;));
+            
+            LValue prevLength = m_out.load32(storage, m_heaps.Butterfly_publicLength);
+            
+            Vector&lt;ValueFromBlock, 3&gt; results;
+            results.append(m_out.anchor(m_out.constInt64(JSValue::encode(jsUndefined()))));
+            m_out.branch(m_out.isZero32(prevLength), continuation, fastCase);
+            
+            LBasicBlock lastNext = m_out.appendTo(fastCase, slowCase);
+            LValue newLength = m_out.sub(prevLength, m_out.int32One);
+            m_out.store32(newLength, storage, m_heaps.Butterfly_publicLength);
+            TypedPointer pointer = m_out.baseIndex(
+                heap, storage, m_out.zeroExt(newLength, m_out.intPtr));
+            if (m_node-&gt;arrayMode().type() != Array::Double) {
+                LValue result = m_out.load64(pointer);
+                m_out.store64(m_out.int64Zero, pointer);
+                results.append(m_out.anchor(result));
+                m_out.branch(m_out.notZero64(result), continuation, slowCase);
+            } else {
+                LValue result = m_out.loadDouble(pointer);
+                m_out.store64(m_out.constInt64(bitwise_cast&lt;int64_t&gt;(QNaN)), pointer);
+                results.append(m_out.anchor(boxDouble(result)));
+                m_out.branch(m_out.doubleEqual(result, result), continuation, slowCase);
+            }
+            
+            m_out.appendTo(slowCase, continuation);
+            results.append(m_out.anchor(vmCall(
+                m_out.operation(operationArrayPopAndRecoverLength), m_callFrame, base)));
+            m_out.jump(continuation);
+            
+            m_out.appendTo(continuation, lastNext);
+            setJSValue(m_out.phi(m_out.int64, results));
+            return;
+        }
+
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return;
+        }
+    }
+    
</ins><span class="cx">     void compileNewObject()
</span><span class="cx">     {
</span><span class="cx">         Structure* structure = m_node-&gt;structure();
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressarraypopcontiguousjs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-contiguous.js (0 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-contiguous.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-contiguous.js        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+function foo(array) {
+    return [array.pop(), array.pop(), array.pop(), array.pop()];
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 100000; ++i) {
+    var result = foo([&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]);
+    if (result.toString() != &quot;baz,bar,foo,&quot;)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressarraypopdoublejs"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-double.js (0 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-double.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-double.js        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+function foo(array) {
+    return [array.pop(), array.pop(), array.pop(), array.pop()];
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 100000; ++i) {
+    var result = foo([1.5, 2.5, 3.5]);
+    if (result.toString() != &quot;3.5,2.5,1.5,&quot;)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoretestsstressarraypopint32js"></a>
<div class="addfile"><h4>Added: branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-int32.js (0 => 163004)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-int32.js                                (rev 0)
+++ branches/jsCStack/Source/JavaScriptCore/tests/stress/array-pop-int32.js        2014-01-29 06:29:22 UTC (rev 163004)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+function foo(array) {
+    return [array.pop(), array.pop(), array.pop(), array.pop()];
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 100000; ++i) {
+    var result = foo([1, 2, 3]);
+    if (result.toString() != &quot;3,2,1,&quot;)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre>
</div>
</div>

</body>
</html>