<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jan 15, 2019 at 7:55 AM Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@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">Broadwell hardware has a bug that manifests in SIMD8 executions of<br>
16-bit MAD instructions when any of the sources is a Y or W component.<br>
We pack these components in the same SIMD register as components X and<br>
Z respectively, but starting at offset 16B (so they live in the second<br>
half of the register). The problem does not exist in SKL or later.<br>
<br>
We work around this issue by moving any such sources to a temporary<br>
starting at offset 0B. We want to do this after the main optimization loop<br>
to prevent copy-propagation and friends to undo the fix.<br>
<br>
Reviewed-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com" target="_blank">topi.pohjolainen@intel.com</a>><br>
---<br>
 src/intel/compiler/brw_fs.cpp | 48 +++++++++++++++++++++++++++++++++++<br>
 src/intel/compiler/brw_fs.h   |  1 +<br>
 2 files changed, 49 insertions(+)<br>
<br>
diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp<br>
index 0b3ec94e2d2..d6096cd667d 100644<br>
--- a/src/intel/compiler/brw_fs.cpp<br>
+++ b/src/intel/compiler/brw_fs.cpp<br>
@@ -6540,6 +6540,48 @@ fs_visitor::optimize()<br>
    validate();<br>
 }<br>
<br>
+/**<br>
+ * Broadwell hardware has a bug that manifests in SIMD8 executions of 16-bit<br>
+ * MAD instructions when any of the sources is a Y or W component. We pack<br>
+ * these components in the same SIMD register as components X and Z<br>
+ * respectively, but starting at offset 16B (so they live in the second half<br>
+ * of the register).<br></blockquote><div><br></div><div>What exactly do you mean by a Y or W component?  Is this for the case where you have a scalar that happens to land at certain offsets?  Or does it apply to regular stride == 1 MADs?  If it applied in the stride == 1 case, then I really don't see what this is doing to fix it.  It might help if you provided some before and after assembly example.</div><div><br></div><div>Also, this seems like something that should go in the new region restrictions pass as a special case in has_invalid_src_region.</div><div><br></div><div>--Jason<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">
+ *<br>
+ * We work around this issue by moving any such sources to a temporary<br>
+ * starting at offset 0B. We want to do this after the main optimization loop<br>
+ * to prevent copy-propagation and friends to undo the fix.<br>
+ */<br>
+void<br>
+fs_visitor::fixup_hf_mad()<br>
+{<br>
+   if (devinfo->gen != 8)<br>
+      return;<br>
+<br>
+   bool progress = false;<br>
+<br>
+   foreach_block_and_inst_safe (block, fs_inst, inst, cfg) {<br>
+      if (inst->opcode != BRW_OPCODE_MAD ||<br>
+          inst->dst.type != BRW_REGISTER_TYPE_HF ||<br>
+          inst->exec_size > 8)<br>
+         continue;<br>
+<br>
+      for (int i = 0; i < 3; i++) {<br>
+         if (inst->src[i].offset > 0) {<br>
+            assert(inst->src[i].type == BRW_REGISTER_TYPE_HF);<br>
+            const fs_builder ibld =<br>
+               <a href="http://bld.at" rel="noreferrer" target="_blank">bld.at</a>(block, inst).exec_all().group(inst->exec_size, 0);<br>
+            fs_reg tmp = ibld.vgrf(inst->src[i].type);<br>
+            ibld.MOV(tmp, inst->src[i]);<br>
+            inst->src[i] = tmp;<br>
+            progress = true;<br>
+         }<br>
+      }<br>
+   }<br>
+<br>
+   if (progress)<br>
+      invalidate_live_intervals();<br>
+}<br>
+<br>
 /**<br>
  * Three source instruction must have a GRF/MRF destination register.<br>
  * ARF NULL is not allowed.  Fix that up by allocating a temporary GRF.<br>
@@ -6698,6 +6740,7 @@ fs_visitor::run_vs()<br>
    assign_curb_setup();<br>
    assign_vs_urb_setup();<br>
<br>
+   fixup_hf_mad();<br>
    fixup_3src_null_dest();<br>
    allocate_registers(8, true);<br>
<br>
@@ -6782,6 +6825,7 @@ fs_visitor::run_tcs_single_patch()<br>
    assign_curb_setup();<br>
    assign_tcs_single_patch_urb_setup();<br>
<br>
+   fixup_hf_mad();<br>
    fixup_3src_null_dest();<br>
    allocate_registers(8, true);<br>
<br>
@@ -6816,6 +6860,7 @@ fs_visitor::run_tes()<br>
    assign_curb_setup();<br>
    assign_tes_urb_setup();<br>
<br>
+   fixup_hf_mad();<br>
    fixup_3src_null_dest();<br>
    allocate_registers(8, true);<br>
<br>
@@ -6865,6 +6910,7 @@ fs_visitor::run_gs()<br>
    assign_curb_setup();<br>
    assign_gs_urb_setup();<br>
<br>
+   fixup_hf_mad();<br>
    fixup_3src_null_dest();<br>
    allocate_registers(8, true);<br>
<br>
@@ -6965,6 +7011,7 @@ fs_visitor::run_fs(bool allow_spilling, bool do_rep_send)<br>
<br>
       assign_urb_setup();<br>
<br>
+      fixup_hf_mad();<br>
       fixup_3src_null_dest();<br>
       allocate_registers(8, allow_spilling);<br>
<br>
@@ -7009,6 +7056,7 @@ fs_visitor::run_cs(unsigned min_dispatch_width)<br>
<br>
    assign_curb_setup();<br>
<br>
+   fixup_hf_mad();<br>
    fixup_3src_null_dest();<br>
    allocate_registers(min_dispatch_width, true);<br>
<br>
diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h<br>
index 68287bcdcea..1879d4bc7f7 100644<br>
--- a/src/intel/compiler/brw_fs.h<br>
+++ b/src/intel/compiler/brw_fs.h<br>
@@ -103,6 +103,7 @@ public:<br>
    void setup_vs_payload();<br>
    void setup_gs_payload();<br>
    void setup_cs_payload();<br>
+   void fixup_hf_mad();<br>
    void fixup_3src_null_dest();<br>
    void assign_curb_setup();<br>
    void calculate_urb_setup();<br>
-- <br>
2.17.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>