#include <ctype.h>
#include <string.h>
#include "midgard.h"
-#include "midgard-parse.h"
#include "midgard_ops.h"
#include "midgard_quirks.h"
#include "disassemble.h"
}
}
-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);
+ printf(" r%u", word->reg + (OP_IS_STORE(word->op) ? 26 : 0));
print_mask_4(word->mask, false);
if (!OP_IS_STORE(word->op))
if (texture->offset_register) {
printf(" + ");
- bool full = texture->offset_x & 1;
- bool select = texture->offset_x & 2;
- bool upper = texture->offset_x & 4;
+ bool full = texture->offset & 1;
+ bool select = texture->offset & 2;
+ bool upper = texture->offset & 4;
printf("%sr%u", full ? "" : "h", in_reg_base + select);
assert(!(texture->out_full && texture->out_upper));
if (upper)
printf("'");
- /* The less questions you ask, the better. */
-
- unsigned swizzle_lo, swizzle_hi;
- unsigned orig_y = texture->offset_y;
- unsigned orig_z = texture->offset_z;
-
- memcpy(&swizzle_lo, &orig_y, sizeof(unsigned));
- memcpy(&swizzle_hi, &orig_z, sizeof(unsigned));
-
- /* Duplicate hi swizzle over */
- assert(swizzle_hi < 4);
- swizzle_hi = (swizzle_hi << 2) | swizzle_hi;
-
- 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(", ");
}
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) {
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");
+ /* We are parsing per bundle anyway. Add before we start
+ * breaking out so we don't miss the final bundle. */
- unsigned next = (words[i] & 0xF0) >> 4;
-
- /* 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;
}