Signed-off-by: Samuel Iglesias Gonsálvez <sigles...@igalia.com> --- src/compiler/nir/nir_constant_expressions.py | 46 +++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-)
diff --git a/src/compiler/nir/nir_constant_expressions.py b/src/compiler/nir/nir_constant_expressions.py index dc2132df0d0..84cf819e921 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" /** @@ -324,7 +325,15 @@ struct ${type}${width}_vec { % elif input_types[j] == "float16": _mesa_half_to_float(_src[${j}].u16[${k}]), % else: - _src[${j}].${get_const_field(input_types[j])}[${k}], + % if ("rtne" in op.rounding_mode) and ("float" in input_types[j]) and ("int" in output_type): + % if "float32" in input_types[j]: + _mesa_roundevenf(_src[${j}].${get_const_field(input_types[j])}[${k}]), + % else: + _mesa_roundeven(_src[${j}].${get_const_field(input_types[j])}[${k}]), + % endif + % else: + _src[${j}].${get_const_field(input_types[j])}[${k}], + % endif % endif % endfor % for k in range(op.input_sizes[j], 4): @@ -353,8 +362,27 @@ struct ${type}${width}_vec { const float src${j} = _mesa_half_to_float(_src[${j}].u16[_i]); % else: - const ${input_types[j]}_t src${j} = - _src[${j}].${get_const_field(input_types[j])}[_i]; + % if ("rtne" in op.rounding_mode) and ("float" in input_types[j]) and ("int" in output_type): + % if "float32" in input_types[j]: + const ${input_types[j]}_t src${j} = + _mesa_roundevenf(_src[${j}].${get_const_field(input_types[j])}[_i]); + % else: + const ${input_types[j]}_t src${j} = + _mesa_roundeven(_src[${j}].${get_const_field(input_types[j])}[_i]); + + % endif + % elif ("float64" in input_types[j]) and ("float32" in output_type): + % if ("rtz" in op.rounding_mode): + const ${input_types[j]}_t src${j} = + _mesa_double_to_float_rtz(_src[${j}].${get_const_field(input_types[j])}[_i]); + % else: + const ${input_types[j]}_t src${j} = + _mesa_double_to_float_rtne(_src[${j}].${get_const_field(input_types[j])}[_i]); + % endif + % else: + const ${input_types[j]}_t src${j} = + _src[${j}].${get_const_field(input_types[j])}[_i]; + % endif % endif % endfor @@ -378,7 +406,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 @@ -416,7 +448,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 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev