pan/bi: Add constant state constructor
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Sat, 6 Feb 2021 00:53:49 +0000 (19:53 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 8 Feb 2021 14:07:29 +0000 (14:07 +0000)
Based on the tuple state's constants, satisfying the pcrel invariant we
impose.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8354>

src/panfrost/bifrost/bi_schedule.c

index 74b4676..3e76816 100644 (file)
@@ -951,6 +951,35 @@ bi_rewrite_constants_to_pass(bi_tuple *tuple, uint64_t constant, bool pcrel)
         }
 }
 
+/* Constructs a constant state given a tuple state. This has the
+ * postcondition that pcrel applies to the first constant by convention,
+ * and PC-relative constants will be #0 by convention here, so swap to
+ * match if needed */
+
+static struct bi_const_state
+bi_get_const_state(struct bi_tuple_state *tuple)
+{
+        struct bi_const_state consts = {
+                .constant_count = tuple->constant_count,
+                .constants[0] = tuple->constants[0],
+                .constants[1] = tuple->constants[1],
+                .pcrel = tuple->add && tuple->add->branch_target,
+        };
+
+        /* pcrel applies to the first constant by convention, and
+         * PC-relative constants will be #0 by convention here, so swap
+         * to match if needed */
+        if (consts.pcrel && consts.constants[0]) {
+                assert(consts.constant_count == 2);
+                assert(consts.constants[1] == 0);
+
+                consts.constants[1] = consts.constants[0];
+                consts.constants[0] = 0;
+        }
+
+        return consts;
+}
+
 #ifndef NDEBUG
 
 static bi_builder *