pan/bi: Preliminary branch packing
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 28 May 2020 16:39:42 +0000 (12:39 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 29 May 2020 20:34:55 +0000 (20:34 +0000)
Simple == 0 branch packing. Offset is still to-do.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5260>

src/panfrost/bifrost/bi_pack.c
src/panfrost/bifrost/bifrost.h

index b5cbc5fa948defb8e60ffe07fc6e9123b224491d..7366b16c6c6b1f9f046a9d317514f3f4fceb6a34 100644 (file)
@@ -1619,6 +1619,40 @@ bi_pack_add_imath(bi_instruction *ins, bi_registers *regs)
         return bi_pack_add_2src(ins, regs, op);
 }
 
+static unsigned
+bi_pack_add_branch(bi_instruction *ins, bi_registers *regs)
+{
+        assert(ins->cond == BI_COND_EQ);
+        assert(ins->src[1] == BIR_INDEX_ZERO);
+
+        unsigned zero_ctrl = 0;
+        unsigned size = nir_alu_type_get_type_size(ins->src_types[0]);
+
+        if (size == 16) {
+                /* See BR_SIZE_ZERO swizzle disassembly */
+                zero_ctrl = ins->swizzle[0][0] ? 1 : 2;
+        } else {
+                assert(size == 32);
+        }
+
+        /* EQ swap to NE */
+        bool port_swapped = false;
+
+        /* We assigned the constant port to fetch the branch offset so we can
+         * just passthrough here. We put in the HI slot to match the blob since
+         * that's where the magic flags end up */
+        struct bifrost_branch pack = {
+                .src0 = bi_get_src(ins, regs, 0),
+                .src1 = (zero_ctrl << 1) | !port_swapped,
+                .src2 = BIFROST_SRC_CONST_HI,
+                .cond = BR_COND_EQ,
+                .size = BR_SIZE_ZERO,
+                .op = BIFROST_ADD_OP_BRANCH
+        };
+
+        RETURN_PACKED(pack);
+}
+
 static unsigned
 bi_pack_add(bi_clause *clause, bi_bundle bundle, bi_registers *regs, gl_shader_stage stage)
 {
@@ -1631,7 +1665,7 @@ bi_pack_add(bi_clause *clause, bi_bundle bundle, bi_registers *regs, gl_shader_s
         case BI_ATEST:
                 return bi_pack_add_atest(clause, bundle.add, regs);
         case BI_BRANCH:
-                unreachable("Packing todo");
+                return bi_pack_add_branch(bundle.add, regs);
         case BI_CMP:
                 return bi_pack_add_cmp(bundle.add, regs);
         case BI_BLEND:
index 9ccc30bd8b79cf7c8443fd193a7bf8a1044d9685..fa07b749e5e5a82615a4f5040fad496183419d11 100644 (file)
@@ -734,6 +734,8 @@ enum bifrost_branch_code {
         BR_ALWAYS = 63,
 };
 
+#define BIFROST_ADD_OP_BRANCH (0x0d000 >> 12)
+
 struct bifrost_branch {
         unsigned src0 : 3;