[Mesa-dev] [PATCH] i965: Replace illegal compacted NOP with valid compact instruction

Zhenyu Wang zhenyuw at linux.intel.com
Mon Jun 1 03:19:51 PDT 2015


NOP actually has no compact version, but we use it for instruction
alignment for compact kernel. Although it seems working on HW, it is
illegal and might not be valid for any future one.

This trys to get a temporary compact instruction with no effect for
alignment to replace compacted NOP. G45 spec has note that HW compact
logic could determine NENOP and drop it right away, so we can still
keep with that.

Signed-off-by: Zhenyu Wang <zhenyuw at linux.intel.com>
---
 src/mesa/drivers/dri/i965/brw_eu_compact.c | 41 +++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_eu_compact.c b/src/mesa/drivers/dri/i965/brw_eu_compact.c
index 67f0b45..719667a 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_compact.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_compact.c
@@ -1367,6 +1367,39 @@ brw_init_compaction_tables(const struct brw_device_info *devinfo)
    }
 }
 
+static void
+brw_get_noop_compact(struct brw_codegen *p, brw_compact_inst *dst)
+{
+   const struct brw_device_info *devinfo = p->devinfo;
+   brw_inst *inst, i;
+   struct brw_reg g0 = brw_vec8_grf(0, 0);
+
+   memset(dst, 0, sizeof(*dst));
+
+   /* G45 compact logic could recognize NENOP and drop right away. */
+   if (devinfo->is_g4x) {
+      brw_compact_inst_set_opcode(dst, BRW_OPCODE_NENOP);
+      brw_compact_inst_set_cmpt_control(dst, true);
+      return;
+   }
+
+   /*
+    * As NOP has no legal compact version, try to use a legal compact
+    * instruction for compact instruction alignment.
+    */
+   brw_push_insn_state(p);
+   brw_set_default_predicate_control(p, BRW_PREDICATE_NONE);
+   brw_set_default_access_mode(p, BRW_ALIGN_1);
+   inst = brw_MOV(p, g0, g0);
+   memcpy(&i, inst, sizeof(brw_inst));
+   brw_pop_insn_state(p);
+
+   if (!brw_try_compact_instruction(devinfo, dst, &i)) {
+      fprintf(stderr, "Failed to generate compact inst for alignment!\n");
+      exit(1);
+   }
+}
+
 void
 brw_compact_instructions(struct brw_codegen *p, int start_offset,
                          int num_annotations, struct annotation *annotation)
@@ -1414,9 +1447,7 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
          /* All uncompacted instructions need to be aligned on G45. */
          if ((offset & sizeof(brw_compact_inst)) != 0 && devinfo->is_g4x){
             brw_compact_inst *align = store + offset;
-            memset(align, 0, sizeof(*align));
-            brw_compact_inst_set_opcode(align, BRW_OPCODE_NENOP);
-            brw_compact_inst_set_cmpt_control(align, true);
+            brw_get_noop_compact(p, align);
             offset += sizeof(brw_compact_inst);
             compacted_count--;
             compacted_counts[src_offset / sizeof(brw_inst)] = compacted_count;
@@ -1523,9 +1554,7 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
     */
    if (p->next_insn_offset & sizeof(brw_compact_inst)) {
       brw_compact_inst *align = store + offset;
-      memset(align, 0, sizeof(*align));
-      brw_compact_inst_set_opcode(align, BRW_OPCODE_NOP);
-      brw_compact_inst_set_cmpt_control(align, true);
+      brw_get_noop_compact(p, align);
       p->next_insn_offset += sizeof(brw_compact_inst);
    }
    p->nr_insn = p->next_insn_offset / sizeof(brw_inst);
-- 
2.1.4



More information about the mesa-dev mailing list