Debian Codegraph @

src/asahi/compiler/agx_opcodes.h.py

raw
1 template = """/*
2 * Copyright 2021 Alyssa Rosenzweig
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef _AGX_OPCODES_
7 #define _AGX_OPCODES_
8
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include "util/macros.h"
12
13 enum agx_schedule_class {
14 AGX_SCHEDULE_CLASS_INVALID,
15 AGX_SCHEDULE_CLASS_NONE,
16 AGX_SCHEDULE_CLASS_LOAD,
17 AGX_SCHEDULE_CLASS_STORE,
18 AGX_SCHEDULE_CLASS_ATOMIC,
19 AGX_SCHEDULE_CLASS_COVERAGE,
20 AGX_SCHEDULE_CLASS_PRELOAD,
21 AGX_SCHEDULE_CLASS_BARRIER,
22 };
23
24 /* Listing of opcodes */
25
26 enum agx_opcode {
27 % for op in opcodes:
28 AGX_OPCODE_${op.upper()},
29 % endfor
30 AGX_NUM_OPCODES
31 };
32
33 % for name in enums:
34 enum agx_${name} {
35 % for k, v in enums[name].items():
36 AGX_${name.upper()}_${v.replace('.', '_').upper()} = ${k},
37 % endfor
38 };
39
40 static inline const char *
41 agx_${name}_as_str(enum agx_${name} x)
42 {
43 switch (x) {
44 % for k, v in enums[name].items():
45 case AGX_${name.upper()}_${v.replace('.', '_').upper()}: return "${v}";
46 % endfor
47 default: UNREACHABLE("Nonexhaustive enum");
48 }
49 }
50
51 % endfor
52
53 /* Runtime accessible info on each defined opcode */
54
55 <% assert(len(immediates) < 64); %>
56
57 enum agx_immediate {
58 % for i, imm in enumerate(immediates):
59 AGX_IMMEDIATE_${imm.upper()} = (1ull << ${i}),
60 % endfor
61 };
62
63 struct agx_encoding {
64 uint64_t exact;
65 unsigned length_short : 4;
66 bool extensible : 1;
67 };
68
69 struct agx_opcode_info {
70 const char *name;
71 unsigned nr_srcs;
72 unsigned nr_dests;
73 uint64_t immediates;
74 struct agx_encoding encoding;
75 enum agx_schedule_class schedule_class;
76 bool is_float : 1;
77 bool can_eliminate : 1;
78 bool can_reorder : 1;
79 };
80
81 extern const struct agx_opcode_info agx_opcodes_info[AGX_NUM_OPCODES];
82
83 #endif
84 """
85
86 from mako.template import Template
87 from agx_opcodes import opcodes, immediates, enums
88
89 print(Template(template).render(opcodes=opcodes, immediates=immediates,
90 enums=enums))