Title: [204849] trunk
Revision
204849
Author
[email protected]
Date
2016-08-23 12:09:50 -0700 (Tue, 23 Aug 2016)

Log 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 <[email protected]> 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/_javascript_Core:

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):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (204848 => 204849)


--- trunk/JSTests/ChangeLog	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/JSTests/ChangeLog	2016-08-23 19:09:50 UTC (rev 204849)
@@ -1,3 +1,13 @@
+2016-08-23  Benjamin Poulain  <[email protected]>
+
+        [JSC] Make Math.cos() and Math.sin() work with any argument type
+        https://bugs.webkit.org/show_bug.cgi?id=161069
+
+        Reviewed by Geoffrey Garen.
+
+        * stress/arith-cos-on-various-types.js: Added.
+        * stress/arith-sin-on-various-types.js: Added.
+
 2016-08-23  Yusuke Suzuki  <[email protected]>
 
         [ES6] Module namespace object's Symbol.iterator method should only accept module namespace objects

Added: trunk/JSTests/stress/arith-cos-on-various-types.js (0 => 204849)


--- trunk/JSTests/stress/arith-cos-on-various-types.js	                        (rev 0)
+++ trunk/JSTests/stress/arith-cos-on-various-types.js	2016-08-23 19:09:50 UTC (rev 204849)
@@ -0,0 +1,168 @@
+"use strict";
+
+let cosOfFour = Math.cos(4);
+
+let validInputTestCases = [
+    // input as string, expected result as string.
+    ["undefined", "NaN"],
+    ["null", "1"],
+    ["0", "1"],
+    ["-0.", "1"],
+    ["4", "" + cosOfFour],
+    ["Math.PI", "-1"],
+    ["Infinity", "NaN"],
+    ["-Infinity", "NaN"],
+    ["NaN", "NaN"],
+    ["\"WebKit\"", "NaN"],
+    ["\"4\"", "" + cosOfFour],
+    ["{ valueOf: () => { return 4; } }", "" + cosOfFour],
+];
+
+let validInputTypedTestCases = validInputTestCases.map((element) => { return [eval("(" + element[0] + ")"), eval(element[1])] });
+
+function isIdentical(result, expected)
+{
+    if (expected === expected) {
+        if (result !== expected)
+            return false;
+        if (!expected && 1 / expected === -Infinity && 1 / result !== -Infinity)
+            return false;
+
+        return true;
+    }
+    return result !== result;
+}
+
+
+// Test Math.cos() with a very polymorphic input. All test cases are seen at each iteration.
+function opaqueAllTypesCos(argument) {
+    return Math.cos(argument);
+}
+noInline(opaqueAllTypesCos);
+noOSRExitFuzzing(opaqueAllTypesCos);
+
+function testAllTypesCall() {
+    for (let i = 0; i < 1e3; ++i) {
+        for (let testCaseInput of validInputTypedTestCases) {
+            let output = opaqueAllTypesCos(testCaseInput[0]);
+            if (!isIdentical(output, testCaseInput[1]))
+                throw "Failed testAllTypesCall for input " + testCaseInput[0] + " expected " + testCaseInput[1] + " got " + output;
+        }
+    }
+    if (numberOfDFGCompiles(opaqueAllTypesCos) > 2)
+        throw "We should have detected cos() was polymorphic and generated a generic version.";
+}
+testAllTypesCall();
+
+
+// Test Math.cos() on a completely typed input. Every call see only one type.
+function testSingleTypeCall() {
+    for (let testCaseInput of validInputTestCases) {
+        eval(`
+            function opaqueCos(argument) {
+                return Math.cos(argument);
+            }
+            noInline(opaqueCos);
+            noOSRExitFuzzing(opaqueCos);
+
+            for (let i = 0; i < 1e4; ++i) {
+                if (!isIdentical(opaqueCos(${testCaseInput[0]}), ${testCaseInput[1]})) {
+                    throw "Failed testSingleTypeCall()";
+                }
+            }
+            if (numberOfDFGCompiles(opaqueCos) > 1)
+                throw "We should have compiled a single cos for the expected type.";
+        `);
+    }
+}
+testSingleTypeCall();
+
+
+// Verify we call valueOf() exactly once per call.
+function opaqueCosForSideEffects(argument) {
+    return Math.cos(argument);
+}
+noInline(opaqueCosForSideEffects);
+noOSRExitFuzzing(opaqueCosForSideEffects);
+
+function testSideEffect() {
+    let testObject = {
+        counter: 0,
+        valueOf: function() { ++this.counter; return 16; }
+    };
+    let cos16 = Math.cos(16);
+    for (let i = 0; i < 1e4; ++i) {
+        if (opaqueCosForSideEffects(testObject) !== cos16)
+            throw "Incorrect result in testSideEffect()";
+    }
+    if (testObject.counter !== 1e4)
+        throw "Failed testSideEffect()";
+    if (numberOfDFGCompiles(opaqueCosForSideEffects) > 1)
+        throw "opaqueCosForSideEffects() is predictable, it should only be compiled once.";
+}
+testSideEffect();
+
+
+// Verify SQRT is not subject to CSE if the argument has side effects.
+function opaqueCosForCSE(argument) {
+    return Math.cos(argument) + Math.cos(argument) + Math.cos(argument);
+}
+noInline(opaqueCosForCSE);
+noOSRExitFuzzing(opaqueCosForCSE);
+
+function testCSE() {
+    let testObject = {
+        counter: 0,
+        valueOf: function() { ++this.counter; return 16; }
+    };
+    let cos16 = Math.cos(16);
+    let threeCos16 = cos16 + cos16 + cos16;
+    for (let i = 0; i < 1e4; ++i) {
+        if (opaqueCosForCSE(testObject) !== threeCos16)
+            throw "Incorrect result in testCSE()";
+    }
+    if (testObject.counter !== 3e4)
+        throw "Failed testCSE()";
+    if (numberOfDFGCompiles(opaqueCosForCSE) > 1)
+        throw "opaqueCosForCSE() is predictable, it should only be compiled once.";
+}
+testCSE();
+
+
+// Test exceptions in the argument.
+function testException() {
+    let counter = 0;
+    function opaqueCosWithException(argument) {
+        let result = Math.cos(argument);
+        ++counter;
+        return result;
+    }
+    noInline(opaqueCosWithException);
+
+    let testObject = { valueOf: () => {  return 64; } };
+    let cos64 = Math.cos(64);
+
+    // Warm up without exception.
+    for (let i = 0; i < 1e3; ++i) {
+        if (opaqueCosWithException(testObject) !== cos64)
+            throw "Incorrect result in opaqueCosWithException()";
+    }
+
+    let testThrowObject = { valueOf: () => { throw testObject; return 64; } };
+
+    for (let i = 0; i < 1e2; ++i) {
+        try {
+            if (opaqueCosWithException(testThrowObject) !== 8)
+                throw "This code should not be reached!!";
+        } catch (e) {
+            if (e !== testObject) {
+                throw "Wrong object thrown from opaqueCosWithException."
+            }
+        }
+    }
+
+    if (counter !== 1e3) {
+        throw "Invalid count in testException()";
+    }
+}
+testException();

Added: trunk/JSTests/stress/arith-sin-on-various-types.js (0 => 204849)


--- trunk/JSTests/stress/arith-sin-on-various-types.js	                        (rev 0)
+++ trunk/JSTests/stress/arith-sin-on-various-types.js	2016-08-23 19:09:50 UTC (rev 204849)
@@ -0,0 +1,168 @@
+"use strict";
+
+let sinOfFour = Math.sin(4);
+
+let validInputTestCases = [
+    // input as string, expected result as string.
+    ["undefined", "NaN"],
+    ["null", "0"],
+    ["0", "0"],
+    ["-0.", "-0"],
+    ["4", "" + sinOfFour],
+    ["Math.PI", "" + Math.sin(Math.PI)],
+    ["Infinity", "NaN"],
+    ["-Infinity", "NaN"],
+    ["NaN", "NaN"],
+    ["\"WebKit\"", "NaN"],
+    ["\"4\"", "" + sinOfFour],
+    ["{ valueOf: () => { return 4; } }", "" + sinOfFour],
+];
+
+let validInputTypedTestCases = validInputTestCases.map((element) => { return [eval("(" + element[0] + ")"), eval(element[1])] });
+
+function isIdentical(result, expected)
+{
+    if (expected === expected) {
+        if (result !== expected)
+            return false;
+        if (!expected && 1 / expected === -Infinity && 1 / result !== -Infinity)
+            return false;
+
+        return true;
+    }
+    return result !== result;
+}
+
+
+// Test Math.sin() with a very polymorphic input. All test cases are seen at each iteration.
+function opaqueAllTypesSin(argument) {
+    return Math.sin(argument);
+}
+noInline(opaqueAllTypesSin);
+noOSRExitFuzzing(opaqueAllTypesSin);
+
+function testAllTypesCall() {
+    for (let i = 0; i < 1e3; ++i) {
+        for (let testCaseInput of validInputTypedTestCases) {
+            let output = opaqueAllTypesSin(testCaseInput[0]);
+            if (!isIdentical(output, testCaseInput[1]))
+                throw "Failed testAllTypesCall for input " + testCaseInput[0] + " expected " + testCaseInput[1] + " got " + output;
+        }
+    }
+    if (numberOfDFGCompiles(opaqueAllTypesSin) > 2)
+        throw "We should have detected sin() was polymorphic and generated a generic version.";
+}
+testAllTypesCall();
+
+
+// Test Math.sin() on a completely typed input. Every call see only one type.
+function testSingleTypeCall() {
+    for (let testCaseInput of validInputTestCases) {
+        eval(`
+            function opaqueSin(argument) {
+                return Math.sin(argument);
+            }
+            noInline(opaqueSin);
+            noOSRExitFuzzing(opaqueSin);
+
+            for (let i = 0; i < 1e4; ++i) {
+                if (!isIdentical(opaqueSin(${testCaseInput[0]}), ${testCaseInput[1]})) {
+                    throw "Failed testSingleTypeCall()";
+                }
+            }
+            if (numberOfDFGCompiles(opaqueSin) > 1)
+                throw "We should have compiled a single sin for the expected type.";
+        `);
+    }
+}
+testSingleTypeCall();
+
+
+// Verify we call valueOf() exactly once per call.
+function opaqueSinForSideEffects(argument) {
+    return Math.sin(argument);
+}
+noInline(opaqueSinForSideEffects);
+noOSRExitFuzzing(opaqueSinForSideEffects);
+
+function testSideEffect() {
+    let testObject = {
+        counter: 0,
+        valueOf: function() { ++this.counter; return 16; }
+    };
+    let sin16 = Math.sin(16);
+    for (let i = 0; i < 1e4; ++i) {
+        if (opaqueSinForSideEffects(testObject) !== sin16)
+            throw "Incorrect result in testSideEffect()";
+    }
+    if (testObject.counter !== 1e4)
+        throw "Failed testSideEffect()";
+    if (numberOfDFGCompiles(opaqueSinForSideEffects) > 1)
+        throw "opaqueSinForSideEffects() is predictable, it should only be compiled once.";
+}
+testSideEffect();
+
+
+// Verify SQRT is not subject to CSE if the argument has side effects.
+function opaqueSinForCSE(argument) {
+    return Math.sin(argument) + Math.sin(argument) + Math.sin(argument);
+}
+noInline(opaqueSinForCSE);
+noOSRExitFuzzing(opaqueSinForCSE);
+
+function testCSE() {
+    let testObject = {
+        counter: 0,
+        valueOf: function() { ++this.counter; return 16; }
+    };
+    let sin16 = Math.sin(16);
+    let threeSin16 = sin16 + sin16 + sin16;
+    for (let i = 0; i < 1e4; ++i) {
+        if (opaqueSinForCSE(testObject) !== threeSin16)
+            throw "Incorrect result in testCSE()";
+    }
+    if (testObject.counter !== 3e4)
+        throw "Failed testCSE()";
+    if (numberOfDFGCompiles(opaqueSinForCSE) > 1)
+        throw "opaqueSinForCSE() is predictable, it should only be compiled once.";
+}
+testCSE();
+
+
+// Test exceptions in the argument.
+function testException() {
+    let counter = 0;
+    function opaqueSinWithException(argument) {
+        let result = Math.sin(argument);
+        ++counter;
+        return result;
+    }
+    noInline(opaqueSinWithException);
+
+    let testObject = { valueOf: () => {  return 64; } };
+    let sin64 = Math.sin(64);
+
+    // Warm up without exception.
+    for (let i = 0; i < 1e3; ++i) {
+        if (opaqueSinWithException(testObject) !== sin64)
+            throw "Incorrect result in opaqueSinWithException()";
+    }
+
+    let testThrowObject = { valueOf: () => { throw testObject; return 64; } };
+
+    for (let i = 0; i < 1e2; ++i) {
+        try {
+            if (opaqueSinWithException(testThrowObject) !== 8)
+                throw "This code should not be reached!!";
+        } catch (e) {
+            if (e !== testObject) {
+                throw "Wrong object thrown from opaqueSinWithException."
+            }
+        }
+    }
+
+    if (counter !== 1e3) {
+        throw "Invalid count in testException()";
+    }
+}
+testException();

Modified: trunk/Source/_javascript_Core/ChangeLog (204848 => 204849)


--- trunk/Source/_javascript_Core/ChangeLog	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-08-23 19:09:50 UTC (rev 204849)
@@ -1,3 +1,34 @@
+2016-08-23  Benjamin Poulain  <[email protected]>
+
+        [JSC] Make Math.cos() and Math.sin() work with any argument type
+        https://bugs.webkit.org/show_bug.cgi?id=161069
+
+        Reviewed by Geoffrey Garen.
+
+        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):
+
 2016-08-23  Yusuke Suzuki  <[email protected]>
 
         [ES6] Module namespace object's Symbol.iterator method should only accept module namespace objects

Modified: trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGAbstractInterpreterInlines.h	2016-08-23 19:09:50 UTC (rev 204849)
@@ -984,7 +984,10 @@
             setConstant(node, jsDoubleNumber(sin(child.asNumber())));
             break;
         }
-        forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
+        SpeculatedType sinType = SpecFullNumber;
+        if (node->child1().useKind() == DoubleRepUse)
+            sinType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
+        forNode(node).setType(sinType);
         break;
     }
     
@@ -994,7 +997,10 @@
             setConstant(node, jsDoubleNumber(cos(child.asNumber())));
             break;
         }
-        forNode(node).setType(typeOfDoubleUnaryOp(forNode(node->child1()).m_type));
+        SpeculatedType cosType = SpecFullNumber;
+        if (node->child1().useKind() == DoubleRepUse)
+            cosType = typeOfDoubleUnaryOp(forNode(node->child1()).m_type);
+        forNode(node).setType(cosType);
         break;
     }
 

Modified: trunk/Source/_javascript_Core/dfg/DFGClobberize.h (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGClobberize.h	2016-08-23 19:09:50 UTC (rev 204849)
@@ -155,8 +155,6 @@
     case ArithMax:
     case ArithPow:
     case ArithFRound:
-    case ArithSin:
-    case ArithCos:
     case ArithLog:
     case GetScope:
     case SkipScope:
@@ -189,6 +187,8 @@
         def(PureValue(node));
         return;
 
+    case ArithCos:
+    case ArithSin:
     case ArithSqrt:
         if (node->child1().useKind() == DoubleRepUse)
             def(PureValue(node));

Modified: trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGFixupPhase.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -385,7 +385,9 @@
             }
             break;
         }
-            
+
+        case ArithCos:
+        case ArithSin:
         case ArithSqrt: {
             Edge& child1 = node->child1();
             if (child1->shouldSpeculateNumberOrBoolean())
@@ -395,8 +397,6 @@
             break;
         }
         case ArithFRound:
-        case ArithSin:
-        case ArithCos:
         case ArithLog: {
             fixDoubleOrBooleanEdge(node->child1());
             node->setResult(NodeResultDouble);

Modified: trunk/Source/_javascript_Core/dfg/DFGNodeType.h (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGNodeType.h	2016-08-23 19:09:50 UTC (rev 204849)
@@ -160,8 +160,8 @@
     macro(ArithCeil, NodeResultNumber) \
     macro(ArithTrunc, NodeResultNumber) \
     macro(ArithSqrt, NodeResultDouble) \
-    macro(ArithSin, NodeResultNumber) \
-    macro(ArithCos, NodeResultNumber) \
+    macro(ArithSin, NodeResultDouble) \
+    macro(ArithCos, NodeResultDouble) \
     macro(ArithLog, NodeResultNumber) \
     \
     /* Add of values may either be arithmetic, or result in string concatenation. */\

Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -322,6 +322,30 @@
     return JSValue::encode(jsNumber(a / b));
 }
 
+double JIT_OPERATION operationArithCos(ExecState* exec, EncodedJSValue encodedOp1)
+{
+    VM* vm = &exec->vm();
+    NativeCallFrameTracer tracer(vm, exec);
+
+    JSValue op1 = JSValue::decode(encodedOp1);
+    double a = op1.toNumber(exec);
+    if (UNLIKELY(vm->exception()))
+        return JSValue::encode(JSValue());
+    return cos(a);
+}
+
+double JIT_OPERATION operationArithSin(ExecState* exec, EncodedJSValue encodedOp1)
+{
+    VM* vm = &exec->vm();
+    NativeCallFrameTracer tracer(vm, exec);
+
+    JSValue op1 = JSValue::decode(encodedOp1);
+    double a = op1.toNumber(exec);
+    if (UNLIKELY(vm->exception()))
+        return JSValue::encode(JSValue());
+    return sin(a);
+}
+
 double JIT_OPERATION operationArithSqrt(ExecState* exec, EncodedJSValue encodedOp1)
 {
     VM* vm = &exec->vm();

Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.h (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGOperations.h	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.h	2016-08-23 19:09:50 UTC (rev 204849)
@@ -53,6 +53,8 @@
 EncodedJSValue JIT_OPERATION operationValueBitURShift(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
 EncodedJSValue JIT_OPERATION operationValueAddNotNumber(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
 EncodedJSValue JIT_OPERATION operationValueDiv(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2) WTF_INTERNAL;
+double JIT_OPERATION operationArithCos(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
+double JIT_OPERATION operationArithSin(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
 double JIT_OPERATION operationArithSqrt(ExecState*, EncodedJSValue encodedOp1) WTF_INTERNAL;
 EncodedJSValue JIT_OPERATION operationGetByVal(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty) WTF_INTERNAL;
 EncodedJSValue JIT_OPERATION operationGetByValCell(ExecState*, JSCell*, EncodedJSValue encodedProperty) WTF_INTERNAL;

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -3885,6 +3885,29 @@
     int32Result(resultReg, node);
 }
 
+void SpeculativeJIT::compileArithCos(Node* node)
+{
+    if (node->child1().useKind() == DoubleRepUse) {
+        SpeculateDoubleOperand op1(this, node->child1());
+        FPRReg op1FPR = op1.fpr();
+
+        flushRegisters();
+        
+        FPRResult result(this);
+        callOperation(cos, result.fpr(), op1FPR);
+        doubleResult(result.fpr(), node);
+        return;
+    }
+
+    JSValueOperand op1(this, node->child1());
+    JSValueRegs op1Regs = op1.jsValueRegs();
+    flushRegisters();
+    FPRResult result(this);
+    callOperation(operationArithCos, result.fpr(), op1Regs);
+    m_jit.exceptionCheck();
+    doubleResult(result.fpr(), node);
+}
+
 void SpeculativeJIT::compileArithSub(Node* node)
 {
     switch (node->binaryUseKind()) {
@@ -4888,6 +4911,29 @@
     }
 }
 
+void SpeculativeJIT::compileArithSin(Node* node)
+{
+    if (node->child1().useKind() == DoubleRepUse) {
+        SpeculateDoubleOperand op1(this, node->child1());
+        FPRReg op1FPR = op1.fpr();
+
+        flushRegisters();
+        
+        FPRResult result(this);
+        callOperation(sin, result.fpr(), op1FPR);
+        doubleResult(result.fpr(), node);
+        return;
+    }
+
+    JSValueOperand op1(this, node->child1());
+    JSValueRegs op1Regs = op1.jsValueRegs();
+    flushRegisters();
+    FPRResult result(this);
+    callOperation(operationArithSin, result.fpr(), op1Regs);
+    m_jit.exceptionCheck();
+    doubleResult(result.fpr(), node);
+}
+
 void SpeculativeJIT::compileArithSqrt(Node* node)
 {
     if (node->child1().useKind() == DoubleRepUse) {

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT.h	2016-08-23 19:09:50 UTC (rev 204849)
@@ -2469,6 +2469,7 @@
     void compileArithAdd(Node*);
     void compileMakeRope(Node*);
     void compileArithClz32(Node*);
+    void compileArithCos(Node*);
     void compileArithSub(Node*);
     void compileArithNegate(Node*);
     void compileArithMul(Node*);
@@ -2477,6 +2478,7 @@
     void compileArithPow(Node*);
     void compileArithRounding(Node*);
     void compileArithRandom(Node*);
+    void compileArithSin(Node*);
     void compileArithSqrt(Node*);
     void compileArithLog(Node*);
     void compileConstantStoragePointer(Node*);

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT32_64.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -2389,29 +2389,13 @@
         compileArithRounding(node);
         break;
 
-    case ArithSin: {
-        SpeculateDoubleOperand op1(this, node->child1());
-        FPRReg op1FPR = op1.fpr();
-
-        flushRegisters();
-        
-        FPRResult result(this);
-        callOperation(sin, result.fpr(), op1FPR);
-        doubleResult(result.fpr(), node);
+    case ArithSin:
+        compileArithSin(node);
         break;
-    }
 
-    case ArithCos: {
-        SpeculateDoubleOperand op1(this, node->child1());
-        FPRReg op1FPR = op1.fpr();
-
-        flushRegisters();
-        
-        FPRResult result(this);
-        callOperation(cos, result.fpr(), op1FPR);
-        doubleResult(result.fpr(), node);
+    case ArithCos:
+        compileArithCos(node);
         break;
-    }
 
     case ArithLog:
         compileArithLog(node);

Modified: trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/dfg/DFGSpeculativeJIT64.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -2513,29 +2513,13 @@
         compileArithRounding(node);
         break;
 
-    case ArithSin: {
-        SpeculateDoubleOperand op1(this, node->child1());
-        FPRReg op1FPR = op1.fpr();
-
-        flushRegisters();
-        
-        FPRResult result(this);
-        callOperation(sin, result.fpr(), op1FPR);
-        doubleResult(result.fpr(), node);
+    case ArithSin:
+        compileArithSin(node);
         break;
-    }
 
-    case ArithCos: {
-        SpeculateDoubleOperand op1(this, node->child1());
-        FPRReg op1FPR = op1.fpr();
-
-        flushRegisters();
-        
-        FPRResult result(this);
-        callOperation(cos, result.fpr(), op1FPR);
-        doubleResult(result.fpr(), node);
+    case ArithCos:
+        compileArithCos(node);
         break;
-    }
 
     case ArithLog:
         compileArithLog(node);

Modified: trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp (204848 => 204849)


--- trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2016-08-23 19:07:33 UTC (rev 204848)
+++ trunk/Source/_javascript_Core/ftl/FTLLowerDFGToB3.cpp	2016-08-23 19:09:50 UTC (rev 204849)
@@ -2020,9 +2020,27 @@
         }
     }
 
-    void compileArithSin() { setDouble(m_out.doubleSin(lowDouble(m_node->child1()))); }
+    void compileArithSin()
+    {
+        if (m_node->child1().useKind() == DoubleRepUse) {
+            setDouble(m_out.doubleSin(lowDouble(m_node->child1())));
+            return;
+        }
+        LValue argument = lowJSValue(m_node->child1());
+        LValue result = vmCall(Double, m_out.operation(operationArithSin), m_callFrame, argument);
+        setDouble(result);
+    }
 
-    void compileArithCos() { setDouble(m_out.doubleCos(lowDouble(m_node->child1()))); }
+    void compileArithCos()
+    {
+        if (m_node->child1().useKind() == DoubleRepUse) {
+            setDouble(m_out.doubleCos(lowDouble(m_node->child1())));
+            return;
+        }
+        LValue argument = lowJSValue(m_node->child1());
+        LValue result = vmCall(Double, m_out.operation(operationArithCos), m_callFrame, argument);
+        setDouble(result);
+    }
 
     void compileArithPow()
     {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to