<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 28, 2014 at 8:10 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
 src/mesa/drivers/dri/i965/brw_eu_compact.c | 215 ++++++++++++++++++++++++++++-<br>
 1 file changed, 210 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_eu_compact.c b/src/mesa/drivers/dri/i965/brw_eu_compact.c<br>
index acce663..5008ba6 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_eu_compact.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_eu_compact.c<br>
@@ -41,6 +41,146 @@<br>
 #include "brw_eu.h"<br>
 #include "intel_asm_annotation.h"<br>
<br>
+static const uint32_t g45_control_index_table[32] = {<br>
+   0b00000000000000000,<br>
+   0b01000000000000000,<br>
+   0b00110000000000000,<br>
+   0b00000000000000010,<br>
+   0b00100000000000000,<br>
+   0b00010000000000000,<br>
+   0b01000000000100000,<br>
+   0b01000000100000000,<br>
+   0b01010000000100000,<br>
+   0b00000000100000010,<br>
+   0b11000000000000000,<br>
+   0b00001000100000010,<br>
+   0b01001000100000000,<br>
+   0b00000000100000000,<br>
+   0b11000000000100000,<br>
+   0b00001000100000000,<br>
+   0b10110000000000000,<br>
+   0b11010000000100000,<br>
+   0b00110000100000000,<br>
+   0b00100000100000000,<br>
+   0b01000000000001000,<br>
+   0b01000000000000100,<br>
+   0b00111100000000000,<br>
+   0b00101011000000000,<br>
+   0b00110000000010000,<br>
+   0b00010000100000000,<br>
+   0b01000000000100100,<br>
+   0b01000000000101000,<br>
+   0b00110000000000110,<br>
+   0b00000000000001010,<br>
+   0b01010000000101000,<br>
+   0b01010000000100100<br>
+};<br>
+<br>
+static const uint32_t g45_datatype_table[32] = {<br>
+   0b001000000000100001,<br>
+   0b001011010110101101,<br>
+   0b001000001000110001,<br>
+   0b001111011110111101,<br>
+   0b001011010110101100,<br>
+   0b001000000110101101,<br>
+   0b001000000000100000,<br>
+   0b010100010110110001,<br>
+   0b001100011000101101,<br>
+   0b001000000000100010,<br>
+   0b001000001000110110,<br>
+   0b010000001000110001,<br>
+   0b001000001000110010,<br>
+   0b011000001000110010,<br>
+   0b001111011110111100,<br>
+   0b001000000100101000,<br>
+   0b010100011000110001,<br>
+   0b001010010100101001,<br>
+   0b001000001000101001,<br>
+   0b010000001000110110,<br>
+   0b101000001000110001,<br>
+   0b001011011000101101,<br>
+   0b001000000100001001,<br>
+   0b001011011000101100,<br>
+   0b110100011000110001,<br>
+   0b001000001110111101,<br>
+   0b110000001000110001,<br>
+   0b011000000100101010,<br>
+   0b101000001000101001,<br>
+   0b001011010110001100,<br>
+   0b001000000110100001,<br>
+   0b001010010100001000<br>
+};<br>
+<br>
+static const uint16_t g45_subreg_table[32] = {<br>
+   0b000000000000000,<br>
+   0b000000010000000,<br>
+   0b000001000000000,<br>
+   0b000100000000000,<br>
+   0b000000000100000,<br>
+   0b100000000000000,<br>
+   0b000000000010000,<br>
+   0b001100000000000,<br>
+   0b001010000000000,<br>
+   0b000000100000000,<br>
+   0b001000000000000,<br>
+   0b000000000001000,<br>
+   0b000000001000000,<br>
+   0b000000000000001,<br>
+   0b000010000000000,<br>
+   0b000000010100000,<br>
+   0b000000000000111,<br>
+   0b000001000100000,<br>
+   0b011000000000000,<br>
+   0b000000110000000,<br>
+   0b000000000000010,<br>
+   0b000000000000100,<br>
+   0b000000001100000,<br>
+   0b000100000000010,<br>
+   0b001110011000110,<br>
+   0b001110100001000,<br>
+   0b000110011000110,<br>
+   0b000001000011000,<br>
+   0b000110010000100,<br>
+   0b001100000000110,<br>
+   0b000000010000110,<br>
+   0b000001000110000<br>
+};<br>
+<br>
+static const uint16_t g45_src_index_table[32] = {<br>
+   0b000000000000,<br>
+   0b010001101000,<br>
+   0b010110001000,<br>
+   0b011010010000,<br>
+   0b001101001000,<br>
+   0b010110001010,<br>
+   0b010101110000,<br>
+   0b011001111000,<br>
+   0b001000101000,<br>
+   0b000000101000,<br>
+   0b010001010000,<br>
+   0b111101101100,<br>
+   0b010110001100,<br>
+   0b010001101100,<br>
+   0b011010010100,<br>
+   0b010001001100,<br>
+   0b001100101000,<br>
+   0b000000000010,<br>
+   0b111101001100,<br>
+   0b011001101000,<br>
+   0b010101001000,<br>
+   0b000000000100,<br>
+   0b000000101100,<br>
+   0b010001101010,<br>
+   0b000000111000,<br>
+   0b010101011000,<br>
+   0b000100100000,<br>
+   0b010110000000,<br>
+   0b010000000100,<br>
+   0b010000111000,<br>
+   0b000101100000,<br>
+   0b111101110100<br>
+};<br>
+<br>
 static const uint32_t gen6_control_index_table[32] = {<br>
    0b00000000000000000,<br>
    0b01000000000000000,<br>
@@ -496,7 +636,7 @@ static const uint16_t *src_index_table;<br>
 static bool<br>
 set_control_index(struct brw_context *brw, brw_compact_inst *dst, brw_inst *src)<br>
 {<br>
-   uint32_t uncompacted = brw->gen >= 8      /* 17b/SNB; 19b/IVB+ */<br>
+   uint32_t uncompacted = brw->gen >= 8      /* 17b/G45; 19b/IVB+ */<br>
       ? (brw_inst_bits(src, 33, 31) << 16) | /*  3b */<br>
         (brw_inst_bits(src, 23, 12) <<  4) | /* 12b */<br>
         (brw_inst_bits(src, 10,  9) <<  2) | /*  2b */<br>
@@ -525,7 +665,7 @@ static bool<br>
 set_datatype_index(struct brw_context *brw, brw_compact_inst *dst,<br>
                    brw_inst *src)<br>
 {<br>
-   uint32_t uncompacted = brw->gen >= 8      /* 18b/SNB+; 21b/BDW+ */<br>
+   uint32_t uncompacted = brw->gen >= 8      /* 18b/G45+; 21b/BDW+ */<br>
       ? (brw_inst_bits(src, 63, 61) << 18) | /*  3b */<br>
         (brw_inst_bits(src, 94, 89) << 12) | /*  6b */<br>
         (brw_inst_bits(src, 46, 35))         /* 12b */<br>
@@ -740,6 +880,7 @@ brw_try_compact_instruction(struct brw_context *brw, brw_compact_inst *dst,<br>
    assert(brw_inst_cmpt_control(brw, src) == 0);<br>
<br>
    if (brw_inst_opcode(brw, src) == BRW_OPCODE_IF ||<br>
+       brw_inst_opcode(brw, src) == BRW_OPCODE_IFF ||<br>
        brw_inst_opcode(brw, src) == BRW_OPCODE_ELSE ||<br>
        brw_inst_opcode(brw, src) == BRW_OPCODE_ENDIF ||<br>
        brw_inst_opcode(brw, src) == BRW_OPCODE_HALT ||<br>
@@ -768,7 +909,8 @@ brw_try_compact_instruction(struct brw_context *brw, brw_compact_inst *dst,<br>
    bool is_immediate =<br>
       brw_inst_src0_reg_file(brw, src) == BRW_IMMEDIATE_VALUE ||<br>
       brw_inst_src1_reg_file(brw, src) == BRW_IMMEDIATE_VALUE;<br>
-   if (is_immediate && !is_compactable_immediate(brw_inst_imm_ud(brw, src))) {<br>
+   if (is_immediate &&<br>
+       (brw->gen < 6 || !is_compactable_immediate(brw_inst_imm_ud(brw, src)))) {<br>
       return false;<br>
    }<br>
<br>
@@ -1061,9 +1203,35 @@ update_uip_jip(struct brw_context *brw, brw_inst *insn,<br>
                     uip_compacted * (brw->gen >= 8 ? sizeof(brw_inst) : 1));<br>
 }<br>
<br>
+static void<br>
+update_gen4_jump_count(struct brw_context *brw, brw_inst *insn,<br>
+                       int this_old_ip, int *compacted_counts)<br>
+{<br>
+   assert(brw->gen == 5);<br>
+<br>
+   /* Jump Count is in units of:<br>
+    *    - compacted instructions on Gen5.<br>
+    */<br>
+   int jump_count = brw_inst_gen4_jump_count(brw, insn);<br>
+   int jump_count_compacted = jump_count;<br>
+   int jump_count_uncompacted = jump_count / 2;<br>
+<br>
+   int target_old_ip = this_old_ip + jump_count_uncompacted;<br>
+<br>
+   int this_compacted_count = compacted_counts[this_old_ip];<br>
+   int target_compacted_count = compacted_counts[target_old_ip];<br>
+<br>
+   jump_count_compacted -= (target_compacted_count - this_compacted_count);<br>
+   brw_inst_set_gen4_jump_count(brw, insn, jump_count_compacted);<br>
+}<br>
+<br>
 void<br>
 brw_init_compaction_tables(struct brw_context *brw)<br>
 {<br>
+   assert(g45_control_index_table[ARRAY_SIZE(g45_control_index_table) - 1] != 0);<br>
+   assert(g45_datatype_table[ARRAY_SIZE(g45_datatype_table) - 1] != 0);<br>
+   assert(g45_subreg_table[ARRAY_SIZE(g45_subreg_table) - 1] != 0);<br>
+   assert(g45_src_index_table[ARRAY_SIZE(g45_src_index_table) - 1] != 0);<br>
    assert(gen6_control_index_table[ARRAY_SIZE(gen6_control_index_table) - 1] != 0);<br>
    assert(gen6_datatype_table[ARRAY_SIZE(gen6_datatype_table) - 1] != 0);<br>
    assert(gen6_subreg_table[ARRAY_SIZE(gen6_subreg_table) - 1] != 0);<br>
@@ -1096,6 +1264,12 @@ brw_init_compaction_tables(struct brw_context *brw)<br>
       subreg_table = gen6_subreg_table;<br>
       src_index_table = gen6_src_index_table;<br>
       break;<br>
+   case 5:<br>
+      control_index_table = g45_control_index_table;<br>
+      datatype_table = g45_datatype_table;<br>
+      subreg_table = g45_subreg_table;<br>
+      src_index_table = g45_src_index_table;<br>
+      break;<br>
    default:<br>
       return;<br>
    }<br>
@@ -1116,7 +1290,7 @@ brw_compact_instructions(struct brw_compile *p, int start_offset,<br>
     */<br>
    int old_ip[(p->next_insn_offset - start_offset) / sizeof(brw_compact_inst)];<br>
<br>
-   if (brw->gen < 6)<br>
+   if (brw->gen == 4)<br>
       return;<br>
<br>
    int offset = 0;<br>
@@ -1184,10 +1358,15 @@ brw_compact_instructions(struct brw_compile *p, int start_offset,<br>
       case BRW_OPCODE_BREAK:<br>
       case BRW_OPCODE_CONTINUE:<br>
       case BRW_OPCODE_HALT:<br>
-         update_uip_jip(brw, insn, this_old_ip, compacted_counts);<br>
+         if (brw->gen >= 6) {<br>
+            update_uip_jip(brw, insn, this_old_ip, compacted_counts);<br>
+         } else {<br>
+            update_gen4_jump_count(brw, insn, this_old_ip, compacted_counts);<br>
+         }<br>
          break;<br>
<br>
       case BRW_OPCODE_IF:<br>
+      case BRW_OPCODE_IFF:<br>
       case BRW_OPCODE_ELSE:<br>
       case BRW_OPCODE_ENDIF:<br>
       case BRW_OPCODE_WHILE:<br>
@@ -1202,6 +1381,32 @@ brw_compact_instructions(struct brw_compile *p, int start_offset,<br>
             target_compacted_count = compacted_counts[target_old_ip];<br>
             jump_count_compacted -= (target_compacted_count - this_compacted_count);<br>
             brw_inst_set_gen6_jump_count(brw, insn, jump_count_compacted);<br>
+         } else {<br>
+            update_gen4_jump_count(brw, insn, this_old_ip, compacted_counts);<br>
+         }<br>
+         break;<br>
+<br>
+      case BRW_OPCODE_ADD:<br>
+         /* Add instructions modifying the IP register use an immediate src1,<br>
+          * and Gens that use this cannot compact instructions with immediate<br>
+          * operands.<br>
+          */<br>
+         if (brw_inst_cmpt_control(brw, insn))<br>
+            break;<br>
+<br>
+         if (brw_inst_dst_reg_file(brw, insn) == BRW_ARCHITECTURE_REGISTER_FILE &&<br>
+             brw_inst_dst_da_reg_nr(brw, insn) == BRW_ARF_IP) {<br>
+            assert(brw_inst_src1_reg_file(brw, insn) == BRW_IMMEDIATE_VALUE);<br>
+<br>
+            int jump = brw_inst_imm_d(brw, insn);<br>
+            int jump_compacted = jump / sizeof(brw_compact_inst);<br>
+            int jump_uncompacted = jump / sizeof(brw_inst);<br>
+<br>
+            target_old_ip = this_old_ip + jump_uncompacted;<br>
+            target_compacted_count = compacted_counts[target_old_ip];<br>
+            jump_compacted -= (target_compacted_count - this_compacted_count);<br>
+            brw_inst_set_imm_ud(brw, insn, jump_compacted *<br>
+                                           sizeof(brw_compact_inst));<br></blockquote><div><br></div><div>Any reason why you're reading it as a signed value and then writing it back in unsigned?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
          }<br>
          break;<br>
       }<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.5.5<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>