1*61046927SAndroid Build Coastguard Worker# 2*61046927SAndroid Build Coastguard Worker# Copyright (C) 2020 Collabora, Ltd. 3*61046927SAndroid Build Coastguard Worker# 4*61046927SAndroid Build Coastguard Worker# Permission is hereby granted, free of charge, to any person obtaining a 5*61046927SAndroid Build Coastguard Worker# copy of this software and associated documentation files (the "Software"), 6*61046927SAndroid Build Coastguard Worker# to deal in the Software without restriction, including without limitation 7*61046927SAndroid Build Coastguard Worker# the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*61046927SAndroid Build Coastguard Worker# and/or sell copies of the Software, and to permit persons to whom the 9*61046927SAndroid Build Coastguard Worker# Software is furnished to do so, subject to the following conditions: 10*61046927SAndroid Build Coastguard Worker# 11*61046927SAndroid Build Coastguard Worker# The above copyright notice and this permission notice (including the next 12*61046927SAndroid Build Coastguard Worker# paragraph) shall be included in all copies or substantial portions of the 13*61046927SAndroid Build Coastguard Worker# Software. 14*61046927SAndroid Build Coastguard Worker# 15*61046927SAndroid Build Coastguard Worker# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*61046927SAndroid Build Coastguard Worker# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*61046927SAndroid Build Coastguard Worker# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18*61046927SAndroid Build Coastguard Worker# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*61046927SAndroid Build Coastguard Worker# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20*61046927SAndroid Build Coastguard Worker# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21*61046927SAndroid Build Coastguard Worker# IN THE SOFTWARE. 22*61046927SAndroid Build Coastguard Worker 23*61046927SAndroid Build Coastguard WorkerTEMPLATE = """#include "bi_opcodes.h" 24*61046927SAndroid Build Coastguard Worker<% 25*61046927SAndroid Build Coastguard Workerdef hasmod(mods, name): 26*61046927SAndroid Build Coastguard Worker return 1 if name in mods else 0 27*61046927SAndroid Build Coastguard Worker%> 28*61046927SAndroid Build Coastguard Workerstruct bi_op_props bi_opcode_props[BI_NUM_OPCODES] = { 29*61046927SAndroid Build Coastguard Worker% for opcode in sorted(mnemonics): 30*61046927SAndroid Build Coastguard Worker <% 31*61046927SAndroid Build Coastguard Worker add = instructions["+" + opcode][0][1] if "+" + opcode in instructions else None 32*61046927SAndroid Build Coastguard Worker size = typesize(opcode) 33*61046927SAndroid Build Coastguard Worker message = add["message"].upper() if add else "NONE" 34*61046927SAndroid Build Coastguard Worker sr_count = add["staging_count"].upper() if add else "0" 35*61046927SAndroid Build Coastguard Worker sr_read = int(add["staging"] in ["r", "rw"] if add else False) 36*61046927SAndroid Build Coastguard Worker sr_write = int(add["staging"] in ["w", "rw"] if add else False) 37*61046927SAndroid Build Coastguard Worker last = int(bool(add["last"]) if add else False) 38*61046927SAndroid Build Coastguard Worker table = int(bool(add["table"]) if add else False) 39*61046927SAndroid Build Coastguard Worker branch = int(opcode.startswith('BRANCH')) 40*61046927SAndroid Build Coastguard Worker has_fma = int("*" + opcode in instructions) 41*61046927SAndroid Build Coastguard Worker has_add = int("+" + opcode in instructions) 42*61046927SAndroid Build Coastguard Worker mods = ops[opcode]['modifiers'] 43*61046927SAndroid Build Coastguard Worker clamp = hasmod(mods, 'clamp') 44*61046927SAndroid Build Coastguard Worker not_result = hasmod(mods, 'not_result') 45*61046927SAndroid Build Coastguard Worker abs = hasmod(mods, 'abs0') | (hasmod(mods, 'abs1') << 1) | (hasmod(mods, 'abs2') << 2) 46*61046927SAndroid Build Coastguard Worker neg = hasmod(mods, 'neg0') | (hasmod(mods, 'neg1') << 1) | (hasmod(mods, 'neg2') << 2) 47*61046927SAndroid Build Coastguard Worker m_not = hasmod(mods, 'not1') 48*61046927SAndroid Build Coastguard Worker %> 49*61046927SAndroid Build Coastguard Worker [BI_OPCODE_${opcode.replace('.', '_').upper()}] = { 50*61046927SAndroid Build Coastguard Worker "${opcode}", BIFROST_MESSAGE_${message}, BI_SIZE_${size}, 51*61046927SAndroid Build Coastguard Worker BI_SR_COUNT_${sr_count}, ${sr_read}, ${sr_write}, ${last}, ${branch}, 52*61046927SAndroid Build Coastguard Worker ${table}, ${has_fma}, ${has_add}, ${clamp}, ${not_result}, ${abs}, 53*61046927SAndroid Build Coastguard Worker ${neg}, ${m_not}, 54*61046927SAndroid Build Coastguard Worker }, 55*61046927SAndroid Build Coastguard Worker% endfor 56*61046927SAndroid Build Coastguard Worker};""" 57*61046927SAndroid Build Coastguard Worker 58*61046927SAndroid Build Coastguard Workerimport sys 59*61046927SAndroid Build Coastguard Workerfrom bifrost_isa import * 60*61046927SAndroid Build Coastguard Workerfrom mako.template import Template 61*61046927SAndroid Build Coastguard Worker 62*61046927SAndroid Build Coastguard Workerinstructions = {} 63*61046927SAndroid Build Coastguard Workerfor arg in sys.argv[1:]: 64*61046927SAndroid Build Coastguard Worker new_instructions = parse_instructions(arg, include_pseudo = True) 65*61046927SAndroid Build Coastguard Worker instructions.update(new_instructions) 66*61046927SAndroid Build Coastguard Worker 67*61046927SAndroid Build Coastguard Workerir_instructions = partition_mnemonics(instructions) 68*61046927SAndroid Build Coastguard Workermnemonics = set(x[1:] for x in instructions.keys()) 69*61046927SAndroid Build Coastguard Worker 70*61046927SAndroid Build Coastguard Workerprint(Template(COPYRIGHT + TEMPLATE).render(ops = ir_instructions, mnemonics = mnemonics, instructions = instructions, typesize = typesize)) 71