Skip to content

Instantly share code, notes, and snippets.

@stassats
Created November 27, 2024 22:52
Show Gist options
  • Save stassats/d0b8b8c89558ed3a589197f695eea019 to your computer and use it in GitHub Desktop.
Save stassats/d0b8b8c89558ed3a589197f695eea019 to your computer and use it in GitHub Desktop.
(defun simd-downcase (vector start end)
;; (declare (type index start end)
;; (optimize speed (safety 0)))
(let ((pages #.(map '(vector (unsigned-byte 32))
(lambda (x)
(ash x 6))
sb-impl::+character-case-pages+))
(cases sb-impl::+character-cases+))
(declare (optimize sb-c::preserve-single-use-debug-variables))
(with-pinned-objects (vector pages)
(inline-vop (((32-bit-array* sap-reg t) (vector-sap vector))
((pages sap-reg t) (vector-sap pages))
((cases sap-reg t) (vector-sap cases))
((start any-reg) start)
((end any-reg) end)
((left))
((32-bit-array sap-reg t))
((bytes int-avx2-reg))
((page-index))
((page-index-mask))
((search))
((mask)))
()
(inst lea 32-bit-array (ea 32-bit-array* start 2))
(inst mov left 63)
(inst vmovd page-index-mask left)
(inst vpbroadcastd page-index-mask page-index-mask)
LOOP
(inst vmovdqu bytes (ea 32-bit-array))
(inst vpsrld-imm page-index bytes 6)
(inst vpcmpeqd mask mask mask)
(inst vpgatherdd search (ea pages page-index 4) mask)
(inst vpand bytes bytes page-index-mask)
(inst vpaddd bytes bytes search)
(inst vpslld-imm bytes bytes 1)
(inst vpcmpeqd mask mask mask)
(inst vpgatherdd search (ea cases bytes 4) mask)
(inst vmovdqu (ea 32-bit-array) search)
(inst vzeroupper)
))
vector))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment