Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/asahi/compiler/agx_builder.h.py
4564 views
1
template = """/*
2
* Copyright (C) 2021 Alyssa Rosenzweig <[email protected]>
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 FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*/
23
24
#ifndef _AGX_BUILDER_
25
#define _AGX_BUILDER_
26
27
#include "agx_compiler.h"
28
29
static inline agx_instr *
30
agx_alloc_instr(agx_builder *b, enum agx_opcode op)
31
{
32
agx_instr *I = rzalloc(b->shader, agx_instr);
33
I->op = op;
34
return I;
35
}
36
37
% for opcode in opcodes:
38
<%
39
op = opcodes[opcode]
40
dests = op.dests
41
srcs = op.srcs
42
imms = op.imms
43
suffix = "_to" if dests > 0 else ""
44
%>
45
46
static inline agx_instr *
47
agx_${opcode}${suffix}(agx_builder *b
48
49
% for dest in range(dests):
50
, agx_index dst${dest}
51
% endfor
52
53
% for src in range(srcs):
54
, agx_index src${src}
55
% endfor
56
57
% for imm in imms:
58
, ${imm.ctype} ${imm.name}
59
% endfor
60
61
) {
62
agx_instr *I = agx_alloc_instr(b, AGX_OPCODE_${opcode.upper()});
63
64
% for dest in range(dests):
65
I->dest[${dest}] = dst${dest};
66
% endfor
67
68
% for src in range(srcs):
69
I->src[${src}] = src${src};
70
% endfor
71
72
% for imm in imms:
73
I->${imm.name} = ${imm.name};
74
% endfor
75
76
agx_builder_insert(&b->cursor, I);
77
return I;
78
}
79
80
% if dests == 1:
81
static inline agx_index
82
agx_${opcode}(agx_builder *b
83
84
% if srcs == 0:
85
, unsigned size
86
% endif
87
88
% for src in range(srcs):
89
, agx_index src${src}
90
% endfor
91
92
% for imm in imms:
93
, ${imm.ctype} ${imm.name}
94
% endfor
95
96
) {
97
<%
98
args = ["tmp"]
99
args += ["src" + str(i) for i in range(srcs)]
100
args += [imm.name for imm in imms]
101
%>
102
% if srcs == 0:
103
agx_index tmp = agx_temp(b->shader, agx_size_for_bits(size));
104
% else:
105
agx_index tmp = agx_temp(b->shader, src0.size);
106
% endif
107
agx_${opcode}_to(b, ${", ".join(args)});
108
return tmp;
109
}
110
% endif
111
112
% endfor
113
114
/* Convenience methods */
115
116
enum agx_bitop_table {
117
AGX_BITOP_NOT = 0x5,
118
AGX_BITOP_XOR = 0x6,
119
AGX_BITOP_AND = 0x8,
120
AGX_BITOP_MOV = 0xA,
121
AGX_BITOP_OR = 0xE
122
};
123
124
#define UNOP_BITOP(name, table) \
125
static inline agx_instr * \
126
agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0) \
127
{ \
128
return agx_bitop_to(b, dst0, src0, agx_zero(), AGX_BITOP_ ## table); \
129
}
130
131
#define BINOP_BITOP(name, table) \
132
static inline agx_instr * \
133
agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0, agx_index src1) \
134
{ \
135
return agx_bitop_to(b, dst0, src0, src1, AGX_BITOP_ ## table); \
136
}
137
138
UNOP_BITOP(mov, MOV)
139
UNOP_BITOP(not, NOT)
140
141
BINOP_BITOP(and, AND)
142
BINOP_BITOP(xor, XOR)
143
BINOP_BITOP(or, OR)
144
145
#undef UNOP_BITOP
146
#undef BINOP_BITOP
147
148
static inline agx_instr *
149
agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0)
150
{
151
return agx_fadd_to(b, dst0, src0, agx_negzero());
152
}
153
154
static inline agx_instr *
155
agx_push_exec(agx_builder *b, unsigned n)
156
{
157
return agx_if_fcmp(b, agx_zero(), agx_zero(), n, AGX_FCOND_EQ, false);
158
}
159
160
#endif
161
"""
162
163
from mako.template import Template
164
from agx_opcodes import opcodes
165
166
print(Template(template).render(opcodes=opcodes))
167
168