Debian Codegraph @

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

raw
1 # Copyright (C) 2020 Collabora, Ltd.
2 # SPDX-License-Identifier: MIT
3
4 TEMPLATE = """
5 #ifndef _BI_OPCODES_H_
6 #define _BI_OPCODES_H_
7
8 #include "bifrost.h"
9
10 % for mod in sorted(modifiers):
11 % if len(modifiers[mod]) > 2: # otherwise just boolean
12 enum bi_${mod.lower()} {
13 % for i, state in enumerate(modifiers[mod]):
14 % if state != "reserved":
15 BI_${mod.upper()}_${state.upper()} = ${i},
16 % endif
17 % endfor
18 };
19
20 % endif
21 % endfor
22 enum bi_opcode {
23 % for opcode in sorted(mnemonics):
24 BI_OPCODE_${opcode.replace('.', '_').upper()},
25 % endfor
26 BI_NUM_OPCODES
27 };
28
29 /* Number of staging registers accessed, note this fits into 3-bits */
30
31 enum bi_sr_count {
32 /* fixed counts */
33 BI_SR_COUNT_0 = 0,
34 BI_SR_COUNT_1 = 1,
35 BI_SR_COUNT_2 = 2,
36 BI_SR_COUNT_3 = 3,
37 BI_SR_COUNT_4 = 4,
38
39 /* derived from register_format and vecsize */
40 BI_SR_COUNT_FORMAT = 5,
41
42 /* equal to vecsize alone */
43 BI_SR_COUNT_VECSIZE = 6,
44
45 /* specified directly as the sr_count immediate */
46 BI_SR_COUNT_SR_COUNT = 7
47 };
48
49 enum bi_size {
50 BI_SIZE_8 = 0,
51 BI_SIZE_16,
52 BI_SIZE_24,
53 BI_SIZE_32,
54 BI_SIZE_48,
55 BI_SIZE_64,
56 BI_SIZE_96,
57 BI_SIZE_128,
58 };
59
60 /* Description of an opcode in the IR */
61 struct bi_op_props {
62 const char *name;
63
64 enum bifrost_message_type message : 4;
65 enum bi_size size : 3;
66 enum bi_sr_count sr_count : 3;
67 bool sr_read : 1;
68 bool sr_write : 1;
69 bool last : 1;
70 bool branch : 1;
71 bool table : 1;
72 bool fma : 1;
73 bool add : 1;
74 bool is_float : 1;
75
76 /* Supported propagable modifiers */
77 bool clamp : 1;
78 bool not_result : 1;
79 unsigned abs : 3;
80 unsigned neg : 3;
81 bool not_mod : 1;
82 };
83
84 /* Generated in bi_opcodes.c.py */
85 extern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES];
86
87 #endif
88 """
89
90 import sys
91 from bifrost_isa import *
92 from mako.template import Template
93
94 instructions = {}
95 for arg in sys.argv[1:]:
96 new_instructions = parse_instructions(arg, include_pseudo = True)
97 instructions.update(new_instructions)
98
99 ir_instructions = partition_mnemonics(instructions)
100 modifier_lists = order_modifiers(ir_instructions)
101
102 # Generate sorted list of mnemonics without regard to unit
103 mnemonics = set(x[1:] for x in instructions.keys())
104
105 print(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists))