pan/mdg: Track ALU src types
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 27 Apr 2020 22:55:11 +0000 (18:55 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 15:35:54 +0000 (15:35 +0000)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4793>

src/panfrost/midgard/midgard_compile.c

index c65ce2d97a0b398a26e009d12741563599429acb..2e10aae117f330d3c8fe797bc753341bf298cd3b 100644 (file)
@@ -625,6 +625,15 @@ reg_mode_for_nir(nir_alu_instr *instr)
         }
 }
 
+static void
+mir_copy_src(midgard_instruction *ins, nir_alu_instr *instr, unsigned i, unsigned to)
+{
+        unsigned bits = nir_src_bit_size(instr->src[i].src);
+
+        ins->src[to] = nir_src_index(NULL, &instr->src[i].src);
+        ins->src_types[to] = nir_op_infos[instr->op].input_types[i] | bits;
+}
+
 static void
 emit_alu(compiler_context *ctx, nir_alu_instr *instr)
 {
@@ -908,29 +917,22 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
         unsigned opcode_props = alu_opcode_props[op].props;
         bool quirk_flipped_r24 = opcode_props & QUIRK_FLIPPED_R24;
 
-        /* src0 will always exist afaik, but src1 will not for 1-argument
-         * instructions. The latter can only be fetched if the instruction
-         * needs it, or else we may segfault. */
-
-        unsigned src0 = nir_src_index(ctx, &instr->src[0].src);
-        unsigned src1 = nr_inputs >= 2 ? nir_src_index(ctx, &instr->src[1].src) : ~0;
-        unsigned src2 = nr_inputs == 3 ? nir_src_index(ctx, &instr->src[2].src) : ~0;
-        assert(nr_inputs <= 3);
-
-        /* Rather than use the instruction generation helpers, we do it
-         * ourselves here to avoid the mess */
-
         midgard_instruction ins = {
                 .type = TAG_ALU_4,
-                .src = {
-                        quirk_flipped_r24 ? ~0 : src0,
-                        quirk_flipped_r24 ? src0       : src1,
-                        src2,
-                        ~0
-                },
                 .dest = dest,
         };
 
+        for (unsigned i = nr_inputs; i < ARRAY_SIZE(ins.src); ++i)
+                ins.src[i] = ~0;
+
+        if (quirk_flipped_r24) {
+                ins.src[0] = ~0;
+                mir_copy_src(&ins, instr, 0, 1);
+        } else {
+                for (unsigned i = 0; i < nr_inputs; ++i)
+                        mir_copy_src(&ins, instr, i, quirk_flipped_r24 ? 1 : i);
+        }
+
         nir_alu_src *nirmods[3] = { NULL };
 
         if (nr_inputs >= 2) {