⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 204947 in webkit


Ignore:
Timestamp:
Aug 24, 2016, 6:21:43 PM (10 years ago)
Author:
benjamin@webkit.org
Message:

[JSC] Make FRound work with any type
https://bugs.webkit.org/show_bug.cgi?id=161129

Reviewed by Geoffrey Garen.

JSTests:

  • stress/arith-fround-on-various-types.js: Added.

Source/JavaScriptCore:

Math.fround() does nothing with arguments past the first one
(https://tc39.github.io/ecma262/#sec-math.fround).
We can unify ArithFRound with the other single-input intrinsics.

Everything else is same old: if the input type is not a number,
be pessimistic about everything and do a C call.

  • dfg/DFGAbstractInterpreterInlines.h:

(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::handleIntrinsicCall):

  • dfg/DFGClobberize.h:

(JSC::DFG::clobberize):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::fixupNode):

  • dfg/DFGNodeType.h:
  • dfg/DFGOperations.cpp:
  • dfg/DFGOperations.h:
  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileArithFRound):

  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileArithFRound):

Location:
trunk
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r204912 r204947  
     12016-08-24  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        [JSC] Make FRound work with any type
     4        https://bugs.webkit.org/show_bug.cgi?id=161129
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * stress/arith-fround-on-various-types.js: Added.
     9
    1102016-08-24  Filip Pizlo  <fpizlo@apple.com>
    211
  • trunk/Source/JavaScriptCore/ChangeLog

    r204942 r204947  
     12016-08-24  Benjamin Poulain  <benjamin@webkit.org>
     2
     3        [JSC] Make FRound work with any type
     4        https://bugs.webkit.org/show_bug.cgi?id=161129
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Math.fround() does nothing with arguments past the first one
     9        (https://tc39.github.io/ecma262/#sec-math.fround).
     10        We can unify ArithFRound with the other single-input intrinsics.
     11
     12        Everything else is same old: if the input type is not a number,
     13        be pessimistic about everything and do a C call.
     14
     15        * dfg/DFGAbstractInterpreterInlines.h:
     16        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
     17        * dfg/DFGByteCodeParser.cpp:
     18        (JSC::DFG::ByteCodeParser::handleIntrinsicCall):
     19        * dfg/DFGClobberize.h:
     20        (JSC::DFG::clobberize):
     21        * dfg/DFGFixupPhase.cpp:
     22        (JSC::DFG::FixupPhase::fixupNode):
     23        * dfg/DFGNodeType.h:
     24        * dfg/DFGOperations.cpp:
     25        * dfg/DFGOperations.h:
     26        * dfg/DFGSpeculativeJIT.cpp:
     27        (JSC::DFG::SpeculativeJIT::compileArithFRound):
     28        * dfg/DFGSpeculativeJIT.h:
     29        * dfg/DFGSpeculativeJIT32_64.cpp:
     30        (JSC::DFG::SpeculativeJIT::compile):
     31        * dfg/DFGSpeculativeJIT64.cpp:
     32        (JSC::DFG::SpeculativeJIT::compile):
     33        * ftl/FTLLowerDFGToB3.cpp:
     34        (JSC::FTL::DFG::LowerDFGToB3::compileArithFRound):
     35
    1362016-08-24  Andreas Kling  <akling@apple.com>
    237
  • trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h

    r204881 r204947  
    975975            break;
    976976        }
    977         forNode(node).setType(typeOfDoubleRounding(forNode(node->child1()).m_type));
     977        SpeculatedType froundType = SpecFullNumber;
     978        if (node->child1().useKind() == DoubleRepUse)
     979            froundType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
     980        forNode(node).setType(froundType);
    978981        break;
    979982    }
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r204439 r204947  
    21412141        return handleMinMax(resultOperand, ArithMax, registerOffset, argumentCountIncludingThis, insertChecks);
    21422142
    2143     case SqrtIntrinsic:
    21442143    case CosIntrinsic:
     2144    case FRoundIntrinsic:
     2145    case LogIntrinsic:
    21452146    case SinIntrinsic:
    2146     case LogIntrinsic: {
     2147    case SqrtIntrinsic: {
    21472148        if (argumentCountIncludingThis == 1) {
    21482149            insertChecks();
     
    21502151            return true;
    21512152        }
    2152        
     2153
     2154        NodeType nodeType = Unreachable;
    21532155        switch (intrinsic) {
     2156        case CosIntrinsic:
     2157            nodeType = ArithCos;
     2158            break;
     2159        case FRoundIntrinsic:
     2160            nodeType = ArithFRound;
     2161            break;
     2162        case LogIntrinsic:
     2163            nodeType = ArithLog;
     2164            break;
     2165        case SinIntrinsic:
     2166            nodeType = ArithSin;
     2167            break;
    21542168        case SqrtIntrinsic:
    2155             insertChecks();
    2156             set(VirtualRegister(resultOperand), addToGraph(ArithSqrt, get(virtualRegisterForArgument(1, registerOffset))));
    2157             return true;
    2158            
    2159         case CosIntrinsic:
    2160             insertChecks();
    2161             set(VirtualRegister(resultOperand), addToGraph(ArithCos, get(virtualRegisterForArgument(1, registerOffset))));
    2162             return true;
    2163            
    2164         case SinIntrinsic:
    2165             insertChecks();
    2166             set(VirtualRegister(resultOperand), addToGraph(ArithSin, get(virtualRegisterForArgument(1, registerOffset))));
    2167             return true;
    2168 
    2169         case LogIntrinsic:
    2170             insertChecks();
    2171             set(VirtualRegister(resultOperand), addToGraph(ArithLog, get(virtualRegisterForArgument(1, registerOffset))));
    2172             return true;
    2173            
     2169            nodeType = ArithSqrt;
     2170            break;
    21742171        default:
    21752172            RELEASE_ASSERT_NOT_REACHED();
    2176             return false;
    2177         }
     2173        }
     2174        insertChecks();
     2175        set(VirtualRegister(resultOperand), addToGraph(nodeType, get(virtualRegisterForArgument(1, registerOffset))));
     2176        return true;
    21782177    }
    21792178
     
    24742473        insertChecks();
    24752474        set(VirtualRegister(resultOperand), addToGraph(ArithRandom));
    2476         return true;
    2477     }
    2478        
    2479     case FRoundIntrinsic: {
    2480         if (argumentCountIncludingThis != 2)
    2481             return false;
    2482         insertChecks();
    2483         VirtualRegister operand = virtualRegisterForArgument(1, registerOffset);
    2484         set(VirtualRegister(resultOperand), addToGraph(ArithFRound, get(operand)));
    24852475        return true;
    24862476    }
  • trunk/Source/JavaScriptCore/dfg/DFGClobberize.h

    r204881 r204947  
    155155    case ArithMax:
    156156    case ArithPow:
    157     case ArithFRound:
    158157    case GetScope:
    159158    case SkipScope:
     
    188187
    189188    case ArithCos:
     189    case ArithFRound:
    190190    case ArithLog:
    191191    case ArithSin:
  • trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp

    r204881 r204947  
    388388
    389389        case ArithCos:
     390        case ArithFRound:
    390391        case ArithLog:
    391392        case ArithSin:
     
    396397            else
    397398                fixEdge<UntypedUse>(child1);
    398             break;
    399         }
    400         case ArithFRound: {
    401             fixDoubleOrBooleanEdge(node->child1());
    402             node->setResult(NodeResultDouble);
    403399            break;
    404400        }
  • trunk/Source/JavaScriptCore/dfg/DFGNodeType.h

    r204881 r204947  
    153153    macro(ArithMin, NodeResultNumber) \
    154154    macro(ArithMax, NodeResultNumber) \
    155     macro(ArithFRound, NodeResultNumber) \
     155    macro(ArithFRound, NodeResultDouble) \
    156156    macro(ArithPow, NodeResultDouble) \
    157157    macro(ArithRandom, NodeResultDouble | NodeMustGenerate) \
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r204912 r204947  
    335335}
    336336
     337double JIT_OPERATION operationArithFRound(ExecState* exec, EncodedJSValue encodedOp1)
     338{
     339    VM* vm = &exec->vm();
     340    NativeCallFrameTracer tracer(vm, exec);
     341
     342    JSValue op1 = JSValue::decode(encodedOp1);
     343    double a = op1.toNumber(exec);
     344    if (UNLIKELY(vm->exception()))
     345        return JSValue::encode(JSValue());
     346    return static_cast<float>(a);
     347}
     348
    337349double JIT_OPERATION operationArithLog(ExecState* exec, EncodedJSValue encodedOp1)
    338350{
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.h

    r204881 r204947  
    5555EncodedJSValue JIT_OPERATION operationValueDiv(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
    5656double JIT_OPERATION operationArithCos(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
     57double JIT_OPERATION operationArithFRound(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
    5758double JIT_OPERATION operationArithLog(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
    5859double JIT_OPERATION operationArithSin(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r204912 r204947  
    45374537        break;
    45384538    }
     4539}
     4540
     4541void SpeculativeJIT::compileArithFRound(Node* node)
     4542{
     4543    if (node->child1().useKind() == DoubleRepUse) {
     4544        SpeculateDoubleOperand op1(this, node->child1());
     4545        FPRTemporary result(this, op1);
     4546        m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
     4547        m_jit.convertFloatToDouble(result.fpr(), result.fpr());
     4548        doubleResult(result.fpr(), node);
     4549        return;
     4550    }
     4551
     4552    JSValueOperand op1(this, node->child1());
     4553    JSValueRegs op1Regs = op1.jsValueRegs();
     4554    flushRegisters();
     4555    FPRResult result(this);
     4556    callOperation(operationArithFRound, result.fpr(), op1Regs);
     4557    m_jit.exceptionCheck();
     4558    doubleResult(result.fpr(), node);
    45394559}
    45404560
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r204912 r204947  
    24752475    void compileArithMul(Node*);
    24762476    void compileArithDiv(Node*);
     2477    void compileArithFRound(Node*);
    24772478    void compileArithMod(Node*);
    24782479    void compileArithPow(Node*);
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp

    r204912 r204947  
    23682368        break;
    23692369
    2370     case ArithFRound: {
    2371         SpeculateDoubleOperand op1(this, node->child1());
    2372         FPRTemporary result(this, op1);
    2373        
    2374         m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
    2375         m_jit.convertFloatToDouble(result.fpr(), result.fpr());
    2376        
    2377         doubleResult(result.fpr(), node);
    2378         break;
    2379     }
     2370    case ArithFRound:
     2371        compileArithFRound(node);
     2372        break;
    23802373
    23812374    case ArithRandom:
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp

    r204912 r204947  
    24922492        break;
    24932493
    2494     case ArithFRound: {
    2495         SpeculateDoubleOperand op1(this, node->child1());
    2496         FPRTemporary result(this, op1);
    2497        
    2498         m_jit.convertDoubleToFloat(op1.fpr(), result.fpr());
    2499         m_jit.convertFloatToDouble(result.fpr(), result.fpr());
    2500        
    2501         doubleResult(result.fpr(), node);
    2502         break;
    2503     }
     2494    case ArithFRound:
     2495        compileArithFRound(node);
     2496        break;
    25042497
    25052498    case ArithRandom:
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r204912 r204947  
    23162316    void compileArithFRound()
    23172317    {
    2318         setDouble(m_out.fround(lowDouble(m_node->child1())));
     2318        if (m_node->child1().useKind() == DoubleRepUse) {
     2319            setDouble(m_out.fround(lowDouble(m_node->child1())));
     2320            return;
     2321        }
     2322        LValue argument = lowJSValue(m_node->child1());
     2323        LValue result = vmCall(Double, m_out.operation(operationArithFRound), m_callFrame, argument);
     2324        setDouble(result);
    23192325    }
    23202326   
Note: See TracChangeset for help on using the changeset viewer.