2 # Copyright (C) 2014 Connor Abbott
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
20 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 # Connor Abbott (cwabbott0@gmail.com)
26 from __future__
import print_function
28 from nir_opcodes
import opcodes
29 from mako
.template
import Template
31 template
= Template("""
35 nir_type_conversion_op(nir_alu_type src, nir_alu_type dst, nir_rounding_mode rnd)
37 nir_alu_type src_base = (nir_alu_type) nir_alu_type_get_base_type(src);
38 nir_alu_type dst_base = (nir_alu_type) nir_alu_type_get_base_type(dst);
39 unsigned src_bit_size = nir_alu_type_get_type_size(src);
40 unsigned dst_bit_size = nir_alu_type_get_type_size(dst);
42 if (src == dst && src_base == nir_type_float) {
44 } else if ((src_base == nir_type_int || src_base == nir_type_uint) &&
45 (dst_base == nir_type_int || dst_base == nir_type_uint) &&
46 src_bit_size == dst_bit_size) {
47 /* Integer <-> integer conversions with the same bit-size on both
48 * ends are just no-op moves.
54 % for src_t in ['int', 'uint', 'float']:
55 case nir_type_${src_t}:
57 % for dst_t in ['int', 'uint', 'float']:
58 case nir_type_${dst_t}:
59 % if src_t in ['int', 'uint'] and dst_t in ['int', 'uint']:
66 switch (dst_bit_size) {
67 % if dst_t == 'float':
68 <% bit_sizes = [16, 32, 64] %>
70 <% bit_sizes = [8, 16, 32, 64] %>
72 % for dst_bits in bit_sizes:
74 % if src_t == 'float' and dst_t == 'float' and dst_bits == 16:
76 % for rnd_t in [('rtne', '_rtne'), ('rtz', '_rtz'), ('undef', '')]:
77 case nir_rounding_mode_${rnd_t[0]}:
78 return ${'nir_op_{0}2{1}{2}{3}'.format(src_t[0], dst_t[0],
82 unreachable("Invalid 16-bit nir rounding mode");
85 assert(rnd == nir_rounding_mode_undef);
86 return ${'nir_op_{0}2{1}{2}'.format(src_t[0], dst_t[0], dst_bits)};
90 unreachable("Invalid nir alu bit size");
94 % if src_t == 'float':
100 unreachable("Invalid nir alu base type");
111 unreachable("Invalid nir alu base type");
114 unreachable("Invalid nir alu base type");
118 const nir_op_info nir_op_infos[nir_num_opcodes] = {
119 % for name, opcode in sorted(opcodes.items()):
122 .num_inputs = ${opcode.num_inputs},
123 .output_size = ${opcode.output_size},
124 .output_type = ${"nir_type_" + opcode.output_type},
126 ${ ", ".join(str(size) for size in opcode.input_sizes) }
129 ${ ", ".join("nir_type_" + type for type in opcode.input_types) }
131 .algebraic_properties =
132 ${ "0" if opcode.algebraic_properties == "" else " | ".join(
133 "NIR_OP_IS_" + prop.upper() for prop in
134 opcode.algebraic_properties.strip().split(" ")) }
140 print(template
.render(opcodes
=opcodes
))