semantics of SPIR-V's composite and vector operations.
(defspv OpCompositeExtract (composite &rest indexes)
"The constituent INDEXES (literals) lead to, one level per index."
(:expand (rt ts lits)
(declare (ignore rt))
(spv-extract-form (first ts) 'composite lits)))
(defspv OpCompositeInsert (object composite &rest indexes)
"COMPOSITE with the constituent INDEXES lead to replaced by OBJECT."
(:expand (rt ts lits)
(declare (ignore rt))
(let ((lw (spv-v128-lanes (second ts))))
(if (and lw (= (length lits) 1))
`(set-lane ,lw composite ,(first lits) object)
(multiple-value-bind (sub pos width) (spv-path (second ts) lits)
(declare (ignore sub))
`(dpb object (byte ,width ,pos) composite))))))
(defspv OpCompositeConstruct (&rest constituents)
"The constituents concatenated: one per constituent of the result, or
for a vector also smaller vectors (their components in order)."
(:expand (rt ts lits)
(declare (ignore lits))
(unless (= (spv-type-bits rt) (reduce #'+ (mapcar #'spv-type-bits ts) :initial-value 0))
(error "OpCompositeConstruct: ~S from ~S" rt ts))
(spv-concat-form ts (loop for i below (length ts) collect (spv-operand-var i)))))
(defspv OpVectorShuffle (vector1 vector2 &rest components)
"Result component i is component COMPONENTS[i] of VECTOR1 followed by
VECTOR2. A component literal of #xFFFFFFFF gives an undefined component."
(:expand (rt ts lits)
(let* ((n1 (nth-value 2 (spv-comp (first ts))))
(ct (third rt))
(w (spv-type-bits ct)))
(unless (= (length lits) (nth-value 2 (spv-comp rt)))
(error "OpVectorShuffle: ~D components for ~S" (length lits) rt))
(spv-concat-form
(make-list (length lits) :initial-element ct)
(mapcar (lambda (c)
(cond ((= c #xFFFFFFFF) `(spv-undef ,w))
((< c n1) (spv-extract-form (first ts) 'vector1 (list c)))
(t (spv-extract-form (second ts) 'vector2 (list (- c n1))))))
lits)))))
(defspv OpVectorExtractDynamic (vector index)
"Behavior is undefined if Index is out of range (read unsigned)."
(:expand (rt ts lits)
(declare (ignore rt lits))
(multiple-value-bind (class w n) (spv-comp (first ts))
(declare (ignore class))
`(if (< index ,n)
,(if (= (* w n) 128)
`(lane ,w vector index)
`(ldb (byte ,w (* ,w (- ,(1- n) index))) vector))
(spv-ub)))))
(defspv OpVectorInsertDynamic (vector component index)
"Behavior is undefined if Index is out of range (read unsigned)."
(:expand (rt ts lits)
(declare (ignore rt lits))
(multiple-value-bind (class w n) (spv-comp (first ts))
(declare (ignore class))
`(if (< index ,n)
,(if (= (* w n) 128)
`(set-lane ,w vector index component)
`(dpb component (byte ,w (* ,w (- ,(1- n) index))) vector))
(spv-ub)))))
(defspv OpBitcast (operand)
"The same bits. Between a vector and a scalar or a vector of another
component count, the lower-numbered components are the lower-order bits
(the SPIR-V rule), which with constituent 0 most significant here is a
reversal of component order."
(:expand (rt ts lits)
(declare (ignore lits))
(multiple-value-bind (sc sw sn) (spv-comp (first ts))
(declare (ignore sc))
(multiple-value-bind (rc rw rn) (spv-comp rt)
(declare (ignore rc))
(unless (= (* sw sn) (* rw rn))
(error "OpBitcast: ~S and ~S differ in size" rt (first ts)))
(if (= sn rn)
'operand
(let* ((l (if (= sn 1)
'operand
`(logior ,@(loop for i below sn
collect (spv-ash-form `(ldb (byte ,sw ,(* sw (- sn 1 i))) operand)
(* i sw))))))
(parts (loop for j below rn
collect (spv-ash-form `(ldb (byte ,rw ,(* j rw)) ,(if (= sn 1) 'operand 'l))
(* rw (- rn 1 j))))))
(if (= sn 1)
`(logior ,@parts)
(if (= rn 1) l `(let ((l ,l)) (logior ,@parts))))))))))
(defspv OpVectorTimesScalar (vector scalar)
"Each component times the scalar: OpFMul's precision."
(:float (w) (fop w (vector scalar) (fmul (ffmt w) :rne vector scalar))))
Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.