17e102996Smaya#
27e102996Smaya# Copyright (C) 2016 Intel Corporation
37e102996Smaya#
47e102996Smaya# Permission is hereby granted, free of charge, to any person obtaining a
57e102996Smaya# copy of this software and associated documentation files (the "Software"),
67e102996Smaya# to deal in the Software without restriction, including without limitation
77e102996Smaya# the rights to use, copy, modify, merge, publish, distribute, sublicense,
87e102996Smaya# and/or sell copies of the Software, and to permit persons to whom the
97e102996Smaya# Software is furnished to do so, subject to the following conditions:
107e102996Smaya#
117e102996Smaya# The above copyright notice and this permission notice (including the next
127e102996Smaya# paragraph) shall be included in all copies or substantial portions of the
137e102996Smaya# Software.
147e102996Smaya#
157e102996Smaya# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167e102996Smaya# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177e102996Smaya# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187e102996Smaya# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197e102996Smaya# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207e102996Smaya# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217e102996Smaya# IN THE SOFTWARE.
227e102996Smaya
237e102996Smayaimport argparse
247e102996Smayaimport sys
257e102996Smaya
267e102996Smayatrig_workarounds = [
277ec681f3Smrg   (('fsin', 'x@32'), ('fsin', ('!ffma', 6.2831853, ('ffract', ('!ffma', 0.15915494, 'x', 0.5)), -3.14159265))),
287ec681f3Smrg   (('fcos', 'x@32'), ('fcos', ('!ffma', 6.2831853, ('ffract', ('!ffma', 0.15915494, 'x', 0.5)), -3.14159265))),
297e102996Smaya]
307e102996Smaya
317e102996Smaya
327e102996Smayadef main():
337e102996Smaya    parser = argparse.ArgumentParser()
347e102996Smaya    parser.add_argument('-p', '--import-path', required=True)
357e102996Smaya    args = parser.parse_args()
367e102996Smaya    sys.path.insert(0, args.import_path)
377e102996Smaya    run()
387e102996Smaya
397e102996Smaya
407e102996Smayadef run():
417e102996Smaya    import nir_algebraic  # pylint: disable=import-error
427e102996Smaya
437e102996Smaya    print('#include "ir3_nir.h"')
447e102996Smaya    print(nir_algebraic.AlgebraicPass("ir3_nir_apply_trig_workarounds",
457e102996Smaya                                      trig_workarounds).render())
467e102996Smaya
477e102996Smaya
487e102996Smayaif __name__ == '__main__':
497e102996Smaya    main()
50