17ec681f3Smrg# Copyright (C) 2020 Collabora, Ltd. 27ec681f3Smrg# 37ec681f3Smrg# Permission is hereby granted, free of charge, to any person obtaining a 47ec681f3Smrg# copy of this software and associated documentation files (the "Software"), 57ec681f3Smrg# to deal in the Software without restriction, including without limitation 67ec681f3Smrg# the rights to use, copy, modify, merge, publish, distribute, sublicense, 77ec681f3Smrg# and/or sell copies of the Software, and to permit persons to whom the 87ec681f3Smrg# Software is furnished to do so, subject to the following conditions: 97ec681f3Smrg# 107ec681f3Smrg# The above copyright notice and this permission notice (including the next 117ec681f3Smrg# paragraph) shall be included in all copies or substantial portions of the 127ec681f3Smrg# Software. 137ec681f3Smrg# 147ec681f3Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157ec681f3Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167ec681f3Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 177ec681f3Smrg# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 187ec681f3Smrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 197ec681f3Smrg# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 207ec681f3Smrg# IN THE SOFTWARE. 217ec681f3Smrg 227ec681f3SmrgTEMPLATE = """ 237ec681f3Smrg#ifndef _BI_OPCODES_H_ 247ec681f3Smrg#define _BI_OPCODES_H_ 257ec681f3Smrg 267ec681f3Smrg#include "bifrost.h" 277ec681f3Smrg 287ec681f3Smrg% for mod in sorted(modifiers): 297ec681f3Smrg% if len(modifiers[mod]) > 2: # otherwise just boolean 307ec681f3Smrgenum bi_${mod.lower()} { 317ec681f3Smrg% for i, state in enumerate(modifiers[mod]): 327ec681f3Smrg% if state != "reserved": 337ec681f3Smrg BI_${mod.upper()}_${state.upper()} = ${i}, 347ec681f3Smrg% endif 357ec681f3Smrg% endfor 367ec681f3Smrg}; 377ec681f3Smrg 387ec681f3Smrg% endif 397ec681f3Smrg% endfor 407ec681f3Smrgenum bi_opcode { 417ec681f3Smrg% for opcode in sorted(mnemonics): 427ec681f3Smrg BI_OPCODE_${opcode.replace('.', '_').upper()}, 437ec681f3Smrg% endfor 447ec681f3Smrg BI_NUM_OPCODES 457ec681f3Smrg}; 467ec681f3Smrg 477ec681f3Smrg/* Number of staging registers accessed, note this fits into 3-bits */ 487ec681f3Smrg 497ec681f3Smrgenum bi_sr_count { 507ec681f3Smrg /* fixed counts */ 517ec681f3Smrg BI_SR_COUNT_0 = 0, 527ec681f3Smrg BI_SR_COUNT_1 = 1, 537ec681f3Smrg BI_SR_COUNT_2 = 2, 547ec681f3Smrg BI_SR_COUNT_3 = 3, 557ec681f3Smrg BI_SR_COUNT_4 = 4, 567ec681f3Smrg 577ec681f3Smrg /* derived from register_format and vecsize */ 587ec681f3Smrg BI_SR_COUNT_FORMAT = 5, 597ec681f3Smrg 607ec681f3Smrg /* equal to vecsize alone */ 617ec681f3Smrg BI_SR_COUNT_VECSIZE = 6, 627ec681f3Smrg 637ec681f3Smrg /* specified directly as the sr_count immediate */ 647ec681f3Smrg BI_SR_COUNT_SR_COUNT = 7 657ec681f3Smrg}; 667ec681f3Smrg 677ec681f3Smrgenum bi_size { 687ec681f3Smrg BI_SIZE_8 = 0, 697ec681f3Smrg BI_SIZE_16, 707ec681f3Smrg BI_SIZE_24, 717ec681f3Smrg BI_SIZE_32, 727ec681f3Smrg BI_SIZE_48, 737ec681f3Smrg BI_SIZE_64, 747ec681f3Smrg BI_SIZE_96, 757ec681f3Smrg BI_SIZE_128, 767ec681f3Smrg}; 777ec681f3Smrg 787ec681f3Smrg/* Description of an opcode in the IR */ 797ec681f3Smrgstruct bi_op_props { 807ec681f3Smrg const char *name; 817ec681f3Smrg 827ec681f3Smrg enum bifrost_message_type message : 4; 837ec681f3Smrg enum bi_size size : 3; 847ec681f3Smrg enum bi_sr_count sr_count : 3; 857ec681f3Smrg bool sr_read : 1; 867ec681f3Smrg bool sr_write : 1; 877ec681f3Smrg bool last : 1; 887ec681f3Smrg bool branch : 1; 897ec681f3Smrg bool table : 1; 907ec681f3Smrg bool fma : 1; 917ec681f3Smrg bool add : 1; 927ec681f3Smrg 937ec681f3Smrg /* Supported propagable modifiers */ 947ec681f3Smrg bool clamp : 1; 957ec681f3Smrg bool not_result : 1; 967ec681f3Smrg unsigned abs : 3; 977ec681f3Smrg unsigned neg : 3; 987ec681f3Smrg bool not : 1; 997ec681f3Smrg}; 1007ec681f3Smrg 1017ec681f3Smrg/* Generated in bi_opcodes.c.py */ 1027ec681f3Smrgextern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES]; 1037ec681f3Smrg 1047ec681f3Smrg#endif 1057ec681f3Smrg""" 1067ec681f3Smrg 1077ec681f3Smrgimport sys 1087ec681f3Smrgfrom bifrost_isa import * 1097ec681f3Smrgfrom mako.template import Template 1107ec681f3Smrg 1117ec681f3Smrginstructions = parse_instructions(sys.argv[1], include_pseudo = True) 1127ec681f3Smrgir_instructions = partition_mnemonics(instructions) 1137ec681f3Smrgmodifier_lists = order_modifiers(ir_instructions) 1147ec681f3Smrg 1157ec681f3Smrg# Generate sorted list of mnemonics without regard to unit 1167ec681f3Smrgmnemonics = set(x[1:] for x in instructions.keys()) 1177ec681f3Smrg 1187ec681f3Smrgprint(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists)) 119