2018-07-05 15:17:32 +02:00
|
|
|
from __future__ import print_function
|
2014-11-10 11:16:30 -08: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 12:26:07 -07: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 17:17:55 +01: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 12:26:07 -07:00
|
|
|
%>
|
|
|
|
|
|
2018-07-06 12:20:26 +02:00
|
|
|
% for name, opcode in sorted(opcodes.items()):
|
2016-04-29 12:26:07 -07:00
|
|
|
static inline nir_ssa_def *
|
2018-10-19 11:14:47 -05:00
|
|
|
nir_${name}(nir_builder *build, ${src_decl_list(opcode.num_inputs)})
|
2016-04-29 12:26:07 -07:00
|
|
|
{
|
2019-03-09 17:17:55 +01:00
|
|
|
% if opcode.num_inputs <= 4:
|
2016-04-29 12:26:07 -07:00
|
|
|
return nir_build_alu(build, nir_op_${name}, ${src_list(opcode.num_inputs)});
|
2019-03-09 17:17:55 +01: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 12:26:07 -07:00
|
|
|
}
|
2014-11-10 11:16:30 -08:00
|
|
|
% endfor
|
|
|
|
|
|
2018-07-19 11:42:08 +02:00
|
|
|
<%
|
|
|
|
|
def sysval_decl_list(opcode):
|
|
|
|
|
res = ''
|
|
|
|
|
if opcode.indices:
|
2020-11-24 12:51:59 +00:00
|
|
|
res += ', unsigned ' + opcode.indices[0].name.lower()
|
2020-07-14 13:27:53 -05:00
|
|
|
if opcode.dest_components == 0:
|
|
|
|
|
res += ', unsigned num_components'
|
2018-12-04 16:40:30 +01:00
|
|
|
if len(opcode.bit_sizes) != 1:
|
|
|
|
|
res += ', unsigned bit_size'
|
2018-07-19 11:42:08 +02:00
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def sysval_arg_list(opcode):
|
|
|
|
|
args = []
|
|
|
|
|
if opcode.indices:
|
2020-11-24 12:51:59 +00:00
|
|
|
args.append(opcode.indices[0].name.lower())
|
2018-07-19 11:42:08 +02:00
|
|
|
else:
|
|
|
|
|
args.append('0')
|
2018-12-04 16:40:30 +01:00
|
|
|
|
2020-07-14 13:27:53 -05:00
|
|
|
if opcode.dest_components == 0:
|
|
|
|
|
args.append('num_components')
|
|
|
|
|
else:
|
|
|
|
|
args.append(str(opcode.dest_components))
|
|
|
|
|
|
2018-12-04 16:40:30 +01:00
|
|
|
if len(opcode.bit_sizes) == 1:
|
|
|
|
|
bit_size = opcode.bit_sizes[0]
|
|
|
|
|
args.append(str(bit_size))
|
|
|
|
|
else:
|
|
|
|
|
args.append('bit_size')
|
|
|
|
|
|
2018-07-19 11:42:08 +02:00
|
|
|
return ', '.join(args)
|
|
|
|
|
%>
|
|
|
|
|
|
2018-07-06 12:20:26 +02:00
|
|
|
% for name, opcode in filter(lambda v: v[1].sysval, sorted(INTR_OPCODES.items())):
|
2018-12-04 16:40:30 +01:00
|
|
|
<% assert len(opcode.bit_sizes) > 0 %>
|
2018-03-15 18:42:44 -04:00
|
|
|
static inline nir_ssa_def *
|
2018-07-19 11:42:08 +02:00
|
|
|
nir_${name}(nir_builder *build${sysval_decl_list(opcode)})
|
2018-03-15 18:42:44 -04:00
|
|
|
{
|
2018-07-19 11:42:08 +02:00
|
|
|
return nir_load_system_value(build, nir_intrinsic_${name},
|
|
|
|
|
${sysval_arg_list(opcode)});
|
2018-03-15 18:42:44 -04:00
|
|
|
}
|
|
|
|
|
% endfor
|
|
|
|
|
|
2014-11-10 11:16:30 -08:00
|
|
|
#endif /* _NIR_BUILDER_OPCODES_ */"""
|
|
|
|
|
|
|
|
|
|
from nir_opcodes import opcodes
|
2018-03-15 18:42:44 -04:00
|
|
|
from nir_intrinsics import INTR_OPCODES
|
2014-11-10 11:16:30 -08:00
|
|
|
from mako.template import Template
|
|
|
|
|
|
2018-07-05 15:17:32 +02:00
|
|
|
print(Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES))
|