forked from notaz/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagx_builder.h.py
168 lines (138 loc) · 3.85 KB
/
agx_builder.h.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
template = """/*
* Copyright (C) 2021 Alyssa Rosenzweig <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _AGX_BUILDER_
#define _AGX_BUILDER_
#include "agx_compiler.h"
static inline agx_instr *
agx_alloc_instr(agx_builder *b, enum agx_opcode op)
{
agx_instr *I = rzalloc(b->shader, agx_instr);
I->op = op;
return I;
}
% for opcode in opcodes:
<%
op = opcodes[opcode]
dests = op.dests
srcs = op.srcs
imms = op.imms
suffix = "_to" if dests > 0 else ""
%>
static inline agx_instr *
agx_${opcode}${suffix}(agx_builder *b
% for dest in range(dests):
, agx_index dst${dest}
% endfor
% if op.variable_srcs:
, unsigned nr_srcs
% endif
% for src in range(srcs):
, agx_index src${src}
% endfor
% for imm in imms:
, ${imm.ctype} ${imm.name}
% endfor
) {
agx_instr *I = agx_alloc_instr(b, AGX_OPCODE_${opcode.upper()});
% for dest in range(dests):
I->dest[${dest}] = dst${dest};
% endfor
% if op.variable_srcs:
I->src = ralloc_array(I, agx_index, nr_srcs);
I->nr_srcs = nr_srcs;
% elif srcs > 0:
I->src = ralloc_array(I, agx_index, ${srcs});
I->nr_srcs = ${srcs};
% for src in range(srcs):
I->src[${src}] = src${src};
% endfor
% endif
% for imm in imms:
I->${imm.name} = ${imm.name};
% endfor
agx_builder_insert(&b->cursor, I);
return I;
}
% if dests == 1 and not op.variable_srcs:
static inline agx_index
agx_${opcode}(agx_builder *b
% if srcs == 0:
, unsigned size
% endif
% for src in range(srcs):
, agx_index src${src}
% endfor
% for imm in imms:
, ${imm.ctype} ${imm.name}
% endfor
) {
<%
args = ["tmp"]
args += ["src" + str(i) for i in range(srcs)]
args += [imm.name for imm in imms]
%>
% if srcs == 0:
agx_index tmp = agx_temp(b->shader, agx_size_for_bits(size));
% else:
agx_index tmp = agx_temp(b->shader, src0.size);
% endif
agx_${opcode}_to(b, ${", ".join(args)});
return tmp;
}
% endif
% endfor
/* Convenience methods */
enum agx_bitop_table {
AGX_BITOP_NOT = 0x5,
AGX_BITOP_XOR = 0x6,
AGX_BITOP_AND = 0x8,
AGX_BITOP_MOV = 0xA,
AGX_BITOP_OR = 0xE
};
static inline agx_instr *
agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0)
{
return agx_fadd_to(b, dst0, src0, agx_negzero());
}
static inline agx_instr *
agx_push_exec(agx_builder *b, unsigned n)
{
return agx_if_fcmp(b, agx_zero(), agx_zero(), n, AGX_FCOND_EQ, false);
}
static inline agx_instr *
agx_ushr_to(agx_builder *b, agx_index dst, agx_index s0, agx_index s1)
{
return agx_bfeil_to(b, dst, agx_zero(), s0, s1, 0);
}
static inline agx_index
agx_ushr(agx_builder *b, agx_index s0, agx_index s1)
{
agx_index tmp = agx_temp(b->shader, s0.size);
agx_ushr_to(b, tmp, s0, s1);
return tmp;
}
#endif
"""
from mako.template import Template
from agx_opcodes import opcodes
print(Template(template).render(opcodes=opcodes))