pan/bi: Fix bi_get_immediate with multiple imms
[mesa.git] / src / panfrost / bifrost / bir.c
index f110564aa642e49a5520730814edad0341afd9b6..8d0aaca6ce12a0e15ca40ad2b4819f1dfb438040 100644 (file)
@@ -136,3 +136,32 @@ bi_bytemask_of_read_components(bi_instruction *ins, unsigned node)
 
         return mask;
 }
+
+uint64_t
+bi_get_immediate(bi_instruction *ins, unsigned index)
+{
+        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
+bi_writes_component(bi_instruction *ins, unsigned comp)
+{
+        /* TODO: Do we want something less coarse? */
+        if (bi_class_props[ins->type] & BI_VECTOR)
+                return true;
+
+        nir_alu_type T = ins->dest_type;
+        unsigned size = nir_alu_type_get_type_size(T);
+        return ins->writemask & (0xF << (comp * (size / 8)));
+}