panfrost/midgard: Refactor schedule/emit pipeline
[mesa.git] / src / gallium / drivers / panfrost / midgard / midgard_ops.c
1 /* Copyright (c) 2018-2019 Alyssa Rosenzweig (alyssa@rosenzweig.io)
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
22 #include "midgard.h"
23
24 /* Include the definitions of the macros and such */
25
26 #define MIDGARD_OPS_TABLE
27 #include "helpers.h"
28 #undef MIDGARD_OPS_TABLE
29
30 /* Table of mapping opcodes to accompanying properties. This is used for both
31 * the disassembler and the compiler. It is placed in a .c file like this to
32 * avoid duplications in the binary */
33
34 struct mir_op_props alu_opcode_props[256] = {
35 [midgard_alu_op_fadd] = {"fadd", UNITS_ADD | OP_COMMUTES},
36 [midgard_alu_op_fmul] = {"fmul", UNITS_MUL | UNIT_VLUT | OP_COMMUTES},
37 [midgard_alu_op_fmin] = {"fmin", UNITS_MUL | UNITS_ADD | OP_COMMUTES},
38 [midgard_alu_op_fmax] = {"fmax", UNITS_MUL | UNITS_ADD | OP_COMMUTES},
39 [midgard_alu_op_imin] = {"imin", UNITS_MOST | OP_COMMUTES},
40 [midgard_alu_op_imax] = {"imax", UNITS_MOST | OP_COMMUTES},
41 [midgard_alu_op_umin] = {"umin", UNITS_MOST | OP_COMMUTES},
42 [midgard_alu_op_umax] = {"umax", UNITS_MOST | OP_COMMUTES},
43 [midgard_alu_op_fmov] = {"fmov", UNITS_ALL | QUIRK_FLIPPED_R24},
44 [midgard_alu_op_fround] = {"fround", UNITS_ADD},
45 [midgard_alu_op_froundeven] = {"froundeven", UNITS_ADD},
46 [midgard_alu_op_ftrunc] = {"ftrunc", UNITS_ADD},
47 [midgard_alu_op_ffloor] = {"ffloor", UNITS_ADD},
48 [midgard_alu_op_fceil] = {"fceil", UNITS_ADD},
49 [midgard_alu_op_ffma] = {"ffma", UNIT_VLUT},
50
51 /* Though they output a scalar, they need to run on a vector unit
52 * since they process vectors */
53 [midgard_alu_op_fdot3] = {"fdot3", UNIT_VMUL | OP_CHANNEL_COUNT(3) | OP_COMMUTES},
54 [midgard_alu_op_fdot3r] = {"fdot3r", UNIT_VMUL | OP_CHANNEL_COUNT(3) | OP_COMMUTES},
55 [midgard_alu_op_fdot4] = {"fdot4", UNIT_VMUL | OP_CHANNEL_COUNT(4) | OP_COMMUTES},
56
57 /* Incredibly, iadd can run on vmul, etc */
58 [midgard_alu_op_iadd] = {"iadd", UNITS_MOST | OP_COMMUTES},
59 [midgard_alu_op_iabs] = {"iabs", UNITS_ADD},
60 [midgard_alu_op_isub] = {"isub", UNITS_MOST},
61 [midgard_alu_op_imul] = {"imul", UNITS_MUL | OP_COMMUTES},
62 [midgard_alu_op_imov] = {"imov", UNITS_MOST | QUIRK_FLIPPED_R24},
63
64 /* For vector comparisons, use ball etc */
65 [midgard_alu_op_feq] = {"feq", UNITS_MOST | OP_COMMUTES},
66 [midgard_alu_op_fne] = {"fne", UNITS_MOST | OP_COMMUTES},
67 [midgard_alu_op_fle] = {"fle", UNITS_MOST},
68 [midgard_alu_op_flt] = {"flt", UNITS_MOST},
69 [midgard_alu_op_ieq] = {"ieq", UNITS_MOST | OP_COMMUTES},
70 [midgard_alu_op_ine] = {"ine", UNITS_MOST | OP_COMMUTES},
71 [midgard_alu_op_ilt] = {"ilt", UNITS_MOST},
72 [midgard_alu_op_ile] = {"ile", UNITS_MOST},
73 [midgard_alu_op_ult] = {"ult", UNITS_MOST},
74 [midgard_alu_op_ule] = {"ule", UNITS_MOST},
75
76 [midgard_alu_op_icsel] = {"icsel", UNITS_ADD},
77 [midgard_alu_op_icsel_v] = {"icsel_v", UNITS_ADD},
78 [midgard_alu_op_fcsel_v] = {"fcsel_v", UNITS_ADD},
79 [midgard_alu_op_fcsel] = {"fcsel", UNITS_ADD | UNIT_SMUL},
80
81 [midgard_alu_op_frcp] = {"frcp", UNIT_VLUT},
82 [midgard_alu_op_frsqrt] = {"frsqrt", UNIT_VLUT},
83 [midgard_alu_op_fsqrt] = {"fsqrt", UNIT_VLUT},
84 [midgard_alu_op_fpow_pt1] = {"fpow_pt1", UNIT_VLUT},
85 [midgard_alu_op_fexp2] = {"fexp2", UNIT_VLUT},
86 [midgard_alu_op_flog2] = {"flog2", UNIT_VLUT},
87
88 [midgard_alu_op_f2i] = {"f2i", UNITS_ADD | OP_TYPE_CONVERT},
89 [midgard_alu_op_f2u] = {"f2u", UNITS_ADD | OP_TYPE_CONVERT},
90 [midgard_alu_op_f2u8] = {"f2u8", UNITS_ADD | OP_TYPE_CONVERT},
91 [midgard_alu_op_i2f] = {"i2f", UNITS_ADD | OP_TYPE_CONVERT},
92 [midgard_alu_op_u2f] = {"u2f", UNITS_ADD | OP_TYPE_CONVERT},
93
94 [midgard_alu_op_fsin] = {"fsin", UNIT_VLUT},
95 [midgard_alu_op_fcos] = {"fcos", UNIT_VLUT},
96
97 /* XXX: Test case where it's right on smul but not sadd */
98 [midgard_alu_op_iand] = {"iand", UNITS_MOST | OP_COMMUTES},
99 [midgard_alu_op_iandnot] = {"iandnot", UNITS_MOST},
100
101 [midgard_alu_op_ior] = {"ior", UNITS_MOST | OP_COMMUTES},
102 [midgard_alu_op_iornot] = {"iornot", UNITS_MOST | OP_COMMUTES},
103 [midgard_alu_op_inor] = {"inor", UNITS_MOST | OP_COMMUTES},
104 [midgard_alu_op_ixor] = {"ixor", UNITS_MOST | OP_COMMUTES},
105 [midgard_alu_op_inxor] = {"inxor", UNITS_MOST | OP_COMMUTES},
106 [midgard_alu_op_iclz] = {"iclz", UNITS_ADD},
107 [midgard_alu_op_ibitcount8] = {"ibitcount8", UNITS_ADD},
108 [midgard_alu_op_inand] = {"inand", UNITS_MOST},
109 [midgard_alu_op_ishl] = {"ishl", UNITS_ADD},
110 [midgard_alu_op_iasr] = {"iasr", UNITS_ADD},
111 [midgard_alu_op_ilsr] = {"ilsr", UNITS_ADD},
112
113 [midgard_alu_op_fball_eq] = {"fball_eq", UNITS_VECTOR | OP_COMMUTES},
114 [midgard_alu_op_fbany_neq] = {"fbany_neq", UNITS_VECTOR | OP_COMMUTES},
115 [midgard_alu_op_iball_eq] = {"iball_eq", UNITS_VECTOR | OP_COMMUTES},
116 [midgard_alu_op_iball_neq] = {"iball_neq", UNITS_VECTOR | OP_COMMUTES},
117 [midgard_alu_op_ibany_eq] = {"ibany_eq", UNITS_VECTOR | OP_COMMUTES},
118 [midgard_alu_op_ibany_neq] = {"ibany_neq", UNITS_VECTOR | OP_COMMUTES},
119
120 /* These instructions are not yet emitted by the compiler, so
121 * don't speculate about units yet */
122 [midgard_alu_op_ishladd] = {"ishladd", 0},
123
124 [midgard_alu_op_uball_lt] = {"uball_lt", 0},
125 [midgard_alu_op_uball_lte] = {"uball_lte", 0},
126 [midgard_alu_op_iball_lt] = {"iball_lt", 0},
127 [midgard_alu_op_iball_lte] = {"iball_lte", 0},
128 [midgard_alu_op_ubany_lt] = {"ubany_lt", 0},
129 [midgard_alu_op_ubany_lte] = {"ubany_lte", 0},
130 [midgard_alu_op_ibany_lt] = {"ibany_lt", 0},
131 [midgard_alu_op_ibany_lte] = {"ibany_lte", 0},
132
133 [midgard_alu_op_freduce] = {"freduce", 0},
134 [midgard_alu_op_bball_eq] = {"bball_eq", 0 | OP_COMMUTES},
135 [midgard_alu_op_bbany_neq] = {"bball_eq", 0 | OP_COMMUTES},
136 [midgard_alu_op_fatan2_pt1] = {"fatan2_pt1", 0},
137 [midgard_alu_op_fatan_pt2] = {"fatan_pt2", 0},
138 };
139
140 const char *load_store_opcode_names[256] = {
141 [midgard_op_st_cubemap_coords] = "st_cubemap_coords",
142 [midgard_op_ld_global_id] = "ld_global_id",
143
144 [midgard_op_atomic_add] = "atomic_add",
145 [midgard_op_atomic_and] = "atomic_and",
146 [midgard_op_atomic_or] = "atomic_or",
147 [midgard_op_atomic_xor] = "atomic_xor",
148 [midgard_op_atomic_imin] = "atomic_imin",
149 [midgard_op_atomic_umin] = "atomic_umin",
150 [midgard_op_atomic_imax] = "atomic_imax",
151 [midgard_op_atomic_umax] = "atomic_umax",
152 [midgard_op_atomic_xchg] = "atomic_xchg",
153
154 [midgard_op_ld_char] = "ld_char",
155 [midgard_op_ld_char2] = "ld_char2",
156 [midgard_op_ld_short] = "ld_short",
157 [midgard_op_ld_char4] = "ld_char4",
158 [midgard_op_ld_short4] = "ld_short4",
159 [midgard_op_ld_int4] = "ld_int4",
160
161 [midgard_op_ld_attr_32] = "ld_attr_32",
162 [midgard_op_ld_attr_16] = "ld_attr_16",
163 [midgard_op_ld_attr_32i] = "ld_attr_32i",
164
165 [midgard_op_ld_vary_32] = "ld_vary_32",
166 [midgard_op_ld_vary_16] = "ld_vary_16",
167 [midgard_op_ld_vary_32i] = "ld_vary_32i",
168
169 [midgard_op_ld_color_buffer_16] = "ld_color_buffer_16",
170
171 [midgard_op_ld_uniform_16] = "ld_uniform_16",
172 [midgard_op_ld_uniform_32] = "ld_uniform_32",
173 [midgard_op_ld_color_buffer_8] = "ld_color_buffer_8",
174
175 [midgard_op_st_char] = "st_char",
176 [midgard_op_st_char2] = "st_char2",
177 [midgard_op_st_char4] = "st_char4",
178 [midgard_op_st_short4] = "st_short4",
179 [midgard_op_st_int4] = "st_int4",
180
181 [midgard_op_st_vary_32] = "st_vary_32",
182 [midgard_op_st_vary_16] = "st_vary_16",
183 [midgard_op_st_vary_32i] = "st_vary_32i",
184
185 [midgard_op_st_image_f] = "st_image_f",
186 [midgard_op_st_image_ui] = "st_image_ui",
187 [midgard_op_st_image_i] = "st_image_i",
188 };