[Mesa-dev] [PATCH 3/7] i965/disasm: Wrap opcode_desc look-up in a function.

Francisco Jerez currojerez at riseup.net
Thu Apr 28 07:19:14 UTC 2016


The function takes a device info struct as argument in addition to the
opcode number in order to disambiguate between multiple opcode_desc
entries for different instructions with the same opcode number.
---
 src/mesa/drivers/dri/i965/brw_context.h     |  1 -
 src/mesa/drivers/dri/i965/brw_disasm.c      | 39 +++++++++++++++++++++--------
 src/mesa/drivers/dri/i965/brw_eu.h          |  6 ++++-
 src/mesa/drivers/dri/i965/brw_eu_validate.c |  6 ++++-
 src/mesa/drivers/dri/i965/brw_shader.cpp    |  4 +--
 5 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index e449982..c001c6a 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1800,7 +1800,6 @@ struct opcode_desc {
     int	    ndst;
 };
 
-extern const struct opcode_desc opcode_descs[128];
 extern const char * const conditional_modifier[16];
 extern const char *const pred_ctrl_align16[16];
 
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index 88bd7a4..15d9383 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -28,8 +28,9 @@
 #include "brw_defines.h"
 #include "brw_reg.h"
 #include "brw_inst.h"
+#include "brw_eu.h"
 
-const struct opcode_desc opcode_descs[128] = {
+static const struct opcode_desc opcode_descs[128] = {
    [BRW_OPCODE_MOV]      = { .name = "mov",     .nsrc = 1, .ndst = 1 },
    [BRW_OPCODE_MOVI]     = { .name = "movi",    .nsrc = 2, .ndst = 1 },
    [BRW_OPCODE_FRC]      = { .name = "frc",     .nsrc = 1, .ndst = 1 },
@@ -103,6 +104,19 @@ const struct opcode_desc opcode_descs[128] = {
    [BRW_OPCODE_ENDIF]    = { .name = "endif",   .nsrc = 0, .ndst = 0 },
 };
 
+/* Return the matching opcode_desc for the specified opcode number and
+ * hardware generation, or NULL if the opcode is not supported by the device.
+ * XXX -- Actually check whether the opcode is supported.
+ */
+const struct opcode_desc *
+brw_opcode_desc(const struct brw_device_info *devinfo, enum opcode opcode)
+{
+   if (opcode_descs[opcode].name)
+      return &opcode_descs[opcode];
+   else
+      return NULL;
+}
+
 static bool
 has_jip(const struct brw_device_info *devinfo, enum opcode opcode)
 {
@@ -705,13 +719,15 @@ control(FILE *file, const char *name, const char *const ctrl[],
 }
 
 static int
-print_opcode(FILE *file, int id)
+print_opcode(FILE *file, const struct brw_device_info *devinfo,
+             enum opcode id)
 {
-   if (!opcode_descs[id].name) {
+   const struct opcode_desc *desc = brw_opcode_desc(devinfo, id);
+   if (!desc) {
       format(file, "*** invalid opcode value %d ", id);
       return 1;
    }
-   string(file, opcode_descs[id].name);
+   string(file, desc->name);
    return 0;
 }
 
@@ -1277,6 +1293,7 @@ brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
    int space = 0;
 
    const enum opcode opcode = brw_inst_opcode(devinfo, inst);
+   const struct opcode_desc *desc = brw_opcode_desc(devinfo, opcode);
 
    if (brw_inst_pred_control(devinfo, inst)) {
       string(file, "(");
@@ -1295,7 +1312,7 @@ brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
       string(file, ") ");
    }
 
-   err |= print_opcode(file, opcode);
+   err |= print_opcode(file, devinfo, opcode);
    err |= control(file, "saturate", saturate, brw_inst_saturate(devinfo, inst),
                   NULL);
 
@@ -1366,7 +1383,7 @@ brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
    } else if (opcode == BRW_OPCODE_JMPI) {
       pad(file, 16);
       err |= src1(file, devinfo, inst);
-   } else if (opcode_descs[opcode].nsrc == 3) {
+   } else if (desc && desc->nsrc == 3) {
       pad(file, 16);
       err |= dest_3src(file, devinfo, inst);
 
@@ -1378,18 +1395,18 @@ brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
 
       pad(file, 64);
       err |= src2_3src(file, devinfo, inst);
-   } else {
-      if (opcode_descs[opcode].ndst > 0) {
+   } else if (desc) {
+      if (desc->ndst > 0) {
          pad(file, 16);
          err |= dest(file, devinfo, inst);
       }
 
-      if (opcode_descs[opcode].nsrc > 0) {
+      if (desc->nsrc > 0) {
          pad(file, 32);
          err |= src0(file, devinfo, inst);
       }
 
-      if (opcode_descs[opcode].nsrc > 1) {
+      if (desc->nsrc > 1) {
          pad(file, 48);
          err |= src1(file, devinfo, inst);
       }
@@ -1659,7 +1676,7 @@ brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
          err |= qtr_ctrl(file, devinfo, inst);
       else {
          if (brw_inst_qtr_control(devinfo, inst) == BRW_COMPRESSION_COMPRESSED &&
-             opcode_descs[opcode].ndst > 0 &&
+             desc && desc->ndst > 0 &&
              brw_inst_dst_reg_file(devinfo, inst) == BRW_MESSAGE_REGISTER_FILE &&
              brw_inst_dst_da_reg_nr(devinfo, inst) & BRW_MRF_COMPR4) {
             format(file, " compr4");
diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h
index 89b4e7f..563a105 100644
--- a/src/mesa/drivers/dri/i965/brw_eu.h
+++ b/src/mesa/drivers/dri/i965/brw_eu.h
@@ -545,10 +545,14 @@ next_offset(const struct brw_device_info *devinfo, void *store, int offset)
       return offset + 16;
 }
 
+const struct opcode_desc *
+brw_opcode_desc(const struct brw_device_info *devinfo, enum opcode opcode);
+
 static inline bool
 is_3src(const struct brw_device_info *devinfo, enum opcode opcode)
 {
-   return opcode_descs[opcode].nsrc == 3;
+   const struct opcode_desc *desc = brw_opcode_desc(devinfo, opcode);
+   return desc && desc->nsrc == 3;
 }
 
 /** Maximum SEND message length */
diff --git a/src/mesa/drivers/dri/i965/brw_eu_validate.c b/src/mesa/drivers/dri/i965/brw_eu_validate.c
index 2de2ea1..75e161b 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_validate.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_validate.c
@@ -300,6 +300,8 @@ static unsigned
 num_sources_from_inst(const struct brw_device_info *devinfo,
                       const brw_inst *inst)
 {
+   const struct opcode_desc *desc =
+      brw_opcode_desc(devinfo, brw_inst_opcode(devinfo, inst));
    unsigned math_function;
 
    if (brw_inst_opcode(devinfo, inst) == BRW_OPCODE_MATH) {
@@ -314,8 +316,10 @@ num_sources_from_inst(const struct brw_device_info *devinfo,
           */
          return 0;
       }
+   } else if (desc) {
+      return desc->nsrc;
    } else {
-      return opcode_descs[brw_inst_opcode(devinfo, inst)].nsrc;
+      return 0;
    }
 
    switch (math_function) {
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index d417d3d..068244b 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -167,8 +167,8 @@ brw_instruction_name(const struct brw_device_info *devinfo, enum opcode op)
 {
    switch (op) {
    case BRW_OPCODE_ILLEGAL ... BRW_OPCODE_NOP:
-      assert(opcode_descs[op].name);
-      return opcode_descs[op].name;
+      assert(brw_opcode_desc(devinfo, op)->name);
+      return brw_opcode_desc(devinfo, op)->name;
    case FS_OPCODE_FB_WRITE:
       return "fb_write";
    case FS_OPCODE_FB_WRITE_LOGICAL:
-- 
2.7.3



More information about the mesa-dev mailing list