Debian Codegraph @

src/panfrost/compiler/bifrost/bi_opcodes.c.py

raw
1 # Copyright (C) 2020 Collabora, Ltd.
2 # SPDX-License-Identifier: MIT
3
4 TEMPLATE = """#include "bi_opcodes.h"
5 <%
6 def hasmod(mods, name):
7 return 1 if name in mods else 0
8 %>
9 struct bi_op_props bi_opcode_props[BI_NUM_OPCODES] = {
10 % for opcode in sorted(mnemonics):
11 <%
12 add = instructions["+" + opcode][0][1] if "+" + opcode in instructions else None
13 size = typesize(opcode)
14 message = add["message"].upper() if add else "NONE"
15 sr_count = add["staging_count"].upper() if add else "0"
16 sr_read = int(add["staging"] in ["r", "rw"] if add else False)
17 sr_write = int(add["staging"] in ["w", "rw"] if add else False)
18 last = int(bool(add["last"]) if add else False)
19 table = int(bool(add["table"]) if add else False)
20 branch = int(opcode.startswith('BRANCH'))
21 has_fma = int("*" + opcode in instructions)
22 has_add = int("+" + opcode in instructions)
23 is_float = int(opcode.endswith("f32") or opcode.endswith("f16"))
24 mods = ops[opcode]['modifiers']
25 clamp = hasmod(mods, 'clamp')
26 not_result = hasmod(mods, 'not_result')
27 abs = hasmod(mods, 'abs0') | (hasmod(mods, 'abs1') << 1) | (hasmod(mods, 'abs2') << 2)
28 neg = hasmod(mods, 'neg0') | (hasmod(mods, 'neg1') << 1) | (hasmod(mods, 'neg2') << 2)
29 m_not = hasmod(mods, 'not1')
30 %>
31 [BI_OPCODE_${opcode.replace('.', '_').upper()}] = {
32 "${opcode}", BIFROST_MESSAGE_${message}, BI_SIZE_${size},
33 BI_SR_COUNT_${sr_count}, ${sr_read}, ${sr_write}, ${last}, ${branch},
34 ${table}, ${has_fma}, ${has_add}, ${is_float}, ${clamp}, ${not_result},
35 ${abs}, ${neg}, ${m_not},
36 },
37 % endfor
38 };"""
39
40 import sys
41 from bifrost_isa import *
42 from mako.template import Template
43
44 instructions = {}
45 for arg in sys.argv[1:]:
46 new_instructions = parse_instructions(arg, include_pseudo = True)
47 instructions.update(new_instructions)
48
49 ir_instructions = partition_mnemonics(instructions)
50 mnemonics = set(x[1:] for x in instructions.keys())
51
52 print(Template(COPYRIGHT + TEMPLATE).render(ops = ir_instructions, mnemonics = mnemonics, instructions = instructions, typesize = typesize))