spirv: ext450.lisp

semantics of the GLSL.std.450 extended instructions used for selection.

['glsl', 'SAbs'] source

(defspv (glsl SAbs) (x)
  "|x| as a signed integer; the most negative value is its own absolute value."
  (:int (w) (wrap w (abs (sext w x)))))

['glsl', 'SSign'] source

(defspv (glsl SSign) (x) (:int (w) (wrap w (signum (sext w x)))))

['glsl', 'UMin'] source

(defspv (glsl UMin) (x y) (:int (w) (if (< y x) y x)))

['glsl', 'UMax'] source

(defspv (glsl UMax) (x y) (:int (w) (if (< x y) y x)))

['glsl', 'SMin'] source

(defspv (glsl SMin) (x y) (:int (w) (if (< (sext w y) (sext w x)) y x)))

['glsl', 'SMax'] source

(defspv (glsl SMax) (x y) (:int (w) (if (< (sext w x) (sext w y)) y x)))

['glsl', 'UClamp'] source

(defspv (glsl UClamp) (x minval maxval)
  "min(max(x, minVal), maxVal); undefined if minVal > maxVal."
  (:int (w) (if (> minval maxval)
                (spv-undef w)
                (if (< maxval x) maxval (if (< x minval) minval x)))))

['glsl', 'SClamp'] source

(defspv (glsl SClamp) (x minval maxval)
  "min(max(x, minVal), maxVal), signed; undefined if minVal > maxVal."
  (:int (w) (if (> (sext w minval) (sext w maxval))
                (spv-undef w)
                (if (< (sext w maxval) (sext w x)) maxval (if (< (sext w x) (sext w minval)) minval x)))))

['glsl', 'FindILsb'] source

(defspv (glsl FindILsb) (value)
  "The bit number of the least-significant 1 bit; -1 for 0."
  (:int (w) :require (= w 32) (if (= value 0) (ones w) (ctz w value))))

['glsl', 'FindUMsb'] source

(defspv (glsl FindUMsb) (value)
  "The bit number of the most-significant 1 bit; -1 for 0."
  (:int (w) :require (= w 32) (if (= value 0) (ones w) (- (1- w) (clz w value)))))

['glsl', 'FindSMsb'] source

(defspv (glsl FindSMsb) (value)
  "For a positive value the most-significant 1 bit, for a negative one the
   most-significant 0 bit; -1 for 0 and -1."
  (:int (w) :require (= w 32)
    (let ((v (if (logbitp (1- w) value) (wrap w (lognot value)) value)))
      (if (= v 0) (ones w) (- (1- w) (clz w v))))))

['glsl', 'FAbs'] source

(defspv (glsl FAbs) (x)
  "Clears the sign bit. Exact."
  (:float (w) (fop w (x) (fabs (ffmt w) x))))

['glsl', 'FMin'] source

FMin, FMax and FClamp are GLSL's definitions, comparisons with the
primitive's <, not IEEE minimum/maximum: FMin(+0, -0) is +0
(defspv (glsl FMin) (x y)
  "y if y < x, else x. Exact. Undefined if either operand is a NaN."
  (:float (w) (fop w (x y) (if (= (flt (ffmt w) y x) 1) y x)
                   :guard ((or (fnan-p (ffmt w) x) (fnan-p (ffmt w) y)) (spv-undef w)))))

['glsl', 'FMax'] source

(defspv (glsl FMax) (x y)
  "y if x < y, else x. Exact. Undefined if either operand is a NaN."
  (:float (w) (fop w (x y) (if (= (flt (ffmt w) x y) 1) y x)
                   :guard ((or (fnan-p (ffmt w) x) (fnan-p (ffmt w) y)) (spv-undef w)))))

['glsl', 'FClamp'] source

(defspv (glsl FClamp) (x minval maxval)
  "min(max(x, minVal), maxVal); undefined if minVal > maxVal (or a NaN)."
  (:float (w)
    (fop w (x minval maxval)
         (if (= (flt (ffmt w) maxval x) 1) maxval (if (= (flt (ffmt w) x minval) 1) minval x))
         :guard ((or (fnan-p (ffmt w) x) (fnan-p (ffmt w) minval) (fnan-p (ffmt w) maxval)
                     (= (flt (ffmt w) maxval minval) 1))
                 (spv-undef w)))))

['glsl', 'NMin'] source

NMin, NMax, NClamp: "If one operand is a NaN, the other operand is the
result. If both operands are NaN, the result is a NaN" [GLSL450]; else as
FMin, FMax, FClamp. Not IEEE 754-2008 minNum (which may choose either zero)
(defspv (glsl NMin) (x y)
  "y if y < x, else x; a NaN operand gives the other."
  (:float (w) (fop w (x y) (cond ((fnan-p (ffmt w) x) y) ((fnan-p (ffmt w) y) x)
                                 ((= (flt (ffmt w) y x) 1) y) (t x)))))

['glsl', 'NMax'] source

(defspv (glsl NMax) (x y)
  "y if x < y, else x; a NaN operand gives the other."
  (:float (w) (fop w (x y) (cond ((fnan-p (ffmt w) x) y) ((fnan-p (ffmt w) y) x)
                                 ((= (flt (ffmt w) x y) 1) y) (t x)))))

['glsl', 'NClamp'] source

(defspv (glsl NClamp) (x minval maxval)
  "NMin(NMax(x, minVal), maxVal); undefined if minVal > maxVal."
  (:float (w)
    (fop w (x minval maxval)
         (let ((m (cond ((fnan-p (ffmt w) x) minval) ((fnan-p (ffmt w) minval) x)
                        ((= (flt (ffmt w) x minval) 1) minval) (t x))))
           (cond ((fnan-p (ffmt w) m) maxval) ((fnan-p (ffmt w) maxval) m)
                 ((= (flt (ffmt w) maxval m) 1) maxval) (t m)))
         :guard ((= (flt (ffmt w) maxval minval) 1) (spv-undef w)))))

['glsl', 'Fma'] source

(defspv (glsl Fma) (a b c)
  "a * b + c. Vulkan: the precision is inherited from OpFMul then OpFAdd,
   so a fused (FFMA) and an unfused result are both allowed: written as the
   unfused one, inexact."
  (:float (w) (fop w (a b c) (fadd (ffmt w) :rne (fmul (ffmt w) :rne a b) c) :inexact t)))

['glsl', 'FMix'] source

(defspv (glsl FMix) (x y a)
  "x * (1 - a) + y * a. Precision inherited."
  (:float (w) (fop w (x y a)
                   (fadd (ffmt w) :rne (fmul (ffmt w) :rne x (fsub (ffmt w) :rne (fconst (ffmt w) 1.0) a))
                         (fmul (ffmt w) :rne y a))
                   :inexact t)))

['glsl', 'Fract'] source

(defspv (glsl Fract) (x)
  "x - floor(x). Precision inherited."
  (:float (w) (fop w (x) (fsub (ffmt w) :rne x (fround-int (ffmt w) :rdn x)) :inexact t)))

['glsl', 'Sqrt'] source

(defspv (glsl Sqrt) (x)
  "Precision inherited from 1.0 / InverseSqrt. A negative x makes a NaN."
  (:float (w) (fop w (x) (fsqrt (ffmt w) :rne x) :inexact t
                   :guard ((and (= (fsign (ffmt w) x) 1) (not (fzero-p (ffmt w) x)))
                           (fnonfinite w (fdefault-nan (ffmt w)))))))

['glsl', 'InverseSqrt'] source

(defspv (glsl InverseSqrt) (x)
  "Within 2 ULP. A zero makes an infinity, a negative x a NaN (exactly)."
  (:float (w) (fop w (x) (fdiv (ffmt w) :rne (fconst (ffmt w) 1.0) (fsqrt (ffmt w) :rne x)) :ulp 20
                   :guard ((or (fzero-p (ffmt w) x) (= (fsign (ffmt w) x) 1))
                           (fnonfinite w (fdiv (ffmt w) :rne (fconst (ffmt w) 1.0) (fsqrt (ffmt w) :rne x)))))))

['glsl', 'Trunc'] source

the roundings: roundToIntegral, exact
(defspv (glsl Trunc) (x)
  "The nearest whole number toward 0. Exact."
  (:float (w) (fop w (x) (fround-int (ffmt w) :rtz x))))

['glsl', 'Floor'] source

(defspv (glsl Floor) (x) (:float (w) (fop w (x) (fround-int (ffmt w) :rdn x))))

['glsl', 'Ceil'] source

(defspv (glsl Ceil) (x) (:float (w) (fop w (x) (fround-int (ffmt w) :rup x))))

['glsl', 'RoundEven'] source

(defspv (glsl RoundEven) (x)
  "The nearest whole number, a fraction of 0.5 to the even one. Exact."
  (:float (w) (fop w (x) (fround-int (ffmt w) :rne x))))

['glsl', 'Round'] source

(defspv (glsl Round) (x)
  "The nearest whole number; 'a fractional part of 0.5 will round in a
   direction chosen by the implementation': to even or away from 0."
  (:float (w) (fop w (x) (spv-either (fround-int (ffmt w) :rne x) (fround-int (ffmt w) :rna x)))))

['glsl', 'Exp2'] source

(defspv (glsl Exp2) (x)
  "2^x. Vulkan: within 3 + 2|x| ULP."
  (:float (w) (fop w (x) (fexp2 (ffmt w) x) :inexact t)))

['glsl', 'Log2'] source

(defspv (glsl Log2) (x)
  "log2(x); a negative x makes a NaN. Vulkan: absolute error 2^-21 in
   [0.5, 2.0], else 3 ULP."
  (:float (w) (fop w (x) (flog2 (ffmt w) x) :inexact t)))

['glsl', 'Sin'] source

(defspv (glsl Sin) (x)
  "sin(x). Vulkan: absolute error 2^-11 in [-pi, pi]."
  (:float (w) (fop w (x) (fsin (ffmt w) x) :inexact t)))

['glsl', 'Cos'] source

(defspv (glsl Cos) (x)
  "cos(x). Vulkan: absolute error 2^-11 in [-pi, pi]."
  (:float (w) (fop w (x) (fcos (ffmt w) x) :inexact t)))

['glsl', 'Pow'] source

(defspv (glsl Pow) (x y)
  "x^y; undefined for x < 0, or x = 0 and y <= 0. Vulkan: inherited from exp2(y * log2(x))."
  (:float (w) (fop w (x y) (fpow (ffmt w) x y) :inexact t
                   :guard ((or (and (= (fsign (ffmt w) x) 1) (not (fzero-p (ffmt w) x)))
                               (and (fzero-p (ffmt w) x) (or (fzero-p (ffmt w) y) (= (fsign (ffmt w) y) 1))))
                           (spv-undef w)))))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.