<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 6, 2019 at 11:46 AM Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">According to Vulkan spec, the new execution modes affect only<br>
correctly rounded SPIR-V instructions, which includes fadd,<br>
fsub and fmul.<br>
<br>
Signed-off-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>><br>
---<br>
 src/compiler/nir/nir_opcodes.py | 17 +++++++++++++++++<br>
 1 file changed, 17 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py<br>
index f8997444c28..7b45d38f460 100644<br>
--- a/src/compiler/nir/nir_opcodes.py<br>
+++ b/src/compiler/nir/nir_opcodes.py<br>
@@ -453,9 +453,15 @@ def binop_convert(name, out_type, in_type, alg_props, const_expr):<br>
    opcode(name, 0, out_type, [0, 0], [in_type, in_type],<br>
           False, alg_props, const_expr, "")<br>
<br>
+def binop_convert_rounding_mode(name, out_type, in_type, alg_props, const_expr, rounding_mode):<br>
+   opcode(name, 0, out_type, [0, 0], [in_type, in_type], False, alg_props, const_expr, rounding_mode)<br>
+<br>
 def binop(name, ty, alg_props, const_expr):<br>
    binop_convert(name, ty, ty, alg_props, const_expr)<br>
<br>
+def binop_rounding_mode(name, ty, alg_props, const_expr, rounding_mode):<br>
+   binop_convert_rounding_mode(name, ty, ty, alg_props, const_expr, rounding_mode)<br>
+<br>
 def binop_compare(name, ty, alg_props, const_expr):<br>
    binop_convert(name, tbool1, ty, alg_props, const_expr)<br>
<br>
@@ -490,13 +496,24 @@ def binop_reduce(name, output_size, output_type, src_type, prereduce_expr,<br>
           final(reduce_(reduce_(src0, src1), reduce_(src2, src3))), "")<br>
<br>
 binop("fadd", tfloat, commutative + associative, "src0 + src1")<br>
+binop_rounding_mode("fadd_rtne", tfloat, commutative + associative,<br>
+                    "_mesa_roundeven(src0 + src1)", "_rtne")<br></blockquote><div><br></div><div>There are two things wrong here:</div><div>- The default floating-point environment, and the one Mesa expects, does round-to-nearest-even so it's rtz that needs special handling.<br></div><div>- _mesa_roundeven here is a no-op (it'll implicitly expand to a double and then convert back to a float). The rounding actually happens as part of the addition itself. I'm not sure if adding as double (with round-to-nearest-even) and then rounding back to a float will work, but that definitely won't work for doubles. I think you'll have to implement round-to-zero addition yourself, or fiddle with the CPU's floating-point environment.</div><div><br></div><div>The same goes multiply and fma.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+binop_rounding_mode("fadd_rtz", tfloat, commutative + associative, "src0 + src1", "_rtz")<br>
+<br>
 binop("iadd", tint, commutative + associative, "src0 + src1")<br>
 binop("uadd_sat", tuint, commutative,<br>
       "(src0 + src1) < src0 ? UINT64_MAX : (src0 + src1)")<br>
 binop("fsub", tfloat, "", "src0 - src1")<br>
+binop_rounding_mode("fsub_rtne", tfloat, "",<br>
+                    "_mesa_roundeven(src0 - src1)", "_rtne")<br>
+binop_rounding_mode("fsub_rtz", tfloat, "", "src0 - src1", "_rtz")<br>
 binop("isub", tint, "", "src0 - src1")<br>
<br>
 binop("fmul", tfloat, commutative + associative, "src0 * src1")<br>
+binop_rounding_mode("fmul_rtne", tfloat, commutative + associative,<br>
+                    "_mesa_roundeven(src0 * src1)", "_rtne")<br>
+binop_rounding_mode("fmul_rtz", tfloat, commutative + associative, "src0 * src1", "_rtz")<br>
+<br>
 # low 32-bits of signed/unsigned integer multiply<br>
 binop("imul", tint, commutative + associative, "src0 * src1")<br>
<br>
-- <br>
2.19.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>