<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 11, 2017 at 8:00 AM, Jose Maria Casanova Crespo <span dir="ltr"><<a href="mailto:jmcasanova@igalia.com" target="_blank">jmcasanova@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>><br>
<span class=""><br>
Although from SPIR-V point of view, rounding modes are attached to the<br>
operation/destination, on i965 it is a status, so we don't need to<br>
explicitly set the rounding mode if the one we want is already set.<br>
<br>
</span>Taking into account that the default mode is RTE, one possible<br>
optimization would be optimize out the first RTE set for each<br>
block. For in order to work, we would need to take into account block<br>
interrelationships. At this point, it is not worth to complicate the<br>
optimization for such small gain.<br>
<span class=""><br>
v2: Use a single SHADER_OPCODE_RND_MODE opcode taking an immediate<br>
with the rounding mode (Curro)<br>
</span>v3: Reset optimization for every block. (Jason Ekstrand)<br>
<span class=""><br>
Signed-off-by: Jose Maria Casanova Crespo <<a href="mailto:jmcasanova@igalia.com">jmcasanova@igalia.com</a>><br>
Signed-off-by: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>><br>
---<br>
</span> src/intel/compiler/brw_eu_<wbr>defines.h | 3 ++-<br>
src/intel/compiler/brw_fs.cpp | 37 ++++++++++++++++++++++++++++++<wbr>+++++++<br>
src/intel/compiler/brw_fs.h | 1 +<br>
3 files changed, 40 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/intel/compiler/brw_eu_<wbr>defines.h b/src/intel/compiler/brw_eu_<wbr>defines.h<br>
index 72f773352e..aea58284bc 100644<br>
--- a/src/intel/compiler/brw_eu_<wbr>defines.h<br>
+++ b/src/intel/compiler/brw_eu_<wbr>defines.h<br>
@@ -1227,7 +1227,8 @@ enum PACKED brw_rnd_mode {<br>
BRW_RND_MODE_RTNE = 0, /* Round to Nearest or Even */<br>
BRW_RND_MODE_RU = 1, /* Round Up, toward +inf */<br>
BRW_RND_MODE_RD = 2, /* Round Down, toward -inf */<br>
- BRW_RND_MODE_RTZ = 3 /* Round Toward Zero */<br>
+ BRW_RND_MODE_RTZ = 3, /* Round Toward Zero */<br>
+ BRW_RND_MODE_UNSPECIFIED /* Unspecified rounding mode */<br></blockquote><div><br></div><div>In the future, please end enum lists with commas. The C grammar allows it and it means you don't have an extra +- line if you add an entry to the end.</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
};<br>
<br>
#endif /* BRW_EU_DEFINES_H */<br>
diff --git a/src/intel/compiler/brw_fs.<wbr>cpp b/src/intel/compiler/brw_fs.<wbr>cpp<br>
index 45236e3cab..9b33a32917 100644<br>
--- a/src/intel/compiler/brw_fs.<wbr>cpp<br>
+++ b/src/intel/compiler/brw_fs.<wbr>cpp<br>
@@ -3071,6 +3071,42 @@ fs_visitor::remove_duplicate_<wbr>mrf_writes()<br>
<span class=""> return progress;<br>
}<br>
<br>
+/**<br>
+ * Rounding modes for conversion instructions are included for each<br>
+ * conversion, but right now it is a state. So once it is set,<br>
+ * we don't need to call it again for subsequent calls.<br>
+ *<br>
+ * This is useful for vector/matrices conversions, as setting the<br>
+ * mode once is enough for the full vector/matrix<br>
+ */<br>
+bool<br>
+fs_visitor::remove_extra_<wbr>rounding_modes()<br>
+{<br>
+ bool progress = false;<br>
+<br>
</span>+ foreach_block (block, cfg) {<br>
+ brw_rnd_mode prev_mode = BRW_RND_MODE_UNSPECIFIED;<br>
+<br>
+ foreach_inst_in_block_safe (fs_inst, inst, block) {<br>
<span class="">+ if (inst->opcode == SHADER_OPCODE_RND_MODE) {<br>
+ assert(inst->src[0].file == BRW_IMMEDIATE_VALUE);<br>
</span>+ const brw_rnd_mode mode = (brw_rnd_mode) inst->src[0].d;<br>
+ if (mode == prev_mode) {<br>
<span class="">+ inst->remove(block);<br>
+ progress = true;<br>
+ } else {<br>
</span>+ prev_mode = mode;<br>
<span class="">+ }<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ if (progress)<br>
+ invalidate_live_intervals();<br>
+<br>
+ return progress;<br>
+}<br>
+<br>
</span><span class=""> static void<br>
clear_deps_for_inst_src(fs_<wbr>inst *inst, bool *deps, int first_grf, int grf_len)<br>
{<br>
</span>@@ -5748,6 +5784,7 @@ fs_visitor::optimize()<br>
<span class=""> int pass_num = 0;<br>
<br>
OPT(opt_drop_redundant_mov_to_<wbr>flags);<br>
+ OPT(remove_extra_rounding_<wbr>modes);<br>
<br>
do {<br>
progress = false;<br>
diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h<br>
</span>index f1ba193de7..b9476e69ed 100644<br>
<span class="">--- a/src/intel/compiler/brw_fs.h<br>
+++ b/src/intel/compiler/brw_fs.h<br>
@@ -150,6 +150,7 @@ public:<br>
bool eliminate_find_live_channel();<br>
bool dead_code_eliminate();<br>
bool remove_duplicate_mrf_writes();<br>
+ bool remove_extra_rounding_modes();<br>
<br>
bool opt_sampler_eot();<br>
bool virtual_grf_interferes(int a, int b);<br>
--<br>
</span>2.13.5<br>
<br>
</blockquote></div><br></div></div>