Path: blob/21.2-virgl/src/compiler/nir/nir_intrinsics_indices_h.py
4545 views
1template = """\2/* Copyright (C) 2018 Red Hat3* Copyright (C) 2020 Valve Corporation4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the "Software"),7* to deal in the Software without restriction, including without limitation8* the rights to use, copy, modify, merge, publish, distribute, sublicense,9* and/or sell copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice (including the next13* paragraph) shall be included in all copies or substantial portions of the14* Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL19* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING21* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS22* IN THE SOFTWARE.23*/2425#ifndef _NIR_INTRINSICS_INDICES_26#define _NIR_INTRINSICS_INDICES_2728% for index in INTR_INDICES:29<%30data_type = index.c_data_type31name = index.name32enum = "NIR_INTRINSIC_" + name.upper()33%>3435static inline ${data_type}36nir_intrinsic_${name}(const nir_intrinsic_instr *instr)37{38const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];39assert(info->index_map[${enum}] > 0);40% if "struct" in data_type:41${data_type} res;42STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(res));43memcpy(&res, &instr->const_index[info->index_map[${enum}] - 1], sizeof(res));44return res;45% else:46return (${data_type})instr->const_index[info->index_map[${enum}] - 1];47% endif48}4950static inline void51nir_intrinsic_set_${name}(nir_intrinsic_instr *instr, ${data_type} val)52{53const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];54assert(info->index_map[${enum}] > 0);55% if "struct" in data_type:56val._pad = 0; /* clear padding bits */57STATIC_ASSERT(sizeof(instr->const_index[0]) == sizeof(val));58memcpy(&instr->const_index[info->index_map[${enum}] - 1], &val, sizeof(val));59% else:60instr->const_index[info->index_map[${enum}] - 1] = val;61% endif62}6364static inline bool65nir_intrinsic_has_${name}(const nir_intrinsic_instr *instr)66{67const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];68return info->index_map[${enum}] > 0;69}70% endfor7172#endif /* _NIR_INTRINSICS_INDICES_ */"""7374from nir_intrinsics import INTR_INDICES75from mako.template import Template76import argparse77import os787980def main():81parser = argparse.ArgumentParser()82parser.add_argument('--outdir', required=True,83help='Directory to put the generated files in')8485args = parser.parse_args()8687path = os.path.join(args.outdir, 'nir_intrinsics_indices.h')88with open(path, 'wb') as f:89f.write(Template(template, output_encoding='utf-8').render(INTR_INDICES=INTR_INDICES))9091if __name__ == '__main__':92main()93949596