panfrost: Use memctx for sysvals
[mesa.git] / src / panfrost / bifrost / bi_print.c
index 1c9c8a72a314ce329f7e08375d56ab038d778f3e..7b231c39b65ee0850e16f4baf19fcae5da3e586f 100644 (file)
  */
 
 #include "bi_print.h"
-
-const char *
-bi_clause_type_name(enum bifrost_clause_type T)
-{
-        switch (T) {
-        case BIFROST_CLAUSE_NONE: return "";
-        case BIFROST_CLAUSE_LOAD_VARY: return "load_vary";
-        case BIFROST_CLAUSE_UBO: return "ubo";
-        case BIFROST_CLAUSE_TEX: return "tex";
-        case BIFROST_CLAUSE_SSBO_LOAD: return "load";
-        case BIFROST_CLAUSE_SSBO_STORE: return "store";
-        case BIFROST_CLAUSE_BLEND: return "blend";
-        case BIFROST_CLAUSE_ATEST: return "atest";
-        case BIFROST_CLAUSE_64BIT: return "64";
-        default: return "??";
-        }
-}
-
-const char *
-bi_output_mod_name(enum bifrost_outmod mod)
-{
-        switch (mod) {
-        case BIFROST_NONE: return "";
-        case BIFROST_POS: return ".pos";
-        case BIFROST_SAT_SIGNED: return ".sat_signed";
-        case BIFROST_SAT: return ".sat";
-        default: return "invalid";
-        }
-}
-
-const char *
-bi_minmax_mode_name(enum bifrost_minmax_mode mod)
-{
-        switch (mod) {
-        case BIFROST_MINMAX_NONE: return "";
-        case BIFROST_NAN_WINS: return ".nan_wins";
-        case BIFROST_SRC1_WINS: return ".src1_wins";
-        case BIFROST_SRC0_WINS: return ".src0_wins";
-        default: return "invalid";
-        }
-}
-
-const char *
-bi_round_mode_name(enum bifrost_roundmode mod)
-{
-        switch (mod) {
-        case BIFROST_RTE: return "";
-        case BIFROST_RTP: return ".rtp";
-        case BIFROST_RTN: return ".rtn";
-        case BIFROST_RTZ: return ".rtz";
-        default: return "invalid";
-        }
-}
-
-const char *
-bi_csel_cond_name(enum bifrost_csel_cond cond)
-{
-        switch (cond) {
-        case BIFROST_FEQ_F: return "feq.f";
-        case BIFROST_FGT_F: return "fgt.f";
-        case BIFROST_FGE_F: return "fge.f";
-        case BIFROST_IEQ_F: return "ieq.f";
-        case BIFROST_IGT_I: return "igt.i";
-        case BIFROST_IGE_I: return "uge.i";
-        case BIFROST_UGT_I: return "ugt.i";
-        case BIFROST_UGE_I: return "uge.i";
-        default: return "invalid";
-        }
-}
-
-const char *
-bi_interp_mode_name(enum bifrost_interp_mode mode)
-{
-        switch (mode) {
-        case BIFROST_INTERP_PER_FRAG: return ".per_frag";
-        case BIFROST_INTERP_CENTROID: return ".centroid";
-        case BIFROST_INTERP_DEFAULT: return "";
-        case BIFROST_INTERP_EXPLICIT: return ".explicit";
-        default: return ".unknown";
-        }
-}
-
-const char *
-bi_ldst_type_name(enum bifrost_ldst_type type)
-{
-        switch (type) {
-        case BIFROST_LDST_F16: return "f16";
-        case BIFROST_LDST_F32: return "f32";
-        case BIFROST_LDST_I32: return "i32";
-        case BIFROST_LDST_U32: return "u32";
-        default: return "invalid";
-        }
-}
-
-/* The remaining functions in this file are for IR-internal
- * structures; the disassembler doesn't use them */
+#include "bi_print_common.h"
 
 const char *
 bi_class_name(enum bi_class cl)
@@ -139,7 +44,7 @@ bi_class_name(enum bi_class cl)
         case BI_FMA: return "fma";
         case BI_FMOV: return "fmov";
         case BI_FREXP: return "frexp";
-        case BI_ISUB: return "isub";
+        case BI_IMATH: return "imath";
         case BI_LOAD: return "load";
         case BI_LOAD_UNIFORM: return "load_uniform";
         case BI_LOAD_ATTR: return "load_attr";
@@ -148,13 +53,13 @@ bi_class_name(enum bi_class cl)
         case BI_MINMAX: return "minmax";
         case BI_MOV: return "mov";
         case BI_SELECT: return "select";
-        case BI_SHIFT: return "shift";
         case BI_STORE: return "store";
         case BI_STORE_VAR: return "store_var";
         case BI_SPECIAL: return "special";
         case BI_TABLE: return "table";
         case BI_TEX: return "tex";
         case BI_ROUND: return "round";
+        case BI_IMUL: return "imul";
         default: return "unknown_class";
         }
 }
@@ -166,7 +71,7 @@ bi_print_dest_index(FILE *fp, bi_instruction *ins, unsigned index)
                 fprintf(fp, "_");
         else if (index & BIR_INDEX_REGISTER)
                 fprintf(fp, "br%u", index & ~BIR_INDEX_REGISTER);
-        else if (index & BIR_IS_REG)
+        else if (index & PAN_IS_REG)
                 fprintf(fp, "r%u", index >> 1);
         else if (!(index & BIR_SPECIAL))
                 fprintf(fp, "%u", (index >> 1) - 1);
@@ -215,35 +120,6 @@ bi_print_src(FILE *fp, bi_instruction *ins, unsigned s)
                 fprintf(fp, ")");
 }
 
-/* Prints a NIR ALU type in Bifrost-style ".f32" ".i8" etc */
-
-static void
-bi_print_alu_type(nir_alu_type t, FILE *fp)
-{
-        unsigned size = nir_alu_type_get_type_size(t);
-        nir_alu_type base = nir_alu_type_get_base_type(t);
-
-        switch (base) {
-        case nir_type_int:
-                fprintf(fp, ".i");
-                break;
-        case nir_type_uint:
-                fprintf(fp, ".u");
-                break;
-        case nir_type_bool:
-                fprintf(fp, ".b");
-                break;
-        case nir_type_float:
-                fprintf(fp, ".f");
-                break;
-        default:
-                fprintf(fp, ".unknown");
-                break;
-        }
-
-        fprintf(fp, "%u", size);
-}
-
 static void
 bi_print_swizzle(bi_instruction *ins, unsigned src, FILE *fp)
 {
@@ -266,6 +142,16 @@ bi_bitwise_op_name(enum bi_bitwise_op op)
         }
 }
 
+static const char *
+bi_imath_op_name(enum bi_imath_op op)
+{
+        switch (op) {
+        case BI_IMATH_ADD: return "iadd";
+        case BI_IMATH_SUB: return "isub";
+        default: return "invalid";
+        }
+}
+
 const char *
 bi_table_op_name(enum bi_table_op op)
 {
@@ -343,9 +229,10 @@ bi_cond_name(enum bi_cond cond)
 }
 
 static void
-bi_print_branch(struct bi_branch *branch, FILE *fp)
+bi_print_texture(struct bi_texture *tex, FILE *fp)
 {
-        fprintf(fp, ".%s", bi_cond_name(branch->cond));
+        fprintf(fp, " - texture %u, sampler %u",
+                        tex->texture_index, tex->sampler_index);
 }
 
 void
@@ -355,6 +242,8 @@ bi_print_instruction(bi_instruction *ins, FILE *fp)
                 fprintf(fp, "%s", ins->op.minmax == BI_MINMAX_MIN ? "min" : "max");
         else if (ins->type == BI_BITWISE)
                 fprintf(fp, "%s", bi_bitwise_op_name(ins->op.bitwise));
+        else if (ins->type == BI_IMATH)
+                fprintf(fp, "%s", bi_imath_op_name(ins->op.imath));
         else if (ins->type == BI_SPECIAL)
                 fprintf(fp, "%s", bi_special_op_name(ins->op.special));
         else if (ins->type == BI_TABLE)
@@ -373,22 +262,21 @@ bi_print_instruction(bi_instruction *ins, FILE *fp)
                 fprintf(fp, "%s", bi_minmax_mode_name(ins->minmax));
         else if (ins->type == BI_LOAD_VAR)
                 bi_print_load_vary(&ins->load_vary, fp);
-        else if (ins->type == BI_BRANCH)
-                bi_print_branch(&ins->branch, fp);
-        else if (ins->type == BI_CSEL || ins->type == BI_CMP)
-                fprintf(fp, ".%s", bi_cond_name(ins->cond));
         else if (ins->type == BI_BLEND)
                 fprintf(fp, ".loc%u", ins->blend_location);
-        else if (ins->type == BI_TEX)
+        else if (ins->type == BI_TEX) {
                 fprintf(fp, ".%s", bi_tex_op_name(ins->op.texture));
-        else if (ins->type == BI_BITWISE)
+        else if (ins->type == BI_BITWISE)
                 fprintf(fp, ".%cshift", ins->bitwise.rshift ? 'r' : 'l');
 
+        if (bi_class_props[ins->type] & BI_CONDITIONAL)
+                fprintf(fp, ".%s", bi_cond_name(ins->cond));
+
         if (ins->vector_channels)
                 fprintf(fp, ".v%u", ins->vector_channels);
 
         if (ins->dest)
-                bi_print_alu_type(ins->dest_type, fp);
+                pan_print_alu_type(ins->dest_type, fp);
 
         if (bi_has_outmod(ins))
                 fprintf(fp, "%s", bi_output_mod_name(ins->outmod));
@@ -409,7 +297,7 @@ bi_print_instruction(bi_instruction *ins, FILE *fp)
                 bi_print_src(fp, ins, s);
 
                 if (ins->src[s] && !(ins->src[s] & (BIR_INDEX_CONSTANT | BIR_INDEX_ZERO))) {
-                        bi_print_alu_type(ins->src_types[s], fp);
+                        pan_print_alu_type(ins->src_types[s], fp);
                         bi_print_swizzle(ins, s, fp);
                 }
 
@@ -418,15 +306,39 @@ bi_print_instruction(bi_instruction *ins, FILE *fp)
         }
 
         if (ins->type == BI_BRANCH) {
-                if (ins->branch.target)
-                        fprintf(fp, "-> block%u", ins->branch.target->base.name);
-                else
-                        fprintf(fp, "-> blockhole");
+                if (ins->branch_target) {
+                        fprintf(fp, "-> block%u", ins->branch_target->base.name);
+                } else {
+                        fprintf(fp, "-> void");
+                }
+        } else if (ins->type == BI_TEX) {
+                bi_print_texture(&ins->texture, fp);
         }
 
         fprintf(fp, "\n");
 }
 
+void
+bi_print_ports(bi_registers *regs, FILE *fp)
+{
+        for (unsigned i = 0; i < 2; ++i) {
+                if (regs->enabled[i])
+                        fprintf(fp, "port %u: %u\n", i, regs->port[i]);
+        }
+
+        if (regs->write_fma || regs->write_add) {
+                fprintf(fp, "port 2 (%s): %u\n",
+                                regs->write_add ? "ADD" : "FMA",
+                                regs->port[2]);
+        }
+
+        if ((regs->write_fma && regs->write_add) || regs->read_port3) {
+                fprintf(fp, "port 3 (%s): %u\n",
+                                regs->read_port3 ? "read" : "FMA",
+                                regs->port[3]);
+        }
+}
+
 void
 bi_print_bundle(bi_bundle *bundle, FILE *fp)
 {
@@ -464,22 +376,16 @@ bi_print_clause(bi_clause *clause, FILE *fp)
 
         fprintf(fp, "\n");
 
-        if (clause->instruction_count) {
-                assert(!clause->bundle_count);
-
-                for (unsigned i = 0; i < clause->instruction_count; ++i)
-                        bi_print_instruction(clause->instructions[i], fp);
-        } else {
-                assert(clause->bundle_count);
-
-                for (unsigned i = 0; i < clause->bundle_count; ++i)
-                        bi_print_bundle(&clause->bundles[i], fp);
-        }
+        for (unsigned i = 0; i < clause->bundle_count; ++i)
+                bi_print_bundle(&clause->bundles[i], fp);
 
         if (clause->constant_count) {
                 for (unsigned i = 0; i < clause->constant_count; ++i)
                         fprintf(fp, "%" PRIx64 " ", clause->constants[i]);
 
+                if (clause->branch_constant)
+                        fprintf(fp, "*");
+
                 fprintf(fp, "\n");
         }
 }