#include <ctype.h>
#include <string.h>
#include "midgard.h"
-#include "midgard-parse.h"
#include "midgard_ops.h"
+#include "midgard_quirks.h"
#include "disassemble.h"
#include "helpers.h"
#include "util/half_float.h"
print_reg(reg, bits);
//swizzle
- if (bits == 16)
- print_swizzle_vec8(src->swizzle, src->rep_high, src->rep_low);
- else if (bits == 8)
+ if (bits == 16) {
+ /* When the mode of the instruction is itself 16-bit,
+ * rep_low/high work more or less as expected. But if the mode
+ * is 32-bit and we're stepping down, you only have vec4 and
+ * the meaning shifts to rep_low as higher-half and rep_high is
+ * never seen. TODO: are other modes similar? */
+
+ if (mode == midgard_reg_mode_32) {
+ printf(".");
+ print_swizzle_helper(src->swizzle, src->rep_low);
+ assert(!src->rep_high);
+ } else {
+ print_swizzle_vec8(src->swizzle, src->rep_high, src->rep_low);
+ }
+ } else if (bits == 8)
print_swizzle_vec16(src->swizzle, src->rep_high, src->rep_low, override);
else if (bits == 32)
print_swizzle_vec4(src->swizzle, src->rep_high, src->rep_low);
const char *alphabet = components;
- if (override == midgard_dest_override_upper) {
- unsigned components = 128 / bits;
- alphabet += components;
- }
+ if (override == midgard_dest_override_upper)
+ alphabet += (128 / bits);
for (unsigned i = 0; i < 8; i += skip) {
bool a = (mask & (1 << i)) != 0;
}
/* Prints the 4-bit masks found in texture and load/store ops, as opposed to
- * the 8-bit masks found in (vector) ALU ops */
+ * the 8-bit masks found in (vector) ALU ops. Supports texture-style 16-bit
+ * mode as well, but not load/store-style 16-bit mode. */
static void
-print_mask_4(unsigned mask)
+print_mask_4(unsigned mask, bool upper)
{
- if (mask == 0xF) return;
+ if (mask == 0xF) {
+ if (upper)
+ printf("'");
+
+ return;
+ }
printf(".");
for (unsigned i = 0; i < 4; ++i) {
bool a = (mask & (1 << i)) != 0;
if (a)
- printf("%c", components[i]);
+ printf("%c", components[i + (upper ? 4 : 0)]);
}
}
}
}
-static void
+static bool
print_compact_branch_writeout_field(uint16_t word)
{
midgard_jmp_writeout_op op = word & 0x7;
+ midg_stats.instruction_count++;
switch (op) {
case midgard_jmp_writeout_op_branch_uncond: {
print_tag_short(br_uncond.dest_tag);
printf("\n");
- break;
+ return br_uncond.offset >= 0;
}
case midgard_jmp_writeout_op_branch_cond:
print_tag_short(br_cond.dest_tag);
printf("\n");
- break;
+ return br_cond.offset >= 0;
}
}
- midg_stats.instruction_count++;
+ return false;
}
-static void
+static bool
print_extended_branch_writeout_field(uint8_t *words, unsigned next)
{
midgard_branch_extended br;
midg_tags[I] = br.dest_tag;
midg_stats.instruction_count++;
+ return br.offset >= 0;
}
static unsigned
return v.f;
}
-static void
+static bool
print_alu_word(uint32_t *words, unsigned num_quad_words,
unsigned tabs, unsigned next)
{
unsigned num_fields = num_alu_fields_enabled(control_word);
uint16_t *word_ptr = beginning_ptr + num_fields;
unsigned num_words = 2 + num_fields;
+ bool branch_forward = false;
if ((control_word >> 16) & 1)
printf("unknown bit 16 enabled\n");
}
if ((control_word >> 26) & 1) {
- print_compact_branch_writeout_field(*word_ptr);
+ branch_forward |= print_compact_branch_writeout_field(*word_ptr);
word_ptr += 1;
num_words += 1;
}
if ((control_word >> 27) & 1) {
- print_extended_branch_writeout_field((uint8_t *) word_ptr, next);
+ branch_forward |= print_extended_branch_writeout_field((uint8_t *) word_ptr, next);
word_ptr += 3;
num_words += 3;
}
}
}
+
+ return branch_forward;
}
static void
midg_stats.attribute_count = -16;
}
- printf(" r%u", word->reg);
- print_mask_4(word->mask);
+ printf(" r%u", word->reg + (OP_IS_STORE(word->op) ? 26 : 0));
+ print_mask_4(word->mask, false);
if (!OP_IS_STORE(word->op))
update_dest(word->reg);
}
static void
-print_texture_reg(bool full, bool select, bool upper)
-{
- if (full)
- printf("r%d", REG_TEX_BASE + select);
- else
- printf("hr%d", (REG_TEX_BASE + select) * 2 + upper);
-
- if (full && upper)
- printf("// error: out full / upper mutually exclusive\n");
-
-}
-
-static void
-print_texture_reg_triple(unsigned triple)
-{
- bool full = triple & 1;
- bool select = triple & 2;
- bool upper = triple & 4;
-
- print_texture_reg(full, select, upper);
-}
-
-static void
-print_texture_reg_select(uint8_t u)
+print_texture_reg_select(uint8_t u, unsigned base)
{
midgard_tex_register_select sel;
memcpy(&sel, &u, sizeof(u));
if (!sel.full)
printf("h");
- printf("r%u", REG_TEX_BASE + sel.select);
+ printf("r%u", base + sel.select);
unsigned component = sel.component;
#undef DEFINE_CASE
static void
-print_texture_word(uint32_t *word, unsigned tabs)
+print_texture_word(uint32_t *word, unsigned tabs, unsigned in_reg_base, unsigned out_reg_base)
{
midgard_texture_word *texture = (midgard_texture_word *) word;
/* Output modifiers are always interpreted floatly */
print_outmod(texture->outmod, false);
- printf(" ");
-
- print_texture_reg(texture->out_full, texture->out_reg_select, texture->out_upper);
- print_mask_4(texture->mask);
+ printf(" %sr%u", texture->out_full ? "" : "h",
+ out_reg_base + texture->out_reg_select);
+ print_mask_4(texture->mask, texture->out_upper);
+ assert(!(texture->out_full && texture->out_upper));
printf(", ");
/* Depending on whether we read from textures directly or indirectly,
if (texture->texture_register) {
printf("texture[");
- print_texture_reg_select(texture->texture_handle);
+ print_texture_reg_select(texture->texture_handle, in_reg_base);
printf("], ");
/* Indirect, tut tut */
if (texture->sampler_register) {
printf("[");
- print_texture_reg_select(texture->sampler_handle);
+ print_texture_reg_select(texture->sampler_handle, in_reg_base);
printf("]");
midg_stats.sampler_count = -16;
}
print_swizzle_vec4(texture->swizzle, false, false);
- printf(", ");
+ printf(", %sr%u", texture->in_reg_full ? "" : "h", in_reg_base + texture->in_reg_select);
+ assert(!(texture->in_reg_full && texture->in_reg_upper));
+
+ /* TODO: integrate with swizzle */
+ if (texture->in_reg_upper)
+ printf("'");
- print_texture_reg(texture->in_reg_full, texture->in_reg_select, texture->in_reg_upper);
print_swizzle_vec4(texture->in_reg_swizzle, false, false);
/* There is *always* an offset attached. Of
if (texture->offset_register) {
printf(" + ");
- print_texture_reg_triple(texture->offset_x);
-
- /* The less questions you ask, the better. */
- unsigned swizzle_lo, swizzle_hi;
- unsigned orig_y = texture->offset_y;
- unsigned orig_z = texture->offset_z;
+ bool full = texture->offset & 1;
+ bool select = texture->offset & 2;
+ bool upper = texture->offset & 4;
- memcpy(&swizzle_lo, &orig_y, sizeof(unsigned));
- memcpy(&swizzle_hi, &orig_z, sizeof(unsigned));
+ printf("%sr%u", full ? "" : "h", in_reg_base + select);
+ assert(!(texture->out_full && texture->out_upper));
- /* Duplicate hi swizzle over */
- assert(swizzle_hi < 4);
- swizzle_hi = (swizzle_hi << 2) | swizzle_hi;
+ /* TODO: integrate with swizzle */
+ if (upper)
+ printf("'");
- unsigned swiz = (swizzle_lo << 4) | swizzle_hi;
- unsigned reversed = util_bitreverse(swiz) >> 24;
- print_swizzle_vec4(reversed, false, false);
+ print_swizzle_vec4(texture->offset >> 3, false, false);
printf(", ");
- } else if (texture->offset_x || texture->offset_y || texture->offset_z) {
+ } else if (texture->offset) {
/* Only select ops allow negative immediate offsets, verify */
- bool neg_x = texture->offset_x < 0;
- bool neg_y = texture->offset_y < 0;
- bool neg_z = texture->offset_z < 0;
+ signed offset_x = (texture->offset & 0xF);
+ signed offset_y = ((texture->offset >> 4) & 0xF);
+ signed offset_z = ((texture->offset >> 8) & 0xF);
+
+ bool neg_x = offset_x < 0;
+ bool neg_y = offset_y < 0;
+ bool neg_z = offset_z < 0;
bool any_neg = neg_x || neg_y || neg_z;
if (any_neg && texture->op != TEXTURE_OP_TEXEL_FETCH)
/* Regardless, just print the immediate offset */
- printf(" + <%d, %d, %d>, ",
- texture->offset_x,
- texture->offset_y,
- texture->offset_z);
+ printf(" + <%d, %d, %d>, ", offset_x, offset_y, offset_z);
} else {
printf(", ");
}
if (texture->lod_register) {
printf("lod %c ", lod_operand);
- print_texture_reg_select(texture->bias);
+ print_texture_reg_select(texture->bias, in_reg_base);
printf(", ");
if (texture->bias_int)
}
struct midgard_disasm_stats
-disassemble_midgard(uint8_t *code, size_t size)
+disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage stage)
{
uint32_t *words = (uint32_t *) code;
unsigned num_words = size / 4;
int tabs = 0;
- bool prefetch_flag = false;
+ bool branch_forward = false;
int last_next_tag = -1;
while (i < num_words) {
unsigned tag = words[i] & 0xF;
unsigned next_tag = (words[i] >> 4) & 0xF;
+ printf("\t%X -> %X\n", tag, next_tag);
unsigned num_quad_words = midgard_word_size[tag];
if (midg_tags[i] && midg_tags[i] != tag) {
last_next_tag = next_tag;
switch (midgard_word_types[tag]) {
- case midgard_word_type_texture:
- print_texture_word(&words[i], tabs);
+ case midgard_word_type_texture: {
+ bool interpipe_aliasing =
+ midgard_get_quirks(gpu_id) & MIDGARD_INTERPIPE_REG_ALIASING;
+
+ print_texture_word(&words[i], tabs,
+ interpipe_aliasing ? 0 : REG_TEX_BASE,
+ interpipe_aliasing ? REGISTER_LDST_BASE : REG_TEX_BASE);
break;
+ }
case midgard_word_type_load_store:
print_load_store_word(&words[i], tabs);
break;
case midgard_word_type_alu:
- print_alu_word(&words[i], num_quad_words, tabs, i + 4*num_quad_words);
+ branch_forward = print_alu_word(&words[i], num_quad_words, tabs, i + 4*num_quad_words);
/* Reset word static analysis state */
is_embedded_constant_half = false;
break;
}
- if (prefetch_flag && midgard_word_types[tag] == midgard_word_type_alu)
- break;
-
- printf("\n");
-
- unsigned next = (words[i] & 0xF0) >> 4;
+ /* We are parsing per bundle anyway. Add before we start
+ * breaking out so we don't miss the final bundle. */
- /* We are parsing per bundle anyway */
midg_stats.bundle_count++;
midg_stats.quadword_count += num_quad_words;
- /* Break based on instruction prefetch flag */
+ printf("\n");
- if (i < num_words && next == 1) {
- prefetch_flag = true;
+ unsigned next = (words[i] & 0xF0) >> 4;
- if (midgard_word_types[words[i] & 0xF] != midgard_word_type_alu)
- break;
- }
+ if (i < num_words && next == 1 && !branch_forward)
+ break;
i += 4 * num_quad_words;
}