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

Changeset 286639 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 7:59:13 PM (5 years ago)
Author:
sbarati@apple.com
Message:

TypedArray prototype set should go down the fast path when using non clamped integer types of the same byte size
https://bugs.webkit.org/show_bug.cgi?id=233905

Reviewed by Keith Miller.

JSTests:

  • microbenchmarks/typed-array-prototype-set.js: Added.
  • microbenchmarks/typed-array-prototype-set-order.js: Added.
  • stress/typed-array-prototype-set.js: Added.

Source/JavaScriptCore:

We can use memmove in this scenario because the bitpattern of the
data between the signed and unsigned values will be the same.

This patch also fixes a bug where we were looking at the wrong
pointer when determining to do a forward or backwards loop in
our memmove. We were looking at the vector instead of vector+offset.

  • runtime/JSGenericTypedArrayViewInlines.h:

(JSC::JSGenericTypedArrayView<Adaptor>::set):

LayoutTests:

  • js/script-tests/typedarray-set-overlapping-elements-of-same-size.js:
  • js/typedarray-set-overlapping-elements-of-same-size-expected.txt:
Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r286478 r286639  
     12021-12-07  Saam Barati  <sbarati@apple.com>
     2
     3        TypedArray prototype set should go down the fast path when using non clamped integer types of the same byte size
     4        https://bugs.webkit.org/show_bug.cgi?id=233905
     5
     6        Reviewed by Keith Miller.
     7
     8        * microbenchmarks/typed-array-prototype-set.js: Added.
     9        * microbenchmarks/typed-array-prototype-set-order.js: Added.
     10        * stress/typed-array-prototype-set.js: Added.
     11
    1122021-12-02  Yusuke Suzuki  <ysuzuki@apple.com>
    213
  • trunk/LayoutTests/ChangeLog

    r286628 r286639  
     12021-12-07  Saam Barati  <sbarati@apple.com>
     2
     3        TypedArray prototype set should go down the fast path when using non clamped integer types of the same byte size
     4        https://bugs.webkit.org/show_bug.cgi?id=233905
     5
     6        Reviewed by Keith Miller.
     7
     8        * js/script-tests/typedarray-set-overlapping-elements-of-same-size.js:
     9        * js/typedarray-set-overlapping-elements-of-same-size-expected.txt:
     10
    1112021-12-07  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
    212
  • trunk/LayoutTests/js/script-tests/typedarray-set-overlapping-elements-of-same-size.js

    r154518 r286639  
    1919}
    2020
    21 shouldBe("foo(10)", "[42,42,42,42,42,42,42,42,42,42,42]");
     21shouldBe("foo(10)", "[42,42,43,44,45,46,47,48,49,50,51]");
    2222shouldBe("bar(10)", "[42,43,44,45,46,47,48,49,50,51,51]");
    2323
  • trunk/LayoutTests/js/typedarray-set-overlapping-elements-of-same-size-expected.txt

    r154518 r286639  
    44
    55
    6 PASS foo(10) is [42,42,42,42,42,42,42,42,42,42,42]
     6PASS foo(10) is [42,42,43,44,45,46,47,48,49,50,51]
    77PASS bar(10) is [42,43,44,45,46,47,48,49,50,51,51]
    88PASS successfullyParsed is true
  • trunk/Source/JavaScriptCore/ChangeLog

    r286635 r286639  
     12021-12-07  Saam Barati  <sbarati@apple.com>
     2
     3        TypedArray prototype set should go down the fast path when using non clamped integer types of the same byte size
     4        https://bugs.webkit.org/show_bug.cgi?id=233905
     5
     6        Reviewed by Keith Miller.
     7
     8        We can use memmove in this scenario because the bitpattern of the
     9        data between the signed and unsigned values will be the same.
     10
     11        This patch also fixes a bug where we were looking at the wrong
     12        pointer when determining to do a forward or backwards loop in
     13        our memmove. We were looking at the vector instead of vector+offset.
     14
     15        * runtime/JSGenericTypedArrayViewInlines.h:
     16        (JSC::JSGenericTypedArrayView<Adaptor>::set):
     17
    1182021-12-07  Ross Kirsling  <ross.kirsling@sony.com>
    219
  • trunk/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h

    r285971 r286639  
    217217    if (!hasArrayBuffer() || !other->hasArrayBuffer()
    218218        || existingBuffer() != other->existingBuffer()
    219         || (elementSize == otherElementSize && vector() <= other->vector())
     219        || (elementSize == otherElementSize && (static_cast<void*>(typedVector() + offset) <= static_cast<void*>(other->typedVector() + otherOffset)))
    220220        || type == CopyType::LeftToRight) {
    221221        for (size_t i = 0; i < length; ++i) {
     
    256256    auto scope = DECLARE_THROW_SCOPE(vm);
    257257
    258     auto memmoveFastPath = [&] (auto* other) {
     258    auto memmoveFastPath = [&] (JSArrayBufferView* other) {
    259259        // The super fast case: we can just memmove since we're the same underlying storage type.
    260260        length = std::min(length, other->length());
    261261       
    262         RELEASE_ASSERT(other->canAccessRangeQuickly(objectOffset, length));
    263262        bool success = validateRange(globalObject, offset, length);
    264263        EXCEPTION_ASSERT(!scope.exception() == success);
     
    266265            return false;
    267266
    268         RELEASE_ASSERT((std::is_same_v<decltype(typedVector()), decltype(other->typedVector())>));
    269         memmove(typedVector() + offset, other->typedVector() + objectOffset, length * elementSize);
     267        RELEASE_ASSERT(JSC::elementSize(Adaptor::typeValue) == JSC::elementSize(other->classInfo(vm)->typedArrayStorageType));
     268        memmove(typedVector() + offset, bitwise_cast<typename Adaptor::Type*>(other->vector()) + objectOffset, length * elementSize);
    270269        return true;
    271270    };
     
    273272    const ClassInfo* ci = object->classInfo(vm);
    274273    if (ci->typedArrayStorageType == Adaptor::typeValue)
    275         return memmoveFastPath(jsCast<JSGenericTypedArrayView*>(object));
     274        return memmoveFastPath(jsCast<JSArrayBufferView*>(object));
    276275
    277276    auto isSomeUint8 = [] (TypedArrayType type) {
    278277        return type == TypedArrayType::TypeUint8 || type == TypedArrayType::TypeUint8Clamped;
    279278    };
    280     if (isSomeUint8(ci->typedArrayStorageType) && isSomeUint8(Adaptor::typeValue)) {
    281         if (ci->typedArrayStorageType == TypedArrayType::TypeUint8)
    282             return memmoveFastPath(jsCast<JSGenericTypedArrayView<Uint8Adaptor>*>(object));
    283         return memmoveFastPath(jsCast<JSGenericTypedArrayView<Uint8ClampedAdaptor>*>(object));
    284     }
    285    
     279
     280    if (isSomeUint8(ci->typedArrayStorageType) && isSomeUint8(Adaptor::typeValue))
     281        return memmoveFastPath(jsCast<JSArrayBufferView*>(object));
     282
     283    if (isInt(Adaptor::typeValue) && isInt(ci->typedArrayStorageType) && !isClamped(Adaptor::typeValue) && JSC::elementSize(Adaptor::typeValue) == JSC::elementSize(ci->typedArrayStorageType))
     284        return memmoveFastPath(jsCast<JSArrayBufferView*>(object));
     285
    286286    switch (ci->typedArrayStorageType) {
    287287    case TypeInt8:
Note: See TracChangeset for help on using the changeset viewer.