zink: use bitfield for dirty flagging
[mesa.git] / src / 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 c = 'c'
32
33 algebraic_late = [
34 # ineg must be lowered late, but only for integers; floats will try to
35 # have modifiers attached... hence why this has to be here rather than
36 # a more standard lower_negate approach
37
38 (('ineg', a), ('isub', 0, a)),
39
40 # These two special-cases save space/an op than the actual csel op +
41 # scheduler flexibility
42
43 (('b32csel', a, 'b@32', 0), ('iand', a, b)),
44 (('b32csel', a, 0, 'b@32'), ('iand', ('inot', a), b)),
45 ]
46
47
48 # Midgard is able to type convert down by only one "step" per instruction; if
49 # NIR wants more than one step, we need to break up into multiple instructions
50
51 converts = [
52 (('i2i8', 'a@32'), ('i2i8', ('i2i16', a))),
53 (('u2u8', 'a@32'), ('u2u8', ('u2u16', a))),
54
55 (('i2i32', 'a@8'), ('i2i32', ('i2i16', a))),
56 (('u2u32', 'a@8'), ('u2u32', ('u2u16', a))),
57
58 (('f2i32', 'a@16'), ('f2i32', ('f2f32', a))),
59 (('f2u32', 'a@16'), ('f2u32', ('f2f32', a))),
60
61 # Totally redundant
62 (('~f2f16', ('f2f32', 'a@16')), a),
63
64 (('pack_half_2x16_split', 'a@32', 'b@32'), ('ior', ('ishl', ('i2i32', ('f2f16', b)), 16), ('i2i32', ('f2f16', a)))),
65 ]
66
67 # Midgard scales fsin/fcos arguments by pi.
68 # Pass must be run only once, after the main loop
69
70 scale_trig = [
71 (('fsin', a), ('fsin', ('fdiv', a, math.pi))),
72 (('fcos', a), ('fcos', ('fdiv', a, math.pi))),
73 ]
74
75 def main():
76 parser = argparse.ArgumentParser()
77 parser.add_argument('-p', '--import-path', required=True)
78 args = parser.parse_args()
79 sys.path.insert(0, args.import_path)
80 run()
81
82
83 def run():
84 import nir_algebraic # pylint: disable=import-error
85
86 print('#include "midgard_nir.h"')
87
88 print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic_late",
89 algebraic_late + converts).render())
90
91 print(nir_algebraic.AlgebraicPass("midgard_nir_scale_trig",
92 scale_trig).render())
93
94
95 if __name__ == '__main__':
96 main()