master: avx2 simd-copy-character-string-to-utf8-byte-array
stassats via Sbcl-commits <[email protected]> Thu, 02 Jul 2026 00:13:24 +0000
| Newsgroups | gmane.lisp.steel-bank.cvs |
|---|---|
| Message-ID | <[email protected]> |
The branch "master" has been updated in SBCL:
via ff7a653710315dd1d3a4a2ecdc70a9ca02a8ad7f (commit)
from 8b5a25e7cd1c62449fa751a5068652459aadae6a (commit)
- Log -----------------------------------------------------------------
commit ff7a653710315dd1d3a4a2ecdc70a9ca02a8ad7f
Author: Stas Boukarev <[email protected]>
Date: Thu Jul 2 02:32:42 2026 +0300
avx2 simd-copy-character-string-to-utf8-byte-array
---
src/code/x86-64-simd.lisp | 54 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/src/code/x86-64-simd.lisp b/src/code/x86-64-simd.lisp
index a3386903b..fc96e9e08 100644
--- a/src/code/x86-64-simd.lisp
+++ b/src/code/x86-64-simd.lisp
@@ -803,6 +803,60 @@
do (setf (aref string i)
(code-char (sap-ref-8 sap i))))))
+(def-variant simd-copy-character-string-to-utf8-byte-array :avx2 (byte-array string length)
+ (declare (index length)
+ (simple-character-string string)
+ ((simple-array (unsigned-byte 8) (*)) byte-array)
+ (optimize speed (safety 0)))
+ (with-pinned-objects (string byte-array)
+ (inline-vop (((byte-array sap-reg t) (vector-sap byte-array))
+ ((32-bit-array sap-reg t) (vector-sap string))
+ ((n unsigned-reg) (logand (+ (* length 4) 15) -16))
+ ((bytes1 int-avx2-reg))
+ ((bytes2 int-avx2-reg)))
+ ()
+ (inst sub n 64)
+ (inst jmp :b TAIL)
+
+ LOOP
+ (inst vmovdqu bytes1 (ea 32-bit-array))
+
+ (inst vpackusdw bytes1 bytes1 (ea 32 32-bit-array))
+ (inst vpermq bytes1 bytes1 216)
+ (inst vpackuswb bytes1 bytes1 bytes1)
+ (inst vpermq bytes1 bytes1 216)
+
+ (inst add 32-bit-array 64)
+
+ (inst vmovdqa (ea byte-array) (reg-in-sc bytes1 'int-sse-reg))
+ (inst add byte-array 16)
+ (inst sub n 64)
+ (inst jmp :ae LOOP)
+
+ TAIL
+ (inst add :dword n 64)
+ (inst jmp :z DONE)
+ (inst vpxor bytes2 bytes2 bytes2)
+
+ (inst cmp :dword n 32)
+ (inst jmp :l ONE)
+ (inst vmovdqu bytes1 (ea 32-bit-array))
+ (inst jmp :e NARROW)
+ (inst vmovdqa (reg-in-sc bytes2 'int-sse-reg) (ea 32 32-bit-array))
+ (inst jmp NARROW)
+ ONE
+ (inst vmovdqa (reg-in-sc bytes1 'int-sse-reg) (ea 32-bit-array))
+
+ NARROW
+ (inst vpackusdw bytes1 bytes1 bytes2)
+ (inst vpermq bytes1 bytes1 216)
+ (inst vpackuswb bytes1 bytes1 bytes1)
+ (inst vpermq bytes1 bytes1 216)
+ (inst vmovdqa (ea byte-array) (reg-in-sc bytes1 'int-sse-reg))
+
+ DONE
+ (inst vzeroupper))))
+
#+sb-unicode
(defun simd-copy-utf8-to-base-string (start end string ibuf)
(declare (type index start end)
-----------------------------------------------------------------------
hooks/post-receive
--
SBCL