pan/bi: Generate bi_opcodes.h

A header for enums for each opcode and each modifier.

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:
Alyssa Rosenzweig 2020-11-27 13:51:00 -05:00
parent bfa1163980
commit f9084b6c3f
2 changed files with 111 additions and 1 deletions

View File

@ -0,0 +1,96 @@
# 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 = """
#ifndef _BI_OPCODES_H_
#define _BI_OPCODES_H_
#include "bifrost.h"
% for mod in sorted(modifiers):
% if len(modifiers[mod]) > 2: # otherwise just boolean
enum bi_${mod.lower()} {
% for i, state in enumerate(modifiers[mod]):
% if state != "reserved":
BI_${mod.upper()}_${state.upper()} = ${i},
% endif
% endfor
};
% endif
% endfor
enum bi_opcode {
% for opcode in sorted(mnemonics):
BI_OPCODE_${opcode.replace('.', '_').upper()},
% endfor
BI_NUM_OPCODES
};
/* Number of staging registers accessed, note this fits into 3-bits */
enum bi_sr_count {
/* fixed counts */
BI_SR_COUNT_0 = 0,
BI_SR_COUNT_1 = 1,
BI_SR_COUNT_2 = 2,
BI_SR_COUNT_3 = 3,
BI_SR_COUNT_4 = 4,
/* derived from register_format and vecsize */
BI_SR_COUNT_FORMAT = 5,
/* equal to vecsize alone */
BI_SR_COUNT_VECSIZE = 6,
/* specified directly as the sr_count immediate */
BI_SR_COUNT_SR_COUNT = 7
};
/* Description of an opcode in the IR */
struct bi_op_props {
const char *name;
enum bifrost_message_type message : 4;
enum bi_sr_count sr_count : 3;
bool sr_read : 1;
bool sr_write : 1;
bool fma : 1;
bool add : 1;
};
/* Generated in bi_opcodes.c.py */
extern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES];
#endif
"""
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)
modifier_lists = order_modifiers(ir_instructions)
# Generate sorted list of mnemonics without regard to unit
mnemonics = set(x[1:] for x in instructions.keys())
print(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists))

View File

@ -69,6 +69,20 @@ idep_bi_generated_pack_h = declare_dependency(
include_directories : include_directories('.'),
)
bi_opcodes_h = custom_target(
'bi_opcodes.h',
input : ['bi_opcodes.h.py', 'ISA.xml'],
output : 'bi_opcodes.h',
command : [prog_python, '@INPUT@'],
capture : true,
depend_files : files('bifrost_isa.py'),
)
idep_bi_opcodes_h = declare_dependency(
sources : [bi_opcodes_h],
include_directories : include_directories('.'),
)
libpanfrost_bifrost_disasm = static_library(
'panfrost_bifrost_disasm',
['disassemble.c', 'bi_print_common.c', bifrost_gen_disasm_c],
@ -84,7 +98,7 @@ libpanfrost_bifrost = static_library(
'panfrost_bifrost',
[libpanfrost_bifrost_files, bifrost_nir_algebraic_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],
dependencies: [idep_nir, idep_bi_generated_pack_h, idep_bi_opcodes_h],
link_with: [libpanfrost_util, libpanfrost_bifrost_disasm],
c_args : [no_override_init_args],
gnu_symbol_visibility : 'hidden',