• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1template = """/*
2 * Copyright (C) 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io>
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
29static inline agx_instr *
30agx_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
46static inline agx_instr *
47agx_${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% if srcs > 0:
69   I->src = ralloc_array(I, agx_index, ${srcs});
70   I->nr_srcs = ${srcs};
71
72% for src in range(srcs):
73   I->src[${src}] = src${src};
74% endfor
75% endif
76
77% for imm in imms:
78   I->${imm.name} = ${imm.name};
79% endfor
80
81   agx_builder_insert(&b->cursor, I);
82   return I;
83}
84
85% if dests == 1:
86static inline agx_index
87agx_${opcode}(agx_builder *b
88
89% if srcs == 0:
90   , unsigned size
91% endif
92
93% for src in range(srcs):
94   , agx_index src${src}
95% endfor
96
97% for imm in imms:
98   , ${imm.ctype} ${imm.name}
99% endfor
100
101) {
102<%
103   args = ["tmp"]
104   args += ["src" + str(i) for i in range(srcs)]
105   args += [imm.name for imm in imms]
106%>
107% if srcs == 0:
108   agx_index tmp = agx_temp(b->shader, agx_size_for_bits(size));
109% else:
110   agx_index tmp = agx_temp(b->shader, src0.size);
111% endif
112   agx_${opcode}_to(b, ${", ".join(args)});
113   return tmp;
114}
115% endif
116
117% endfor
118
119/* Convenience methods */
120
121enum agx_bitop_table {
122   AGX_BITOP_NOT = 0x5,
123   AGX_BITOP_XOR = 0x6,
124   AGX_BITOP_AND = 0x8,
125   AGX_BITOP_MOV = 0xA,
126   AGX_BITOP_OR  = 0xE
127};
128
129static inline agx_instr *
130agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0)
131{
132   return agx_fadd_to(b, dst0, src0, agx_negzero());
133}
134
135static inline agx_instr *
136agx_push_exec(agx_builder *b, unsigned n)
137{
138   return agx_if_fcmp(b, agx_zero(), agx_zero(), n, AGX_FCOND_EQ, false);
139}
140
141static inline agx_instr *
142agx_ushr_to(agx_builder *b, agx_index dst, agx_index s0, agx_index s1)
143{
144    return agx_bfeil_to(b, dst, agx_zero(), s0, s1, 0);
145}
146
147static inline agx_index
148agx_ushr(agx_builder *b, agx_index s0, agx_index s1)
149{
150    agx_index tmp = agx_temp(b->shader, s0.size);
151    agx_ushr_to(b, tmp, s0, s1);
152    return tmp;
153}
154
155#endif
156"""
157
158from mako.template import Template
159from agx_opcodes import opcodes
160
161print(Template(template).render(opcodes=opcodes))
162