[Mesa-dev] [PATCH v3 16/44] nir/constant_expressions: take into account rounding mode to convert from float to float16 destinations

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Feb 6 10:44:45 UTC 2019


Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
 src/compiler/nir/nir_constant_expressions.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py
index e79590f8359..0b3da1b21ac 100644
--- a/src/compiler/nir/nir_constant_expressions.py
+++ b/src/compiler/nir/nir_constant_expressions.py
@@ -64,6 +64,7 @@ template = """\
 #include "util/rounding.h" /* for _mesa_roundeven */
 #include "util/half_float.h"
 #include "util/bigmath.h"
+#include "util/double.h"
 #include "nir_constant_expressions.h"
 
 /**
@@ -370,7 +371,11 @@ struct ${type}${width}_vec {
             ## Sanitize the C value to a proper NIR 0/-1 bool
             _dst_val.${get_const_field(output_type)}[_i] = -(int)dst;
          % elif output_type == "float16":
-            _dst_val.u16[_i] = _mesa_float_to_half(dst);
+            % if "rtz" in op.rounding_mode:
+               _dst_val.u16[_i] = _mesa_float_to_float16_rtz(dst);
+            % else:
+               _dst_val.u16[_i] = _mesa_float_to_float16_rtne(dst);
+            % endif
          % else:
             _dst_val.${get_const_field(output_type)}[_i] = dst;
          % endif
@@ -414,7 +419,11 @@ struct ${type}${width}_vec {
             ## Sanitize the C value to a proper NIR 0/-1 bool
             _dst_val.${get_const_field(output_type)}[${k}] = -(int)dst.${"xyzw"[k]};
          % elif output_type == "float16":
-            _dst_val.u16[${k}] = _mesa_float_to_half(dst.${"xyzw"[k]});
+            % if "rtz" in op.rounding_mode:
+               _dst_val.u16[${k}] = _mesa_float_to_float16_rtz(dst.${"xyzw"[k]});
+            % else:
+               _dst_val.u16[${k}] = _mesa_float_to_float16_rtne(dst.${"xyzw"[k]});
+            % endif
          % else:
             _dst_val.${get_const_field(output_type)}[${k}] = dst.${"xyzw"[k]};
          % endif
-- 
2.19.1



More information about the mesa-dev mailing list