xref: /aosp_15_r20/external/mesa3d/src/asahi/compiler/agx_opcodes.h.py (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1template = """/*
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
13enum 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
26enum 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:
34enum agx_${name} {
35% for k, v in enums[name].items():
36   AGX_${name.upper()}_${v.replace('.', '_').upper()} = ${k},
37% endfor
38};
39
40static inline const char *
41agx_${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) < 32); %>
56
57enum agx_immediate {
58% for i, imm in enumerate(immediates):
59   AGX_IMMEDIATE_${imm.upper()} = (1 << ${i}),
60% endfor
61};
62
63struct agx_encoding {
64   uint64_t exact;
65   unsigned length_short : 4;
66   bool extensible : 1;
67};
68
69struct agx_opcode_info {
70   const char *name;
71   unsigned nr_srcs;
72   unsigned nr_dests;
73   enum agx_immediate immediates;
74   struct agx_encoding encoding;
75   struct agx_encoding encoding_16;
76   enum agx_schedule_class schedule_class;
77   bool is_float : 1;
78   bool can_eliminate : 1;
79   bool can_reorder : 1;
80};
81
82extern const struct agx_opcode_info agx_opcodes_info[AGX_NUM_OPCODES];
83
84#endif
85"""
86
87from mako.template import Template
88from agx_opcodes import opcodes, immediates, enums
89
90print(Template(template).render(opcodes=opcodes, immediates=immediates,
91         enums=enums))
92