master: arm64/character-string-to-utf8: jump to ascii-loop from a better place

stassats via Sbcl-commits <[email protected]>
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  bd76fc4481386d6f4f295f7968e6c459e62fce99 (commit)
      from  0eb8b556ac414e9c3e4f5efaec69022af69537fc (commit)

- Log -----------------------------------------------------------------
commit bd76fc4481386d6f4f295f7968e6c459e62fce99
Author: Stas Boukarev <[email protected]>
Date:   Sat Aug 22 17:19:52 2026 +0300

    arm64/character-string-to-utf8: jump to ascii-loop from a better place
---
 src/code/arm64-simd.lisp | 27 ++++++++++++++-------------
 tests/utf-8.impure.lisp  |  3 ++-
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/src/code/arm64-simd.lisp b/src/code/arm64-simd.lisp
index 2ef9424f3..b86a50584 100644
--- a/src/code/arm64-simd.lisp
+++ b/src/code/arm64-simd.lisp
@@ -1721,9 +1721,11 @@
                    (inst ld1 (list bytes bytes2) (@ string) :4s)
                    ;; Stop if anything is 3-4 bytes in utf8
                    (inst orr temp bytes bytes2 :4s)
-                   1-2-LOOP-START
                    (inst umaxv temp temp :4s)
                    (inst umov tmp temp 0 :s)
+                   (inst cmp tmp 127)
+                   (inst b :ls 32-ASCII-START)
+                   1-2-LOOP-START
                    (inst cmp tmp #x800)
                    (inst b :ge FULL-START)
 
@@ -1746,8 +1748,6 @@
                    (inst umov tmp ascii 0 :h)
 
                    (inst ubfiz tmp2 tmp 4 8) ;; shift the low 8 bits left
-                   (inst cmp tmp2 #xFF0)
-                   (inst b :eq 32-ASCII-START)
 
                    ;; Construct
                    ;; (logior
@@ -1780,18 +1780,19 @@
                    32-ASCII-LOOP
                    (inst ld1 (list bytes bytes2) (@ string) :4s)
                    (inst orr temp bytes bytes2 :4s)
-                   (check-ascii temp temp2 1-2-LOOP-START :4s)
-
-                   ;; Narrow to 16 bits
-                   (inst uzp1 bytes bytes bytes2 :8h)
-
-                   ;; Track newlines
-                   (inst cmeq temp bytes newlines :8h)
-                   (inst cmeq f1 temp 0 :4s)
-                   (inst bif last-newlines indexes f1 :16b)
-                   (inst add indexes indexes increment :4s)
+                   (check-ascii temp temp2 1-2-LOOP-START :4s :gpr tmp)
 
                    32-ASCII-START
+
+                   ;; Narrow to 16 bits
+                   (inst uzp1 bytes bytes bytes2 :8h)
+
+                   ;; Track newlines
+                   (inst cmeq temp bytes newlines :8h)
+                   (inst cmeq f1 temp 0 :4s)
+                   (inst bif last-newlines indexes f1 :16b)
+                   (inst add indexes indexes increment :4s)
+
                    ;; Narrow to 8 bytes
                    (inst xtn bytes bytes :8b)
                    (inst str bytes (@ byte-array 8 :post-index) :d)
diff --git a/tests/utf-8.impure.lisp b/tests/utf-8.impure.lisp
index 0f1023f67..c55941dce 100644
--- a/tests/utf-8.impure.lisp
+++ b/tests/utf-8.impure.lisp
@@ -71,7 +71,8 @@
                         0
                         (random 4))
         while (< i (length string))
-        do (loop repeat (1+ (random (- (length string) i)))
+        do (loop repeat (1+ (random (min (- (length string) i)
+                                         80)))
                  for char = (case width
                               (0 (random 128))
                               (1 (+ 128 (random (- 2048 128))))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.