Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b8d759043c8880de7528a5acecc3207b8e79d9c8
      
https://github.com/WebKit/WebKit/commit/b8d759043c8880de7528a5acecc3207b8e79d9c8
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-04-22 (Wed, 22 Apr 2026)

  Changed paths:
    A JSTests/microbenchmarks/arithmetic-shift-and-mask.js
    M Source/JavaScriptCore/b3/B3LowerToAir.cpp
    M Source/JavaScriptCore/b3/testb3.h
    M Source/JavaScriptCore/b3/testb3_2.cpp

  Log Message:
  -----------
  [JSC] Lower `BitAnd(SShr(x, lsb), mask)` to `ubfx` for ARM64
https://bugs.webkit.org/show_bug.cgi?id=312963

Reviewed by Yusuke Suzuki.

tryAppendUBFX previously matched only BitAnd(ZShr, mask). Extend it to
also accept SShr (arithmetic right shift). This is safe because the
existing lsb + width <= datasize guard ensures the mask never reaches
the sign-extension bits introduced by the arithmetic shift, so ubfx
(which zero-extends) produces the identical result.

Also move tryAppendUBFX before the 0xff/0xffff/0xffffffff zero-extend
special cases so that the common pixel-unpacking pattern
(pixel >> N) & 0xff is not stolen by ZeroExtend8To32 and instead
collapses into a single ubfx. Non-shift BitAnd(x, 0xff) still falls
through to the existing zero-extend path, and x86_64 is unaffected
since ExtractUnsignedBitfield* has no valid form there.

This mirrors a recent V8 change that reported ~2% on JetStream3
gaussian-blur: https://chromium-review.googlesource.com/c/v8/v8/+/7768219

FTL codegen for `((p>>24)&0xff)+((p>>16)&0xff)+((p>>8)&0xff)+(p&0xff)`:

Before:
    asr   w2, w0, #0x18
    and   w2, w2, #0xff
    asr   w3, w0, #0x10
    and   w3, w3, #0xff
    asr   w4, w0, #0x8
    and   w4, w4, #0xff
    and   w0, w0, #0xff
    add   w2, w2, w3
    add   w0, w4, w0
    add   w0, w2, w0

After:
    lsr   w2, w0, #0x18
    ubfx  w3, w0, #0x10, #0x8
    ubfx  w4, w0, #0x8, #0x8
    and   w0, w0, #0xff
    add   w2, w2, w3
    add   w0, w4, w0
    add   w0, w2, w0

Microbenchmark (Apple Silicon):

                                   TipOfTree                  Patched

arithmetic-shift-and-mask       19.0037+-0.2975           18.6483+-0.0836      
might be 1.0191x faster

Tests: JSTests/microbenchmarks/arithmetic-shift-and-mask.js
       Source/JavaScriptCore/b3/testb3_2.cpp

* JSTests/microbenchmarks/arithmetic-shift-and-mask.js: Added.
(test):
* Source/JavaScriptCore/b3/B3LowerToAir.cpp:
* Source/JavaScriptCore/b3/testb3.h:
* Source/JavaScriptCore/b3/testb3_2.cpp:
(testUbfx32ArithmeticShiftAnd):
(testUbfx64ArithmeticShiftAnd):
(addBitTests):

Canonical link: https://commits.webkit.org/311756@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to