panfrost/midgard: Print the actual source register for store operations
[mesa.git] / src / panfrost / midgard / disassemble.c
index 0b4dc72be9f9b7b475bb51d2ca0f4316c60b5739..e92214417c41b91d8a81acec959157d48ca59d2e 100644 (file)
@@ -32,7 +32,6 @@
 #include <ctype.h>
 #include <string.h>
 #include "midgard.h"
-#include "midgard-parse.h"
 #include "midgard_ops.h"
 #include "midgard_quirks.h"
 #include "disassemble.h"
@@ -736,10 +735,11 @@ print_branch_cond(int cond)
         }
 }
 
-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: {
@@ -757,7 +757,7 @@ print_compact_branch_writeout_field(uint16_t word)
                 print_tag_short(br_uncond.dest_tag);
                 printf("\n");
 
-                break;
+                return br_uncond.offset >= 0;
         }
 
         case midgard_jmp_writeout_op_branch_cond:
@@ -781,14 +781,14 @@ print_compact_branch_writeout_field(uint16_t word)
                 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;
@@ -836,6 +836,7 @@ print_extended_branch_writeout_field(uint8_t *words, unsigned next)
         midg_tags[I] = br.dest_tag;
 
         midg_stats.instruction_count++;
+        return br.offset >= 0;
 }
 
 static unsigned
@@ -873,7 +874,7 @@ float_bitcast(uint32_t integer)
         return v.f;
 }
 
-static void
+static bool
 print_alu_word(uint32_t *words, unsigned num_quad_words,
                unsigned tabs, unsigned next)
 {
@@ -882,6 +883,7 @@ print_alu_word(uint32_t *words, unsigned num_quad_words,
         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");
@@ -933,13 +935,13 @@ print_alu_word(uint32_t *words, unsigned num_quad_words,
         }
 
         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;
         }
@@ -984,6 +986,8 @@ print_alu_word(uint32_t *words, unsigned num_quad_words,
 
                 }
         }
+
+        return branch_forward;
 }
 
 static void
@@ -1117,7 +1121,7 @@ print_load_store_instr(uint64_t data,
                         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))
@@ -1366,9 +1370,9 @@ print_texture_word(uint32_t *word, unsigned tabs, unsigned in_reg_base, unsigned
         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));
@@ -1377,30 +1381,19 @@ print_texture_word(uint32_t *word, unsigned tabs, unsigned in_reg_base, unsigned
                 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)
@@ -1408,10 +1401,7 @@ print_texture_word(uint32_t *word, unsigned tabs, unsigned in_reg_base, unsigned
 
                 /* 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(", ");
         }
@@ -1469,7 +1459,7 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage
         unsigned num_words = size / 4;
         int tabs = 0;
 
-        bool prefetch_flag = false;
+        bool branch_forward = false;
 
         int last_next_tag = -1;
 
@@ -1484,6 +1474,7 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage
         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) {
@@ -1527,7 +1518,7 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage
                         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;
@@ -1543,25 +1534,18 @@ disassemble_midgard(uint8_t *code, size_t size, unsigned gpu_id, gl_shader_stage
                         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;
         }