master: sse2 simd-copy-utf8-sap-to-character-string
stassats via Sbcl-commits <[email protected]> Sun, 28 Jun 2026 22:23:03 +0000
| Newsgroups | gmane.lisp.steel-bank.cvs |
|---|---|
| Message-ID | <[email protected]> |
The branch "master" has been updated in SBCL:
via f7c75a2020bbd00c74968aa7afd938f12b65c7f4 (commit)
from c0bf0a6cd87273b967184d8e3a241dc9e96ce539 (commit)
- Log -----------------------------------------------------------------
commit f7c75a2020bbd00c74968aa7afd938f12b65c7f4
Author: Stas Boukarev <[email protected]>
Date: Mon Jun 29 01:07:55 2026 +0300
sse2 simd-copy-utf8-sap-to-character-string
---
src/code/external-formats/enc-basic.lisp | 2 +-
src/code/x86-64-simd.lisp | 76 ++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/src/code/external-formats/enc-basic.lisp b/src/code/external-formats/enc-basic.lisp
index c7a8c0fe8..7903b7ade 100644
--- a/src/code/external-formats/enc-basic.lisp
+++ b/src/code/external-formats/enc-basic.lisp
@@ -664,7 +664,7 @@
(truly-the index (values (truncate string-offset 4))))))
;;; No validations
-#+(and sb-unicode 64-bit little-endian (not arm64))
+#+(and sb-unicode 64-bit little-endian (not (or arm64 x86-64)))
(defun sb-vm::simd-copy-utf8-sap-to-character-string (sap string length)
(declare (index length)
(simple-character-string string)
diff --git a/src/code/x86-64-simd.lisp b/src/code/x86-64-simd.lisp
index 09ac9b6d6..9e31b4efd 100644
--- a/src/code/x86-64-simd.lisp
+++ b/src/code/x86-64-simd.lisp
@@ -728,6 +728,82 @@
(setf (sb-impl::buffer-head ibuf) (+ head copied))
(+ start copied))))
+#+sb-unicode
+(defun simd-copy-utf8-sap-to-character-string (sap string length)
+ (declare (optimize speed (safety 0))
+ (system-area-pointer sap)
+ (index length))
+ (let ((n (logand length -16)))
+ (with-pinned-objects (string)
+ (inline-vop (((byte-array* sap-reg t) sap)
+ ((byte-array sap-reg t))
+ ((32-bit-array sap-reg t) (vector-sap string))
+ ((bytes int-sse-reg))
+ ((16-bits int-sse-reg))
+ ((32-bits int-sse-reg))
+ ((32-bits-2 int-sse-reg))
+ ((end unsigned-reg))
+ ((n unsigned-reg) n)
+ ((temp))
+ ((32-bits-4 int-sse-reg))
+ ((zero)))
+ ((res unsigned-reg unsigned-num))
+ (let ((16-bits-2 bytes)
+ (32-bits-3 bytes))
+ (assemble ()
+ (inst mov byte-array byte-array*)
+ (inst lea end (ea byte-array* n))
+ (inst pxor zero zero)
+ (inst jmp start)
+
+
+ LOOP
+ (inst movdqu bytes (ea byte-array))
+ (inst add byte-array 16)
+
+ (move 16-bits bytes)
+ (inst punpcklbw 16-bits zero)
+ (move 32-bits-2 16-bits)
+
+
+ (move 32-bits 16-bits)
+ (inst punpcklwd 32-bits zero)
+
+ (inst movdqa (ea 32-bit-array) 32-bits)
+ (inst psrldq 32-bits-2 8)
+ (inst punpcklwd 32-bits-2 zero)
+
+ (inst movdqa (ea 16 32-bit-array) 32-bits-2)
+
+ (move 16-bits-2 bytes)
+
+ (inst psrldq 16-bits-2 8)
+ (inst punpcklbw 16-bits-2 zero)
+ (move 32-bits-4 16-bits-2)
+ (move 32-bits-3 16-bits-2)
+
+ (inst punpcklwd 32-bits-3 zero)
+
+ (inst movdqa (ea 32 32-bit-array) 32-bits-3)
+ (inst psrldq 32-bits-4 8)
+ (inst punpcklwd 32-bits-4 zero)
+
+ (inst movdqa (ea 48 32-bit-array) 32-bits-4)
+
+ (inst add 32-bit-array (* 16 4))
+
+ START
+ (inst cmp byte-array end)
+ (inst jmp :l LOOP)
+
+ DONE))
+
+ (inst sub byte-array byte-array*)
+ (move res byte-array)))
+ (loop for i from n below length
+ do (setf (aref string i)
+ (code-char (sap-ref-8 sap i))))))
+
#+sb-unicode
(defun simd-copy-utf8-to-base-string (start end string ibuf)
(declare (type index start end)
-----------------------------------------------------------------------
hooks/post-receive
--
SBCL