Path: blob/21.2-virgl/src/gallium/drivers/lima/ir/lima_nir_algebraic.py
4574 views
#1# Copyright (C) 2019 Vasily Khoruzhick <[email protected]>2#3# Permission is hereby granted, free of charge, to any person obtaining a4# copy of this software and associated documentation files (the "Software"),5# to deal in the Software without restriction, including without limitation6# the rights to use, copy, modify, merge, publish, distribute, sublicense,7# and/or sell copies of the Software, and to permit persons to whom the8# Software is furnished to do so, subject to the following conditions:9#10# The above copyright notice and this permission notice (including the next11# paragraph) shall be included in all copies or substantial portions of the12# Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20# IN THE SOFTWARE.2122import argparse23import sys24from math import pi2526# Utgard scales fsin/fcos arguments by 2*pi.27# Pass must be run only once, after the main loop2829scale_trig = [30(('fsin', 'a'), ('fsin', ('fmul', 'a', 1.0 / (2.0 * pi)))),31(('fcos', 'a'), ('fcos', ('fmul', 'a', 1.0 / (2.0 * pi)))),32]3334# GP has fsign op, so we can use cheaper lowering than one in generic opt_algebraic35lower_ftrunc = [36(('ftrunc', 'a'), ('fmul', ('fsign', 'a'), ('ffloor', ('fmax', 'a', ('fneg', 'a')))))37]3839def main():40parser = argparse.ArgumentParser()41parser.add_argument('-p', '--import-path', required=True)42args = parser.parse_args()43sys.path.insert(0, args.import_path)44run()454647def run():48import nir_algebraic # pylint: disable=import-error4950print('#include "ir/lima_ir.h"')5152print(nir_algebraic.AlgebraicPass("lima_nir_scale_trig",53scale_trig).render())54print(nir_algebraic.AlgebraicPass("lima_nir_lower_ftrunc",55lower_ftrunc).render())5657if __name__ == '__main__':58main()596061