aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2020-03-09 20:19:29 -0400
committerMarge Bot <[email protected]>2020-03-10 19:25:59 +0000
commit9b8cb9f5aee3428e49d80b2154718cae6c29938c (patch)
tree331812c161774e0b2bdcdedcd5ce8efd4e2033f9 /src
parentba03e308b66b0b88f60b99d9d47851a5e1522e6e (diff)
panfrost: Move mir_to_bytemask to common code
...also so we can start sharing code properly between the panfrost compilers. Signed-off-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4139>
Diffstat (limited to 'src')
-rw-r--r--src/panfrost/bifrost/compiler.h1
-rw-r--r--src/panfrost/bifrost/meson.build1
-rw-r--r--src/panfrost/meson.build1
-rw-r--r--src/panfrost/midgard/compiler.h2
-rw-r--r--src/panfrost/midgard/meson.build1
-rw-r--r--src/panfrost/midgard/midgard_compile.c2
-rw-r--r--src/panfrost/midgard/mir.c49
-rw-r--r--src/panfrost/util/meson.build34
-rw-r--r--src/panfrost/util/pan_ir.c72
-rw-r--r--src/panfrost/util/pan_ir.h32
10 files changed, 146 insertions, 49 deletions
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index 3b2794095b4..14e0bc87567 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -29,6 +29,7 @@
#include "bifrost.h"
#include "compiler/nir/nir.h"
+#include "panfrost/util/pan_ir.h"
/* Bifrost opcodes are tricky -- the same op may exist on both FMA and
* ADD with two completely different opcodes, and opcodes can be varying
diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build
index 5eafb1bb178..acc54ee25bb 100644
--- a/src/panfrost/bifrost/meson.build
+++ b/src/panfrost/bifrost/meson.build
@@ -33,6 +33,7 @@ libpanfrost_bifrost = static_library(
[libpanfrost_bifrost_files],
include_directories : [inc_common, inc_include, inc_src],
dependencies: [idep_nir],
+ link_with: [libpanfrost_util],
c_args : [c_vis_args, no_override_init_args],
cpp_args : [cpp_vis_args],
build_by_default : false,
diff --git a/src/panfrost/meson.build b/src/panfrost/meson.build
index aecbb7018c8..6ea0739b112 100644
--- a/src/panfrost/meson.build
+++ b/src/panfrost/meson.build
@@ -28,6 +28,7 @@ inc_panfrost = include_directories([
])
subdir('shared')
+subdir('util')
subdir('midgard')
subdir('bifrost')
subdir('pandecode')
diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 8ee99ab3549..51ac9566f2e 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -38,6 +38,7 @@
#include "main/mtypes.h"
#include "compiler/nir_types.h"
#include "compiler/nir/nir.h"
+#include "panfrost/util/pan_ir.h"
/* Forward declare */
struct midgard_block;
@@ -553,7 +554,6 @@ midgard_reg_mode mir_srcsize(midgard_instruction *ins, unsigned i);
unsigned mir_bytes_for_mode(midgard_reg_mode mode);
midgard_reg_mode mir_mode_for_destsize(unsigned size);
uint16_t mir_from_bytemask(uint16_t bytemask, midgard_reg_mode mode);
-uint16_t mir_to_bytemask(midgard_reg_mode mode, unsigned mask);
uint16_t mir_bytemask(midgard_instruction *ins);
uint16_t mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode);
void mir_set_bytemask(midgard_instruction *ins, uint16_t bytemask);
diff --git a/src/panfrost/midgard/meson.build b/src/panfrost/midgard/meson.build
index af2c09d5902..ba69b3fe55a 100644
--- a/src/panfrost/midgard/meson.build
+++ b/src/panfrost/midgard/meson.build
@@ -68,6 +68,7 @@ libpanfrost_midgard = static_library(
dependencies: [
idep_nir
],
+ link_with: [libpanfrost_util],
c_args : [c_vis_args, no_override_init_args],
cpp_args : [cpp_vis_args],
build_by_default : false,
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index eb50e215d9e..a312f5e1cfa 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -1216,7 +1216,7 @@ mir_set_intr_mask(nir_instr *instr, midgard_instruction *ins, bool is_read)
}
/* Once we have the NIR mask, we need to normalize to work in 32-bit space */
- unsigned bytemask = mir_to_bytemask(mir_mode_for_destsize(dsize), nir_mask);
+ unsigned bytemask = pan_to_bytemask(dsize, nir_mask);
mir_set_bytemask(ins, bytemask);
if (dsize == 64)
diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c
index 2acfe445a2b..772b6956de3 100644
--- a/src/panfrost/midgard/mir.c
+++ b/src/panfrost/midgard/mir.c
@@ -310,51 +310,6 @@ mir_mode_for_destsize(unsigned size)
}
}
-
-/* Converts per-component mask to a byte mask */
-
-uint16_t
-mir_to_bytemask(midgard_reg_mode mode, unsigned mask)
-{
- switch (mode) {
- case midgard_reg_mode_8:
- return mask;
-
- case midgard_reg_mode_16: {
- unsigned space =
- (mask & 0x1) |
- ((mask & 0x2) << (2 - 1)) |
- ((mask & 0x4) << (4 - 2)) |
- ((mask & 0x8) << (6 - 3)) |
- ((mask & 0x10) << (8 - 4)) |
- ((mask & 0x20) << (10 - 5)) |
- ((mask & 0x40) << (12 - 6)) |
- ((mask & 0x80) << (14 - 7));
-
- return space | (space << 1);
- }
-
- case midgard_reg_mode_32: {
- unsigned space =
- (mask & 0x1) |
- ((mask & 0x2) << (4 - 1)) |
- ((mask & 0x4) << (8 - 2)) |
- ((mask & 0x8) << (12 - 3));
-
- return space | (space << 1) | (space << 2) | (space << 3);
- }
-
- case midgard_reg_mode_64: {
- unsigned A = (mask & 0x1) ? 0xFF : 0x00;
- unsigned B = (mask & 0x2) ? 0xFF : 0x00;
- return A | (B << 8);
- }
-
- default:
- unreachable("Invalid register mode");
- }
-}
-
/* ...and the inverse */
unsigned
@@ -417,7 +372,7 @@ mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode)
uint16_t
mir_bytemask(midgard_instruction *ins)
{
- return mir_to_bytemask(mir_typesize(ins), ins->mask);
+ return pan_to_bytemask(mir_bytes_for_mode(mir_typesize(ins)) * 8, ins->mask);
}
void
@@ -473,7 +428,7 @@ mir_bytemask_of_read_components_single(unsigned *swizzle, unsigned inmask, midga
cmask |= (1 << swizzle[c]);
}
- return mir_to_bytemask(mode, cmask);
+ return pan_to_bytemask(mir_bytes_for_mode(mode) * 8, cmask);
}
uint16_t
diff --git a/src/panfrost/util/meson.build b/src/panfrost/util/meson.build
new file mode 100644
index 00000000000..63ca75697e3
--- /dev/null
+++ b/src/panfrost/util/meson.build
@@ -0,0 +1,34 @@
+# Copyright © 2018 Rob Clark
+# Copyright © 2019 Collabora
+
+# 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 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.
+
+libpanfrost_util_files = files(
+ 'pan_ir.c',
+ 'pan_ir.h',
+)
+
+libpanfrost_util = static_library(
+ 'panfrost_util',
+ [libpanfrost_util_files],
+ include_directories : [inc_common],
+ c_args : [c_vis_args, no_override_init_args],
+ cpp_args : [cpp_vis_args],
+ build_by_default : false,
+)
diff --git a/src/panfrost/util/pan_ir.c b/src/panfrost/util/pan_ir.c
new file mode 100644
index 00000000000..95f8e6b5326
--- /dev/null
+++ b/src/panfrost/util/pan_ir.c
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ *
+ * Authors (Collabora):
+ * Alyssa Rosenzweig <[email protected]>
+ */
+
+#include "pan_ir.h"
+#include "util/macros.h"
+
+/* Converts a per-component mask to a byte mask */
+
+uint16_t
+pan_to_bytemask(unsigned bytes, unsigned mask)
+{
+ switch (bytes) {
+ case 8:
+ return mask;
+
+ case 16: {
+ unsigned space =
+ (mask & 0x1) |
+ ((mask & 0x2) << (2 - 1)) |
+ ((mask & 0x4) << (4 - 2)) |
+ ((mask & 0x8) << (6 - 3)) |
+ ((mask & 0x10) << (8 - 4)) |
+ ((mask & 0x20) << (10 - 5)) |
+ ((mask & 0x40) << (12 - 6)) |
+ ((mask & 0x80) << (14 - 7));
+
+ return space | (space << 1);
+ }
+
+ case 32: {
+ unsigned space =
+ (mask & 0x1) |
+ ((mask & 0x2) << (4 - 1)) |
+ ((mask & 0x4) << (8 - 2)) |
+ ((mask & 0x8) << (12 - 3));
+
+ return space | (space << 1) | (space << 2) | (space << 3);
+ }
+
+ case 64: {
+ unsigned A = (mask & 0x1) ? 0xFF : 0x00;
+ unsigned B = (mask & 0x2) ? 0xFF : 0x00;
+ return A | (B << 8);
+ }
+
+ default:
+ unreachable("Invalid register mode");
+ }
+}
diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h
new file mode 100644
index 00000000000..e6cb7e5a95e
--- /dev/null
+++ b/src/panfrost/util/pan_ir.h
@@ -0,0 +1,32 @@
+/*
+ * 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 __PAN_IR_H
+#define __PAN_IR_H
+
+#include <stdint.h>
+
+uint16_t
+pan_to_bytemask(unsigned bytes, unsigned mask);
+
+#endif