Changeset 204849 in webkit


Ignore:
Timestamp:
Aug 23, 2016, 12:09:50 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

[JSC] Make Math.cos() and Math.sin() work with any argument type
https://bugs.webkit.org/show_bug.cgi?id=161069

Patch by Benjamin Poulain <bpoulain@apple.com> on 2016-08-23
Reviewed by Geoffrey Garen.

JSTests:

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

Source/JavaScriptCore:

Same as the ArithSqrt patch: add a generic path if the argument
is not a number.

  • dfg/DFGAbstractInterpreterInlines.h:

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

  • 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::compileArithCos):
(JSC::DFG::SpeculativeJIT::compileArithSin):

  • 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::compileArithSin):
(JSC::FTL::DFG::LowerDFGToB3::compileArithCos):

Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r204848 r204849  
     12016-08-23  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] Make Math.cos() and Math.sin() work with any argument type
     4        https://bugs.webkit.org/show_bug.cgi?id=161069
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * stress/arith-cos-on-various-types.js: Added.
     9        * stress/arith-sin-on-various-types.js: Added.
     10
    1112016-08-23  Yusuke Suzuki  <utatane.tea@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r204848 r204849  
     12016-08-23  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] Make Math.cos() and Math.sin() work with any argument type
     4        https://bugs.webkit.org/show_bug.cgi?id=161069
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Same as the ArithSqrt patch: add a generic path if the argument
     9        is not a number.
     10
     11        * dfg/DFGAbstractInterpreterInlines.h:
     12        (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
     13        * dfg/DFGClobberize.h:
     14        (JSC::DFG::clobberize):
     15        * dfg/DFGFixupPhase.cpp:
     16        (JSC::DFG::FixupPhase::fixupNode):
     17        * dfg/DFGNodeType.h:
     18        * dfg/DFGOperations.cpp:
     19        * dfg/DFGOperations.h:
     20        * dfg/DFGSpeculativeJIT.cpp:
     21        (JSC::DFG::SpeculativeJIT::compileArithCos):
     22        (JSC::DFG::SpeculativeJIT::compileArithSin):
     23        * dfg/DFGSpeculativeJIT.h:
     24        * dfg/DFGSpeculativeJIT32_64.cpp:
     25        (JSC::DFG::SpeculativeJIT::compile):
     26        * dfg/DFGSpeculativeJIT64.cpp:
     27        (JSC::DFG::SpeculativeJIT::compile):
     28        * ftl/FTLLowerDFGToB3.cpp:
     29        (JSC::FTL::DFG::LowerDFGToB3::compileArithSin):
     30        (JSC::FTL::DFG::LowerDFGToB3::compileArithCos):
     31
    1322016-08-23  Yusuke Suzuki  <utatane.tea@gmail.com>
    233
  • trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h

    r204670 r204849  
    985985            break;
    986986        }
    987         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
     987        SpeculatedType sinType = SpecFullNumber;
     988        if (node->child1().useKind() == DoubleRepUse)
     989            sinType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
     990        forNode(node).setType(sinType);
    988991        break;
    989992    }
     
    995998            break;
    996999        }
    997         forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
     1000        SpeculatedType cosType = SpecFullNumber;
     1001        if (node->child1().useKind() == DoubleRepUse)
     1002            cosType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
     1003        forNode(node).setType(cosType);
    9981004        break;
    9991005    }
  • trunk/Source/JavaScriptCore/dfg/DFGClobberize.h

    r204670 r204849  
    156156    case ArithPow:
    157157    case ArithFRound:
    158     case ArithSin:
    159     case ArithCos:
    160158    case ArithLog:
    161159    case GetScope:
     
    190188        return;
    191189
     190    case ArithCos:
     191    case ArithSin:
    192192    case ArithSqrt:
    193193        if (node->child1().useKind() == DoubleRepUse)
  • trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp

    r204699 r204849  
    386386            break;
    387387        }
    388            
     388
     389        case ArithCos:
     390        case ArithSin:
    389391        case ArithSqrt: {
    390392            Edge& child1 = node->child1();
     
    396398        }
    397399        case ArithFRound:
    398         case ArithSin:
    399         case ArithCos:
    400400        case ArithLog: {
    401401            fixDoubleOrBooleanEdge(node->child1());
  • trunk/Source/JavaScriptCore/dfg/DFGNodeType.h

    r204670 r204849  
    161161    macro(ArithTrunc, NodeResultNumber) \
    162162    macro(ArithSqrt, NodeResultDouble) \
    163     macro(ArithSin, NodeResultNumber) \
    164     macro(ArithCos, NodeResultNumber) \
     163    macro(ArithSin, NodeResultDouble) \
     164    macro(ArithCos, NodeResultDouble) \
    165165    macro(ArithLog, NodeResultNumber) \
    166166    \
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r204670 r204849  
    323323}
    324324
     325double JIT_OPERATION operationArithCos(ExecState* exec, EncodedJSValue encodedOp1)
     326{
     327    VM* vm = &exec->vm();
     328    NativeCallFrameTracer tracer(vm, exec);
     329
     330    JSValue op1 = JSValue::decode(encodedOp1);
     331    double a = op1.toNumber(exec);
     332    if (UNLIKELY(vm->exception()))
     333        return JSValue::encode(JSValue());
     334    return cos(a);
     335}
     336
     337double JIT_OPERATION operationArithSin(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 sin(a);
     347}
     348
    325349double JIT_OPERATION operationArithSqrt(ExecState* exec, EncodedJSValue encodedOp1)
    326350{
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.h

    r204670 r204849  
    5454EncodedJSValue JIT_OPERATION operationValueAddNotNumber(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
    5555EncodedJSValue JIT_OPERATION operationValueDiv(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
     56double JIT_OPERATION operationArithCos(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
     57double JIT_OPERATION operationArithSin(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
    5658double JIT_OPERATION operationArithSqrt(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
    5759EncodedJSValue JIT_OPERATION operationGetByVal(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty) WTF_INTERNAL;
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r204670 r204849  
    38843884    m_jit.countLeadingZeros32(valueReg, resultReg);
    38853885    int32Result(resultReg, node);
     3886}
     3887
     3888void SpeculativeJIT::compileArithCos(Node* node)
     3889{
     3890    if (node->child1().useKind() == DoubleRepUse) {
     3891        SpeculateDoubleOperand op1(this, node->child1());
     3892        FPRReg op1FPR = op1.fpr();
     3893
     3894        flushRegisters();
     3895       
     3896        FPRResult result(this);
     3897        callOperation(cos, result.fpr(), op1FPR);
     3898        doubleResult(result.fpr(), node);
     3899        return;
     3900    }
     3901
     3902    JSValueOperand op1(this, node->child1());
     3903    JSValueRegs op1Regs = op1.jsValueRegs();
     3904    flushRegisters();
     3905    FPRResult result(this);
     3906    callOperation(operationArithCos, result.fpr(), op1Regs);
     3907    m_jit.exceptionCheck();
     3908    doubleResult(result.fpr(), node);
    38863909}
    38873910
     
    48894912}
    48904913
     4914void SpeculativeJIT::compileArithSin(Node* node)
     4915{
     4916    if (node->child1().useKind() == DoubleRepUse) {
     4917        SpeculateDoubleOperand op1(this, node->child1());
     4918        FPRReg op1FPR = op1.fpr();
     4919
     4920        flushRegisters();
     4921       
     4922        FPRResult result(this);
     4923        callOperation(sin, result.fpr(), op1FPR);
     4924        doubleResult(result.fpr(), node);
     4925        return;
     4926    }
     4927
     4928    JSValueOperand op1(this, node->child1());
     4929    JSValueRegs op1Regs = op1.jsValueRegs();
     4930    flushRegisters();
     4931    FPRResult result(this);
     4932    callOperation(operationArithSin, result.fpr(), op1Regs);
     4933    m_jit.exceptionCheck();
     4934    doubleResult(result.fpr(), node);
     4935}
     4936
    48914937void SpeculativeJIT::compileArithSqrt(Node* node)
    48924938{
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r204670 r204849  
    24702470    void compileMakeRope(Node*);
    24712471    void compileArithClz32(Node*);
     2472    void compileArithCos(Node*);
    24722473    void compileArithSub(Node*);
    24732474    void compileArithNegate(Node*);
     
    24782479    void compileArithRounding(Node*);
    24792480    void compileArithRandom(Node*);
     2481    void compileArithSin(Node*);
    24802482    void compileArithSqrt(Node*);
    24812483    void compileArithLog(Node*);
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp

    r204570 r204849  
    23902390        break;
    23912391
    2392     case ArithSin: {
    2393         SpeculateDoubleOperand op1(this, node->child1());
    2394         FPRReg op1FPR = op1.fpr();
    2395 
    2396         flushRegisters();
    2397        
    2398         FPRResult result(this);
    2399         callOperation(sin, result.fpr(), op1FPR);
    2400         doubleResult(result.fpr(), node);
    2401         break;
    2402     }
    2403 
    2404     case ArithCos: {
    2405         SpeculateDoubleOperand op1(this, node->child1());
    2406         FPRReg op1FPR = op1.fpr();
    2407 
    2408         flushRegisters();
    2409        
    2410         FPRResult result(this);
    2411         callOperation(cos, result.fpr(), op1FPR);
    2412         doubleResult(result.fpr(), node);
    2413         break;
    2414     }
     2392    case ArithSin:
     2393        compileArithSin(node);
     2394        break;
     2395
     2396    case ArithCos:
     2397        compileArithCos(node);
     2398        break;
    24152399
    24162400    case ArithLog:
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp

    r204570 r204849  
    25142514        break;
    25152515
    2516     case ArithSin: {
    2517         SpeculateDoubleOperand op1(this, node->child1());
    2518         FPRReg op1FPR = op1.fpr();
    2519 
    2520         flushRegisters();
    2521        
    2522         FPRResult result(this);
    2523         callOperation(sin, result.fpr(), op1FPR);
    2524         doubleResult(result.fpr(), node);
    2525         break;
    2526     }
    2527 
    2528     case ArithCos: {
    2529         SpeculateDoubleOperand op1(this, node->child1());
    2530         FPRReg op1FPR = op1.fpr();
    2531 
    2532         flushRegisters();
    2533        
    2534         FPRResult result(this);
    2535         callOperation(cos, result.fpr(), op1FPR);
    2536         doubleResult(result.fpr(), node);
    2537         break;
    2538     }
     2516    case ArithSin:
     2517        compileArithSin(node);
     2518        break;
     2519
     2520    case ArithCos:
     2521        compileArithCos(node);
     2522        break;
    25392523
    25402524    case ArithLog:
  • trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp

    r204670 r204849  
    20212021    }
    20222022
    2023     void compileArithSin() { setDouble(m_out.doubleSin(lowDouble(m_node->child1()))); }
    2024 
    2025     void compileArithCos() { setDouble(m_out.doubleCos(lowDouble(m_node->child1()))); }
     2023    void compileArithSin()
     2024    {
     2025        if (m_node->child1().useKind() == DoubleRepUse) {
     2026            setDouble(m_out.doubleSin(lowDouble(m_node->child1())));
     2027            return;
     2028        }
     2029        LValue argument = lowJSValue(m_node->child1());
     2030        LValue result = vmCall(Double, m_out.operation(operationArithSin), m_callFrame, argument);
     2031        setDouble(result);
     2032    }
     2033
     2034    void compileArithCos()
     2035    {
     2036        if (m_node->child1().useKind() == DoubleRepUse) {
     2037            setDouble(m_out.doubleCos(lowDouble(m_node->child1())));
     2038            return;
     2039        }
     2040        LValue argument = lowJSValue(m_node->child1());
     2041        LValue result = vmCall(Double, m_out.operation(operationArithCos), m_callFrame, argument);
     2042        setDouble(result);
     2043    }
    20262044
    20272045    void compileArithPow()
Note: See TracChangeset for help on using the changeset viewer.