mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-31 17:50:35 +01:00
pan/bi: Generate bi_opcodes.c
So we can lookup various properties rather than generating piles of switch statements. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8215>
This commit is contained in:
parent
2d4597de2e
commit
25c9946883
2 changed files with 61 additions and 1 deletions
51
src/panfrost/bifrost/bi_opcodes.c.py
Normal file
51
src/panfrost/bifrost/bi_opcodes.c.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# 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.
|
||||
|
||||
TEMPLATE = """#include "bi_opcodes.h"
|
||||
|
||||
struct bi_op_props bi_opcode_props[BI_NUM_OPCODES] = {
|
||||
% for opcode in sorted(mnemonics):
|
||||
<%
|
||||
add = instructions["+" + opcode][0][1] if "+" + opcode in instructions else None
|
||||
message = add["message"].upper() if add else "NONE"
|
||||
sr_count = add["staging_count"].upper() if add else "0"
|
||||
sr_read = int(add["staging"] in ["r", "rw"] if add else False)
|
||||
sr_write = int(add["staging"] in ["w", "rw"] if add else False)
|
||||
has_fma = int("*" + opcode in instructions)
|
||||
has_add = int("+" + opcode in instructions)
|
||||
%>
|
||||
[BI_OPCODE_${opcode.replace('.', '_').upper()}] = {
|
||||
"${opcode}", BIFROST_MESSAGE_${message}, BI_SR_COUNT_${sr_count},
|
||||
${sr_read}, ${sr_write}, ${has_fma}, ${has_add},
|
||||
},
|
||||
% endfor
|
||||
};"""
|
||||
|
||||
import sys
|
||||
from bifrost_isa import *
|
||||
from mako.template import Template
|
||||
|
||||
instructions = parse_instructions(sys.argv[1], include_pseudo = True)
|
||||
ir_instructions = partition_mnemonics(instructions)
|
||||
mnemonics = set(x[1:] for x in instructions.keys())
|
||||
|
||||
print(Template(COPYRIGHT + TEMPLATE).render(ops = ir_instructions, mnemonics = mnemonics, instructions = instructions))
|
||||
|
|
@ -55,6 +55,15 @@ bifrost_gen_disasm_c = custom_target(
|
|||
depend_files : files('bifrost_isa.py'),
|
||||
)
|
||||
|
||||
bi_opcodes_c = custom_target(
|
||||
'bi_opcodes.c',
|
||||
input : ['bi_opcodes.c.py', 'ISA.xml'],
|
||||
output : 'bi_opcodes.c',
|
||||
command : [prog_python, '@INPUT@'],
|
||||
capture : true,
|
||||
depend_files : files('bifrost_isa.py'),
|
||||
)
|
||||
|
||||
bi_generated_pack_h = custom_target(
|
||||
'bi_generated_pack.h',
|
||||
input : ['gen_pack.py', 'ISA.xml'],
|
||||
|
|
@ -96,7 +105,7 @@ libpanfrost_bifrost_disasm = static_library(
|
|||
|
||||
libpanfrost_bifrost = static_library(
|
||||
'panfrost_bifrost',
|
||||
[libpanfrost_bifrost_files, bifrost_nir_algebraic_c],
|
||||
[libpanfrost_bifrost_files, bifrost_nir_algebraic_c, bi_opcodes_c],
|
||||
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_panfrost_hw],
|
||||
dependencies: [idep_nir, idep_bi_generated_pack_h, idep_bi_opcodes_h],
|
||||
link_with: [libpanfrost_util, libpanfrost_bifrost_disasm],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue