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 *
tgsi_get_opcode_info(enum tgsi_opcode opcode)54 tgsi_get_opcode_info(enum tgsi_opcode opcode)
55 {
56 static bool 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 *
tgsi_get_opcode_name(enum tgsi_opcode opcode)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 /**
97 * Infer the type (of the dst) of the opcode.
98 *
99 * MOV and UCMP is special so return VOID
100 */
101 static inline enum tgsi_opcode_type
tgsi_opcode_infer_type(enum tgsi_opcode opcode)102 tgsi_opcode_infer_type(enum tgsi_opcode opcode)
103 {
104 switch (opcode) {
105 case TGSI_OPCODE_MOV:
106 case TGSI_OPCODE_UCMP:
107 return TGSI_TYPE_UNTYPED;
108 case TGSI_OPCODE_NOT:
109 case TGSI_OPCODE_SHL:
110 case TGSI_OPCODE_AND:
111 case TGSI_OPCODE_OR:
112 case TGSI_OPCODE_XOR:
113 case TGSI_OPCODE_TXQ:
114 case TGSI_OPCODE_TXQS:
115 case TGSI_OPCODE_F2U:
116 case TGSI_OPCODE_UDIV:
117 case TGSI_OPCODE_UMAD:
118 case TGSI_OPCODE_UMAX:
119 case TGSI_OPCODE_UMIN:
120 case TGSI_OPCODE_UMOD:
121 case TGSI_OPCODE_UMUL:
122 case TGSI_OPCODE_USEQ:
123 case TGSI_OPCODE_USGE:
124 case TGSI_OPCODE_USHR:
125 case TGSI_OPCODE_USLT:
126 case TGSI_OPCODE_USNE:
127 case TGSI_OPCODE_SVIEWINFO:
128 case TGSI_OPCODE_UMUL_HI:
129 case TGSI_OPCODE_UBFE:
130 case TGSI_OPCODE_BFI:
131 case TGSI_OPCODE_BREV:
132 case TGSI_OPCODE_IMG2HND:
133 case TGSI_OPCODE_SAMP2HND:
134 return TGSI_TYPE_UNSIGNED;
135 case TGSI_OPCODE_ARL:
136 case TGSI_OPCODE_ARR:
137 case TGSI_OPCODE_MOD:
138 case TGSI_OPCODE_F2I:
139 case TGSI_OPCODE_FSEQ:
140 case TGSI_OPCODE_FSGE:
141 case TGSI_OPCODE_FSLT:
142 case TGSI_OPCODE_FSNE:
143 case TGSI_OPCODE_IDIV:
144 case TGSI_OPCODE_IMAX:
145 case TGSI_OPCODE_IMIN:
146 case TGSI_OPCODE_INEG:
147 case TGSI_OPCODE_ISGE:
148 case TGSI_OPCODE_ISHR:
149 case TGSI_OPCODE_ISLT:
150 case TGSI_OPCODE_UADD:
151 case TGSI_OPCODE_UARL:
152 case TGSI_OPCODE_IABS:
153 case TGSI_OPCODE_ISSG:
154 case TGSI_OPCODE_IMUL_HI:
155 case TGSI_OPCODE_IBFE:
156 case TGSI_OPCODE_IMSB:
157 case TGSI_OPCODE_DSEQ:
158 case TGSI_OPCODE_DSGE:
159 case TGSI_OPCODE_DSLT:
160 case TGSI_OPCODE_DSNE:
161 case TGSI_OPCODE_U64SEQ:
162 case TGSI_OPCODE_U64SNE:
163 case TGSI_OPCODE_U64SLT:
164 case TGSI_OPCODE_U64SGE:
165 case TGSI_OPCODE_I64SLT:
166 case TGSI_OPCODE_I64SGE:
167 case TGSI_OPCODE_LSB:
168 case TGSI_OPCODE_POPC:
169 case TGSI_OPCODE_UMSB:
170 return TGSI_TYPE_SIGNED;
171 case TGSI_OPCODE_DADD:
172 case TGSI_OPCODE_DABS:
173 case TGSI_OPCODE_DFMA:
174 case TGSI_OPCODE_DNEG:
175 case TGSI_OPCODE_DMUL:
176 case TGSI_OPCODE_DMAX:
177 case TGSI_OPCODE_DDIV:
178 case TGSI_OPCODE_DMIN:
179 case TGSI_OPCODE_DRCP:
180 case TGSI_OPCODE_DSQRT:
181 case TGSI_OPCODE_DMAD:
182 case TGSI_OPCODE_DLDEXP:
183 case TGSI_OPCODE_DFRAC:
184 case TGSI_OPCODE_DRSQ:
185 case TGSI_OPCODE_DTRUNC:
186 case TGSI_OPCODE_DCEIL:
187 case TGSI_OPCODE_DFLR:
188 case TGSI_OPCODE_DROUND:
189 case TGSI_OPCODE_DSSG:
190 case TGSI_OPCODE_F2D:
191 case TGSI_OPCODE_I2D:
192 case TGSI_OPCODE_U2D:
193 case TGSI_OPCODE_U642D:
194 case TGSI_OPCODE_I642D:
195 return TGSI_TYPE_DOUBLE;
196 case TGSI_OPCODE_U64MAX:
197 case TGSI_OPCODE_U64MIN:
198 case TGSI_OPCODE_U64ADD:
199 case TGSI_OPCODE_U64MUL:
200 case TGSI_OPCODE_U64DIV:
201 case TGSI_OPCODE_U64MOD:
202 case TGSI_OPCODE_U64SHL:
203 case TGSI_OPCODE_U64SHR:
204 case TGSI_OPCODE_F2U64:
205 case TGSI_OPCODE_D2U64:
206 return TGSI_TYPE_UNSIGNED64;
207 case TGSI_OPCODE_I64MAX:
208 case TGSI_OPCODE_I64MIN:
209 case TGSI_OPCODE_I64ABS:
210 case TGSI_OPCODE_I64SSG:
211 case TGSI_OPCODE_I64NEG:
212 case TGSI_OPCODE_I64SHR:
213 case TGSI_OPCODE_I64DIV:
214 case TGSI_OPCODE_I64MOD:
215 case TGSI_OPCODE_F2I64:
216 case TGSI_OPCODE_U2I64:
217 case TGSI_OPCODE_I2I64:
218 case TGSI_OPCODE_D2I64:
219 return TGSI_TYPE_SIGNED64;
220 default:
221 return TGSI_TYPE_FLOAT;
222 }
223 }
224
225 /*
226 * infer the source type of a TGSI opcode.
227 */
228 enum tgsi_opcode_type
tgsi_opcode_infer_src_type(enum tgsi_opcode opcode,unsigned src_idx)229 tgsi_opcode_infer_src_type(enum tgsi_opcode opcode, unsigned src_idx)
230 {
231 if (src_idx == 1 &&
232 (opcode == TGSI_OPCODE_DLDEXP || opcode == TGSI_OPCODE_LDEXP))
233 return TGSI_TYPE_SIGNED;
234
235 if (src_idx == 1 &&
236 (opcode == TGSI_OPCODE_LOAD))
237 return TGSI_TYPE_UNSIGNED;
238
239 if (src_idx == 0 &&
240 (opcode == TGSI_OPCODE_STORE))
241 return TGSI_TYPE_UNSIGNED;
242
243 if (src_idx == 1 &&
244 ((opcode >= TGSI_OPCODE_ATOMUADD && opcode <= TGSI_OPCODE_ATOMIMAX) ||
245 opcode == TGSI_OPCODE_ATOMINC_WRAP || opcode == TGSI_OPCODE_ATOMDEC_WRAP))
246 return TGSI_TYPE_UNSIGNED;
247
248 switch (opcode) {
249 case TGSI_OPCODE_UIF:
250 case TGSI_OPCODE_TXF:
251 case TGSI_OPCODE_TXF_LZ:
252 case TGSI_OPCODE_U2F:
253 case TGSI_OPCODE_U2D:
254 case TGSI_OPCODE_UADD:
255 case TGSI_OPCODE_SWITCH:
256 case TGSI_OPCODE_CASE:
257 case TGSI_OPCODE_SAMPLE_I:
258 case TGSI_OPCODE_SAMPLE_I_MS:
259 case TGSI_OPCODE_UMUL_HI:
260 case TGSI_OPCODE_UP2H:
261 case TGSI_OPCODE_U2I64:
262 case TGSI_OPCODE_MEMBAR:
263 case TGSI_OPCODE_UMSB:
264 return TGSI_TYPE_UNSIGNED;
265 case TGSI_OPCODE_IMUL_HI:
266 case TGSI_OPCODE_I2F:
267 case TGSI_OPCODE_I2D:
268 case TGSI_OPCODE_I2I64:
269 return TGSI_TYPE_SIGNED;
270 case TGSI_OPCODE_ARL:
271 case TGSI_OPCODE_ARR:
272 case TGSI_OPCODE_F2D:
273 case TGSI_OPCODE_F2I:
274 case TGSI_OPCODE_F2U:
275 case TGSI_OPCODE_FSEQ:
276 case TGSI_OPCODE_FSGE:
277 case TGSI_OPCODE_FSLT:
278 case TGSI_OPCODE_FSNE:
279 case TGSI_OPCODE_UCMP:
280 case TGSI_OPCODE_F2U64:
281 case TGSI_OPCODE_F2I64:
282 return TGSI_TYPE_FLOAT;
283 case TGSI_OPCODE_D2F:
284 case TGSI_OPCODE_D2U:
285 case TGSI_OPCODE_D2I:
286 case TGSI_OPCODE_DSEQ:
287 case TGSI_OPCODE_DSGE:
288 case TGSI_OPCODE_DSLT:
289 case TGSI_OPCODE_DSNE:
290 case TGSI_OPCODE_D2U64:
291 case TGSI_OPCODE_D2I64:
292 return TGSI_TYPE_DOUBLE;
293 case TGSI_OPCODE_U64SEQ:
294 case TGSI_OPCODE_U64SNE:
295 case TGSI_OPCODE_U64SLT:
296 case TGSI_OPCODE_U64SGE:
297 case TGSI_OPCODE_U642F:
298 case TGSI_OPCODE_U642D:
299 return TGSI_TYPE_UNSIGNED64;
300 case TGSI_OPCODE_I64SLT:
301 case TGSI_OPCODE_I64SGE:
302 case TGSI_OPCODE_I642F:
303 case TGSI_OPCODE_I642D:
304 return TGSI_TYPE_SIGNED64;
305 default:
306 return tgsi_opcode_infer_type(opcode);
307 }
308 }
309
310 /*
311 * infer the destination type of a TGSI opcode.
312 */
313 enum tgsi_opcode_type
tgsi_opcode_infer_dst_type(enum tgsi_opcode opcode,unsigned dst_idx)314 tgsi_opcode_infer_dst_type(enum tgsi_opcode opcode, unsigned dst_idx)
315 {
316 return tgsi_opcode_infer_type(opcode);
317 }
318