microsoft/compiler: Lower fquantize2f16
authorBoris Brezillon <boris.brezillon@collabora.com>
Mon, 14 Feb 2022 14:58:02 +0000 (06:58 -0800)
committerMarge Bot <emma+marge@anholt.net>
Fri, 10 Jun 2022 07:45:05 +0000 (07:45 +0000)
commitb12417a2c717747e79e572b6d31337d92050f18f
treef5d953c0f57e16216dbb723fcf5360f4d9cf504e
parent279f32e042c3ef9bc4311fd802ecebba61cb17a7
microsoft/compiler: Lower fquantize2f16

As far as I can't tell, there's no native operation doing this
equivalent of fquantize2f16. Let's lower this operation to

   if (val < MIN_FLOAT16)
      return -INFINITY;
   else if (val > MAX_FLOAT16)
      return -INFINITY;
   else if (fabs(val) < SMALLER_NORMALIZED_FLOAT16)
      return 0;
   else
      return val;

which matches the definition of OpQuantizeToF16:

"
If Value is an infinity, the result is the same infinity.
If Value is a NaN, the result is a NaN, but not necessarily the same NaN.
If Value is positive with a magnitude too large to represent as a 16-bit
floating-point value, the result is positive infinity. If Value is negative
with a magnitude too large to represent as a 16-bit floating-point value,
the result is negative infinity. If the magnitude of Value is too small to
represent as a normalized 16-bit floating-point value, the result may be
either +0 or -0.
"

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16959>
src/microsoft/compiler/dxil_nir.c
src/microsoft/compiler/dxil_nir.h
src/microsoft/compiler/nir_to_dxil.c