pan/bi: Fix bi_get_immediate with multiple imms
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 14 Apr 2020 22:29:36 +0000 (18:29 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 17 Apr 2020 20:25:35 +0000 (16:25 -0400)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4615>

src/panfrost/bifrost/bi_pack.c
src/panfrost/bifrost/bi_print.c
src/panfrost/bifrost/bir.c

index 09fefd810adbf9957cde72dc001aa4129c99e444..6f0767223c198d05b876f89a74fbd663e3f972b8 100644 (file)
@@ -162,7 +162,7 @@ bi_assign_uniform_constant_single(
                 if (ins->src[s] & BIR_INDEX_CONSTANT) {
                         bool hi = false;
                         bool b64 = nir_alu_type_get_type_size(ins->src_types[s]) > 32;
-                        uint64_t cons = bi_get_immediate(ins, ins->src[s]);
+                        uint64_t cons = bi_get_immediate(ins, s);
                         unsigned idx = bi_lookup_constant(clause, cons, &hi, b64);
                         unsigned f = bi_constant_field(idx) | (cons & 0xF);
 
@@ -944,7 +944,7 @@ bi_pack_add_ld_vary(bi_clause *clause, bi_instruction *ins, struct bi_registers
 
         if (ins->src[0] & BIR_INDEX_CONSTANT) {
                 /* Direct uses address field directly */
-                packed_addr = bi_get_immediate(ins, ins->src[0]);
+                packed_addr = bi_get_immediate(ins, 0);
                 assert(packed_addr < 0b1000);
         } else {
                 /* Indirect gets an extra source */
@@ -1051,7 +1051,7 @@ bi_pack_add_ld_var_addr(bi_clause *clause, bi_instruction *ins, struct bi_regist
         struct bifrost_ld_var_addr pack = {
                 .src0 = bi_get_src(ins, regs, 1, false),
                 .src1 = bi_get_src(ins, regs, 2, false),
-                .location = bi_get_immediate(ins, ins->src[0]),
+                .location = bi_get_immediate(ins, 0),
                 .type = bi_pack_ldst_type(ins->src_types[3]),
                 .op = BIFROST_ADD_OP_LD_VAR_ADDR
         };
@@ -1066,7 +1066,7 @@ bi_pack_add_ld_attr(bi_clause *clause, bi_instruction *ins, struct bi_registers
         struct bifrost_ld_attr pack = {
                 .src0 = bi_get_src(ins, regs, 1, false),
                 .src1 = bi_get_src(ins, regs, 2, false),
-                .location = bi_get_immediate(ins, ins->src[0]),
+                .location = bi_get_immediate(ins, 0),
                 .channels = MALI_POSITIVE(bi_load32_components(ins)),
                 .type = bi_pack_ldst_type(ins->dest_type),
                 .op = BIFROST_ADD_OP_LD_ATTR
index c80e469b74a541cc773aa8cc63b0c1abdc069db3..5f718e95a37b29f2d3c31dd3fd29367180bd1696 100644 (file)
@@ -185,7 +185,7 @@ bi_print_index(FILE *fp, bi_instruction *ins, unsigned index, unsigned s)
         if (index & BIR_INDEX_UNIFORM)
                 fprintf(fp, "u%u", index & ~BIR_INDEX_UNIFORM);
         else if (index & BIR_INDEX_CONSTANT)
-                fprintf(fp, "#0x%" PRIx64, bi_get_immediate(ins, index));
+                fprintf(fp, "#0x%" PRIx64, bi_get_immediate(ins, s));
         else if (index & BIR_INDEX_ZERO)
                 fprintf(fp, "#0");
         else
index b42db852ce4b7ad15ad76bf4f4a70dce4c58e031..8d0aaca6ce12a0e15ca40ad2b4819f1dfb438040 100644 (file)
@@ -140,9 +140,18 @@ bi_bytemask_of_read_components(bi_instruction *ins, unsigned node)
 uint64_t
 bi_get_immediate(bi_instruction *ins, unsigned index)
 {
-        assert(index & BIR_INDEX_CONSTANT);
-        unsigned shift = index & ~BIR_INDEX_CONSTANT;
-        return ins->constant.u64 >> shift;
+        unsigned v = ins->src[index];
+        assert(v & BIR_INDEX_CONSTANT);
+        unsigned shift = v & ~BIR_INDEX_CONSTANT;
+        uint64_t shifted = ins->constant.u64 >> shift;
+
+        /* Mask off the accessed part */
+        unsigned sz = nir_alu_type_get_type_size(ins->src_types[index]);
+
+        if (sz == 64)
+                return shifted;
+        else
+                return shifted & ((1ull << sz) - 1);
 }
 
 bool