[Mesa-dev] [PATCH 1/7] i965: Add brw_disassemble_inst_str to disassemble into a string
Jordan Justen
jordan.l.justen at intel.com
Tue Jan 10 01:22:12 UTC 2017
Most of the brw_disasm.c file is rewritten to disassemble into a
string, and brw_disassemble_inst uses brw_disassemble_inst_str.
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 | 646 +++++++++++++++++---------------
2 files changed, 350 insertions(+), 298 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index ff3f861a147..b1e32bab034 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1404,6 +1404,8 @@ void brw_fs_alloc_reg_sets(struct brw_compiler *compiler);
void brw_vec4_alloc_reg_set(struct brw_compiler *compiler);
/* brw_disasm.c */
+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);
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index 167067a4b7d..108fc9699da 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -598,21 +598,41 @@ static const char *const sampler_target_format[4] = {
};
-static int column;
+typedef struct {
+ char *buf;
+ int len;
+ int column;
+} OUTPUT;
static int
-string(FILE *file, const char *string)
+append(OUTPUT *o, const char *string, bool adj_column)
{
- fputs(string, file);
- column += strlen(string);
+ const int string_len = strlen(string);
+ if (o->len == 0) {
+ o->buf = malloc(string_len + 1);
+ } else {
+ o->buf = realloc(o->buf, o->len + string_len + 1);
+ }
+ if (o->buf == NULL)
+ return 1;
+ memcpy(o->buf + o->len, string, string_len + 1);
+ if (adj_column)
+ o->column += string_len;
+ o->len += string_len;
return 0;
}
static int
-format(FILE *f, const char *format, ...) PRINTFLIKE(2, 3);
+string(OUTPUT *o, const char *string)
+{
+ return append(o, string, true);
+}
+
+static int
+format(OUTPUT *o, const char *format, ...) PRINTFLIKE(2, 3);
static int
-format(FILE *f, const char *format, ...)
+format(OUTPUT *o, const char *format, ...)
{
char buf[1024];
va_list args;
@@ -620,39 +640,45 @@ format(FILE *f, const char *format, ...)
vsnprintf(buf, sizeof(buf) - 1, format, args);
va_end(args);
- string(f, buf);
- return 0;
+ return string(o, buf);
}
static int
-newline(FILE *f)
+newline(OUTPUT *o)
{
- putc('\n', f);
- column = 0;
- return 0;
+ int err = append(o, "\n", false);
+ o->column = 0;
+ return err;
}
static int
-pad(FILE *f, int c)
+pad(OUTPUT *o, int c)
{
- do
- string(f, " ");
- while (column < c);
- return 0;
+ const int size = MAX2(c - o->column, 1);
+ char padding[80];
+
+ assert(c < sizeof(padding));
+ if (size >= sizeof(padding))
+ return 1;
+
+ memset(padding, ' ', size);
+ padding[size] = '\0';
+ return string(o, padding);
}
static int
-control(FILE *file, const char *name, const char *const ctrl[],
+control(OUTPUT *o, const char *name, const char *const ctrl[],
unsigned id, int *space)
{
if (!ctrl[id]) {
- fprintf(file, "*** invalid %s value %d ", name, id);
- return 1;
+ char buf[80];
+ snprintf(buf, sizeof(buf), "*** invalid %s value %d ", name, id);
+ return append(o, buf, false);
}
if (ctrl[id][0]) {
if (space && *space)
- string(file, " ");
- string(file, ctrl[id]);
+ string(o, " ");
+ string(o, ctrl[id]);
if (space)
*space = 1;
}
@@ -660,20 +686,19 @@ control(FILE *file, const char *name, const char *const ctrl[],
}
static int
-print_opcode(FILE *file, const struct gen_device_info *devinfo,
+print_opcode(OUTPUT *o, const struct gen_device_info *devinfo,
enum opcode id)
{
const struct opcode_desc *desc = brw_opcode_desc(devinfo, id);
if (!desc) {
- format(file, "*** invalid opcode value %d ", id);
+ format(o, "*** invalid opcode value %d ", id);
return 1;
}
- string(file, desc->name);
- return 0;
+ return string(o, desc->name);
}
static int
-reg(FILE *file, unsigned _reg_file, unsigned _reg_nr)
+reg(OUTPUT *o, unsigned _reg_file, unsigned _reg_nr)
{
int err = 0;
@@ -684,104 +709,105 @@ reg(FILE *file, unsigned _reg_file, unsigned _reg_nr)
if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
switch (_reg_nr & 0xf0) {
case BRW_ARF_NULL:
- string(file, "null");
+ string(o, "null");
break;
case BRW_ARF_ADDRESS:
- format(file, "a%d", _reg_nr & 0x0f);
+ format(o, "a%d", _reg_nr & 0x0f);
break;
case BRW_ARF_ACCUMULATOR:
- format(file, "acc%d", _reg_nr & 0x0f);
+ format(o, "acc%d", _reg_nr & 0x0f);
break;
case BRW_ARF_FLAG:
- format(file, "f%d", _reg_nr & 0x0f);
+ format(o, "f%d", _reg_nr & 0x0f);
break;
case BRW_ARF_MASK:
- format(file, "mask%d", _reg_nr & 0x0f);
+ format(o, "mask%d", _reg_nr & 0x0f);
break;
case BRW_ARF_MASK_STACK:
- format(file, "msd%d", _reg_nr & 0x0f);
+ format(o, "msd%d", _reg_nr & 0x0f);
break;
case BRW_ARF_STATE:
- format(file, "sr%d", _reg_nr & 0x0f);
+ format(o, "sr%d", _reg_nr & 0x0f);
break;
case BRW_ARF_CONTROL:
- format(file, "cr%d", _reg_nr & 0x0f);
+ format(o, "cr%d", _reg_nr & 0x0f);
break;
case BRW_ARF_NOTIFICATION_COUNT:
- format(file, "n%d", _reg_nr & 0x0f);
+ format(o, "n%d", _reg_nr & 0x0f);
break;
case BRW_ARF_IP:
- string(file, "ip");
+ string(o, "ip");
return -1;
break;
case BRW_ARF_TDR:
- format(file, "tdr0");
+ format(o, "tdr0");
return -1;
case BRW_ARF_TIMESTAMP:
- format(file, "tm%d", _reg_nr & 0x0f);
+ format(o, "tm%d", _reg_nr & 0x0f);
break;
default:
- format(file, "ARF%d", _reg_nr);
+ format(o, "ARF%d", _reg_nr);
break;
}
} else {
- err |= control(file, "src reg file", reg_file, _reg_file, NULL);
- format(file, "%d", _reg_nr);
+ err |= control(o, "src reg file", reg_file, _reg_file, NULL);
+ format(o, "%d", _reg_nr);
}
return err;
}
static int
-dest(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+dest(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int err = 0;
if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
if (brw_inst_dst_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- err |= reg(file, brw_inst_dst_reg_file(devinfo, inst),
+ err |= reg(o, brw_inst_dst_reg_file(devinfo, inst),
brw_inst_dst_da_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (brw_inst_dst_da1_subreg_nr(devinfo, inst))
- format(file, ".%"PRIu64, brw_inst_dst_da1_subreg_nr(devinfo, inst) /
+ format(o, ".%"PRIu64,
+ brw_inst_dst_da1_subreg_nr(devinfo, inst) /
reg_type_size[brw_inst_dst_reg_type(devinfo, inst)]);
- string(file, "<");
- err |= control(file, "horiz stride", horiz_stride,
+ string(o, "<");
+ err |= control(o, "horiz stride", horiz_stride,
brw_inst_dst_hstride(devinfo, inst), NULL);
- string(file, ">");
- err |= control(file, "dest reg encoding", reg_encoding,
+ string(o, ">");
+ err |= control(o, "dest reg encoding", reg_encoding,
brw_inst_dst_reg_type(devinfo, inst), NULL);
} else {
- string(file, "g[a0");
+ string(o, "g[a0");
if (brw_inst_dst_ia_subreg_nr(devinfo, inst))
- format(file, ".%"PRIu64, brw_inst_dst_ia_subreg_nr(devinfo, inst) /
+ format(o, ".%"PRIu64, brw_inst_dst_ia_subreg_nr(devinfo, inst) /
reg_type_size[brw_inst_dst_reg_type(devinfo, inst)]);
if (brw_inst_dst_ia1_addr_imm(devinfo, inst))
- format(file, " %d", brw_inst_dst_ia1_addr_imm(devinfo, inst));
- string(file, "]<");
- err |= control(file, "horiz stride", horiz_stride,
+ format(o, " %d", brw_inst_dst_ia1_addr_imm(devinfo, inst));
+ string(o, "]<");
+ err |= control(o, "horiz stride", horiz_stride,
brw_inst_dst_hstride(devinfo, inst), NULL);
- string(file, ">");
- err |= control(file, "dest reg encoding", reg_encoding,
+ string(o, ">");
+ err |= control(o, "dest reg encoding", reg_encoding,
brw_inst_dst_reg_type(devinfo, inst), NULL);
}
} else {
if (brw_inst_dst_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- err |= reg(file, brw_inst_dst_reg_file(devinfo, inst),
+ err |= reg(o, brw_inst_dst_reg_file(devinfo, inst),
brw_inst_dst_da_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (brw_inst_dst_da16_subreg_nr(devinfo, inst))
- format(file, ".%u", 16 /
+ format(o, ".%u", 16 /
reg_type_size[brw_inst_dst_reg_type(devinfo, inst)]);
- string(file, "<1>");
- err |= control(file, "writemask", writemask,
+ string(o, "<1>");
+ err |= control(o, "writemask", writemask,
brw_inst_da16_writemask(devinfo, inst), NULL);
- err |= control(file, "dest reg encoding", reg_encoding,
+ err |= control(o, "dest reg encoding", reg_encoding,
brw_inst_dst_reg_type(devinfo, inst), NULL);
} else {
err = 1;
- string(file, "Indirect align16 address mode not supported");
+ string(o, "Indirect align16 address mode not supported");
}
}
@@ -789,7 +815,7 @@ dest(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
}
static int
-dest_3src(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+dest_3src(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int err = 0;
uint32_t reg_file;
@@ -799,38 +825,38 @@ dest_3src(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
else
reg_file = BRW_GENERAL_REGISTER_FILE;
- err |= reg(file, reg_file, brw_inst_3src_dst_reg_nr(devinfo, inst));
+ err |= reg(o, reg_file, brw_inst_3src_dst_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (brw_inst_3src_dst_subreg_nr(devinfo, inst))
- format(file, ".%"PRIu64, brw_inst_3src_dst_subreg_nr(devinfo, inst));
- string(file, "<1>");
- err |= control(file, "writemask", writemask,
+ format(o, ".%"PRIu64, brw_inst_3src_dst_subreg_nr(devinfo, inst));
+ string(o, "<1>");
+ err |= control(o, "writemask", writemask,
brw_inst_3src_dst_writemask(devinfo, inst), NULL);
- err |= control(file, "dest reg encoding", three_source_reg_encoding,
+ err |= control(o, "dest reg encoding", three_source_reg_encoding,
brw_inst_3src_dst_type(devinfo, inst), NULL);
return 0;
}
static int
-src_align1_region(FILE *file,
+src_align1_region(OUTPUT *o,
unsigned _vert_stride, unsigned _width,
unsigned _horiz_stride)
{
int err = 0;
- string(file, "<");
- err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
- string(file, ",");
- err |= control(file, "width", width, _width, NULL);
- string(file, ",");
- err |= control(file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
- string(file, ">");
+ string(o, "<");
+ err |= control(o, "vert stride", vert_stride, _vert_stride, NULL);
+ string(o, ",");
+ err |= control(o, "width", width, _width, NULL);
+ string(o, ",");
+ err |= control(o, "horiz_stride", horiz_stride, _horiz_stride, NULL);
+ string(o, ">");
return err;
}
static int
-src_da1(FILE *file,
+src_da1(OUTPUT *o,
const struct gen_device_info *devinfo,
unsigned opcode,
unsigned type, unsigned _reg_file,
@@ -841,24 +867,24 @@ src_da1(FILE *file,
int err = 0;
if (devinfo->gen >= 8 && is_logic_instruction(opcode))
- err |= control(file, "bitnot", m_bitnot, _negate, NULL);
+ err |= control(o, "bitnot", m_bitnot, _negate, NULL);
else
- err |= control(file, "negate", m_negate, _negate, NULL);
+ err |= control(o, "negate", m_negate, _negate, NULL);
- err |= control(file, "abs", _abs, __abs, NULL);
+ err |= control(o, "abs", _abs, __abs, NULL);
- err |= reg(file, _reg_file, reg_num);
+ err |= reg(o, _reg_file, reg_num);
if (err == -1)
return 0;
if (sub_reg_num)
- format(file, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
- src_align1_region(file, _vert_stride, _width, _horiz_stride);
- err |= control(file, "src reg encoding", reg_encoding, type, NULL);
+ format(o, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
+ src_align1_region(o, _vert_stride, _width, _horiz_stride);
+ err |= control(o, "src reg encoding", reg_encoding, type, NULL);
return err;
}
static int
-src_ia1(FILE *file,
+src_ia1(OUTPUT *o,
const struct gen_device_info *devinfo,
unsigned opcode,
unsigned type,
@@ -872,25 +898,25 @@ src_ia1(FILE *file,
int err = 0;
if (devinfo->gen >= 8 && is_logic_instruction(opcode))
- err |= control(file, "bitnot", m_bitnot, _negate, NULL);
+ err |= control(o, "bitnot", m_bitnot, _negate, NULL);
else
- err |= control(file, "negate", m_negate, _negate, NULL);
+ err |= control(o, "negate", m_negate, _negate, NULL);
- err |= control(file, "abs", _abs, __abs, NULL);
+ err |= control(o, "abs", _abs, __abs, NULL);
- string(file, "g[a0");
+ string(o, "g[a0");
if (_addr_subreg_nr)
- format(file, ".%d", _addr_subreg_nr);
+ format(o, ".%d", _addr_subreg_nr);
if (_addr_imm)
- format(file, " %d", _addr_imm);
- string(file, "]");
- src_align1_region(file, _vert_stride, _width, _horiz_stride);
- err |= control(file, "src reg encoding", reg_encoding, type, NULL);
+ format(o, " %d", _addr_imm);
+ string(o, "]");
+ src_align1_region(o, _vert_stride, _width, _horiz_stride);
+ err |= control(o, "src reg encoding", reg_encoding, type, NULL);
return err;
}
static int
-src_swizzle(FILE *file, unsigned swiz)
+src_swizzle(OUTPUT *o, unsigned swiz)
{
unsigned x = BRW_GET_SWZ(swiz, BRW_CHANNEL_X);
unsigned y = BRW_GET_SWZ(swiz, BRW_CHANNEL_Y);
@@ -899,20 +925,20 @@ src_swizzle(FILE *file, unsigned swiz)
int err = 0;
if (x == y && x == z && x == w) {
- string(file, ".");
- err |= control(file, "channel select", chan_sel, x, NULL);
+ string(o, ".");
+ err |= control(o, "channel select", chan_sel, x, NULL);
} else if (swiz != BRW_SWIZZLE_XYZW) {
- string(file, ".");
- err |= control(file, "channel select", chan_sel, x, NULL);
- err |= control(file, "channel select", chan_sel, y, NULL);
- err |= control(file, "channel select", chan_sel, z, NULL);
- err |= control(file, "channel select", chan_sel, w, NULL);
+ string(o, ".");
+ err |= control(o, "channel select", chan_sel, x, NULL);
+ err |= control(o, "channel select", chan_sel, y, NULL);
+ err |= control(o, "channel select", chan_sel, z, NULL);
+ err |= control(o, "channel select", chan_sel, w, NULL);
}
return err;
}
static int
-src_da16(FILE *file,
+src_da16(OUTPUT *o,
const struct gen_device_info *devinfo,
unsigned opcode,
unsigned _reg_type,
@@ -927,159 +953,160 @@ src_da16(FILE *file,
int err = 0;
if (devinfo->gen >= 8 && is_logic_instruction(opcode))
- err |= control(file, "bitnot", m_bitnot, _negate, NULL);
+ err |= control(o, "bitnot", m_bitnot, _negate, NULL);
else
- err |= control(file, "negate", m_negate, _negate, NULL);
+ err |= control(o, "negate", m_negate, _negate, NULL);
- err |= control(file, "abs", _abs, __abs, NULL);
+ err |= control(o, "abs", _abs, __abs, NULL);
- err |= reg(file, _reg_file, _reg_nr);
+ err |= reg(o, _reg_file, _reg_nr);
if (err == -1)
return 0;
if (_subreg_nr)
/* bit4 for subreg number byte addressing. Make this same meaning as
in da1 case, so output looks consistent. */
- format(file, ".%d", 16 / reg_type_size[_reg_type]);
- string(file, "<");
- err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
- string(file, ">");
- err |= src_swizzle(file, BRW_SWIZZLE4(swz_x, swz_y, swz_z, swz_w));
- err |= control(file, "src da16 reg type", reg_encoding, _reg_type, NULL);
+ format(o, ".%d", 16 / reg_type_size[_reg_type]);
+ string(o, "<");
+ err |= control(o, "vert stride", vert_stride, _vert_stride, NULL);
+ string(o, ">");
+ err |= src_swizzle(o, BRW_SWIZZLE4(swz_x, swz_y, swz_z, swz_w));
+ err |= control(o, "src da16 reg type", reg_encoding, _reg_type, NULL);
return err;
}
static int
-src0_3src(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+src0_3src(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int err = 0;
unsigned src0_subreg_nr = brw_inst_3src_src0_subreg_nr(devinfo, inst);
- err |= control(file, "negate", m_negate,
+ err |= control(o, "negate", m_negate,
brw_inst_3src_src0_negate(devinfo, inst), NULL);
- err |= control(file, "abs", _abs, brw_inst_3src_src0_abs(devinfo, inst), NULL);
+ err |= control(o, "abs", _abs, brw_inst_3src_src0_abs(devinfo, inst),
+ NULL);
- err |= reg(file, BRW_GENERAL_REGISTER_FILE,
+ err |= reg(o, BRW_GENERAL_REGISTER_FILE,
brw_inst_3src_src0_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (src0_subreg_nr || brw_inst_3src_src0_rep_ctrl(devinfo, inst))
- format(file, ".%d", src0_subreg_nr);
+ format(o, ".%d", src0_subreg_nr);
if (brw_inst_3src_src0_rep_ctrl(devinfo, inst))
- string(file, "<0,1,0>");
+ string(o, "<0,1,0>");
else {
- string(file, "<4,4,1>");
- err |= src_swizzle(file, brw_inst_3src_src0_swizzle(devinfo, inst));
+ string(o, "<4,4,1>");
+ err |= src_swizzle(o, brw_inst_3src_src0_swizzle(devinfo, inst));
}
- err |= control(file, "src da16 reg type", three_source_reg_encoding,
+ err |= control(o, "src da16 reg type", three_source_reg_encoding,
brw_inst_3src_src_type(devinfo, inst), NULL);
return err;
}
static int
-src1_3src(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+src1_3src(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int err = 0;
unsigned src1_subreg_nr = brw_inst_3src_src1_subreg_nr(devinfo, inst);
- err |= control(file, "negate", m_negate,
+ err |= control(o, "negate", m_negate,
brw_inst_3src_src1_negate(devinfo, inst), NULL);
- err |= control(file, "abs", _abs, brw_inst_3src_src1_abs(devinfo, inst), NULL);
+ err |= control(o, "abs", _abs, brw_inst_3src_src1_abs(devinfo, inst), NULL);
- err |= reg(file, BRW_GENERAL_REGISTER_FILE,
+ err |= reg(o, BRW_GENERAL_REGISTER_FILE,
brw_inst_3src_src1_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (src1_subreg_nr || brw_inst_3src_src1_rep_ctrl(devinfo, inst))
- format(file, ".%d", src1_subreg_nr);
+ format(o, ".%d", src1_subreg_nr);
if (brw_inst_3src_src1_rep_ctrl(devinfo, inst))
- string(file, "<0,1,0>");
+ string(o, "<0,1,0>");
else {
- string(file, "<4,4,1>");
- err |= src_swizzle(file, brw_inst_3src_src1_swizzle(devinfo, inst));
+ string(o, "<4,4,1>");
+ err |= src_swizzle(o, brw_inst_3src_src1_swizzle(devinfo, inst));
}
- err |= control(file, "src da16 reg type", three_source_reg_encoding,
+ err |= control(o, "src da16 reg type", three_source_reg_encoding,
brw_inst_3src_src_type(devinfo, inst), NULL);
return err;
}
static int
-src2_3src(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+src2_3src(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int err = 0;
unsigned src2_subreg_nr = brw_inst_3src_src2_subreg_nr(devinfo, inst);
- err |= control(file, "negate", m_negate,
+ err |= control(o, "negate", m_negate,
brw_inst_3src_src2_negate(devinfo, inst), NULL);
- err |= control(file, "abs", _abs, brw_inst_3src_src2_abs(devinfo, inst), NULL);
+ err |= control(o, "abs", _abs, brw_inst_3src_src2_abs(devinfo, inst), NULL);
- err |= reg(file, BRW_GENERAL_REGISTER_FILE,
+ err |= reg(o, BRW_GENERAL_REGISTER_FILE,
brw_inst_3src_src2_reg_nr(devinfo, inst));
if (err == -1)
return 0;
if (src2_subreg_nr || brw_inst_3src_src2_rep_ctrl(devinfo, inst))
- format(file, ".%d", src2_subreg_nr);
+ format(o, ".%d", src2_subreg_nr);
if (brw_inst_3src_src2_rep_ctrl(devinfo, inst))
- string(file, "<0,1,0>");
+ string(o, "<0,1,0>");
else {
- string(file, "<4,4,1>");
- err |= src_swizzle(file, brw_inst_3src_src2_swizzle(devinfo, inst));
+ string(o, "<4,4,1>");
+ err |= src_swizzle(o, brw_inst_3src_src2_swizzle(devinfo, inst));
}
- err |= control(file, "src da16 reg type", three_source_reg_encoding,
+ err |= control(o, "src da16 reg type", three_source_reg_encoding,
brw_inst_3src_src_type(devinfo, inst), NULL);
return err;
}
static int
-imm(FILE *file, const struct gen_device_info *devinfo, unsigned type, brw_inst *inst)
+imm(OUTPUT *o, const struct gen_device_info *devinfo, unsigned type, brw_inst *inst)
{
switch (type) {
case BRW_HW_REG_TYPE_UD:
- format(file, "0x%08xUD", brw_inst_imm_ud(devinfo, inst));
+ format(o, "0x%08xUD", brw_inst_imm_ud(devinfo, inst));
break;
case BRW_HW_REG_TYPE_D:
- format(file, "%dD", brw_inst_imm_d(devinfo, inst));
+ format(o, "%dD", brw_inst_imm_d(devinfo, inst));
break;
case BRW_HW_REG_TYPE_UW:
- format(file, "0x%04xUW", (uint16_t) brw_inst_imm_ud(devinfo, inst));
+ format(o, "0x%04xUW", (uint16_t) brw_inst_imm_ud(devinfo, inst));
break;
case BRW_HW_REG_TYPE_W:
- format(file, "%dW", (int16_t) brw_inst_imm_d(devinfo, inst));
+ format(o, "%dW", (int16_t) brw_inst_imm_d(devinfo, inst));
break;
case BRW_HW_REG_IMM_TYPE_UV:
- format(file, "0x%08xUV", brw_inst_imm_ud(devinfo, inst));
+ format(o, "0x%08xUV", brw_inst_imm_ud(devinfo, inst));
break;
case BRW_HW_REG_IMM_TYPE_VF:
- format(file, "[%-gF, %-gF, %-gF, %-gF]VF",
+ format(o, "[%-gF, %-gF, %-gF, %-gF]VF",
brw_vf_to_float(brw_inst_imm_ud(devinfo, inst)),
brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 8),
brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 16),
brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 24));
break;
case BRW_HW_REG_IMM_TYPE_V:
- format(file, "0x%08xV", brw_inst_imm_ud(devinfo, inst));
+ format(o, "0x%08xV", brw_inst_imm_ud(devinfo, inst));
break;
case BRW_HW_REG_TYPE_F:
- format(file, "%-gF", brw_inst_imm_f(devinfo, inst));
+ format(o, "%-gF", brw_inst_imm_f(devinfo, inst));
break;
case GEN8_HW_REG_IMM_TYPE_DF:
- format(file, "%-gDF", brw_inst_imm_df(devinfo, inst));
+ format(o, "%-gDF", brw_inst_imm_df(devinfo, inst));
break;
case GEN8_HW_REG_IMM_TYPE_HF:
- string(file, "Half Float IMM");
+ string(o, "Half Float IMM");
break;
}
return 0;
}
static int
-src0(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+src0(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
if (brw_inst_src0_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
- return imm(file, devinfo, brw_inst_src0_reg_type(devinfo, inst), inst);
+ return imm(o, devinfo, brw_inst_src0_reg_type(devinfo, inst), inst);
} else if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
if (brw_inst_src0_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- return src_da1(file,
+ return src_da1(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src0_reg_type(devinfo, inst),
@@ -1092,7 +1119,7 @@ src0(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
brw_inst_src0_abs(devinfo, inst),
brw_inst_src0_negate(devinfo, inst));
} else {
- return src_ia1(file,
+ return src_ia1(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src0_reg_type(devinfo, inst),
@@ -1107,7 +1134,7 @@ src0(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
}
} else {
if (brw_inst_src0_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- return src_da16(file,
+ return src_da16(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src0_reg_type(devinfo, inst),
@@ -1122,20 +1149,20 @@ src0(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
brw_inst_src0_da16_swiz_z(devinfo, inst),
brw_inst_src0_da16_swiz_w(devinfo, inst));
} else {
- string(file, "Indirect align16 address mode not supported");
+ string(o, "Indirect align16 address mode not supported");
return 1;
}
}
}
static int
-src1(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+src1(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
if (brw_inst_src1_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
- return imm(file, devinfo, brw_inst_src1_reg_type(devinfo, inst), inst);
+ return imm(o, devinfo, brw_inst_src1_reg_type(devinfo, inst), inst);
} else if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
if (brw_inst_src1_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- return src_da1(file,
+ return src_da1(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src1_reg_type(devinfo, inst),
@@ -1148,7 +1175,7 @@ src1(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
brw_inst_src1_abs(devinfo, inst),
brw_inst_src1_negate(devinfo, inst));
} else {
- return src_ia1(file,
+ return src_ia1(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src1_reg_type(devinfo, inst),
@@ -1163,7 +1190,7 @@ src1(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
}
} else {
if (brw_inst_src1_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
- return src_da16(file,
+ return src_da16(o,
devinfo,
brw_inst_opcode(devinfo, inst),
brw_inst_src1_reg_type(devinfo, inst),
@@ -1178,14 +1205,14 @@ src1(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
brw_inst_src1_da16_swiz_z(devinfo, inst),
brw_inst_src1_da16_swiz_w(devinfo, inst));
} else {
- string(file, "Indirect align16 address mode not supported");
+ string(o, "Indirect align16 address mode not supported");
return 1;
}
}
}
static int
-qtr_ctrl(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
+qtr_ctrl(OUTPUT *o, const struct gen_device_info *devinfo, brw_inst *inst)
{
int qtr_ctl = brw_inst_qtr_control(devinfo, inst);
int exec_size = 1 << brw_inst_exec_size(devinfo, inst);
@@ -1193,27 +1220,27 @@ qtr_ctrl(FILE *file, const struct gen_device_info *devinfo, brw_inst *inst)
if (exec_size < 8) {
const unsigned nib_ctl = devinfo->gen < 7 ? 0 :
brw_inst_nib_control(devinfo, inst);
- format(file, " %dN", qtr_ctl * 2 + nib_ctl + 1);
+ format(o, " %dN", qtr_ctl * 2 + nib_ctl + 1);
} else if (exec_size == 8) {
switch (qtr_ctl) {
case 0:
- string(file, " 1Q");
+ string(o, " 1Q");
break;
case 1:
- string(file, " 2Q");
+ string(o, " 2Q");
break;
case 2:
- string(file, " 3Q");
+ string(o, " 3Q");
break;
case 3:
- string(file, " 4Q");
+ string(o, " 4Q");
break;
}
} else if (exec_size == 16) {
if (qtr_ctl < 2)
- string(file, " 1H");
+ string(o, " 1H");
else
- string(file, " 2H");
+ string(o, " 2H");
}
return 0;
}
@@ -1231,45 +1258,48 @@ brw_disassemble_imm(const struct gen_device_info *devinfo,
#endif
int
-brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
- brw_inst *inst, bool is_compacted)
+brw_disassemble_inst_str(char **str, const struct gen_device_info *devinfo,
+ brw_inst *inst, bool is_compacted)
{
+ OUTPUT o;
int err = 0;
int space = 0;
+ memset(&o, 0, sizeof(o));
+
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, "(");
- err |= control(file, "predicate inverse", pred_inv,
+ string(&o, "(");
+ err |= control(&o, "predicate inverse", pred_inv,
brw_inst_pred_inv(devinfo, inst), NULL);
- format(file, "f%"PRIu64, devinfo->gen >= 7 ? brw_inst_flag_reg_nr(devinfo, inst) : 0);
+ format(&o, "f%"PRIu64, devinfo->gen >= 7 ? brw_inst_flag_reg_nr(devinfo, inst) : 0);
if (brw_inst_flag_subreg_nr(devinfo, inst))
- format(file, ".%"PRIu64, brw_inst_flag_subreg_nr(devinfo, inst));
+ format(&o, ".%"PRIu64, brw_inst_flag_subreg_nr(devinfo, inst));
if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
- err |= control(file, "predicate control align1", pred_ctrl_align1,
+ err |= control(&o, "predicate control align1", pred_ctrl_align1,
brw_inst_pred_control(devinfo, inst), NULL);
} else {
- err |= control(file, "predicate control align16", pred_ctrl_align16,
+ err |= control(&o, "predicate control align16", pred_ctrl_align16,
brw_inst_pred_control(devinfo, inst), NULL);
}
- string(file, ") ");
+ string(&o, ") ");
}
- err |= print_opcode(file, devinfo, opcode);
- err |= control(file, "saturate", saturate, brw_inst_saturate(devinfo, inst),
+ err |= print_opcode(&o, devinfo, opcode);
+ err |= control(&o, "saturate", saturate, brw_inst_saturate(devinfo, inst),
NULL);
- err |= control(file, "debug control", debug_ctrl,
+ err |= control(&o, "debug control", debug_ctrl,
brw_inst_debug_control(devinfo, inst), NULL);
if (opcode == BRW_OPCODE_MATH) {
- string(file, " ");
- err |= control(file, "function", math_function,
+ string(&o, " ");
+ err |= control(&o, "function", math_function,
brw_inst_math_function(devinfo, inst), NULL);
} else if (opcode != BRW_OPCODE_SEND && opcode != BRW_OPCODE_SENDC) {
- err |= control(file, "conditional modifier", conditional_modifier,
+ err |= control(&o, "conditional modifier", conditional_modifier,
brw_inst_cond_modifier(devinfo, inst), NULL);
/* If we're using the conditional modifier, print which flags reg is
@@ -1280,80 +1310,80 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
(devinfo->gen < 6 || (opcode != BRW_OPCODE_SEL &&
opcode != BRW_OPCODE_IF &&
opcode != BRW_OPCODE_WHILE))) {
- format(file, ".f%"PRIu64,
+ format(&o, ".f%"PRIu64,
devinfo->gen >= 7 ? brw_inst_flag_reg_nr(devinfo, inst) : 0);
if (brw_inst_flag_subreg_nr(devinfo, inst))
- format(file, ".%"PRIu64, brw_inst_flag_subreg_nr(devinfo, inst));
+ format(&o, ".%"PRIu64, brw_inst_flag_subreg_nr(devinfo, inst));
}
}
if (opcode != BRW_OPCODE_NOP && opcode != BRW_OPCODE_NENOP) {
- string(file, "(");
- err |= control(file, "execution size", exec_size,
+ string(&o, "(");
+ err |= control(&o, "execution size", exec_size,
brw_inst_exec_size(devinfo, inst), NULL);
- string(file, ")");
+ string(&o, ")");
}
if (opcode == BRW_OPCODE_SEND && devinfo->gen < 6)
- format(file, " %"PRIu64, brw_inst_base_mrf(devinfo, inst));
+ format(&o, " %"PRIu64, brw_inst_base_mrf(devinfo, inst));
if (has_uip(devinfo, opcode)) {
/* Instructions that have UIP also have JIP. */
- pad(file, 16);
- format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
- pad(file, 32);
- format(file, "UIP: %d", brw_inst_uip(devinfo, inst));
+ pad(&o, 16);
+ format(&o, "JIP: %d", brw_inst_jip(devinfo, inst));
+ pad(&o, 32);
+ format(&o, "UIP: %d", brw_inst_uip(devinfo, inst));
} else if (has_jip(devinfo, opcode)) {
- pad(file, 16);
+ pad(&o, 16);
if (devinfo->gen >= 7) {
- format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
+ format(&o, "JIP: %d", brw_inst_jip(devinfo, inst));
} else {
- format(file, "JIP: %d", brw_inst_gen6_jump_count(devinfo, inst));
+ format(&o, "JIP: %d", brw_inst_gen6_jump_count(devinfo, inst));
}
} else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_BREAK ||
opcode == BRW_OPCODE_CONTINUE ||
opcode == BRW_OPCODE_ELSE)) {
- pad(file, 16);
- format(file, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
- pad(file, 32);
- format(file, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
+ pad(&o, 16);
+ format(&o, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
+ pad(&o, 32);
+ format(&o, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
} else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_IF ||
opcode == BRW_OPCODE_IFF ||
opcode == BRW_OPCODE_HALT)) {
- pad(file, 16);
- format(file, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
+ pad(&o, 16);
+ format(&o, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
} else if (devinfo->gen < 6 && opcode == BRW_OPCODE_ENDIF) {
- pad(file, 16);
- format(file, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
+ pad(&o, 16);
+ format(&o, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
} else if (opcode == BRW_OPCODE_JMPI) {
- pad(file, 16);
- err |= src1(file, devinfo, inst);
+ pad(&o, 16);
+ err |= src1(&o, devinfo, inst);
} else if (desc && desc->nsrc == 3) {
- pad(file, 16);
- err |= dest_3src(file, devinfo, inst);
+ pad(&o, 16);
+ err |= dest_3src(&o, devinfo, inst);
- pad(file, 32);
- err |= src0_3src(file, devinfo, inst);
+ pad(&o, 32);
+ err |= src0_3src(&o, devinfo, inst);
- pad(file, 48);
- err |= src1_3src(file, devinfo, inst);
+ pad(&o, 48);
+ err |= src1_3src(&o, devinfo, inst);
- pad(file, 64);
- err |= src2_3src(file, devinfo, inst);
+ pad(&o, 64);
+ err |= src2_3src(&o, devinfo, inst);
} else if (desc) {
if (desc->ndst > 0) {
- pad(file, 16);
- err |= dest(file, devinfo, inst);
+ pad(&o, 16);
+ err |= dest(&o, devinfo, inst);
}
if (desc->nsrc > 0) {
- pad(file, 32);
- err |= src0(file, devinfo, inst);
+ pad(&o, 32);
+ err |= src0(&o, devinfo, inst);
}
if (desc->nsrc > 1) {
- pad(file, 48);
- err |= src1(file, devinfo, inst);
+ pad(&o, 48);
+ err |= src1(&o, devinfo, inst);
}
}
@@ -1362,78 +1392,78 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
if (brw_inst_src1_reg_file(devinfo, inst) != BRW_IMMEDIATE_VALUE) {
/* show the indirect descriptor source */
- pad(file, 48);
- err |= src1(file, devinfo, inst);
+ pad(&o, 48);
+ err |= src1(&o, devinfo, inst);
}
- newline(file);
- pad(file, 16);
+ newline(&o);
+ pad(&o, 16);
space = 0;
- fprintf(file, " ");
- err |= control(file, "SFID", devinfo->gen >= 6 ? gen6_sfid : gen4_sfid,
+ append(&o, " ", false);
+ err |= control(&o, "SFID", devinfo->gen >= 6 ? gen6_sfid : gen4_sfid,
sfid, &space);
if (brw_inst_src1_reg_file(devinfo, inst) != BRW_IMMEDIATE_VALUE) {
- format(file, " indirect");
+ format(&o, " indirect");
} else {
switch (sfid) {
case BRW_SFID_MATH:
- err |= control(file, "math function", math_function,
+ err |= control(&o, "math function", math_function,
brw_inst_math_msg_function(devinfo, inst), &space);
- err |= control(file, "math saturate", math_saturate,
+ err |= control(&o, "math saturate", math_saturate,
brw_inst_math_msg_saturate(devinfo, inst), &space);
- err |= control(file, "math signed", math_signed,
+ err |= control(&o, "math signed", math_signed,
brw_inst_math_msg_signed_int(devinfo, inst), &space);
- err |= control(file, "math scalar", math_scalar,
+ err |= control(&o, "math scalar", math_scalar,
brw_inst_math_msg_data_type(devinfo, inst), &space);
- err |= control(file, "math precision", math_precision,
+ err |= control(&o, "math precision", math_precision,
brw_inst_math_msg_precision(devinfo, inst), &space);
break;
case BRW_SFID_SAMPLER:
if (devinfo->gen >= 5) {
- err |= control(file, "sampler message", gen5_sampler_msg_type,
+ err |= control(&o, "sampler message", gen5_sampler_msg_type,
brw_inst_sampler_msg_type(devinfo, inst), &space);
- err |= control(file, "sampler simd mode", gen5_sampler_simd_mode,
+ err |= control(&o, "sampler simd mode", gen5_sampler_simd_mode,
brw_inst_sampler_simd_mode(devinfo, inst), &space);
- format(file, " Surface = %"PRIu64" Sampler = %"PRIu64,
+ format(&o, " Surface = %"PRIu64" Sampler = %"PRIu64,
brw_inst_binding_table_index(devinfo, inst),
brw_inst_sampler(devinfo, inst));
} else {
- format(file, " (%"PRIu64", %"PRIu64", %"PRIu64", ",
+ format(&o, " (%"PRIu64", %"PRIu64", %"PRIu64", ",
brw_inst_binding_table_index(devinfo, inst),
brw_inst_sampler(devinfo, inst),
brw_inst_sampler_msg_type(devinfo, inst));
if (!devinfo->is_g4x) {
- err |= control(file, "sampler target format",
+ err |= control(&o, "sampler target format",
sampler_target_format,
brw_inst_sampler_return_format(devinfo, inst), NULL);
}
- string(file, ")");
+ string(&o, ")");
}
break;
case GEN6_SFID_DATAPORT_SAMPLER_CACHE:
case GEN6_SFID_DATAPORT_CONSTANT_CACHE:
/* aka BRW_SFID_DATAPORT_READ on Gen4-5 */
if (devinfo->gen >= 6) {
- format(file, " (%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")",
+ format(&o, " (%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64")",
brw_inst_binding_table_index(devinfo, inst),
brw_inst_dp_msg_control(devinfo, inst),
brw_inst_dp_msg_type(devinfo, inst),
devinfo->gen >= 7 ? 0 : brw_inst_dp_write_commit(devinfo, inst));
} else {
bool is_965 = devinfo->gen == 4 && !devinfo->is_g4x;
- err |= control(file, "DP read message type",
+ err |= control(&o, "DP read message type",
is_965 ? gen4_dp_read_port_msg_type :
g45_dp_read_port_msg_type,
brw_inst_dp_read_msg_type(devinfo, inst),
&space);
- format(file, " MsgCtrl = 0x%"PRIx64,
+ format(&o, " MsgCtrl = 0x%"PRIx64,
brw_inst_dp_read_msg_control(devinfo, inst));
- format(file, " Surface = %"PRIu64, brw_inst_binding_table_index(devinfo, inst));
+ format(&o, " Surface = %"PRIu64, brw_inst_binding_table_index(devinfo, inst));
}
break;
@@ -1441,7 +1471,7 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
/* aka BRW_SFID_DATAPORT_WRITE on Gen4-5 */
unsigned msg_type = brw_inst_dp_write_msg_type(devinfo, inst);
- err |= control(file, "DP rc message type",
+ err |= control(&o, "DP rc message type",
dp_rc_msg_type(devinfo), msg_type, &space);
bool is_rt_write = msg_type ==
@@ -1449,58 +1479,58 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
: BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE);
if (is_rt_write) {
- err |= control(file, "RT message type", m_rt_write_subtype,
+ err |= control(&o, "RT message type", m_rt_write_subtype,
brw_inst_rt_message_type(devinfo, inst), &space);
if (devinfo->gen >= 6 && brw_inst_rt_slot_group(devinfo, inst))
- string(file, " Hi");
+ string(&o, " Hi");
if (brw_inst_rt_last(devinfo, inst))
- string(file, " LastRT");
+ string(&o, " LastRT");
if (devinfo->gen < 7 && brw_inst_dp_write_commit(devinfo, inst))
- string(file, " WriteCommit");
+ string(&o, " WriteCommit");
} else {
- format(file, " MsgCtrl = 0x%"PRIx64,
+ format(&o, " MsgCtrl = 0x%"PRIx64,
brw_inst_dp_write_msg_control(devinfo, inst));
}
- format(file, " Surface = %"PRIu64, brw_inst_binding_table_index(devinfo, inst));
+ format(&o, " Surface = %"PRIu64, brw_inst_binding_table_index(devinfo, inst));
break;
}
case BRW_SFID_URB: {
unsigned opcode = brw_inst_urb_opcode(devinfo, inst);
- format(file, " %"PRIu64, brw_inst_urb_global_offset(devinfo, inst));
+ format(&o, " %"PRIu64, brw_inst_urb_global_offset(devinfo, inst));
space = 1;
- err |= control(file, "urb opcode",
+ err |= control(&o, "urb opcode",
devinfo->gen >= 7 ? gen7_urb_opcode
: gen5_urb_opcode,
opcode, &space);
if (devinfo->gen >= 7 &&
brw_inst_urb_per_slot_offset(devinfo, inst)) {
- string(file, " per-slot");
+ string(&o, " per-slot");
}
if (opcode == GEN8_URB_OPCODE_SIMD8_WRITE ||
opcode == GEN8_URB_OPCODE_SIMD8_READ) {
if (brw_inst_urb_channel_mask_present(devinfo, inst))
- string(file, " masked");
+ string(&o, " masked");
} else {
- err |= control(file, "urb swizzle", urb_swizzle,
+ err |= control(&o, "urb swizzle", urb_swizzle,
brw_inst_urb_swizzle_control(devinfo, inst),
&space);
}
if (devinfo->gen < 7) {
- err |= control(file, "urb allocate", urb_allocate,
+ err |= control(&o, "urb allocate", urb_allocate,
brw_inst_urb_allocate(devinfo, inst), &space);
- err |= control(file, "urb used", urb_used,
+ err |= control(&o, "urb used", urb_used,
brw_inst_urb_used(devinfo, inst), &space);
}
if (devinfo->gen < 8) {
- err |= control(file, "urb complete", urb_complete,
+ err |= control(&o, "urb complete", urb_complete,
brw_inst_urb_complete(devinfo, inst), &space);
}
break;
@@ -1509,70 +1539,70 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
break;
case BRW_SFID_MESSAGE_GATEWAY:
- format(file, " (%s)",
+ format(&o, " (%s)",
gen7_gateway_subfuncid[brw_inst_gateway_subfuncid(devinfo, inst)]);
break;
case GEN7_SFID_DATAPORT_DATA_CACHE:
if (devinfo->gen >= 7) {
- format(file, " (");
+ format(&o, " (");
- err |= control(file, "DP DC0 message type",
+ err |= control(&o, "DP DC0 message type",
dp_dc0_msg_type_gen7,
brw_inst_dp_msg_type(devinfo, inst), &space);
- format(file, ", %"PRIu64", ", brw_inst_binding_table_index(devinfo, inst));
+ format(&o, ", %"PRIu64", ", brw_inst_binding_table_index(devinfo, inst));
switch (brw_inst_dp_msg_type(devinfo, inst)) {
case GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP:
- control(file, "atomic op", aop,
+ control(&o, "atomic op", aop,
brw_inst_imm_ud(devinfo, inst) >> 8 & 0xf, &space);
break;
default:
- format(file, "%"PRIu64, brw_inst_dp_msg_control(devinfo, inst));
+ format(&o, "%"PRIu64, brw_inst_dp_msg_control(devinfo, inst));
}
- format(file, ")");
+ format(&o, ")");
break;
}
/* FALLTHROUGH */
case HSW_SFID_DATAPORT_DATA_CACHE_1: {
if (devinfo->gen >= 7) {
- format(file, " (");
+ format(&o, " (");
unsigned msg_ctrl = brw_inst_dp_msg_control(devinfo, inst);
- err |= control(file, "DP DC1 message type",
+ err |= control(&o, "DP DC1 message type",
dp_dc1_msg_type_hsw,
brw_inst_dp_msg_type(devinfo, inst), &space);
- format(file, ", Surface = %"PRIu64", ",
+ format(&o, ", Surface = %"PRIu64", ",
brw_inst_binding_table_index(devinfo, inst));
switch (brw_inst_dp_msg_type(devinfo, inst)) {
case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP:
case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP:
case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP:
- format(file, "SIMD%d,", (msg_ctrl & (1 << 4)) ? 8 : 16);
+ format(&o, "SIMD%d,", (msg_ctrl & (1 << 4)) ? 8 : 16);
/* fallthrough */
case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2:
case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2:
case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2:
- control(file, "atomic op", aop, msg_ctrl & 0xf, &space);
+ control(&o, "atomic op", aop, msg_ctrl & 0xf, &space);
break;
case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ:
case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE:
case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ:
case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE: {
static const char *simd_modes[] = { "4x2", "16", "8" };
- format(file, "SIMD%s, Mask = 0x%x",
+ format(&o, "SIMD%s, Mask = 0x%x",
simd_modes[msg_ctrl >> 4], msg_ctrl & 0xf);
break;
}
default:
- format(file, "0x%x", msg_ctrl);
+ format(&o, "0x%x", msg_ctrl);
}
- format(file, ")");
+ format(&o, ")");
break;
}
/* FALLTHROUGH */
@@ -1580,7 +1610,7 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
case GEN7_SFID_PIXEL_INTERPOLATOR:
if (devinfo->gen >= 7) {
- format(file, " (%s, %s, 0x%02"PRIx64")",
+ format(&o, " (%s, %s, 0x%02"PRIx64")",
brw_inst_pi_nopersp(devinfo, inst) ? "linear" : "persp",
pixel_interpolator_msg_types[brw_inst_pi_message_type(devinfo, inst)],
brw_inst_pi_message_data(devinfo, inst));
@@ -1589,65 +1619,85 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
/* FALLTHROUGH */
default:
- format(file, "unsupported shared function ID %d", sfid);
+ format(&o, "unsupported shared function ID %d", sfid);
break;
}
if (space)
- string(file, " ");
- format(file, "mlen %"PRIu64, brw_inst_mlen(devinfo, inst));
- format(file, " rlen %"PRIu64, brw_inst_rlen(devinfo, inst));
+ string(&o, " ");
+ format(&o, "mlen %"PRIu64, brw_inst_mlen(devinfo, inst));
+ format(&o, " rlen %"PRIu64, brw_inst_rlen(devinfo, inst));
}
}
- pad(file, 64);
+ pad(&o, 64);
if (opcode != BRW_OPCODE_NOP && opcode != BRW_OPCODE_NENOP) {
- string(file, "{");
+ string(&o, "{");
space = 1;
- err |= control(file, "access mode", access_mode,
+ err |= control(&o, "access mode", access_mode,
brw_inst_access_mode(devinfo, inst), &space);
if (devinfo->gen >= 6) {
- err |= control(file, "write enable control", wectrl,
+ err |= control(&o, "write enable control", wectrl,
brw_inst_mask_control(devinfo, inst), &space);
} else {
- err |= control(file, "mask control", mask_ctrl,
+ err |= control(&o, "mask control", mask_ctrl,
brw_inst_mask_control(devinfo, inst), &space);
}
- err |= control(file, "dependency control", dep_ctrl,
+ err |= control(&o, "dependency control", dep_ctrl,
((brw_inst_no_dd_check(devinfo, inst) << 1) |
brw_inst_no_dd_clear(devinfo, inst)), &space);
if (devinfo->gen >= 6)
- err |= qtr_ctrl(file, devinfo, inst);
+ err |= qtr_ctrl(&o, devinfo, inst);
else {
if (brw_inst_qtr_control(devinfo, inst) == BRW_COMPRESSION_COMPRESSED &&
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");
+ format(&o, " compr4");
} else {
- err |= control(file, "compression control", compr_ctrl,
+ err |= control(&o, "compression control", compr_ctrl,
brw_inst_qtr_control(devinfo, inst), &space);
}
}
- err |= control(file, "compaction", cmpt_ctrl, is_compacted, &space);
- err |= control(file, "thread control", thread_ctrl,
+ err |= control(&o, "compaction", cmpt_ctrl, is_compacted, &space);
+ err |= control(&o, "thread control", thread_ctrl,
brw_inst_thread_control(devinfo, inst), &space);
if (has_branch_ctrl(devinfo, opcode)) {
- err |= control(file, "branch ctrl", branch_ctrl,
+ err |= control(&o, "branch ctrl", branch_ctrl,
brw_inst_branch_control(devinfo, inst), &space);
} else if (devinfo->gen >= 6) {
- err |= control(file, "acc write control", accwr,
+ err |= control(&o, "acc write control", accwr,
brw_inst_acc_wr_control(devinfo, inst), &space);
}
if (opcode == BRW_OPCODE_SEND || opcode == BRW_OPCODE_SENDC)
- err |= control(file, "end of thread", end_of_thread,
+ err |= control(&o, "end of thread", end_of_thread,
brw_inst_eot(devinfo, inst), &space);
if (space)
- string(file, " ");
- string(file, "}");
+ string(&o, " ");
+ string(&o, "}");
}
- string(file, ";");
- newline(file);
+ string(&o, ";");
+ newline(&o);
+
+ *str = o.buf;
return err;
}
+
+int
+brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
+ brw_inst *inst, bool is_compacted)
+{
+ char *disasm;
+ int err;
+
+ err = brw_disassemble_inst_str(&disasm, devinfo, inst, is_compacted);
+
+ if (disasm == NULL) {
+ return 1;
+ } else {
+ fputs(disasm, file);
+ free(disasm);
+ return err;
+ }
+}
--
2.11.0
More information about the mesa-dev
mailing list