gallium/aux/tgsi_build.c: Fix -Wsign-compare warnings
[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(enum tgsi_opcode opcode)
55 {
56 static boolean firsttime = 1;
57
58 ASSERT_BITFIELD_SIZE(struct tgsi_opcode_info, opcode, TGSI_OPCODE_LAST - 1);
59 ASSERT_BITFIELD_SIZE(struct tgsi_opcode_info, output_mode,
60 TGSI_OUTPUT_OTHER);
61
62 if (firsttime) {
63 unsigned i;
64 firsttime = 0;
65 for (i = 0; i < ARRAY_SIZE(opcode_info); i++)
66 assert(opcode_info[i].opcode == i);
67 }
68
69 if (opcode < TGSI_OPCODE_LAST)
70 return &opcode_info[opcode];
71
72 assert( 0 );
73 return NULL;
74 }
75
76 #define OPCODE(_num_dst, _num_src, _output_mode, name, ...) #name,
77 #define OPCODE_GAP(opc) "UNK" #opc,
78
79 static const char * const opcode_names[TGSI_OPCODE_LAST] =
80 {
81 #include "tgsi_info_opcodes.h"
82 };
83
84 #undef OPCODE
85 #undef OPCODE_GAP
86
87 const char *
88 tgsi_get_opcode_name(enum tgsi_opcode opcode)
89 {
90 if (opcode >= ARRAY_SIZE(opcode_names))
91 return "UNK_OOB";
92 return opcode_names[opcode];
93 }
94
95
96 const char *
97 tgsi_get_processor_name(enum pipe_shader_type processor)
98 {
99 switch (processor) {
100 case PIPE_SHADER_VERTEX:
101 return "vertex shader";
102 case PIPE_SHADER_FRAGMENT:
103 return "fragment shader";
104 case PIPE_SHADER_GEOMETRY:
105 return "geometry shader";
106 case PIPE_SHADER_TESS_CTRL:
107 return "tessellation control shader";
108 case PIPE_SHADER_TESS_EVAL:
109 return "tessellation evaluation shader";
110 case PIPE_SHADER_COMPUTE:
111 return "compute shader";
112 default:
113 return "unknown shader type!";
114 }
115 }
116
117 /**
118 * Infer the type (of the dst) of the opcode.
119 *
120 * MOV and UCMP is special so return VOID
121 */
122 static inline enum tgsi_opcode_type
123 tgsi_opcode_infer_type(enum tgsi_opcode opcode)
124 {
125 switch (opcode) {
126 case TGSI_OPCODE_MOV:
127 case TGSI_OPCODE_UCMP:
128 return TGSI_TYPE_UNTYPED;
129 case TGSI_OPCODE_NOT:
130 case TGSI_OPCODE_SHL:
131 case TGSI_OPCODE_AND:
132 case TGSI_OPCODE_OR:
133 case TGSI_OPCODE_XOR:
134 case TGSI_OPCODE_TXQ:
135 case TGSI_OPCODE_TXQS:
136 case TGSI_OPCODE_F2U:
137 case TGSI_OPCODE_UDIV:
138 case TGSI_OPCODE_UMAD:
139 case TGSI_OPCODE_UMAX:
140 case TGSI_OPCODE_UMIN:
141 case TGSI_OPCODE_UMOD:
142 case TGSI_OPCODE_UMUL:
143 case TGSI_OPCODE_USEQ:
144 case TGSI_OPCODE_USGE:
145 case TGSI_OPCODE_USHR:
146 case TGSI_OPCODE_USLT:
147 case TGSI_OPCODE_USNE:
148 case TGSI_OPCODE_SVIEWINFO:
149 case TGSI_OPCODE_UMUL_HI:
150 case TGSI_OPCODE_UBFE:
151 case TGSI_OPCODE_BFI:
152 case TGSI_OPCODE_BREV:
153 case TGSI_OPCODE_POPC:
154 case TGSI_OPCODE_LSB:
155 case TGSI_OPCODE_UMSB:
156 return TGSI_TYPE_UNSIGNED;
157 case TGSI_OPCODE_ARL:
158 case TGSI_OPCODE_ARR:
159 case TGSI_OPCODE_MOD:
160 case TGSI_OPCODE_F2I:
161 case TGSI_OPCODE_FSEQ:
162 case TGSI_OPCODE_FSGE:
163 case TGSI_OPCODE_FSLT:
164 case TGSI_OPCODE_FSNE:
165 case TGSI_OPCODE_IDIV:
166 case TGSI_OPCODE_IMAX:
167 case TGSI_OPCODE_IMIN:
168 case TGSI_OPCODE_INEG:
169 case TGSI_OPCODE_ISGE:
170 case TGSI_OPCODE_ISHR:
171 case TGSI_OPCODE_ISLT:
172 case TGSI_OPCODE_UADD:
173 case TGSI_OPCODE_UARL:
174 case TGSI_OPCODE_IABS:
175 case TGSI_OPCODE_ISSG:
176 case TGSI_OPCODE_IMUL_HI:
177 case TGSI_OPCODE_IBFE:
178 case TGSI_OPCODE_IMSB:
179 case TGSI_OPCODE_DSEQ:
180 case TGSI_OPCODE_DSGE:
181 case TGSI_OPCODE_DSLT:
182 case TGSI_OPCODE_DSNE:
183 case TGSI_OPCODE_U64SEQ:
184 case TGSI_OPCODE_U64SNE:
185 case TGSI_OPCODE_U64SLT:
186 case TGSI_OPCODE_U64SGE:
187 case TGSI_OPCODE_I64SLT:
188 case TGSI_OPCODE_I64SGE:
189 return TGSI_TYPE_SIGNED;
190 case TGSI_OPCODE_DADD:
191 case TGSI_OPCODE_DABS:
192 case TGSI_OPCODE_DFMA:
193 case TGSI_OPCODE_DNEG:
194 case TGSI_OPCODE_DMUL:
195 case TGSI_OPCODE_DMAX:
196 case TGSI_OPCODE_DDIV:
197 case TGSI_OPCODE_DMIN:
198 case TGSI_OPCODE_DRCP:
199 case TGSI_OPCODE_DSQRT:
200 case TGSI_OPCODE_DMAD:
201 case TGSI_OPCODE_DLDEXP:
202 case TGSI_OPCODE_DFRACEXP:
203 case TGSI_OPCODE_DFRAC:
204 case TGSI_OPCODE_DRSQ:
205 case TGSI_OPCODE_DTRUNC:
206 case TGSI_OPCODE_DCEIL:
207 case TGSI_OPCODE_DFLR:
208 case TGSI_OPCODE_DROUND:
209 case TGSI_OPCODE_DSSG:
210 case TGSI_OPCODE_F2D:
211 case TGSI_OPCODE_I2D:
212 case TGSI_OPCODE_U2D:
213 case TGSI_OPCODE_U642D:
214 case TGSI_OPCODE_I642D:
215 return TGSI_TYPE_DOUBLE;
216 case TGSI_OPCODE_U64MAX:
217 case TGSI_OPCODE_U64MIN:
218 case TGSI_OPCODE_U64ADD:
219 case TGSI_OPCODE_U64MUL:
220 case TGSI_OPCODE_U64DIV:
221 case TGSI_OPCODE_U64MOD:
222 case TGSI_OPCODE_U64SHL:
223 case TGSI_OPCODE_U64SHR:
224 case TGSI_OPCODE_F2U64:
225 case TGSI_OPCODE_D2U64:
226 return TGSI_TYPE_UNSIGNED64;
227 case TGSI_OPCODE_I64MAX:
228 case TGSI_OPCODE_I64MIN:
229 case TGSI_OPCODE_I64ABS:
230 case TGSI_OPCODE_I64SSG:
231 case TGSI_OPCODE_I64NEG:
232 case TGSI_OPCODE_I64SHR:
233 case TGSI_OPCODE_I64DIV:
234 case TGSI_OPCODE_I64MOD:
235 case TGSI_OPCODE_F2I64:
236 case TGSI_OPCODE_U2I64:
237 case TGSI_OPCODE_I2I64:
238 case TGSI_OPCODE_D2I64:
239 return TGSI_TYPE_SIGNED64;
240 default:
241 return TGSI_TYPE_FLOAT;
242 }
243 }
244
245 /*
246 * infer the source type of a TGSI opcode.
247 */
248 enum tgsi_opcode_type
249 tgsi_opcode_infer_src_type(enum tgsi_opcode opcode, uint src_idx)
250 {
251 if (src_idx == 1 &&
252 (opcode == TGSI_OPCODE_DLDEXP || opcode == TGSI_OPCODE_LDEXP))
253 return TGSI_TYPE_SIGNED;
254
255 switch (opcode) {
256 case TGSI_OPCODE_UIF:
257 case TGSI_OPCODE_TXF:
258 case TGSI_OPCODE_TXF_LZ:
259 case TGSI_OPCODE_U2F:
260 case TGSI_OPCODE_U2D:
261 case TGSI_OPCODE_UADD:
262 case TGSI_OPCODE_SWITCH:
263 case TGSI_OPCODE_CASE:
264 case TGSI_OPCODE_SAMPLE_I:
265 case TGSI_OPCODE_SAMPLE_I_MS:
266 case TGSI_OPCODE_UMUL_HI:
267 case TGSI_OPCODE_UP2H:
268 case TGSI_OPCODE_U2I64:
269 case TGSI_OPCODE_MEMBAR:
270 return TGSI_TYPE_UNSIGNED;
271 case TGSI_OPCODE_IMUL_HI:
272 case TGSI_OPCODE_I2F:
273 case TGSI_OPCODE_I2D:
274 case TGSI_OPCODE_I2I64:
275 return TGSI_TYPE_SIGNED;
276 case TGSI_OPCODE_ARL:
277 case TGSI_OPCODE_ARR:
278 case TGSI_OPCODE_F2D:
279 case TGSI_OPCODE_F2I:
280 case TGSI_OPCODE_F2U:
281 case TGSI_OPCODE_FSEQ:
282 case TGSI_OPCODE_FSGE:
283 case TGSI_OPCODE_FSLT:
284 case TGSI_OPCODE_FSNE:
285 case TGSI_OPCODE_UCMP:
286 case TGSI_OPCODE_F2U64:
287 case TGSI_OPCODE_F2I64:
288 return TGSI_TYPE_FLOAT;
289 case TGSI_OPCODE_D2F:
290 case TGSI_OPCODE_D2U:
291 case TGSI_OPCODE_D2I:
292 case TGSI_OPCODE_DSEQ:
293 case TGSI_OPCODE_DSGE:
294 case TGSI_OPCODE_DSLT:
295 case TGSI_OPCODE_DSNE:
296 case TGSI_OPCODE_D2U64:
297 case TGSI_OPCODE_D2I64:
298 return TGSI_TYPE_DOUBLE;
299 case TGSI_OPCODE_U64SEQ:
300 case TGSI_OPCODE_U64SNE:
301 case TGSI_OPCODE_U64SLT:
302 case TGSI_OPCODE_U64SGE:
303 case TGSI_OPCODE_U642F:
304 case TGSI_OPCODE_U642D:
305 return TGSI_TYPE_UNSIGNED64;
306 case TGSI_OPCODE_I64SLT:
307 case TGSI_OPCODE_I64SGE:
308 case TGSI_OPCODE_I642F:
309 case TGSI_OPCODE_I642D:
310 return TGSI_TYPE_SIGNED64;
311 default:
312 return tgsi_opcode_infer_type(opcode);
313 }
314 }
315
316 /*
317 * infer the destination type of a TGSI opcode.
318 */
319 enum tgsi_opcode_type
320 tgsi_opcode_infer_dst_type(enum tgsi_opcode opcode, uint dst_idx)
321 {
322 if (dst_idx == 1 && opcode == TGSI_OPCODE_DFRACEXP)
323 return TGSI_TYPE_SIGNED;
324
325 return tgsi_opcode_infer_type(opcode);
326 }