Path: blob/21.2-virgl/src/panfrost/bifrost/bi_opcodes.c.py
4564 views
#1# Copyright (C) 2020 Collabora, Ltd.2#3# Permission is hereby granted, free of charge, to any person obtaining a4# copy of this software and associated documentation files (the "Software"),5# to deal in the Software without restriction, including without limitation6# the rights to use, copy, modify, merge, publish, distribute, sublicense,7# and/or sell copies of the Software, and to permit persons to whom the8# Software is furnished to do so, subject to the following conditions:9#10# The above copyright notice and this permission notice (including the next11# paragraph) shall be included in all copies or substantial portions of the12# Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20# IN THE SOFTWARE.2122TEMPLATE = """#include "bi_opcodes.h"23<%24def hasmod(mods, name):25return 1 if name in mods else 026%>27struct bi_op_props bi_opcode_props[BI_NUM_OPCODES] = {28% for opcode in sorted(mnemonics):29<%30add = instructions["+" + opcode][0][1] if "+" + opcode in instructions else None31size = typesize(opcode)32message = add["message"].upper() if add else "NONE"33sr_count = add["staging_count"].upper() if add else "0"34sr_read = int(add["staging"] in ["r", "rw"] if add else False)35sr_write = int(add["staging"] in ["w", "rw"] if add else False)36last = int(bool(add["last"]) if add else False)37table = int(bool(add["table"]) if add else False)38branch = int(opcode.startswith('BRANCH'))39has_fma = int("*" + opcode in instructions)40has_add = int("+" + opcode in instructions)41mods = ops[opcode]['modifiers']42clamp = hasmod(mods, 'clamp')43not_result = hasmod(mods, 'not_result')44abs = hasmod(mods, 'abs0') | (hasmod(mods, 'abs1') << 1) | (hasmod(mods, 'abs2') << 2)45neg = hasmod(mods, 'neg0') | (hasmod(mods, 'neg1') << 1) | (hasmod(mods, 'neg2') << 2)46m_not = hasmod(mods, 'not1')47%>48[BI_OPCODE_${opcode.replace('.', '_').upper()}] = {49"${opcode}", BIFROST_MESSAGE_${message}, BI_SIZE_${size},50BI_SR_COUNT_${sr_count}, ${sr_read}, ${sr_write}, ${last}, ${branch},51${table}, ${has_fma}, ${has_add}, ${clamp}, ${not_result}, ${abs},52${neg}, ${m_not},53},54% endfor55};"""5657import sys58from bifrost_isa import *59from mako.template import Template6061instructions = parse_instructions(sys.argv[1], include_pseudo = True)62ir_instructions = partition_mnemonics(instructions)63mnemonics = set(x[1:] for x in instructions.keys())6465print(Template(COPYRIGHT + TEMPLATE).render(ops = ir_instructions, mnemonics = mnemonics, instructions = instructions, typesize = typesize))666768