Title: [280508] trunk/Source/_javascript_Core
Revision
280508
Author
ysuz...@apple.com
Date
2021-07-30 21:46:30 -0700 (Fri, 30 Jul 2021)

Log Message

[JSC] branchTest8 should not emit tst for Zero/NonZero cases
https://bugs.webkit.org/show_bug.cgi?id=228674

Reviewed by Mark Lam.

Previously, branchTest8(NonZero, BaseIndex) emits `tst` instruction
unnecessarily. This is because the mask is truncated into 8bit, which
makes branchTest32 (which is internally used in branchTest8) emits tst.
We observed many unnecessary tst in YarrJIT.

This patch removes this unnecessary truncation since Zero/NonZero does
not care high bits of mask in branchTest8. This is ok because the
ResultCondition version of mask8OnCondition() is always used to generate
a mask that is only used against a value that is loaded with
MacroAssemblerHelpers::load8OnCondition(). For Zero/NonZero conditions,
load8OnCondition() will always zero fill the upper bytes. The 0 filled
upper bytes will not affect the result of a branch on zero or branch on
not zero.

Before:
   0x10a8068b0:    ldrb     w16, [x7, x6]
   0x10a8068b4:    tst      w16, #0xff
   0x10a8068b8:    b.ne   0x10a8068cc

After:
   0x1070068b0:    ldrb     w16, [x7, x6]
   0x1070068b4:    cbnz     w16, 0x1070068c8

* assembler/MacroAssemblerHelpers.h:
(JSC::MacroAssemblerHelpers::mask8OnCondition):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (280507 => 280508)


--- trunk/Source/_javascript_Core/ChangeLog	2021-07-31 01:40:05 UTC (rev 280507)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-07-31 04:46:30 UTC (rev 280508)
@@ -1,3 +1,36 @@
+2021-07-30  Yusuke Suzuki  <ysuz...@apple.com>
+
+        [JSC] branchTest8 should not emit tst for Zero/NonZero cases
+        https://bugs.webkit.org/show_bug.cgi?id=228674
+
+        Reviewed by Mark Lam.
+
+        Previously, branchTest8(NonZero, BaseIndex) emits `tst` instruction
+        unnecessarily. This is because the mask is truncated into 8bit, which
+        makes branchTest32 (which is internally used in branchTest8) emits tst.
+        We observed many unnecessary tst in YarrJIT.
+
+        This patch removes this unnecessary truncation since Zero/NonZero does
+        not care high bits of mask in branchTest8. This is ok because the
+        ResultCondition version of mask8OnCondition() is always used to generate
+        a mask that is only used against a value that is loaded with
+        MacroAssemblerHelpers::load8OnCondition(). For Zero/NonZero conditions,
+        load8OnCondition() will always zero fill the upper bytes. The 0 filled
+        upper bytes will not affect the result of a branch on zero or branch on
+        not zero.
+
+        Before:
+           0x10a8068b0:    ldrb     w16, [x7, x6]
+           0x10a8068b4:    tst      w16, #0xff
+           0x10a8068b8:    b.ne   0x10a8068cc
+
+        After:
+           0x1070068b0:    ldrb     w16, [x7, x6]
+           0x1070068b4:    cbnz     w16, 0x1070068c8
+
+        * assembler/MacroAssemblerHelpers.h:
+        (JSC::MacroAssemblerHelpers::mask8OnCondition):
+
 2021-07-30  Robin Morisset  <rmoris...@apple.com>
 
         Improve OSR entry into Wasm loops with arguments

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerHelpers.h (280507 => 280508)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerHelpers.h	2021-07-31 01:40:05 UTC (rev 280507)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerHelpers.h	2021-07-31 04:46:30 UTC (rev 280508)
@@ -113,6 +113,12 @@
 template<typename MacroAssemblerType>
 inline typename MacroAssemblerType::TrustedImm32 mask8OnCondition(MacroAssemblerType&, typename MacroAssemblerType::ResultCondition cond, typename MacroAssemblerType::TrustedImm32 value)
 {
+    // If condition is Zero or NonZero, upper bits are unrelated.
+    // Since branchTest32 handles -1 in an optimized manner, we keep -1 as is instead of converting it to 255.
+    if (cond == MacroAssemblerType::Zero || cond == MacroAssemblerType::NonZero) {
+        if (value.m_value == -1)
+            return value;
+    }
     if (isUnsigned<MacroAssemblerType>(cond))
         return typename MacroAssemblerType::TrustedImm32(static_cast<uint8_t>(value.m_value));
     ASSERT_WITH_MESSAGE(cond != MacroAssemblerType::Overflow, "Overflow is not used for 8bit test operations.");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to