[Mesa-dev] [PATCH v2 14/29] nir: fix constant expressions for rounding mode conversions
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Thu Jan 31 13:07:09 UTC 2019
On 30/01/2019 16:29, Connor Abbott wrote:
> I think maybe it would be better if we put all this in nir_opcodes.py
> instead. Again, I'd like to make sure that for every opcode, what it
> does is right next to the definition instead of buried in
> nir_constant_expressions.py.
>
OK, I'll do it.
> Also, I don't see anywhere in the series where you handle different
> rounding modes for fadd, fsub, fmul, etc.
>
Right, I did it only for the conversions. I will handle the rounding
modes for all the correctly rounded SPIR-V instructions in nir_opcodes.py.
Thanks for your feedback.
Sam
> On Tue, Dec 18, 2018 at 11:35 AM Samuel Iglesias Gonsálvez
> <siglesias at igalia.com <mailto:siglesias at igalia.com>> wrote:
>
> Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com
> <mailto:siglesias at 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 at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190131/cc189ae3/attachment.sig>
More information about the mesa-dev
mailing list