diff options
author | Rob Clark <[email protected]> | 2018-03-15 18:42:44 -0400 |
---|---|---|
committer | Rob Clark <[email protected]> | 2018-03-27 08:36:37 -0400 |
commit | 76dfed8ae2d5c6c509eb2661389be3c6a25077df (patch) | |
tree | e811d58f7f277c7844c3421eab1203e7d55607a2 /src/compiler/nir/nir_intrinsics_c.py | |
parent | cc3a88e81dbceb12b79eb4ebe7a4ce5ba97fc291 (diff) |
nir: mako all the intrinsics
I threatened to do this a long time ago.. I probably *should* have done
it a long time ago when there where many fewer intrinsics. But the
system of macro/#include magic for dealing with intrinsics is a bit
annoying, and python has the nice property of optional fxn params,
making it possible to define new intrinsics while ignoring parameters
that are not applicable (and naming optional params). And not having to
specify various array lengths explicitly is nice too.
I think the end result makes it easier to add new intrinsics.
v2: couple small fixes found with a test program to compare the old and
new tables
v3: misc comments, don't rely on capture=true for meson.build, get rid
of system_values table to avoid return value of intrinsic() and
*mostly* remove side-effects, add autotools build support
v4: scons build
Signed-off-by: Rob Clark <[email protected]>
Acked-by: Dylan Baker <[email protected]>
Acked-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_intrinsics_c.py')
-rw-r--r-- | src/compiler/nir/nir_intrinsics_c.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_intrinsics_c.py b/src/compiler/nir/nir_intrinsics_c.py new file mode 100644 index 00000000000..556db785c2b --- /dev/null +++ b/src/compiler/nir/nir_intrinsics_c.py @@ -0,0 +1,68 @@ + +template = """\ +/* Copyright (C) 2018 Red Hat + * + * 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. + */ + +#include "nir.h" + +const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = { +% for name, opcode in sorted(INTR_OPCODES.iteritems()): +{ + .name = "${name}", + .num_srcs = ${opcode.num_srcs}, + .src_components = { + ${", ".join(str(comp) for comp in opcode.src_components)} + }, + .has_dest = ${"true" if opcode.has_dest else "false"}, + .dest_components = ${opcode.dest_components}, + .num_variables = ${opcode.num_variables}, + .num_indices = ${opcode.num_indices}, + .index_map = { +% for i in range(len(opcode.indices)): + [${opcode.indices[i]}] = ${i + 1}, +% endfor + }, + .flags = ${"0" if len(opcode.flags) == 0 else " | ".join(opcode.flags)}, +}, +% endfor +}; +""" + +from nir_intrinsics import INTR_OPCODES +from mako.template import Template +import argparse +import os + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--outdir', required=True, + help='Directory to put the generated files in') + + args = parser.parse_args() + + path = os.path.join(args.outdir, 'nir_intrinsics.c') + with open(path, 'wb') as f: + f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES)) + +if __name__ == '__main__': + main() + |