[Mesa-dev] [PATCH 2/7] i965: Add function to disassemble a program into a string buffer

Jordan Justen jordan.l.justen at intel.com
Tue Jan 10 01:22:13 UTC 2017


Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.h |  2 +
 src/mesa/drivers/dri/i965/brw_disasm.c  | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index b1e32bab034..4bb67f84adf 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1408,6 +1408,8 @@ int brw_disassemble_inst_str(char **str, const struct gen_device_info *devinfo,
                              struct brw_inst *inst, bool is_compacted);
 int brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
                          struct brw_inst *inst, bool is_compacted);
+int brw_disassemble_prog(char **out, const struct gen_device_info *devinfo,
+                         void *assembly, int start);
 
 /* brw_vs.c */
 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index 108fc9699da..817cd060aab 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -1701,3 +1701,68 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
       return err;
    }
 }
+
+static bool
+is_send(uint32_t opcode)
+{
+   return (opcode == BRW_OPCODE_SEND  ||
+           opcode == BRW_OPCODE_SENDC ||
+           opcode == BRW_OPCODE_SENDS ||
+           opcode == BRW_OPCODE_SENDSC );
+}
+
+int
+brw_disassemble_prog(char **out, const struct gen_device_info *devinfo,
+                     void *assembly, int start)
+{
+   OUTPUT o;
+   bool dump_hex = false;
+   int offset = start;
+   char *inst_disasm;
+   int err = 0;
+
+   memset(&o, 0, sizeof(o));
+
+   /* This loop exits when send-with-EOT or when opcode is 0 */
+   while (true) {
+      brw_inst *insn = assembly + offset;
+      brw_inst uncompacted;
+      bool compacted = brw_inst_cmpt_control(devinfo, insn);
+      if (0)
+         err |= format(&o, "0x%08x: ", offset);
+
+      if (compacted) {
+         brw_compact_inst *compacted = (void *)insn;
+         if (dump_hex) {
+            err |= format(&o, "0x%08x 0x%08x                       ",
+                          ((uint32_t *)insn)[1],
+                          ((uint32_t *)insn)[0]);
+         }
+
+         brw_uncompact_instruction(devinfo, &uncompacted, compacted);
+         insn = &uncompacted;
+         offset += 8;
+      } else {
+         if (dump_hex) {
+            err |= format(&o, "0x%08x 0x%08x 0x%08x 0x%08x ",
+                          ((uint32_t *)insn)[3],
+                          ((uint32_t *)insn)[2],
+                          ((uint32_t *)insn)[1],
+                          ((uint32_t *)insn)[0]);
+         }
+         offset += 16;
+      }
+
+      brw_disassemble_inst_str(&inst_disasm, devinfo, insn, compacted);
+      err |= string(&o, inst_disasm);
+
+      /* Simplistic, but efficient way to terminate disasm */
+      uint32_t opcode = brw_inst_opcode(devinfo, insn);
+      if (opcode == 0 || (is_send(opcode) && brw_inst_eot(devinfo, insn))) {
+         break;
+      }
+   }
+
+   *out = o.buf;
+   return err;
+}
-- 
2.11.0



More information about the mesa-dev mailing list