1bf215546Sopenharmony_ci# Copyright (C) 2020 Collabora, Ltd. 2bf215546Sopenharmony_ci# 3bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a 4bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"), 5bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation 6bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense, 7bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the 8bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions: 9bf215546Sopenharmony_ci# 10bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next 11bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the 12bf215546Sopenharmony_ci# Software. 13bf215546Sopenharmony_ci# 14bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20bf215546Sopenharmony_ci# IN THE SOFTWARE. 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_ciTEMPLATE = """ 23bf215546Sopenharmony_ci#ifndef _BI_OPCODES_H_ 24bf215546Sopenharmony_ci#define _BI_OPCODES_H_ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "bifrost.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci% for mod in sorted(modifiers): 29bf215546Sopenharmony_ci% if len(modifiers[mod]) > 2: # otherwise just boolean 30bf215546Sopenharmony_cienum bi_${mod.lower()} { 31bf215546Sopenharmony_ci% for i, state in enumerate(modifiers[mod]): 32bf215546Sopenharmony_ci% if state != "reserved": 33bf215546Sopenharmony_ci BI_${mod.upper()}_${state.upper()} = ${i}, 34bf215546Sopenharmony_ci% endif 35bf215546Sopenharmony_ci% endfor 36bf215546Sopenharmony_ci}; 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci% endif 39bf215546Sopenharmony_ci% endfor 40bf215546Sopenharmony_cienum bi_opcode { 41bf215546Sopenharmony_ci% for opcode in sorted(mnemonics): 42bf215546Sopenharmony_ci BI_OPCODE_${opcode.replace('.', '_').upper()}, 43bf215546Sopenharmony_ci% endfor 44bf215546Sopenharmony_ci BI_NUM_OPCODES 45bf215546Sopenharmony_ci}; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci/* Number of staging registers accessed, note this fits into 3-bits */ 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_cienum bi_sr_count { 50bf215546Sopenharmony_ci /* fixed counts */ 51bf215546Sopenharmony_ci BI_SR_COUNT_0 = 0, 52bf215546Sopenharmony_ci BI_SR_COUNT_1 = 1, 53bf215546Sopenharmony_ci BI_SR_COUNT_2 = 2, 54bf215546Sopenharmony_ci BI_SR_COUNT_3 = 3, 55bf215546Sopenharmony_ci BI_SR_COUNT_4 = 4, 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci /* derived from register_format and vecsize */ 58bf215546Sopenharmony_ci BI_SR_COUNT_FORMAT = 5, 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci /* equal to vecsize alone */ 61bf215546Sopenharmony_ci BI_SR_COUNT_VECSIZE = 6, 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /* specified directly as the sr_count immediate */ 64bf215546Sopenharmony_ci BI_SR_COUNT_SR_COUNT = 7 65bf215546Sopenharmony_ci}; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_cienum bi_size { 68bf215546Sopenharmony_ci BI_SIZE_8 = 0, 69bf215546Sopenharmony_ci BI_SIZE_16, 70bf215546Sopenharmony_ci BI_SIZE_24, 71bf215546Sopenharmony_ci BI_SIZE_32, 72bf215546Sopenharmony_ci BI_SIZE_48, 73bf215546Sopenharmony_ci BI_SIZE_64, 74bf215546Sopenharmony_ci BI_SIZE_96, 75bf215546Sopenharmony_ci BI_SIZE_128, 76bf215546Sopenharmony_ci}; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci/* Description of an opcode in the IR */ 79bf215546Sopenharmony_cistruct bi_op_props { 80bf215546Sopenharmony_ci const char *name; 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci enum bifrost_message_type message : 4; 83bf215546Sopenharmony_ci enum bi_size size : 3; 84bf215546Sopenharmony_ci enum bi_sr_count sr_count : 3; 85bf215546Sopenharmony_ci bool sr_read : 1; 86bf215546Sopenharmony_ci bool sr_write : 1; 87bf215546Sopenharmony_ci bool last : 1; 88bf215546Sopenharmony_ci bool branch : 1; 89bf215546Sopenharmony_ci bool table : 1; 90bf215546Sopenharmony_ci bool fma : 1; 91bf215546Sopenharmony_ci bool add : 1; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci /* Supported propagable modifiers */ 94bf215546Sopenharmony_ci bool clamp : 1; 95bf215546Sopenharmony_ci bool not_result : 1; 96bf215546Sopenharmony_ci unsigned abs : 3; 97bf215546Sopenharmony_ci unsigned neg : 3; 98bf215546Sopenharmony_ci bool not_mod : 1; 99bf215546Sopenharmony_ci}; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci/* Generated in bi_opcodes.c.py */ 102bf215546Sopenharmony_ciextern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES]; 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci#endif 105bf215546Sopenharmony_ci""" 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ciimport sys 108bf215546Sopenharmony_cifrom bifrost_isa import * 109bf215546Sopenharmony_cifrom mako.template import Template 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ciinstructions = parse_instructions(sys.argv[1], include_pseudo = True) 112bf215546Sopenharmony_ciir_instructions = partition_mnemonics(instructions) 113bf215546Sopenharmony_cimodifier_lists = order_modifiers(ir_instructions) 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci# Generate sorted list of mnemonics without regard to unit 116bf215546Sopenharmony_cimnemonics = set(x[1:] for x in instructions.keys()) 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ciprint(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists)) 119