Changeset 156784 in webkit


Ignore:
Timestamp:
Oct 2, 2013 11:52:19 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

FTL: Refactor compileArithDiv and compileArithMod into one function.
https://bugs.webkit.org/show_bug.cgi?id=122205

Patch by Nadav Rotem <nrotem@apple.com> on 2013-10-02
Reviewed by Filip Pizlo.

  • ftl/FTLLowerDFGToLLVM.cpp:

(JSC::FTL::LowerDFGToLLVM::compileNode):
(JSC::FTL::LowerDFGToLLVM::compileAddSub):
(JSC::FTL::LowerDFGToLLVM::compileArithDivMod):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r156780 r156784  
     12013-10-02  Nadav Rotem  <nrotem@apple.com>
     2
     3        FTL: Refactor compileArithDiv and compileArithMod into one function.
     4        https://bugs.webkit.org/show_bug.cgi?id=122205
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * ftl/FTLLowerDFGToLLVM.cpp:
     9        (JSC::FTL::LowerDFGToLLVM::compileNode):
     10        (JSC::FTL::LowerDFGToLLVM::compileAddSub):
     11        (JSC::FTL::LowerDFGToLLVM::compileArithDivMod):
     12
    1132013-10-02  Anders Carlsson  <andersca@apple.com>
    214
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp

    r156746 r156784  
    280280        case ArithAdd:
    281281        case ValueAdd:
    282             compileAddSub(Add);
     282            compileAddSub();
    283283            break;
    284284        case ArithSub:
    285             compileAddSub(Sub);
     285            compileAddSub();
    286286            break;
    287287        case ArithMul:
     
    289289            break;
    290290        case ArithDiv:
    291             compileArithDiv();
     291            compileArithDivMod();
    292292            break;
    293293        case ArithMod:
    294             compileArithMod();
     294            compileArithDivMod();
    295295            break;
    296296        case ArithMin:
     
    655655    }
    656656   
    657     enum AddOrSubKind {Add, Sub};
    658     void compileAddSub(AddOrSubKind opKind)
    659     {
    660         bool isSub = opKind == Sub;
     657    void compileAddSub()
     658    {
     659        bool isSub =  m_node->op() == ArithSub;
    661660        switch (m_node->binaryUseKind()) {
    662661        case Int32Use: {
     
    779778        }
    780779    }
    781    
    782     void compileArithDiv()
     780
     781    void compileArithDivMod()
    783782    {
    784783        switch (m_node->binaryUseKind()) {
     
    787786            LValue denominator = lowInt32(m_node->child2());
    788787           
    789             LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, ("ArithDiv unsafe denominator"));
    790             LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithDiv continuation"));
    791             LBasicBlock done = FTL_NEW_BLOCK(m_out, ("ArithDiv done"));
     788            LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, ("ArithDivMod unsafe denominator"));
     789            LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithDivMod continuation"));
     790            LBasicBlock done = FTL_NEW_BLOCK(m_out, ("ArithDivMod done"));
    792791           
    793792            Vector<ValueFromBlock, 3> results;
     
    807806            } else {
    808807                // This is the case where we convert the result to an int after we're done. So,
    809                 // if the denominator is zero, then the result should be result should be zero.
     808                // if the denominator is zero, then the result should be zero.
    810809                // If the denominator is not zero (i.e. it's -1 because we're guarded by the
    811810                // check above) and the numerator is -2^31 then the result should be -2^31.
     
    832831           
    833832            if (!bytecodeCanIgnoreNegativeZero(m_node->arithNodeFlags())) {
    834                 LBasicBlock zeroNumerator = FTL_NEW_BLOCK(m_out, ("ArithDiv zero numerator"));
    835                 LBasicBlock numeratorContinuation = FTL_NEW_BLOCK(m_out, ("ArithDiv numerator continuation"));
     833                LBasicBlock zeroNumerator = FTL_NEW_BLOCK(m_out, ("ArithDivMod zero numerator"));
     834                LBasicBlock numeratorContinuation = FTL_NEW_BLOCK(m_out, ("ArithDivMod numerator continuation"));
    836835               
    837836                m_out.branch(m_out.isZero32(numerator), zeroNumerator, numeratorContinuation);
     
    847846            }
    848847           
    849             LValue divisionResult = m_out.div(numerator, denominator);
     848            LValue divModResult = m_node->op() == ArithDiv
     849                ? m_out.div(numerator, denominator)
     850                : m_out.rem(numerator, denominator);
    850851           
    851852            if (bytecodeUsesAsNumber(m_node->arithNodeFlags())) {
    852853                speculate(
    853854                    Overflow, noValue(), 0,
    854                     m_out.notEqual(m_out.mul(divisionResult, denominator), numerator));
    855             }
    856            
    857             results.append(m_out.anchor(divisionResult));
     855                    m_out.notEqual(m_out.mul(divModResult, denominator), numerator));
     856            }
     857           
     858            results.append(m_out.anchor(divModResult));
    858859            m_out.jump(done);
    859860           
     
    865866           
    866867        case NumberUse: {
    867             setDouble(
    868                 m_out.doubleDiv(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
     868            LValue C1 = lowDouble(m_node->child1());
     869            LValue C2 = lowDouble(m_node->child2());
     870            setDouble(m_node->op() == ArithDiv ? m_out.doubleDiv(C1, C2) : m_out.doubleRem(C1, C2));
    869871            break;
    870872        }
     
    876878    }
    877879   
    878     void compileArithMod()
    879     {
    880         switch (m_node->binaryUseKind()) {
    881         case Int32Use: {
    882             LValue numerator = lowInt32(m_node->child1());
    883             LValue denominator = lowInt32(m_node->child2());
    884            
    885             LBasicBlock unsafeDenominator = FTL_NEW_BLOCK(m_out, ("ArithMod unsafe denominator"));
    886             LBasicBlock continuation = FTL_NEW_BLOCK(m_out, ("ArithMod continuation"));
    887             LBasicBlock done = FTL_NEW_BLOCK(m_out, ("ArithMod done"));
    888            
    889             Vector<ValueFromBlock, 3> results;
    890            
    891             LValue adjustedDenominator = m_out.add(denominator, m_out.int32One);
    892            
    893             m_out.branch(m_out.above(adjustedDenominator, m_out.int32One), continuation, unsafeDenominator);
    894            
    895             LBasicBlock lastNext = m_out.appendTo(unsafeDenominator, continuation);
    896            
    897             LValue neg2ToThe31 = m_out.constInt32(-2147483647-1);
    898            
    899             // FIXME: -2^31 / -1 will actually yield negative zero, so we could have a
    900             // separate case for that. But it probably doesn't matter so much.
    901             if (bytecodeUsesAsNumber(m_node->arithNodeFlags())) {
    902                 LValue cond = m_out.bitOr(m_out.isZero32(denominator), m_out.equal(numerator, neg2ToThe31));
    903                 speculate(Overflow, noValue(), 0, cond);
    904                 m_out.jump(continuation);
    905             } else {
    906                 // This is the case where we convert the result to an int after we're done. So,
    907                 // if the denominator is zero, then the result should be result should be zero.
    908                 // If the denominator is not zero (i.e. it's -1 because we're guarded by the
    909                 // check above) and the numerator is -2^31 then the result should be -2^31.
    910                
    911                 LBasicBlock modByZero = FTL_NEW_BLOCK(m_out, ("ArithMod modulo by zero"));
    912                 LBasicBlock notModByZero = FTL_NEW_BLOCK(m_out, ("ArithMod not modulo by zero"));
    913                 LBasicBlock neg2ToThe31ByNeg1 = FTL_NEW_BLOCK(m_out, ("ArithMod -2^31/-1"));
    914                
    915                 m_out.branch(m_out.isZero32(denominator), modByZero, notModByZero);
    916                
    917                 m_out.appendTo(modByZero, notModByZero);
    918                 results.append(m_out.anchor(m_out.int32Zero));
    919                 m_out.jump(done);
    920                
    921                 m_out.appendTo(notModByZero, neg2ToThe31ByNeg1);
    922                 m_out.branch(m_out.equal(numerator, neg2ToThe31), neg2ToThe31ByNeg1, continuation);
    923                
    924                 m_out.appendTo(neg2ToThe31ByNeg1, continuation);
    925                 results.append(m_out.anchor(m_out.int32Zero));
    926                 m_out.jump(done);
    927             }
    928            
    929             m_out.appendTo(continuation, done);
    930            
    931             LValue remainder = m_out.rem(numerator, denominator);
    932            
    933             if (!bytecodeCanIgnoreNegativeZero(m_node->arithNodeFlags())) {
    934                 LBasicBlock negativeNumerator = FTL_NEW_BLOCK(m_out, ("ArithMod negative numerator"));
    935                 LBasicBlock numeratorContinuation = FTL_NEW_BLOCK(m_out, ("ArithMod numerator continuation"));
    936                
    937                 m_out.branch(
    938                     m_out.lessThan(numerator, m_out.int32Zero),
    939                     negativeNumerator, numeratorContinuation);
    940                
    941                 LBasicBlock innerLastNext = m_out.appendTo(negativeNumerator, numeratorContinuation);
    942                
    943                 speculate(NegativeZero, noValue(), 0, m_out.isZero32(remainder));
    944                
    945                 m_out.jump(numeratorContinuation);
    946                
    947                 m_out.appendTo(numeratorContinuation, innerLastNext);
    948             }
    949            
    950             results.append(m_out.anchor(remainder));
    951             m_out.jump(done);
    952            
    953             m_out.appendTo(done, lastNext);
    954            
    955             setInt32(m_out.phi(m_out.int32, results));
    956             break;
    957         }
    958            
    959         case NumberUse: {
    960             setDouble(
    961                 m_out.doubleRem(lowDouble(m_node->child1()), lowDouble(m_node->child2())));
    962             break;
    963         }
    964            
    965         default:
    966             RELEASE_ASSERT_NOT_REACHED();
    967             break;
    968         }
    969     }
    970 
    971880    void compileArithMinOrMax()
    972881    {
Note: See TracChangeset for help on using the changeset viewer.