pan/bi: Move packing helpers to dedicated file
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 14 Sep 2020 17:44:52 +0000 (13:44 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 16 Sep 2020 20:05:34 +0000 (20:05 +0000)
We'll need to access them from the autogenerated section.

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

src/panfrost/bifrost/bi_pack.c
src/panfrost/bifrost/bi_pack_helpers.h [new file with mode: 0644]

index b16a670..aa0db55 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "compiler.h"
 #include "bi_print.h"
+#include "bi_pack_helpers.h"
 
 #define RETURN_PACKED(str) { \
         uint64_t temp = 0; \
@@ -401,57 +402,6 @@ bi_pack_registers(bi_registers regs)
         return packed;
 }
 
-static void
-bi_set_data_register(bi_clause *clause, unsigned idx)
-{
-        assert(idx & BIR_INDEX_REGISTER);
-        unsigned reg = idx & ~BIR_INDEX_REGISTER;
-        assert(reg <= 63);
-        clause->data_register = reg;
-}
-
-static void
-bi_read_data_register(bi_clause *clause, bi_instruction *ins)
-{
-        bi_set_data_register(clause, ins->src[0]);
-}
-
-static void
-bi_write_data_register(bi_clause *clause, bi_instruction *ins)
-{
-        bi_set_data_register(clause, ins->dest);
-}
-
-static enum bifrost_packed_src
-bi_get_src_reg_port(bi_registers *regs, unsigned src)
-{
-        unsigned reg = src & ~BIR_INDEX_REGISTER;
-
-        if (regs->port[0] == reg && regs->enabled[0])
-                return BIFROST_SRC_PORT0;
-        else if (regs->port[1] == reg && regs->enabled[1])
-                return BIFROST_SRC_PORT1;
-        else if (regs->port[3] == reg && regs->read_port3)
-                return BIFROST_SRC_PORT3;
-        else
-                unreachable("Tried to access register with no port");
-}
-
-static enum bifrost_packed_src
-bi_get_src(bi_instruction *ins, bi_registers *regs, unsigned s)
-{
-        unsigned src = ins->src[s];
-
-        if (src & BIR_INDEX_REGISTER)
-                return bi_get_src_reg_port(regs, src);
-        else if (src & BIR_INDEX_PASS)
-                return src & ~BIR_INDEX_PASS;
-        else {
-                bi_print_instruction(ins, stderr);
-                unreachable("Unknown src in above instruction");
-        }
-}
-
 /* Constructs a packed 2-bit swizzle for a 16-bit vec2 source. Source must be
  * 16-bit and written components must correspond to valid swizzles (component x
  * or y). */
diff --git a/src/panfrost/bifrost/bi_pack_helpers.h b/src/panfrost/bifrost/bi_pack_helpers.h
new file mode 100644 (file)
index 0000000..d806d33
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2020 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __BI_PACK_HELPERS_H
+#define __BI_PACK_HELPERS_H
+
+/* Helpers used by the autogenerated packing routines */
+
+#include "compiler.h"
+
+static inline void
+bi_set_data_register(bi_clause *clause, unsigned idx)
+{
+        assert(idx & BIR_INDEX_REGISTER);
+        unsigned reg = idx & ~BIR_INDEX_REGISTER;
+        assert(reg <= 63);
+        clause->data_register = reg;
+}
+
+static inline void
+bi_read_data_register(bi_clause *clause, bi_instruction *ins)
+{
+        bi_set_data_register(clause, ins->src[0]);
+}
+
+static inline void
+bi_write_data_register(bi_clause *clause, bi_instruction *ins)
+{
+        bi_set_data_register(clause, ins->dest);
+}
+
+static inline enum bifrost_packed_src
+bi_get_src_reg_port(bi_registers *regs, unsigned src)
+{
+        unsigned reg = src & ~BIR_INDEX_REGISTER;
+
+        if (regs->port[0] == reg && regs->enabled[0])
+                return BIFROST_SRC_PORT0;
+        else if (regs->port[1] == reg && regs->enabled[1])
+                return BIFROST_SRC_PORT1;
+        else if (regs->port[3] == reg && regs->read_port3)
+                return BIFROST_SRC_PORT3;
+        else
+                unreachable("Tried to access register with no port");
+}
+
+static inline enum bifrost_packed_src
+bi_get_src(bi_instruction *ins, bi_registers *regs, unsigned s)
+{
+        unsigned src = ins->src[s];
+
+        if (src & BIR_INDEX_REGISTER)
+                return bi_get_src_reg_port(regs, src);
+        else if (src & BIR_INDEX_PASS)
+                return src & ~BIR_INDEX_PASS;
+        else {
+#ifndef NDEBUG
+                bi_print_instruction(ins, stderr);
+#endif
+                unreachable("Unknown src in above instruction");
+        }
+}
+
+#endif