Path: blob/21.2-virgl/src/panfrost/bifrost/bi_opcodes.h.py
4564 views
# Copyright (C) 2020 Collabora, Ltd.1#2# Permission is hereby granted, free of charge, to any person obtaining a3# copy of this software and associated documentation files (the "Software"),4# to deal in the Software without restriction, including without limitation5# the rights to use, copy, modify, merge, publish, distribute, sublicense,6# and/or sell copies of the Software, and to permit persons to whom the7# Software is furnished to do so, subject to the following conditions:8#9# The above copyright notice and this permission notice (including the next10# paragraph) shall be included in all copies or substantial portions of the11# Software.12#13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS19# IN THE SOFTWARE.2021TEMPLATE = """22#ifndef _BI_OPCODES_H_23#define _BI_OPCODES_H_2425#include "bifrost.h"2627% for mod in sorted(modifiers):28% if len(modifiers[mod]) > 2: # otherwise just boolean29enum bi_${mod.lower()} {30% for i, state in enumerate(modifiers[mod]):31% if state != "reserved":32BI_${mod.upper()}_${state.upper()} = ${i},33% endif34% endfor35};3637% endif38% endfor39enum bi_opcode {40% for opcode in sorted(mnemonics):41BI_OPCODE_${opcode.replace('.', '_').upper()},42% endfor43BI_NUM_OPCODES44};4546/* Number of staging registers accessed, note this fits into 3-bits */4748enum bi_sr_count {49/* fixed counts */50BI_SR_COUNT_0 = 0,51BI_SR_COUNT_1 = 1,52BI_SR_COUNT_2 = 2,53BI_SR_COUNT_3 = 3,54BI_SR_COUNT_4 = 4,5556/* derived from register_format and vecsize */57BI_SR_COUNT_FORMAT = 5,5859/* equal to vecsize alone */60BI_SR_COUNT_VECSIZE = 6,6162/* specified directly as the sr_count immediate */63BI_SR_COUNT_SR_COUNT = 764};6566enum bi_size {67BI_SIZE_8 = 0,68BI_SIZE_16,69BI_SIZE_24,70BI_SIZE_32,71BI_SIZE_48,72BI_SIZE_64,73BI_SIZE_96,74BI_SIZE_128,75};7677/* Description of an opcode in the IR */78struct bi_op_props {79const char *name;8081enum bifrost_message_type message : 4;82enum bi_size size : 3;83enum bi_sr_count sr_count : 3;84bool sr_read : 1;85bool sr_write : 1;86bool last : 1;87bool branch : 1;88bool table : 1;89bool fma : 1;90bool add : 1;9192/* Supported propagable modifiers */93bool clamp : 1;94bool not_result : 1;95unsigned abs : 3;96unsigned neg : 3;97bool not : 1;98};99100/* Generated in bi_opcodes.c.py */101extern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES];102103#endif104"""105106import sys107from bifrost_isa import *108from mako.template import Template109110instructions = parse_instructions(sys.argv[1], include_pseudo = True)111ir_instructions = partition_mnemonics(instructions)112modifier_lists = order_modifiers(ir_instructions)113114# Generate sorted list of mnemonics without regard to unit115mnemonics = set(x[1:] for x in instructions.keys())116117print(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists))118119120