intel/compiler: Don't left-shift by >= the number of bits of the type
[mesa.git] / src / intel / compiler / brw_eu_compact.c
index 7b32270957d4d385e236be1066ab48e0bfa48489..6198ad63ba58bd5d4155005a9be84e70b033655c 100644 (file)
@@ -74,8 +74,8 @@
 
 #include "brw_eu.h"
 #include "brw_shader.h"
-#include "intel_asm_annotation.h"
-#include "common/gen_debug.h"
+#include "brw_disasm_info.h"
+#include "dev/gen_debug.h"
 
 static const uint32_t g45_control_index_table[32] = {
    0b00000000000000000,
@@ -109,7 +109,7 @@ static const uint32_t g45_control_index_table[32] = {
    0b00110000000000110,
    0b00000000000001010,
    0b01010000000101000,
-   0b01010000000100100
+   0b01010000000100100,
 };
 
 static const uint32_t g45_datatype_table[32] = {
@@ -144,7 +144,7 @@ static const uint32_t g45_datatype_table[32] = {
    0b101000001000101001,
    0b001011010110001100,
    0b001000000110100001,
-   0b001010010100001000
+   0b001010010100001000,
 };
 
 static const uint16_t g45_subreg_table[32] = {
@@ -179,7 +179,7 @@ static const uint16_t g45_subreg_table[32] = {
    0b000110010000100,
    0b001100000000110,
    0b000000010000110,
-   0b000001000110000
+   0b000001000110000,
 };
 
 static const uint16_t g45_src_index_table[32] = {
@@ -214,7 +214,7 @@ static const uint16_t g45_src_index_table[32] = {
    0b010000000100,
    0b010000111000,
    0b000101100000,
-   0b111101110100
+   0b111101110100,
 };
 
 static const uint32_t gen6_control_index_table[32] = {
@@ -249,7 +249,7 @@ static const uint32_t gen6_control_index_table[32] = {
    0b00110000000000011,
    0b00110000000000100,
    0b00110000100001000,
-   0b00100000000001001
+   0b00100000000001001,
 };
 
 static const uint32_t gen6_datatype_table[32] = {
@@ -389,7 +389,7 @@ static const uint32_t gen7_control_index_table[32] = {
    0b0011000000000000000,
    0b0011000000100000000,
    0b0101000000000000000,
-   0b0101000000100000000
+   0b0101000000100000000,
 };
 
 static const uint32_t gen7_datatype_table[32] = {
@@ -424,7 +424,7 @@ static const uint32_t gen7_datatype_table[32] = {
    0b001111111110111101,
    0b001011110110101100,
    0b001010010100101000,
-   0b001010110100101000
+   0b001010110100101000,
 };
 
 static const uint16_t gen7_subreg_table[32] = {
@@ -459,7 +459,7 @@ static const uint16_t gen7_subreg_table[32] = {
    0b101000000000000,
    0b110000000000000,
    0b111000000000000,
-   0b111000000011100
+   0b111000000011100,
 };
 
 static const uint16_t gen7_src_index_table[32] = {
@@ -494,7 +494,7 @@ static const uint16_t gen7_src_index_table[32] = {
    0b010001101000,
    0b010001101001,
    0b010001101010,
-   0b010110001000
+   0b010110001000,
 };
 
 static const uint32_t gen8_control_index_table[32] = {
@@ -529,7 +529,7 @@ static const uint32_t gen8_control_index_table[32] = {
    0b0011000000000000000,
    0b0011000000100000000,
    0b0101000000000000000,
-   0b0101000000100000000
+   0b0101000000100000000,
 };
 
 static const uint32_t gen8_datatype_table[32] = {
@@ -564,7 +564,7 @@ static const uint32_t gen8_datatype_table[32] = {
    0b001011111011101011101,
    0b001001111001101001100,
    0b001001001001001001000,
-   0b001001011001001001000
+   0b001001011001001001000,
 };
 
 static const uint16_t gen8_subreg_table[32] = {
@@ -599,7 +599,7 @@ static const uint16_t gen8_subreg_table[32] = {
    0b101000000000000,
    0b110000000000000,
    0b111000000000000,
-   0b111000000011100
+   0b111000000011100,
 };
 
 static const uint16_t gen8_src_index_table[32] = {
@@ -634,7 +634,42 @@ static const uint16_t gen8_src_index_table[32] = {
    0b010001101000,
    0b010001101001,
    0b010001101010,
-   0b010110001000
+   0b010110001000,
+};
+
+static const uint32_t gen11_datatype_table[32] = {
+   0b001000000000000000001,
+   0b001000000000001000000,
+   0b001000000000001000001,
+   0b001000000000011000001,
+   0b001000000000101100101,
+   0b001000000101111100101,
+   0b001000000100101000001,
+   0b001000000100101000101,
+   0b001000000100101100101,
+   0b001000001000001000001,
+   0b001000011000001000000,
+   0b001000011000001000001,
+   0b001000101000101000101,
+   0b001000111000101000100,
+   0b001000111000101000101,
+   0b001100100100101100101,
+   0b001100101100100100101,
+   0b001100101100101100100,
+   0b001100101100101100101,
+   0b001100111100101100100,
+   0b000000000010000001100,
+   0b001000000000001100101,
+   0b001000000000101000101,
+   0b001000001000001000000,
+   0b001000101000101000100,
+   0b001000111000100000100,
+   0b001001001001000001001,
+   0b001101111100101100101,
+   0b001100111100101100101,
+   0b001001111001101001100,
+   0b001001001001001001000,
+   0b001001011001001001000,
 };
 
 /* This is actually the control index table for Cherryview (26 bits), but the
@@ -647,7 +682,7 @@ static const uint32_t gen8_3src_control_index_table[4] = {
    0b00100000000110000000000001,
    0b00000000000110000000000001,
    0b00000000001000000000000001,
-   0b00000000001000000000100001
+   0b00000000001000000000100001,
 };
 
 /* This is actually the control index table for Cherryview (49 bits), but the
@@ -661,7 +696,7 @@ static const uint64_t gen8_3src_source_index_table[4] = {
    0b0000001110010011100100111001000001111000000000000,
    0b0000001110010011100100111001000001111000000000010,
    0b0000001110010011100100111001000001111000000001000,
-   0b0000001110010011100100111001000001111000000100000
+   0b0000001110010011100100111001000001111000000100000,
 };
 
 static const uint32_t *control_index_table;
@@ -893,8 +928,11 @@ has_3src_unmapped_bits(const struct gen_device_info *devinfo,
       assert(!brw_inst_bits(src, 127, 126) &&
              !brw_inst_bits(src, 105, 105) &&
              !brw_inst_bits(src, 84, 84) &&
-             !brw_inst_bits(src, 36, 35) &&
              !brw_inst_bits(src, 7,  7));
+
+      /* Src1Type and Src2Type, used for mixed-precision floating point */
+      if (brw_inst_bits(src, 36, 35))
+         return true;
    }
 
    return false;
@@ -911,8 +949,10 @@ brw_try_compact_3src_instruction(const struct gen_device_info *devinfo,
 
 #define compact(field) \
    brw_compact_inst_set_3src_##field(devinfo, dst, brw_inst_3src_##field(devinfo, src))
+#define compact_a16(field) \
+   brw_compact_inst_set_3src_##field(devinfo, dst, brw_inst_3src_a16_##field(devinfo, src))
 
-   compact(opcode);
+   compact(hw_opcode);
 
    if (!set_3src_control_index(devinfo, dst, src))
       return false;
@@ -921,20 +961,21 @@ brw_try_compact_3src_instruction(const struct gen_device_info *devinfo,
       return false;
 
    compact(dst_reg_nr);
-   compact(src0_rep_ctrl);
+   compact_a16(src0_rep_ctrl);
    brw_compact_inst_set_3src_cmpt_control(devinfo, dst, true);
    compact(debug_control);
    compact(saturate);
-   compact(src1_rep_ctrl);
-   compact(src2_rep_ctrl);
+   compact_a16(src1_rep_ctrl);
+   compact_a16(src2_rep_ctrl);
    compact(src0_reg_nr);
    compact(src1_reg_nr);
    compact(src2_reg_nr);
-   compact(src0_subreg_nr);
-   compact(src1_subreg_nr);
-   compact(src2_subreg_nr);
+   compact_a16(src0_subreg_nr);
+   compact_a16(src1_subreg_nr);
+   compact_a16(src2_subreg_nr);
 
 #undef compact
+#undef compact_a16
 
    return true;
 }
@@ -1083,7 +1124,7 @@ brw_try_compact_instruction(const struct gen_device_info *devinfo,
 #define compact(field) \
    brw_compact_inst_set_##field(devinfo, &temp, brw_inst_##field(devinfo, src))
 
-   compact(opcode);
+   compact(hw_opcode);
    compact(debug_control);
 
    if (!set_control_index(devinfo, &temp, src))
@@ -1257,27 +1298,30 @@ brw_uncompact_3src_instruction(const struct gen_device_info *devinfo,
 
 #define uncompact(field) \
    brw_inst_set_3src_##field(devinfo, dst, brw_compact_inst_3src_##field(devinfo, src))
+#define uncompact_a16(field) \
+   brw_inst_set_3src_a16_##field(devinfo, dst, brw_compact_inst_3src_##field(devinfo, src))
 
-   uncompact(opcode);
+   uncompact(hw_opcode);
 
    set_uncompacted_3src_control_index(devinfo, dst, src);
    set_uncompacted_3src_source_index(devinfo, dst, src);
 
    uncompact(dst_reg_nr);
-   uncompact(src0_rep_ctrl);
+   uncompact_a16(src0_rep_ctrl);
    brw_inst_set_3src_cmpt_control(devinfo, dst, false);
    uncompact(debug_control);
    uncompact(saturate);
-   uncompact(src1_rep_ctrl);
-   uncompact(src2_rep_ctrl);
+   uncompact_a16(src1_rep_ctrl);
+   uncompact_a16(src2_rep_ctrl);
    uncompact(src0_reg_nr);
    uncompact(src1_reg_nr);
    uncompact(src2_reg_nr);
-   uncompact(src0_subreg_nr);
-   uncompact(src1_subreg_nr);
-   uncompact(src2_subreg_nr);
+   uncompact_a16(src0_subreg_nr);
+   uncompact_a16(src1_subreg_nr);
+   uncompact_a16(src2_subreg_nr);
 
 #undef uncompact
+#undef uncompact_a16
 }
 
 void
@@ -1287,7 +1331,8 @@ brw_uncompact_instruction(const struct gen_device_info *devinfo, brw_inst *dst,
    memset(dst, 0, sizeof(*dst));
 
    if (devinfo->gen >= 8 &&
-       is_3src(devinfo, brw_compact_inst_3src_opcode(devinfo, src))) {
+       is_3src(devinfo, brw_opcode_decode(
+                  devinfo, brw_compact_inst_3src_hw_opcode(devinfo, src)))) {
       brw_uncompact_3src_instruction(devinfo, dst, src);
       return;
    }
@@ -1295,7 +1340,7 @@ brw_uncompact_instruction(const struct gen_device_info *devinfo, brw_inst *dst,
 #define uncompact(field) \
    brw_inst_set_##field(devinfo, dst, brw_compact_inst_##field(devinfo, src))
 
-   uncompact(opcode);
+   uncompact(hw_opcode);
    uncompact(debug_control);
 
    set_uncompacted_control(devinfo, dst, src);
@@ -1444,8 +1489,21 @@ brw_init_compaction_tables(const struct gen_device_info *devinfo)
    assert(gen8_datatype_table[ARRAY_SIZE(gen8_datatype_table) - 1] != 0);
    assert(gen8_subreg_table[ARRAY_SIZE(gen8_subreg_table) - 1] != 0);
    assert(gen8_src_index_table[ARRAY_SIZE(gen8_src_index_table) - 1] != 0);
+   assert(gen11_datatype_table[ARRAY_SIZE(gen11_datatype_table) - 1] != 0);
 
    switch (devinfo->gen) {
+   case 12:
+      control_index_table = NULL;
+      datatype_table = NULL;
+      subreg_table = NULL;
+      src_index_table = NULL;
+      break;
+   case 11:
+      control_index_table = gen8_control_index_table;
+      datatype_table = gen11_datatype_table;
+      subreg_table = gen8_subreg_table;
+      src_index_table = gen8_src_index_table;
+      break;
    case 10:
    case 9:
    case 8:
@@ -1480,9 +1538,9 @@ brw_init_compaction_tables(const struct gen_device_info *devinfo)
 
 void
 brw_compact_instructions(struct brw_codegen *p, int start_offset,
-                         int num_annotations, struct annotation *annotation)
+                         struct disasm_info *disasm)
 {
-   if (unlikely(INTEL_DEBUG & DEBUG_NO_COMPACTION))
+   if (unlikely(INTEL_DEBUG & DEBUG_NO_COMPACTION) || p->devinfo->gen > 11)
       return;
 
    const struct gen_device_info *devinfo = p->devinfo;
@@ -1495,7 +1553,7 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
    /* For an instruction at byte offset 8*i after compaction, this was its IP
     * (in 16-byte units) before compaction.
     */
-   int old_ip[(p->next_insn_offset - start_offset) / sizeof(brw_compact_inst)];
+   int old_ip[(p->next_insn_offset - start_offset) / sizeof(brw_compact_inst) + 1];
 
    if (devinfo->gen == 4 && !devinfo->is_g4x)
       return;
@@ -1530,7 +1588,8 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
          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(devinfo, align, BRW_OPCODE_NENOP);
+            brw_compact_inst_set_hw_opcode(
+               devinfo, align, brw_opcode_encode(devinfo, BRW_OPCODE_NENOP));
             brw_compact_inst_set_cmpt_control(devinfo, align, true);
             offset += sizeof(brw_compact_inst);
             compacted_count--;
@@ -1550,6 +1609,12 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
       }
    }
 
+   /* Add an entry for the ending offset of the program. This greatly
+    * simplifies the linked list walk at the end of the function.
+    */
+   old_ip[offset / sizeof(brw_compact_inst)] =
+      (p->next_insn_offset - start_offset) / sizeof(brw_inst);
+
    /* Fix up control flow offsets. */
    p->next_insn_offset = start_offset + offset;
    for (offset = 0; offset < p->next_insn_offset - start_offset;
@@ -1628,6 +1693,9 @@ brw_compact_instructions(struct brw_codegen *p, int start_offset,
             brw_inst_set_imm_ud(devinfo, insn, jump_compacted << shift);
          }
          break;
+
+      default:
+         break;
       }
    }
 
@@ -1639,27 +1707,28 @@ 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(devinfo, align, BRW_OPCODE_NOP);
+      brw_compact_inst_set_hw_opcode(
+         devinfo, align, brw_opcode_encode(devinfo, BRW_OPCODE_NOP));
       brw_compact_inst_set_cmpt_control(devinfo, align, true);
       p->next_insn_offset += sizeof(brw_compact_inst);
    }
    p->nr_insn = p->next_insn_offset / sizeof(brw_inst);
 
-   /* Update the instruction offsets for each annotation. */
-   if (annotation) {
-      for (int offset = 0, i = 0; i < num_annotations; i++) {
+   /* Update the instruction offsets for each group. */
+   if (disasm) {
+      int offset = 0;
+
+      foreach_list_typed(struct inst_group, group, link, &disasm->group_list) {
          while (start_offset + old_ip[offset / sizeof(brw_compact_inst)] *
-                sizeof(brw_inst) != annotation[i].offset) {
+                sizeof(brw_inst) != group->offset) {
             assert(start_offset + old_ip[offset / sizeof(brw_compact_inst)] *
-                   sizeof(brw_inst) < annotation[i].offset);
+                   sizeof(brw_inst) < group->offset);
             offset = next_offset(devinfo, store, offset);
          }
 
-         annotation[i].offset = start_offset + offset;
+         group->offset = start_offset + offset;
 
          offset = next_offset(devinfo, store, offset);
       }
-
-      annotation[num_annotations].offset = p->next_insn_offset;
    }
 }