pan/va: Build opcode info structures
authorAlyssa Rosenzweig <alyssa@collabora.com>
Fri, 23 Jul 2021 16:04:13 +0000 (12:04 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 25 Mar 2022 19:00:13 +0000 (19:00 +0000)
Filled out the new structures from XML.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15223>

src/panfrost/bifrost/meson.build
src/panfrost/bifrost/valhall/meson.build
src/panfrost/bifrost/valhall/valhall.c.py [new file with mode: 0644]
src/panfrost/bifrost/valhall/valhall.h [new file with mode: 0644]

index 97d3957..7a1df35 100644 (file)
@@ -21,6 +21,8 @@
 
 subdir('valhall')
 
+inc_valhall = include_directories(['.', 'valhall'])
+
 libpanfrost_bifrost_files = files(
   'bi_helper_invocations.c',
   'bi_layout.c',
@@ -134,8 +136,8 @@ libpanfrost_bifrost_disasm = static_library(
 
 libpanfrost_bifrost = static_library(
   'panfrost_bifrost',
-  [libpanfrost_bifrost_files, bi_opcodes_c, bi_printer_c, bi_packer_c, bifrost_nir_algebraic_c],
-  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_panfrost_hw],
+  [libpanfrost_bifrost_files, bi_opcodes_c, bi_printer_c, bi_packer_c, bifrost_nir_algebraic_c, valhall_c],
+  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_panfrost_hw, inc_valhall],
   dependencies: [idep_nir, idep_bi_opcodes_h, idep_bi_builder_h],
   link_with: [libpanfrost_util, libpanfrost_bifrost_disasm, libpanfrost_valhall_disasm],
   c_args : [no_override_init_args],
index ef8ea8c..e78a4ab 100644 (file)
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+valhall_c = custom_target(
+  'valhall_c',
+  input : ['valhall.c.py', 'ISA.xml'],
+  output : 'valhall.c',
+  command : [prog_python, '@INPUT@'],
+  capture : true,
+  depend_files : files('valhall.py'),
+)
+
 valhall_disasm_c = custom_target(
   'valhall_disasm_c',
   input : ['disasm.py', 'ISA.xml'],
diff --git a/src/panfrost/bifrost/valhall/valhall.c.py b/src/panfrost/bifrost/valhall/valhall.c.py
new file mode 100644 (file)
index 0000000..18ccf9e
--- /dev/null
@@ -0,0 +1,166 @@
+#encoding=utf-8
+
+# Copyright (C) 2021 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.
+
+from valhall import immediates, instructions, typesize
+from mako.template import Template
+from mako import exceptions
+
+SKIP = set([
+        # Extra conversions
+        "S8_TO_S16",
+        "S8_TO_F16",
+        "U8_TO_U16",
+        "U8_TO_F16",
+
+        # Saturating multiplies
+        "IMUL.s32",
+        "IMUL.v2s16",
+        "IMUL.v4s8",
+
+        # 64-bit support
+        "NOT.i64",
+        "IADD.u64",
+        "IADD.s64",
+        "ISUB.u64",
+        "ISUB.s64",
+        "IMULD.u64",
+        "SHADDX.u64",
+        "SHADDX.s64",
+        "IMULD.u64",
+        "CLPER.s64",
+        "CLPER.u64",
+        "LSHIFT_AND.i64",
+        "RSHIFT_AND.i64",
+        "LSHIFT_OR.i64",
+        "RSHIFT_OR.i64",
+        "LSHIFT_XOR.i64",
+        "RSHIFT_XOR.i64",
+        "ATOM.i64",
+        "ATOM_RETURN.i64",
+        "ATOM1_RETURN.i64",
+
+        # CLPER widens
+        "CLPER.s32",
+        "CLPER.v2s16",
+        "CLPER.v4s8",
+        "CLPER.v2u16",
+        "CLPER.v4u8",
+
+        # Special cased
+        "FMA_RSCALE_N.f32",
+        "FMA_RSCALE_LEFT.f32",
+        "FMA_RSCALE_SCALE16.f32",
+
+        # Deprecated instruction
+        "NOT.i32",
+
+        # TODO
+        "IDP.v4s8",
+        "IDP.v4u8",
+        "TEX_DUAL",
+        "TODO.VAR_TEX",
+    ])
+
+template = """
+#include "valhall.h"
+#include "bi_opcodes.h"
+
+const uint32_t valhall_immediates[32] = {
+% for imm in immediates:
+    ${hex(imm)},
+% endfor
+};
+
+<%
+def ibool(x):
+    return '1' if x else '0'
+
+def hasmod(x, mod):
+    return ibool(any([x.name == mod for x in op.modifiers]))
+
+%>
+const struct va_opcode_info
+valhall_opcodes[BI_NUM_OPCODES] = {
+% for op in instructions:
+% if op.name not in skip:
+<%
+    name = op.name
+    if name == 'BRANCHZ':
+        name = 'BRANCHZ.i16'
+    elif name == 'CUBEFACE2':
+        name = 'CUBEFACE2_V9'
+
+    sr_control = 0
+
+    if len(op.staging) > 0:
+        sr_control = op.staging[0].encoded_flags >> 6
+%>
+    [BI_OPCODE_${name.replace('.', '_').upper()}] = {
+        .exact = ${hex(exact(op))}ULL,
+        .srcs = {
+% for src in ([sr for sr in op.staging if sr.read] + op.srcs):
+            {
+                .absneg = ${ibool(src.absneg)},
+                .swizzle = ${ibool(src.swizzle)},
+                .notted = ${ibool(src.notted)},
+                .widen = ${ibool(src.widen)},
+                .lanes = ${ibool(src.lanes)},
+                .halfswizzle = ${ibool(src.halfswizzle)},
+                .lane = ${ibool(src.lane)},
+                .combine = ${ibool(src.combine)},
+% if src.size in [8, 16, 32, 64]:
+                .size = VA_SIZE_${src.size},
+% endif
+            },
+% endfor
+        },
+        .type_size = ${typesize(op.name)},
+        .has_dest = ${ibool(len(op.dests) > 0)},
+        .unit = VA_UNIT_${op.unit},
+        .nr_srcs = ${len(op.srcs)},
+        .nr_staging_srcs = ${sum([sr.read for sr in op.staging])},
+        .nr_staging_dests = ${sum([sr.write for sr in op.staging])},
+        .clamp = ${hasmod(x, 'clamp')},
+        .round_mode = ${hasmod(x, 'round_mode')},
+        .condition = ${hasmod(x, 'condition')},
+        .result_type = ${hasmod(x, 'result_type')},
+        .vecsize = ${hasmod(x, 'vector_size')},
+        .register_format = ${hasmod(x, 'register_format')},
+        .slot = ${hasmod(x, 'slot')},
+        .sr_count = ${hasmod(x, 'staging_register_count')},
+        .sr_write_count = ${hasmod(x, 'staging_register_write_count')},
+        .sr_control = ${sr_control},
+    },
+% endif
+% endfor
+};
+"""
+
+# Exact value to be ORed in to every opcode
+def exact_op(op):
+    return (op.opcode << 48) | (op.opcode2 << op.secondary_shift)
+
+try:
+    print(Template(template).render(immediates = immediates, instructions = instructions, skip = SKIP, exact = exact_op, typesize = typesize))
+except:
+    print(exceptions.text_error_template().render())
diff --git a/src/panfrost/bifrost/valhall/valhall.h b/src/panfrost/bifrost/valhall/valhall.h
new file mode 100644 (file)
index 0000000..debf1f7
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2021 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 <alyssa.rosenzweig@collabora.com>
+ */
+
+#ifndef __VALHALL_H
+#define __VALHALL_H
+
+#include <stdint.h>
+#include "bi_opcodes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const uint32_t valhall_immediates[32];
+
+enum va_size {
+   VA_SIZE_8 = 0,
+   VA_SIZE_16 = 1,
+   VA_SIZE_32 = 2,
+   VA_SIZE_64 = 3,
+};
+
+enum va_unit {
+   /** Fused floating-point multiply-add */
+   VA_UNIT_FMA = 0,
+
+   /** Type conversion and basic arithmetic */
+   VA_UNIT_CVT = 1,
+
+   /** Special function unit */
+   VA_UNIT_SFU = 2,
+
+   /** Varying */
+   VA_UNIT_V = 3,
+
+   /** General load/store */
+   VA_UNIT_LS = 4,
+
+   /** Texture */
+   VA_UNIT_T = 5,
+
+   /** Fused varying and texture */
+   VA_UNIT_VT = 6,
+
+   /** Produces a message for a unit not otherwise specified */
+   VA_UNIT_NONE = 7
+};
+
+struct va_src_info {
+   bool absneg : 1;
+   bool swizzle : 1;
+   bool notted : 1;
+   bool lane : 1;
+   bool lanes : 1;
+   bool halfswizzle : 1;
+   bool widen : 1;
+   bool combine : 1;
+   enum va_size size : 2;
+} __attribute__((packed));
+
+struct va_opcode_info {
+   uint64_t exact;
+   struct va_src_info srcs[4];
+   uint8_t type_size : 8;
+   enum va_unit unit : 3;
+   unsigned nr_srcs : 3;
+   unsigned nr_staging_srcs : 2;
+   unsigned nr_staging_dests : 2;
+   bool has_dest : 1;
+   bool clamp : 1;
+   bool round_mode : 1;
+   bool condition : 1;
+   bool result_type : 1;
+   bool vecsize : 1;
+   bool register_format : 1;
+   bool slot : 1;
+   bool sr_count : 1;
+   bool sr_write_count : 1;
+   unsigned sr_control : 2;
+};
+
+extern const struct va_opcode_info
+valhall_opcodes[BI_NUM_OPCODES];
+
+#ifdef __cplusplus
+} /* extern C */
+#endif
+
+#endif