mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-28 01:18:15 +02:00
Also drop my email address in the copyright lines and fix some "Copyright 208 Alyssa Rosenzweig" lines, I'm not *that* old. Together this drops a lot of boilerplate without losing any meaningful licensing information. SPDX is already in use for the MIT-licensed code in turnip, venus, and a few other scattered parts of the tree, so this should be ok from a Mesa licensing standpoint. This reduces friction to create new files, by parsing the copy/paste boilerplate and being short enough you can easily type it out if you want. It makes new files seem less daunting: 20 lines of header for 30 lines of code is discouraging, but 2 lines of header for 30 lines of code is reasonable for a simple compiler pass. This has technical effects, as lowering the barrier to making new files should encourage people to split code into more modular files with (hopefully positive) effects on project compile time. This helps with consistency between files. Across the tree we have at least a half dozen variants of the MIT license text (probably more), plus code that uses SPDX headers instead. I've already been using SPDX headers in Asahi manually, so you can tell old vs new code based on the headers. Finally, it means less for reviewers to scroll through adding files. Minimal actual cognitive burden for reviewers thanks to banner blindness, but the big headers still bloat diffs that add/delete files. I originally proposed this in December (for much more of the tree) but someone requested I wait until January to discuss. I've been trying to get in touch with them since then. It is now almost April and, with still no response, I'd like to press forward with this. So with a joint sign-off from the major authors of the code in question, let's do this. Signed-off-by: Asahi Lina <lina@asahilina.net> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Acked-by: Emma Anholt <emma@anholt.net> Acked-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Eric Engestrom <eric@igalia.com> Acked-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Rose Hudson <rose@krx.sh> Acked-by: Lyude Paul [over IRC: "yes I'm fine with that"] Meh'd-by: Rob Clark <robdclark@chromium.org> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22062>
157 lines
3.1 KiB
Python
157 lines
3.1 KiB
Python
template = """/*
|
|
* Copyright 2021 Alyssa Rosenzweig
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef _AGX_BUILDER_
|
|
#define _AGX_BUILDER_
|
|
|
|
#include "agx_compiler.h"
|
|
|
|
static inline agx_instr *
|
|
agx_alloc_instr(agx_builder *b, enum agx_opcode op, uint8_t nr_dests, uint8_t nr_srcs)
|
|
{
|
|
size_t size = sizeof(agx_instr);
|
|
size += sizeof(agx_index) * nr_dests;
|
|
size += sizeof(agx_index) * nr_srcs;
|
|
|
|
agx_instr *I = (agx_instr *) rzalloc_size(b->shader, size);
|
|
I->dest = (agx_index *) (I + 1);
|
|
I->src = I->dest + nr_dests;
|
|
|
|
I->op = op;
|
|
I->nr_dests = nr_dests;
|
|
I->nr_srcs = nr_srcs;
|
|
return I;
|
|
}
|
|
|
|
% for opcode in opcodes:
|
|
<%
|
|
op = opcodes[opcode]
|
|
dests = op.dests
|
|
srcs = op.srcs
|
|
imms = op.imms
|
|
suffix = "_to" if dests > 0 else ""
|
|
nr_dests = "nr_dests" if op.variable_dests else str(dests)
|
|
nr_srcs = "nr_srcs" if op.variable_srcs else str(srcs)
|
|
%>
|
|
|
|
static inline agx_instr *
|
|
agx_${opcode}${suffix}(agx_builder *b
|
|
|
|
% if op.variable_dests:
|
|
, unsigned nr_dests
|
|
% endif
|
|
|
|
% 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()}, ${nr_dests}, ${nr_srcs});
|
|
|
|
% for dest in range(dests):
|
|
I->dest[${dest}] = dst${dest};
|
|
% endfor
|
|
|
|
% for src in range(srcs):
|
|
I->src[${src}] = src${src};
|
|
% endfor
|
|
|
|
% 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 and not op.variable_dests:
|
|
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))
|