Changeset 156784 in webkit
- Timestamp:
- Oct 2, 2013 11:52:19 AM (11 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r156780 r156784 1 2013-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 1 13 2013-10-02 Anders Carlsson <andersca@apple.com> 2 14 -
trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp
r156746 r156784 280 280 case ArithAdd: 281 281 case ValueAdd: 282 compileAddSub( Add);282 compileAddSub(); 283 283 break; 284 284 case ArithSub: 285 compileAddSub( Sub);285 compileAddSub(); 286 286 break; 287 287 case ArithMul: … … 289 289 break; 290 290 case ArithDiv: 291 compileArithDiv ();291 compileArithDivMod(); 292 292 break; 293 293 case ArithMod: 294 compileArith Mod();294 compileArithDivMod(); 295 295 break; 296 296 case ArithMin: … … 655 655 } 656 656 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; 661 660 switch (m_node->binaryUseKind()) { 662 661 case Int32Use: { … … 779 778 } 780 779 } 781 782 void compileArithDiv ()780 781 void compileArithDivMod() 783 782 { 784 783 switch (m_node->binaryUseKind()) { … … 787 786 LValue denominator = lowInt32(m_node->child2()); 788 787 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")); 792 791 793 792 Vector<ValueFromBlock, 3> results; … … 807 806 } else { 808 807 // 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 bezero.808 // if the denominator is zero, then the result should be zero. 810 809 // If the denominator is not zero (i.e. it's -1 because we're guarded by the 811 810 // check above) and the numerator is -2^31 then the result should be -2^31. … … 832 831 833 832 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")); 836 835 837 836 m_out.branch(m_out.isZero32(numerator), zeroNumerator, numeratorContinuation); … … 847 846 } 848 847 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); 850 851 851 852 if (bytecodeUsesAsNumber(m_node->arithNodeFlags())) { 852 853 speculate( 853 854 Overflow, noValue(), 0, 854 m_out.notEqual(m_out.mul(div isionResult, denominator), numerator));855 } 856 857 results.append(m_out.anchor(div isionResult));855 m_out.notEqual(m_out.mul(divModResult, denominator), numerator)); 856 } 857 858 results.append(m_out.anchor(divModResult)); 858 859 m_out.jump(done); 859 860 … … 865 866 866 867 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)); 869 871 break; 870 872 } … … 876 878 } 877 879 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 a900 // 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 the909 // 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 971 880 void compileArithMinOrMax() 972 881 {
Note: See TracChangeset
for help on using the changeset viewer.