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