2018-07-05 14:17:32 +01:00
|
|
|
from __future__ import print_function
|
2014-11-10 19:16:30 +00:00
|
|
|
|
|
|
|
template = """\
|
|
|
|
/* Copyright (C) 2015 Broadcom
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NIR_BUILDER_OPCODES_
|
|
|
|
#define _NIR_BUILDER_OPCODES_
|
|
|
|
|
2016-04-29 20:26:07 +01:00
|
|
|
<%
|
|
|
|
def src_decl_list(num_srcs):
|
|
|
|
return ', '.join('nir_ssa_def *src' + str(i) for i in range(num_srcs))
|
|
|
|
|
|
|
|
def src_list(num_srcs):
|
2019-03-09 16:17:55 +00:00
|
|
|
if num_srcs <= 4:
|
|
|
|
return ', '.join('src' + str(i) if i < num_srcs else 'NULL' for i in range(4))
|
|
|
|
else:
|
|
|
|
return ', '.join('src' + str(i) for i in range(num_srcs))
|
2016-04-29 20:26:07 +01:00
|
|
|
%>
|
|
|
|
|
2018-07-06 11:20:26 +01:00
|
|
|
% for name, opcode in sorted(opcodes.items()):
|
2016-04-29 20:26:07 +01:00
|
|
|
static inline nir_ssa_def *
|
2018-10-19 17:14:47 +01:00
|
|
|
nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
|
2016-04-29 20:26:07 +01:00
|
|
|
{
|
2019-03-09 16:17:55 +00:00
|
|
|
% if opcode.num_inputs <= 4:
|
2016-04-29 20:26:07 +01:00
|
|
|
return nir_build_alu(build, nir_op_${name}, ${src_list(opcode.num_inputs)});
|
2019-03-09 16:17:55 +00:00
|
|
|
% else:
|
|
|
|
nir_ssa_def *srcs[${opcode.num_inputs}] = {${src_list(opcode.num_inputs)}};
|
|
|
|
return nir_build_alu_src_arr(build, nir_op_${name}, srcs);
|
|
|
|
% endif
|
2016-04-29 20:26:07 +01:00
|
|
|
}
|
2014-11-10 19:16:30 +00:00
|
|
|
% endfor
|
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
% for name, opcode in sorted(INTR_OPCODES.items()):
|
|
|
|
struct _nir_${name}_indices {
|
|
|
|
int _; /* exists to avoid empty initializers */
|
|
|
|
% for index in opcode.indices:
|
|
|
|
${index.c_data_type} ${index.name};
|
|
|
|
% endfor
|
|
|
|
};
|
|
|
|
% endfor
|
|
|
|
|
2018-07-19 10:42:08 +01:00
|
|
|
<%
|
2020-09-07 13:55:38 +01:00
|
|
|
def intrinsic_decl_list(opcode):
|
|
|
|
need_components = opcode.dest_components == 0 and \
|
|
|
|
0 not in opcode.src_components
|
2018-12-04 15:40:30 +00:00
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
res = ''
|
|
|
|
if (opcode.has_dest or opcode.num_srcs) and need_components:
|
|
|
|
res += ', unsigned num_components'
|
|
|
|
if opcode.has_dest and len(opcode.bit_sizes) != 1 and opcode.bit_size_src == -1:
|
|
|
|
res += ', unsigned bit_size'
|
|
|
|
for i in range(opcode.num_srcs):
|
|
|
|
res += ', nir_ssa_def *src' + str(i)
|
|
|
|
if opcode.indices:
|
|
|
|
res += ', struct _nir_' + opcode.name + '_indices indices'
|
|
|
|
return res
|
2020-07-14 19:27:53 +01:00
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
def intrinsic_macro_list(opcode):
|
|
|
|
need_components = opcode.dest_components == 0 and \
|
|
|
|
0 not in opcode.src_components
|
2018-12-04 15:40:30 +00:00
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
res = ''
|
|
|
|
if (opcode.has_dest or opcode.num_srcs) and need_components:
|
|
|
|
res += ', num_components'
|
|
|
|
if opcode.has_dest and len(opcode.bit_sizes) != 1 and opcode.bit_size_src == -1:
|
|
|
|
res += ', bit_size'
|
|
|
|
for i in range(opcode.num_srcs):
|
|
|
|
res += ', src' + str(i)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def get_intrinsic_bitsize(opcode):
|
|
|
|
if len(opcode.bit_sizes) == 1:
|
|
|
|
return str(opcode.bit_sizes[0])
|
|
|
|
elif opcode.bit_size_src != -1:
|
|
|
|
return 'src' + str(opcode.bit_size_src) + '->bit_size'
|
|
|
|
else:
|
|
|
|
return 'bit_size'
|
2018-07-19 10:42:08 +01:00
|
|
|
%>
|
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
% for name, opcode in sorted(INTR_OPCODES.items()):
|
|
|
|
% if opcode.has_dest:
|
2018-03-15 22:42:44 +00:00
|
|
|
static inline nir_ssa_def *
|
2020-09-07 13:55:38 +01:00
|
|
|
% else:
|
|
|
|
static inline nir_intrinsic_instr *
|
|
|
|
% endif
|
|
|
|
_nir_build_${name}(nir_builder *build${intrinsic_decl_list(opcode)})
|
2018-03-15 22:42:44 +00:00
|
|
|
{
|
2020-09-07 13:55:38 +01:00
|
|
|
nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(
|
|
|
|
build->shader, nir_intrinsic_${name});
|
|
|
|
|
|
|
|
% if 0 in opcode.src_components:
|
|
|
|
intrin->num_components = src${opcode.src_components.index(0)}->num_components;
|
|
|
|
% elif opcode.dest_components == 0:
|
|
|
|
intrin->num_components = num_components;
|
|
|
|
% endif
|
|
|
|
% if opcode.has_dest:
|
|
|
|
% if opcode.dest_components == 0:
|
|
|
|
nir_ssa_dest_init(&intrin->instr, &intrin->dest, intrin->num_components, ${get_intrinsic_bitsize(opcode)}, NULL);
|
|
|
|
% else:
|
|
|
|
nir_ssa_dest_init(&intrin->instr, &intrin->dest, ${opcode.dest_components}, ${get_intrinsic_bitsize(opcode)}, NULL);
|
|
|
|
% endif
|
|
|
|
% endif
|
|
|
|
% for i in range(opcode.num_srcs):
|
|
|
|
intrin->src[${i}] = nir_src_for_ssa(src${i});
|
|
|
|
% endfor
|
|
|
|
% for index in opcode.indices:
|
|
|
|
nir_intrinsic_set_${index.name}(intrin, indices.${index.name});
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
nir_builder_instr_insert(build, &intrin->instr);
|
|
|
|
% if opcode.has_dest:
|
|
|
|
return &intrin->dest.ssa;
|
|
|
|
% else:
|
|
|
|
return intrin;
|
|
|
|
% endif
|
2018-03-15 22:42:44 +00:00
|
|
|
}
|
|
|
|
% endfor
|
|
|
|
|
2020-09-07 13:55:38 +01:00
|
|
|
% for name, opcode in sorted(INTR_OPCODES.items()):
|
|
|
|
% if opcode.indices:
|
|
|
|
#define nir_build_${name}(build${intrinsic_macro_list(opcode)}, ...) ${'\\\\'}
|
|
|
|
_nir_build_${name}(build${intrinsic_macro_list(opcode)}, (struct _nir_${name}_indices){0, __VA_ARGS__})
|
|
|
|
% else:
|
|
|
|
#define nir_build_${name} _nir_build_${name}
|
|
|
|
% endif
|
|
|
|
#define nir_${name} nir_build_${name}
|
|
|
|
% endfor
|
|
|
|
|
2014-11-10 19:16:30 +00:00
|
|
|
#endif /* _NIR_BUILDER_OPCODES_ */"""
|
|
|
|
|
|
|
|
from nir_opcodes import opcodes
|
2018-03-15 22:42:44 +00:00
|
|
|
from nir_intrinsics import INTR_OPCODES
|
2014-11-10 19:16:30 +00:00
|
|
|
from mako.template import Template
|
|
|
|
|
2018-07-05 14:17:32 +01:00
|
|
|
print(Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES))
|