master: x86-64/character-string-utf8-length: support very large strings

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  13b5e0a8ed54f8f3ef5a6ce41438f53df6b229f6 (commit)
      from  6a80d5e791c534ac574594212cfb35c52e5f3a85 (commit)

- Log -----------------------------------------------------------------
commit 13b5e0a8ed54f8f3ef5a6ce41438f53df6b229f6
Author: Stas Boukarev <[email protected]>
Date:   Tue Aug 11 01:17:38 2026 +0300

    x86-64/character-string-utf8-length: support very large strings
    
    Over 4GB of emojis.
---
 src/code/x86-64-simd.lisp | 20 ++++++++++++--------
 src/code/x86-64-vm.lisp   | 11 ++++++++---
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/code/x86-64-simd.lisp b/src/code/x86-64-simd.lisp
index fdd7c819a..e593343f5 100644
--- a/src/code/x86-64-simd.lisp
+++ b/src/code/x86-64-simd.lisp
@@ -2207,7 +2207,7 @@
          ((c-ffff       int-sse-reg))
          ((c-1b         int-sse-reg))
 
-         ((extra-len    int-sse-reg))
+         ((extra-len    int-avx2-reg))
          ((errors       int-sse-reg))
 
          ((current      int-sse-reg))
@@ -2281,24 +2281,28 @@
       (inst vpcmpgtd mask current c-ffff)
       (inst vpaddd tmp1 tmp1 mask)
 
-      (inst vpsubd extra-len extra-len tmp1)
+      (let ((tmp1 (reg-in-sc tmp1 'int-avx2-reg)))
+        (inst vpmovsxdq tmp1 tmp1)
+        (inst vpsubq extra-len extra-len tmp1))
 
       (inst jmp LOOP)
 
       EXIT
       (inst vptest errors errors)
-      (inst jmp :nz DONE)
+      (inst jmp :nz DONE-FULL)
 
-      (inst vpshufd tmp1 extra-len #b01001110)
-      (inst vpaddd tmp1 tmp1 extra-len)
-      (inst vpshufd mask tmp1 #b10110001)
-      (inst vpaddd tmp1 tmp1 mask)
+      (inst vextracti128 tmp1 extra-len 1)
+      (inst vpaddq tmp1 tmp1 extra-len)
+      (inst vpshufd tmp2 tmp1 #b01001110)
+      (inst vpaddq tmp1 tmp1 tmp2)
 
-      (inst vmovd tmp tmp1)
+      (inst vmovq tmp tmp1)
 
       (inst shl tmp n-fixnum-tag-bits)
       (inst add tmp length)
       (inst mov res tmp)
+      DONE-FULL
+      (inst vzeroupper)
 
       DONE)))
 
diff --git a/src/code/x86-64-vm.lisp b/src/code/x86-64-vm.lisp
index 22529b398..5a11109ef 100644
--- a/src/code/x86-64-vm.lisp
+++ b/src/code/x86-64-vm.lisp
@@ -66,9 +66,14 @@
                     (sap-ref-double sap 8))))
       #+sb-simd-pack
       (simd-pack-int
-       (%make-simd-pack-ub64
-        (sap-ref-64 sap 0)
-        (sap-ref-64 sap 8)))
+       (if integer
+           (values (dpb (sap-ref-64 sap 8)
+                        (byte 64 64)
+                        (sap-ref-64 sap 0))
+                   16)
+           (%make-simd-pack-ub64
+            (sap-ref-64 sap 0)
+            (sap-ref-64 sap 8))))
       #+sb-simd-pack
       (simd-pack-single
        (%make-simd-pack-single

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


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.