semantics of SPIR-V's floating-point arithmetic, comparisons, conversions.
(defspv OpFAdd (a b) "Correctly rounded." (:float (w) (fop w (a b) (fadd (ffmt w) :rne a b))))
(defspv OpFSub (a b) "Correctly rounded." (:float (w) (fop w (a b) (fsub (ffmt w) :rne a b))))
(defspv OpFMul (a b) "Correctly rounded." (:float (w) (fop w (a b) (fmul (ffmt w) :rne a b))))
(defspv OpFDiv (a b)
"Within 2.5 ULP. A non-zero over a zero is the signed infinity, exactly."
(:float (w) (fop w (a b) (fdiv (ffmt w) :rne a b) :ulp 25
:guard ((fzero-p (ffmt w) b) (fnonfinite w (fdiv (ffmt w) :rne a b))))))
(defspv OpFRem (a b)
"a - b * trunc(a / b), Vulkan's definition (precision inherited from
those operations): the sign of a non-0 result comes from Operand 1. The
result is undefined if Operand 2 is 0."
(:float (w)
(fop w (a b)
(fsub (ffmt w) :rne a (fmul (ffmt w) :rne b (fround-int (ffmt w) :rtz (fdiv (ffmt w) :rne a b))))
:inexact t :guard ((fzero-p (ffmt w) b) (spv-undef w)))))
(defspv OpFMod (a b)
"a - b * floor(a / b): the sign of a non-0 result comes from Operand 2.
Precision inherited. The result is undefined if Operand 2 is 0."
(:float (w)
(fop w (a b)
(fsub (ffmt w) :rne a (fmul (ffmt w) :rne b (fround-int (ffmt w) :rdn (fdiv (ffmt w) :rne a b))))
:inexact t :guard ((fzero-p (ffmt w) b) (spv-undef w)))))
(defspv OpFNegate (a)
"Inverts the sign bit (still a float operation: denormals, NaNs)."
(:float (w) (fop w (a) (fneg (ffmt w) a))))
(defspv OpFOrdEqual (a b) (:float (w) (fop w (a b) (feq (ffmt w) a b) :result :bool)))
(defspv OpFUnordEqual (a b)
(:float (w) (fop w (a b) (logior (funord (ffmt w) a b) (feq (ffmt w) a b)) :result :bool)))
(defspv OpFOrdNotEqual (a b)
(:float (w) (fop w (a b) (- 1 (logior (funord (ffmt w) a b) (feq (ffmt w) a b))) :result :bool)))
(defspv OpFUnordNotEqual (a b) (:float (w) (fop w (a b) (- 1 (feq (ffmt w) a b)) :result :bool)))
(defspv OpFOrdLessThan (a b) (:float (w) (fop w (a b) (flt (ffmt w) a b) :result :bool)))
(defspv OpFUnordLessThan (a b)
(:float (w) (fop w (a b) (logior (funord (ffmt w) a b) (flt (ffmt w) a b)) :result :bool)))
(defspv OpFOrdGreaterThan (a b) (:float (w) (fop w (a b) (flt (ffmt w) b a) :result :bool)))
(defspv OpFUnordGreaterThan (a b)
(:float (w) (fop w (a b) (logior (funord (ffmt w) a b) (flt (ffmt w) b a)) :result :bool)))
(defspv OpFOrdLessThanEqual (a b) (:float (w) (fop w (a b) (fle (ffmt w) a b) :result :bool)))
(defspv OpFUnordLessThanEqual (a b)
(:float (w) (fop w (a b) (logior (funord (ffmt w) a b) (fle (ffmt w) a b)) :result :bool)))
(defspv OpFOrdGreaterThanEqual (a b) (:float (w) (fop w (a b) (fle (ffmt w) b a) :result :bool)))
(defspv OpFUnordGreaterThanEqual (a b)
(:float (w) (fop w (a b) (logior (funord (ffmt w) a b) (fle (ffmt w) b a)) :result :bool)))
(defspv OpIsNan (x)
"Under :nan :fast an implementation may assume there are no NaNs."
(:float (w) (fop w (x) (b2i (fnan-p (ffmt w) x)) :result :bool)))
(defspv OpIsInf (x)
(:float (w) (fop w (x) (b2i (finf-p (ffmt w) x)) :result :bool)))
(defspv OpConvertFToU (float-value)
"Rounds toward 0. Behavior is undefined if the result type is not wide
enough to hold the converted value (and for an infinity or NaN): the
conversion saturated one past each end tells it."
(:float (w rw)
(fop w (float-value)
(let ((i (fcvt-to-int (ffmt w) :rtz float-value -1 (ash 1 rw))))
(if (<= 0 i (ones rw)) i (spv-ub)))
:result :int :rw rw
:guard ((or (finf-p (ffmt w) float-value) (fnan-p (ffmt w) float-value)) (spv-ub)))))
(defspv OpConvertFToS (float-value)
"Rounds toward 0. Behavior is undefined if the result type is not wide
enough to hold the converted value (and for an infinity or NaN)."
(:float (w rw)
(fop w (float-value)
(let ((i (fcvt-to-int (ffmt w) :rtz float-value (- -1 (ash 1 (1- rw))) (ash 1 (1- rw)))))
(if (<= (- (ash 1 (1- rw))) i (1- (ash 1 (1- rw)))) (wrap rw i) (spv-ub)))
:result :int :rw rw
:guard ((or (finf-p (ffmt w) float-value) (fnan-p (ffmt w) float-value)) (spv-ub)))))
(defspv OpConvertSToF (signed-value)
"Correctly rounded (to nearest even)."
(:int (w rw) (int-to-f (ffmt rw) :rne (sext w signed-value))))
(defspv OpConvertUToF (unsigned-value)
"Correctly rounded (to nearest even)."
(:int (w rw) (int-to-f (ffmt rw) :rne unsigned-value)))
(defspv OpFConvert (float-value)
"To another float width: exact when widening, correctly rounded when
narrowing."
(:float (w rw) :require (/= w rw)
(fop w (float-value) (fcvt (ffmt rw) (ffmt w) :rne float-value) :rw rw)))
Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.