44441727b78c3ce66c33f8e95119d11fa4bba977
[mesa.git] / src / gallium / drivers / panfrost / midgard / midgard_nir_algebraic.py
1 #
2 # Copyright (C) 2018 Alyssa Rosenzweig
3 #
4 # Copyright (C) 2016 Intel Corporation
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
15 # Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24
25 import argparse
26 import sys
27 import math
28
29 a = 'a'
30 b = 'b'
31
32 algebraic = [
33 (('b2i32', a), ('iand@32', "a@32", 1)),
34 (('isign', a), ('imin', ('imax', a, -1), 1)),
35 (('fge', a, b), ('flt', b, a)),
36
37 # XXX: We have hw ops for this, just unknown atm..
38 #(('fsign@32', a), ('i2f32@32', ('isign', ('f2i32@32', ('fmul', a, 0x43800000)))))
39 #(('fsign', a), ('fcsel', ('fge', a, 0), 1.0, ('fcsel', ('flt', a, 0.0), -1.0, 0.0)))
40 (('fsign', a), ('bcsel', ('fge', a, 0), 1.0, -1.0)),
41 ]
42
43 # Midgard scales fsin/fcos arguments by pi.
44 # Pass must be run only once, after the main loop
45
46 scale_trig = [
47 (('fsin', a), ('fsin', ('fdiv', a, math.pi))),
48 (('fcos', a), ('fcos', ('fdiv', a, math.pi))),
49 ]
50
51 def main():
52 parser = argparse.ArgumentParser()
53 parser.add_argument('-p', '--import-path', required=True)
54 args = parser.parse_args()
55 sys.path.insert(0, args.import_path)
56 run()
57
58
59 def run():
60 import nir_algebraic # pylint: disable=import-error
61
62 print('#include "midgard_nir.h"')
63 print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic",
64 algebraic).render())
65
66 print(nir_algebraic.AlgebraicPass("midgard_nir_scale_trig",
67 scale_trig).render())
68
69
70 if __name__ == '__main__':
71 main()