pan/bi: Eliminate writemasks in the IR
[mesa.git] / src / panfrost / bifrost / bir.c
index 8d0aaca6ce12a0e15ca40ad2b4819f1dfb438040..3c5ad9bf71b90af751ff3ed07e13ace758caa792 100644 (file)
@@ -93,28 +93,17 @@ bi_from_bytemask(uint16_t bytemask, unsigned bytes)
 }
 
 unsigned
-bi_get_component_count(bi_instruction *ins, unsigned src)
+bi_get_component_count(bi_instruction *ins, signed src)
 {
         if (bi_class_props[ins->type] & BI_VECTOR) {
-                return (src == 0) ? 4 : 1;
+                assert(ins->vector_channels);
+                return (src <= 0) ? ins->vector_channels : 1;
         } else {
-                /* Stores imply VECTOR */
-                assert(ins->dest_type);
-                unsigned bytes = nir_alu_type_get_type_size(ins->dest_type);
-                return 32 / bytes;
+                unsigned bytes = nir_alu_type_get_type_size(src < 0 ? ins->dest_type : ins->src_types[src]);
+                return MAX2(32 / bytes, 1);
         }
 }
 
-unsigned
-bi_load32_components(bi_instruction *ins)
-{
-        unsigned mask = bi_from_bytemask(ins->writemask, 4);
-        unsigned count = util_bitcount(mask);
-        assert(mask == ((1 << count) - 1));
-        assert(count >= 1 && count <= 4);
-        return count;
-}
-
 uint16_t
 bi_bytemask_of_read_components(bi_instruction *ins, unsigned node)
 {
@@ -157,11 +146,18 @@ bi_get_immediate(bi_instruction *ins, unsigned index)
 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;
+        return comp < bi_get_component_count(ins, -1);
+}
 
+unsigned
+bi_writemask(bi_instruction *ins)
+{
         nir_alu_type T = ins->dest_type;
         unsigned size = nir_alu_type_get_type_size(T);
-        return ins->writemask & (0xF << (comp * (size / 8)));
+        unsigned bytes_per_comp = size / 8;
+        unsigned components = bi_get_component_count(ins, -1);
+        unsigned bytes = bytes_per_comp * components;
+        unsigned mask = (1 << bytes) - 1;
+        unsigned shift = ins->dest_offset * 4; /* 32-bit words */
+        return (mask << shift);
 }