2
* Copyright (C) 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io>
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:
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
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
27
#include "agx_compiler.h"
29
static inline agx_instr *
30
agx_alloc_instr(agx_builder *b, enum agx_opcode op)
32
agx_instr *I = rzalloc(b->shader, agx_instr);
37
% for opcode in opcodes:
43
suffix = "_to" if dests > 0 else ""
46
static inline agx_instr *
47
agx_${opcode}${suffix}(agx_builder *b
49
% for dest in range(dests):
50
, agx_index dst${dest}
53
% for src in range(srcs):
58
, ${imm.ctype} ${imm.name}
62
agx_instr *I = agx_alloc_instr(b, AGX_OPCODE_${opcode.upper()});
64
% for dest in range(dests):
65
I->dest[${dest}] = dst${dest};
68
% for src in range(srcs):
69
I->src[${src}] = src${src};
73
I->${imm.name} = ${imm.name};
76
agx_builder_insert(&b->cursor, I);
81
static inline agx_index
82
agx_${opcode}(agx_builder *b
88
% for src in range(srcs):
93
, ${imm.ctype} ${imm.name}
99
args += ["src" + str(i) for i in range(srcs)]
100
args += [imm.name for imm in imms]
103
agx_index tmp = agx_temp(b->shader, agx_size_for_bits(size));
105
agx_index tmp = agx_temp(b->shader, src0.size);
107
agx_${opcode}_to(b, ${", ".join(args)});
114
/* Convenience methods */
116
enum agx_bitop_table {
124
#define UNOP_BITOP(name, table) \
125
static inline agx_instr * \
126
agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0) \
128
return agx_bitop_to(b, dst0, src0, agx_zero(), AGX_BITOP_ ## table); \
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) \
135
return agx_bitop_to(b, dst0, src0, src1, AGX_BITOP_ ## table); \
141
BINOP_BITOP(and, AND)
142
BINOP_BITOP(xor, XOR)
148
static inline agx_instr *
149
agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0)
151
return agx_fadd_to(b, dst0, src0, agx_negzero());
154
static inline agx_instr *
155
agx_push_exec(agx_builder *b, unsigned n)
157
return agx_if_fcmp(b, agx_zero(), agx_zero(), n, AGX_FCOND_EQ, false);
160
static inline agx_instr *
161
agx_ushr_to(agx_builder *b, agx_index dst, agx_index s0, agx_index s1)
163
return agx_bfeil_to(b, dst, agx_zero(), s0, s1, 0);
166
static inline agx_index
167
agx_ushr(agx_builder *b, agx_index s0, agx_index s1)
169
agx_index tmp = agx_temp(b->shader, s0.size);
170
agx_ushr_to(b, tmp, s0, s1);
174
static inline agx_index
175
agx_mov(agx_builder *b, enum agx_size size, agx_index s0)
177
agx_index tmp = agx_temp(b->shader, size);
178
agx_mov_to(b, tmp, s0);
185
from mako.template import Template
186
from agx_opcodes import opcodes
188
print(Template(template).render(opcodes=opcodes))