master: x86-64, utf8-sap-to-string: use a single ymm register for two xmm

stassats via Sbcl-commits <[email protected]> Sat, 18 Jul 2026 11:00:14 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  3b5740a2970f71a30587b01917f24b452e75eeec (commit)
      from  9939d748662c79b15bfbf0d3a590fe4442632929 (commit)

- Log -----------------------------------------------------------------
commit 3b5740a2970f71a30587b01917f24b452e75eeec
Author: Stas Boukarev <[email protected]>
Date:   Sat Jul 18 13:58:34 2026 +0300

    x86-64, utf8-sap-to-string: use a single ymm register for two xmm
---
 src/code/x86-64-simd.lisp | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/code/x86-64-simd.lisp b/src/code/x86-64-simd.lisp
index 403d095f5..4ee3c78b4 100644
--- a/src/code/x86-64-simd.lisp
+++ b/src/code/x86-64-simd.lisp
@@ -2292,9 +2292,9 @@
                      ((c-c0 complex-double-reg t))
                      ((c-df complex-double-reg t))
                      ((c-bf complex-double-reg t))
-                     ((c-00ff complex-double-reg t))
                      ((c-0f complex-double-reg t))
-                     ((c-shift complex-double-reg t))
+                     ((c-00ff int-avx2-reg t))
+                     ((c-shift int-avx2-reg t))
                      ((c-3080 complex-double-reg t))
                      ((tag-clear complex-double-reg t)))
             ((byte-index unsigned-reg positive-fixnum :from :load)
@@ -2475,23 +2475,24 @@
                 (inst vpshufb x4 tag-clear x4)
                 (inst vpand current current x4)
 
-                ;; Shuffle the bytes into 4-byte lanes
-                (inst vpshufb next current (ea 16 full-table index))    ; chars-high
-                (inst vpshufb current current (ea full-table index)) ; chars-low
+                (let ((current (reg-in-sc current 'int-avx2-reg))
+                      (x2 (reg-in-sc x2 'int-avx2-reg))
+                      (x3 (reg-in-sc x3 'int-avx2-reg)))
+                  ;; Duplicate the low bits, for vpshufb
+                  (inst vinserti128 current current current 1)
 
-                (flet ((decode-lane (chars)
-                         ;; Perform
-                         ;; A + B<<6 + C<<12 + D<<18
-                         (inst vpand x2 c-00ff chars)
-                         (inst vpandn x3 c-00ff chars)
-                         (inst vpsrlw x3 x3 2)
-                         (inst vpaddw x2 x2 x3)
-                         (inst vpmaddwd chars x2 c-shift)))
-                  (decode-lane current)
-                  (decode-lane next))
+                  ;; Shuffle the bytes into 4-byte lanes
+                  (inst vpshufb current current (ea full-table index))
 
-                (inst vmovdqu (ea string char-index 4) current)
-                (inst vmovdqu (ea 16 string char-index 4) next)
+                  ;; Perform
+                  ;; A + B<<6 + C<<12 + D<<18
+                  (inst vpand x2 c-00ff current)
+                  (inst vpandn x3 c-00ff current)
+                  (inst vpsrlw x3 x3 2)
+                  (inst vpaddw x2 x2 x3)
+                  (inst vpmaddwd current x2 c-shift)
+
+                  (inst vmovdqu (ea string char-index 4) current))
 
                 (inst add byte-index 8)
                 (inst add char-index produced)

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


hooks/post-receive
-- 
SBCL