Changeset 260711 in webkit


Ignore:
Timestamp:
Apr 25, 2020 4:56:40 PM (4 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Add fast path for BigInt32 left-shift
https://bugs.webkit.org/show_bug.cgi?id=211029

Reviewed by Saam Barati.

JSTests:

  • stress/bigint-left-shift-overflow.js: Added.

(shouldBe):
(leftShift):
(noInline):

  • stress/bigint-right-shift-large.js: Added.

(shouldBe):

Source/JavaScriptCore:

Currently, the left-shift operation misses the fast path for BigInt32 <> BigInt32 case. This patch adds it. We also fixes
prediction-propagation for left/right shift to use existing heap prediction instead of polluting the result with SpecBigInt.
This offer 4.5% improvement in microbenchmarks/sunspider-sha1-big-int.js.

  • dfg/DFGPredictionPropagationPhase.cpp:
  • runtime/Operations.h:

(JSC::shift):

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r260700 r260711  
     12020-04-25  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Add fast path for BigInt32 left-shift
     4        https://bugs.webkit.org/show_bug.cgi?id=211029
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/bigint-left-shift-overflow.js: Added.
     9        (shouldBe):
     10        (leftShift):
     11        (noInline):
     12        * stress/bigint-right-shift-large.js: Added.
     13        (shouldBe):
     14
    1152020-04-25  Paulo Matos  <pmatos@igalia.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r260710 r260711  
     12020-04-25  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Add fast path for BigInt32 left-shift
     4        https://bugs.webkit.org/show_bug.cgi?id=211029
     5
     6        Reviewed by Saam Barati.
     7
     8        Currently, the left-shift operation misses the fast path for BigInt32 <> BigInt32 case. This patch adds it. We also fixes
     9        prediction-propagation for left/right shift to use existing heap prediction instead of polluting the result with SpecBigInt.
     10        This offer 4.5% improvement in microbenchmarks/sunspider-sha1-big-int.js.
     11
     12        * dfg/DFGPredictionPropagationPhase.cpp:
     13        * runtime/Operations.h:
     14        (JSC::shift):
     15
    1162020-04-25  Ross Kirsling  <ross.kirsling@sony.com>
    217
  • trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp

    r260331 r260711  
    186186
    187187            if (left && right) {
    188                 if (isBigIntSpeculation(left) && isBigIntSpeculation(right))
    189                     changed |= mergePrediction(SpecBigInt);
    190                 else if (isFullNumberOrBooleanSpeculationExpectingDefined(left) && isFullNumberOrBooleanSpeculationExpectingDefined(right))
     188                if (isFullNumberOrBooleanSpeculationExpectingDefined(left) && isFullNumberOrBooleanSpeculationExpectingDefined(right))
    191189                    changed |= mergePrediction(SpecInt32Only);
    192190                else
  • trunk/Source/JavaScriptCore/runtime/Operations.h

    r260683 r260711  
    765765            rightInt32 = -rightInt32;
    766766        }
     767        ASSERT(rightInt32 >= 0);
    767768
    768769        // This std::min is a bit hacky, but required because in C++ it is undefined behavior to do a shift where the right operand is greater or equal to the bit-width of the left operand.
    769770        if (!isLeft)
    770771            return jsBigInt32(leftInt32 >> std::min(rightInt32, 31));
     772
     773        // Do some checks to detect overflow of left-shift. But this is much cheaper compared to allocating two JSBigInt and perform shift operations in JSBigInt.
     774        if (!leftInt32)
     775            return jsBigInt32(0);
     776        if (rightInt32 < 32) {
     777            int64_t result64 = static_cast<int64_t>(leftInt32) << rightInt32;
     778            if (static_cast<int64_t>(static_cast<int32_t>(result64)) == result64)
     779                return jsBigInt32(static_cast<int32_t>(result64));
     780        }
    771781
    772782        // In the case of a left shift we can overflow. I deal with this by allocating HeapBigInts.
Note: See TracChangeset for help on using the changeset viewer.