Path: blob/21.2-virgl/src/asahi/compiler/agx_builder.h.py
4564 views
template = """/*1* Copyright (C) 2021 Alyssa Rosenzweig <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#ifndef _AGX_BUILDER_24#define _AGX_BUILDER_2526#include "agx_compiler.h"2728static inline agx_instr *29agx_alloc_instr(agx_builder *b, enum agx_opcode op)30{31agx_instr *I = rzalloc(b->shader, agx_instr);32I->op = op;33return I;34}3536% for opcode in opcodes:37<%38op = opcodes[opcode]39dests = op.dests40srcs = op.srcs41imms = op.imms42suffix = "_to" if dests > 0 else ""43%>4445static inline agx_instr *46agx_${opcode}${suffix}(agx_builder *b4748% for dest in range(dests):49, agx_index dst${dest}50% endfor5152% for src in range(srcs):53, agx_index src${src}54% endfor5556% for imm in imms:57, ${imm.ctype} ${imm.name}58% endfor5960) {61agx_instr *I = agx_alloc_instr(b, AGX_OPCODE_${opcode.upper()});6263% for dest in range(dests):64I->dest[${dest}] = dst${dest};65% endfor6667% for src in range(srcs):68I->src[${src}] = src${src};69% endfor7071% for imm in imms:72I->${imm.name} = ${imm.name};73% endfor7475agx_builder_insert(&b->cursor, I);76return I;77}7879% if dests == 1:80static inline agx_index81agx_${opcode}(agx_builder *b8283% if srcs == 0:84, unsigned size85% endif8687% for src in range(srcs):88, agx_index src${src}89% endfor9091% for imm in imms:92, ${imm.ctype} ${imm.name}93% endfor9495) {96<%97args = ["tmp"]98args += ["src" + str(i) for i in range(srcs)]99args += [imm.name for imm in imms]100%>101% if srcs == 0:102agx_index tmp = agx_temp(b->shader, agx_size_for_bits(size));103% else:104agx_index tmp = agx_temp(b->shader, src0.size);105% endif106agx_${opcode}_to(b, ${", ".join(args)});107return tmp;108}109% endif110111% endfor112113/* Convenience methods */114115enum agx_bitop_table {116AGX_BITOP_NOT = 0x5,117AGX_BITOP_XOR = 0x6,118AGX_BITOP_AND = 0x8,119AGX_BITOP_MOV = 0xA,120AGX_BITOP_OR = 0xE121};122123#define UNOP_BITOP(name, table) \124static inline agx_instr * \125agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0) \126{ \127return agx_bitop_to(b, dst0, src0, agx_zero(), AGX_BITOP_ ## table); \128}129130#define BINOP_BITOP(name, table) \131static inline agx_instr * \132agx_## name ##_to(agx_builder *b, agx_index dst0, agx_index src0, agx_index src1) \133{ \134return agx_bitop_to(b, dst0, src0, src1, AGX_BITOP_ ## table); \135}136137UNOP_BITOP(mov, MOV)138UNOP_BITOP(not, NOT)139140BINOP_BITOP(and, AND)141BINOP_BITOP(xor, XOR)142BINOP_BITOP(or, OR)143144#undef UNOP_BITOP145#undef BINOP_BITOP146147static inline agx_instr *148agx_fmov_to(agx_builder *b, agx_index dst0, agx_index src0)149{150return agx_fadd_to(b, dst0, src0, agx_negzero());151}152153static inline agx_instr *154agx_push_exec(agx_builder *b, unsigned n)155{156return agx_if_fcmp(b, agx_zero(), agx_zero(), n, AGX_FCOND_EQ, false);157}158159#endif160"""161162from mako.template import Template163from agx_opcodes import opcodes164165print(Template(template).render(opcodes=opcodes))166167168