4e399508e5b2603dea896cc37b86b53e00efd4ee
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_info.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "util/u_debug.h"
29 #include "util/u_memory.h"
30 #include "tgsi_info.h"
31
32 #define NONE TGSI_OUTPUT_NONE
33 #define COMP TGSI_OUTPUT_COMPONENTWISE
34 #define REPL TGSI_OUTPUT_REPLICATE
35 #define CHAN TGSI_OUTPUT_CHAN_DEPENDENT
36 #define OTHR TGSI_OUTPUT_OTHER
37
38 #define OPCODE(_num_dst, _num_src, _output_mode, name, ...) \
39 { .opcode = TGSI_OPCODE_ ## name, \
40 .output_mode = _output_mode, .num_dst = _num_dst, .num_src = _num_src, \
41 ##__VA_ARGS__ },
42
43 #define OPCODE_GAP(opc) { .opcode = opc },
44
45 static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =
46 {
47 #include "tgsi_info_opcodes.h"
48 };
49
50 #undef OPCODE
51 #undef OPCODE_GAP
52
53 const struct tgsi_opcode_info *
54 tgsi_get_opcode_info( uint opcode )
55 {
56 static boolean firsttime = 1;
57
58 if (firsttime) {
59 unsigned i;
60 firsttime = 0;
61 for (i = 0; i < ARRAY_SIZE(opcode_info); i++)
62 assert(opcode_info[i].opcode == i);
63 }
64
65 if (opcode < TGSI_OPCODE_LAST)
66 return &opcode_info[opcode];
67
68 assert( 0 );
69 return NULL;
70 }
71
72 #define OPCODE(_num_dst, _num_src, _output_mode, name, ...) #name,
73 #define OPCODE_GAP(opc) "UNK" #opc,
74
75 static const char * const opcode_names[TGSI_OPCODE_LAST] =
76 {
77 #include "tgsi_info_opcodes.h"
78 };
79
80 #undef OPCODE
81 #undef OPCODE_GAP
82
83 const char *
84 tgsi_get_opcode_name( uint opcode )
85 {
86 if (opcode >= ARRAY_SIZE(opcode_names))
87 return "UNK_OOB";
88 return opcode_names[opcode];
89 }
90
91
92 const char *
93 tgsi_get_processor_name( uint processor )
94 {
95 switch (processor) {
96 case PIPE_SHADER_VERTEX:
97 return "vertex shader";
98 case PIPE_SHADER_FRAGMENT:
99 return "fragment shader";
100 case PIPE_SHADER_GEOMETRY:
101 return "geometry shader";
102 case PIPE_SHADER_TESS_CTRL:
103 return "tessellation control shader";
104 case PIPE_SHADER_TESS_EVAL:
105 return "tessellation evaluation shader";
106 case PIPE_SHADER_COMPUTE:
107 return "compute shader";
108 default:
109 return "unknown shader type!";
110 }
111 }
112
113 /**
114 * Infer the type (of the dst) of the opcode.
115 *
116 * MOV and UCMP is special so return VOID
117 */
118 static inline enum tgsi_opcode_type
119 tgsi_opcode_infer_type( uint opcode )
120 {
121 switch (opcode) {
122 case TGSI_OPCODE_MOV:
123 case TGSI_OPCODE_UCMP:
124 return TGSI_TYPE_UNTYPED;
125 case TGSI_OPCODE_NOT:
126 case TGSI_OPCODE_SHL:
127 case TGSI_OPCODE_AND:
128 case TGSI_OPCODE_OR:
129 case TGSI_OPCODE_XOR:
130 case TGSI_OPCODE_TXQ:
131 case TGSI_OPCODE_TXQS:
132 case TGSI_OPCODE_F2U:
133 case TGSI_OPCODE_UDIV:
134 case TGSI_OPCODE_UMAD:
135 case TGSI_OPCODE_UMAX:
136 case TGSI_OPCODE_UMIN:
137 case TGSI_OPCODE_UMOD:
138 case TGSI_OPCODE_UMUL:
139 case TGSI_OPCODE_USEQ:
140 case TGSI_OPCODE_USGE:
141 case TGSI_OPCODE_USHR:
142 case TGSI_OPCODE_USLT:
143 case TGSI_OPCODE_USNE:
144 case TGSI_OPCODE_SVIEWINFO:
145 case TGSI_OPCODE_UMUL_HI:
146 case TGSI_OPCODE_UBFE:
147 case TGSI_OPCODE_BFI:
148 case TGSI_OPCODE_BREV:
149 case TGSI_OPCODE_POPC:
150 case TGSI_OPCODE_LSB:
151 case TGSI_OPCODE_UMSB:
152 return TGSI_TYPE_UNSIGNED;
153 case TGSI_OPCODE_ARL:
154 case TGSI_OPCODE_ARR:
155 case TGSI_OPCODE_MOD:
156 case TGSI_OPCODE_F2I:
157 case TGSI_OPCODE_FSEQ:
158 case TGSI_OPCODE_FSGE:
159 case TGSI_OPCODE_FSLT:
160 case TGSI_OPCODE_FSNE:
161 case TGSI_OPCODE_IDIV:
162 case TGSI_OPCODE_IMAX:
163 case TGSI_OPCODE_IMIN:
164 case TGSI_OPCODE_INEG:
165 case TGSI_OPCODE_ISGE:
166 case TGSI_OPCODE_ISHR:
167 case TGSI_OPCODE_ISLT:
168 case TGSI_OPCODE_UADD:
169 case TGSI_OPCODE_UARL:
170 case TGSI_OPCODE_IABS:
171 case TGSI_OPCODE_ISSG:
172 case TGSI_OPCODE_IMUL_HI:
173 case TGSI_OPCODE_IBFE:
174 case TGSI_OPCODE_IMSB:
175 case TGSI_OPCODE_DSEQ:
176 case TGSI_OPCODE_DSGE:
177 case TGSI_OPCODE_DSLT:
178 case TGSI_OPCODE_DSNE:
179 case TGSI_OPCODE_U64SEQ:
180 case TGSI_OPCODE_U64SNE:
181 case TGSI_OPCODE_U64SLT:
182 case TGSI_OPCODE_U64SGE:
183 case TGSI_OPCODE_I64SLT:
184 case TGSI_OPCODE_I64SGE:
185 return TGSI_TYPE_SIGNED;
186 case TGSI_OPCODE_DADD:
187 case TGSI_OPCODE_DABS:
188 case TGSI_OPCODE_DFMA:
189 case TGSI_OPCODE_DNEG:
190 case TGSI_OPCODE_DMUL:
191 case TGSI_OPCODE_DMAX:
192 case TGSI_OPCODE_DDIV:
193 case TGSI_OPCODE_DMIN:
194 case TGSI_OPCODE_DRCP:
195 case TGSI_OPCODE_DSQRT:
196 case TGSI_OPCODE_DMAD:
197 case TGSI_OPCODE_DLDEXP:
198 case TGSI_OPCODE_DFRACEXP:
199 case TGSI_OPCODE_DFRAC:
200 case TGSI_OPCODE_DRSQ:
201 case TGSI_OPCODE_DTRUNC:
202 case TGSI_OPCODE_DCEIL:
203 case TGSI_OPCODE_DFLR:
204 case TGSI_OPCODE_DROUND:
205 case TGSI_OPCODE_DSSG:
206 case TGSI_OPCODE_F2D:
207 case TGSI_OPCODE_I2D:
208 case TGSI_OPCODE_U2D:
209 case TGSI_OPCODE_U642D:
210 case TGSI_OPCODE_I642D:
211 return TGSI_TYPE_DOUBLE;
212 case TGSI_OPCODE_U64MAX:
213 case TGSI_OPCODE_U64MIN:
214 case TGSI_OPCODE_U64ADD:
215 case TGSI_OPCODE_U64MUL:
216 case TGSI_OPCODE_U64DIV:
217 case TGSI_OPCODE_U64MOD:
218 case TGSI_OPCODE_U64SHL:
219 case TGSI_OPCODE_U64SHR:
220 case TGSI_OPCODE_F2U64:
221 case TGSI_OPCODE_D2U64:
222 return TGSI_TYPE_UNSIGNED64;
223 case TGSI_OPCODE_I64MAX:
224 case TGSI_OPCODE_I64MIN:
225 case TGSI_OPCODE_I64ABS:
226 case TGSI_OPCODE_I64SSG:
227 case TGSI_OPCODE_I64NEG:
228 case TGSI_OPCODE_I64SHR:
229 case TGSI_OPCODE_I64DIV:
230 case TGSI_OPCODE_I64MOD:
231 case TGSI_OPCODE_F2I64:
232 case TGSI_OPCODE_U2I64:
233 case TGSI_OPCODE_I2I64:
234 case TGSI_OPCODE_D2I64:
235 return TGSI_TYPE_SIGNED64;
236 default:
237 return TGSI_TYPE_FLOAT;
238 }
239 }
240
241 /*
242 * infer the source type of a TGSI opcode.
243 */
244 enum tgsi_opcode_type
245 tgsi_opcode_infer_src_type(uint opcode, uint src_idx)
246 {
247 if (src_idx == 1 &&
248 (opcode == TGSI_OPCODE_DLDEXP || opcode == TGSI_OPCODE_LDEXP))
249 return TGSI_TYPE_SIGNED;
250
251 switch (opcode) {
252 case TGSI_OPCODE_UIF:
253 case TGSI_OPCODE_TXF:
254 case TGSI_OPCODE_TXF_LZ:
255 case TGSI_OPCODE_U2F:
256 case TGSI_OPCODE_U2D:
257 case TGSI_OPCODE_UADD:
258 case TGSI_OPCODE_SWITCH:
259 case TGSI_OPCODE_CASE:
260 case TGSI_OPCODE_SAMPLE_I:
261 case TGSI_OPCODE_SAMPLE_I_MS:
262 case TGSI_OPCODE_UMUL_HI:
263 case TGSI_OPCODE_UP2H:
264 case TGSI_OPCODE_U2I64:
265 case TGSI_OPCODE_MEMBAR:
266 return TGSI_TYPE_UNSIGNED;
267 case TGSI_OPCODE_IMUL_HI:
268 case TGSI_OPCODE_I2F:
269 case TGSI_OPCODE_I2D:
270 case TGSI_OPCODE_I2I64:
271 return TGSI_TYPE_SIGNED;
272 case TGSI_OPCODE_ARL:
273 case TGSI_OPCODE_ARR:
274 case TGSI_OPCODE_F2D:
275 case TGSI_OPCODE_F2I:
276 case TGSI_OPCODE_F2U:
277 case TGSI_OPCODE_FSEQ:
278 case TGSI_OPCODE_FSGE:
279 case TGSI_OPCODE_FSLT:
280 case TGSI_OPCODE_FSNE:
281 case TGSI_OPCODE_UCMP:
282 case TGSI_OPCODE_F2U64:
283 case TGSI_OPCODE_F2I64:
284 return TGSI_TYPE_FLOAT;
285 case TGSI_OPCODE_D2F:
286 case TGSI_OPCODE_D2U:
287 case TGSI_OPCODE_D2I:
288 case TGSI_OPCODE_DSEQ:
289 case TGSI_OPCODE_DSGE:
290 case TGSI_OPCODE_DSLT:
291 case TGSI_OPCODE_DSNE:
292 case TGSI_OPCODE_D2U64:
293 case TGSI_OPCODE_D2I64:
294 return TGSI_TYPE_DOUBLE;
295 case TGSI_OPCODE_U64SEQ:
296 case TGSI_OPCODE_U64SNE:
297 case TGSI_OPCODE_U64SLT:
298 case TGSI_OPCODE_U64SGE:
299 case TGSI_OPCODE_U642F:
300 case TGSI_OPCODE_U642D:
301 return TGSI_TYPE_UNSIGNED64;
302 case TGSI_OPCODE_I64SLT:
303 case TGSI_OPCODE_I64SGE:
304 case TGSI_OPCODE_I642F:
305 case TGSI_OPCODE_I642D:
306 return TGSI_TYPE_SIGNED64;
307 default:
308 return tgsi_opcode_infer_type(opcode);
309 }
310 }
311
312 /*
313 * infer the destination type of a TGSI opcode.
314 */
315 enum tgsi_opcode_type
316 tgsi_opcode_infer_dst_type( uint opcode, uint dst_idx )
317 {
318 if (dst_idx == 1 && opcode == TGSI_OPCODE_DFRACEXP)
319 return TGSI_TYPE_SIGNED;
320
321 return tgsi_opcode_infer_type(opcode);
322 }