[JSC] Micro-optimize YarrJIT's surrogate pair handling
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Sep 2019 18:01:14 +0000 (18:01 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Sep 2019 18:01:14 +0000 (18:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201750

Reviewed by Michael Saboff.

Optimize sequence of machine code used to get code-point with unicode flag.

* yarr/YarrJIT.cpp:
(JSC::Yarr::YarrGenerator::tryReadUnicodeCharImpl):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249842 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/yarr/YarrJIT.cpp

index 3f993f2..488b174 100644 (file)
@@ -1,3 +1,15 @@
+2019-09-13  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Micro-optimize YarrJIT's surrogate pair handling
+        https://bugs.webkit.org/show_bug.cgi?id=201750
+
+        Reviewed by Michael Saboff.
+
+        Optimize sequence of machine code used to get code-point with unicode flag.
+
+        * yarr/YarrJIT.cpp:
+        (JSC::Yarr::YarrGenerator::tryReadUnicodeCharImpl):
+
 2019-09-13  Mark Lam  <mark.lam@apple.com>
 
         We should assert $vm is enabled on entry and exit in its functions.
index 84d940c..8695459 100644 (file)
@@ -543,18 +543,23 @@ class YarrGenerator : public YarrJITInfo, private MacroAssembler {
         JumpList notUnicode;
 
         load16Unaligned(regUnicodeInputAndTrail, resultReg);
+
+        // Is the character a leading surrogate?
         and32(surrogateTagMask, resultReg, regT2);
         notUnicode.append(branch32(NotEqual, regT2, leadingSurrogateTag));
+
+        // Is the input long enough to read a trailing surrogate?
         addPtr(TrustedImm32(2), regUnicodeInputAndTrail);
         notUnicode.append(branchPtr(AboveOrEqual, regUnicodeInputAndTrail, endOfStringAddress));
+
+        // Is the character a trailing surrogate?
         load16Unaligned(Address(regUnicodeInputAndTrail), regUnicodeInputAndTrail);
         and32(surrogateTagMask, regUnicodeInputAndTrail, regT2);
         notUnicode.append(branch32(NotEqual, regT2, trailingSurrogateTag));
-        sub32(leadingSurrogateTag, resultReg);
-        sub32(trailingSurrogateTag, regUnicodeInputAndTrail);
+
+        // Combine leading and trailing surrogates to produce a code point.
         lshift32(TrustedImm32(10), resultReg);
-        or32(regUnicodeInputAndTrail, resultReg);
-        add32(supplementaryPlanesBase, resultReg);
+        getEffectiveAddress(BaseIndex(resultReg, regUnicodeInputAndTrail, TimesOne, -U16_SURROGATE_OFFSET), resultReg);
         notUnicode.link(this);
     }