pan/midgard: Add mir_flip helper
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Sat, 28 Sep 2019 16:38:51 +0000 (12:38 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 30 Sep 2019 12:40:13 +0000 (08:40 -0400)
Useful for various operations on both commutative and anticommutative
ops.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_opt_invert.c
src/panfrost/midgard/mir.c

index cb7d53dd653400336f46b515e5b891be00b4e448..8bbf67aa4e7c3c201beefd64d48a8b56bd038572 100644 (file)
@@ -524,6 +524,7 @@ bool mir_nontrivial_outmod(midgard_instruction *ins);
 
 void mir_insert_instruction_before_scheduled(compiler_context *ctx, midgard_block *block, midgard_instruction *tag, midgard_instruction ins);
 void mir_insert_instruction_after_scheduled(compiler_context *ctx, midgard_block *block, midgard_instruction *tag, midgard_instruction ins);
+void mir_flip(midgard_instruction *ins);
 
 /* MIR goodies */
 
index 729169f9a4a896176d3ea50b47cdb9fe1d42d257..f846bca5bf99e989078a3f6aa47a931d386a430a 100644 (file)
@@ -256,16 +256,9 @@ midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block)
                 if (both) {
                         ins->alu.op = mir_demorgan_op(ins->alu.op);
                 } else if (right || (left && !ins->has_inline_constant)) {
-                        if (left) {
-                                /* Commute */
-                                unsigned temp = ins->src[0];
-                                ins->src[0] = ins->src[1];
-                                ins->src[1] = temp;
-
-                                temp = ins->alu.src1;
-                                ins->alu.src1 = ins->alu.src2;
-                                ins->alu.src2 = temp;
-                        }
+                        /* Commute arguments */
+                        if (left)
+                                mir_flip(ins);
 
                         ins->alu.op = mir_notright_op(ins->alu.op);
                 } else if (left && ins->has_inline_constant) {
index faeac16d18db2e90d663f41d8050467e48891fc4..f02527ff219ba17b9cbad035d4390f078a27d54a 100644 (file)
@@ -527,3 +527,20 @@ mir_insert_instruction_after_scheduled(
         memcpy(bundles + after + 1, &new, sizeof(new));
         list_addtail(&new.instructions[0]->link, &after_bundle_1->instructions[0]->link);
 }
+
+/* Flip the first-two arguments of a (binary) op. Currently ALU
+ * only, no known uses for ldst/tex */
+
+void
+mir_flip(midgard_instruction *ins)
+{
+        unsigned temp = ins->src[0];
+        ins->src[0] = ins->src[1];
+        ins->src[1] = temp;
+
+        assert(ins->type == TAG_ALU_4);
+
+        temp = ins->alu.src1;
+        ins->alu.src1 = ins->alu.src2;
+        ins->alu.src2 = temp;
+}