745f92272f8eeadd1c4aa0300482ef4180cbe267
[mesa.git] / src / gallium / drivers / r600 / r600_compiler_tgsi.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 #include <errno.h>
28 #include <tgsi/tgsi_parse.h>
29 #include <tgsi/tgsi_scan.h>
30 #include "r600_shader.h"
31 #include "r600_context.h"
32
33 struct tgsi_shader {
34 struct c_vector **v[TGSI_FILE_COUNT];
35 struct tgsi_shader_info info;
36 struct tgsi_parse_context parser;
37 const struct tgsi_token *tokens;
38 struct c_shader *shader;
39 struct c_node *node;
40 };
41
42 static unsigned tgsi_file_to_c_file(unsigned file);
43 static unsigned tgsi_sname_to_c_sname(unsigned sname);
44 static int tgsi_opcode_to_c_opcode(unsigned opcode, unsigned *copcode);
45
46 static int tgsi_shader_init(struct tgsi_shader *ts,
47 const struct tgsi_token *tokens,
48 struct c_shader *shader)
49 {
50 int i;
51
52 ts->shader = shader;
53 ts->tokens = tokens;
54 tgsi_scan_shader(ts->tokens, &ts->info);
55 tgsi_parse_init(&ts->parser, ts->tokens);
56 /* initialize to NULL in case of error */
57 for (i = 0; i < C_FILE_COUNT; i++) {
58 ts->v[i] = NULL;
59 }
60 for (i = 0; i < TGSI_FILE_COUNT; i++) {
61 if (ts->info.file_count[i] > 0) {
62 ts->v[i] = calloc(ts->info.file_count[i], sizeof(void*));
63 if (ts->v[i] == NULL) {
64 fprintf(stderr, "%s:%d unsupported %d %d\n", __func__, __LINE__, i, ts->info.file_count[i]);
65 return -ENOMEM;
66 }
67 }
68 }
69 return 0;
70 }
71
72 static void tgsi_shader_destroy(struct tgsi_shader *ts)
73 {
74 int i;
75
76 for (i = 0; i < TGSI_FILE_COUNT; i++) {
77 free(ts->v[i]);
78 }
79 tgsi_parse_free(&ts->parser);
80 }
81
82 static int ntransform_declaration(struct tgsi_shader *ts)
83 {
84 struct tgsi_full_declaration *fd = &ts->parser.FullToken.FullDeclaration;
85 struct c_vector *v;
86 unsigned file;
87 unsigned name;
88 int sid;
89 int i;
90
91 if (fd->Declaration.Dimension) {
92 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
93 return -EINVAL;
94 }
95 for (i = fd->Range.First ; i <= fd->Range.Last; i++) {
96 sid = i;
97 name = C_SEMANTIC_GENERIC;
98 file = tgsi_file_to_c_file(fd->Declaration.File);
99 if (file == TGSI_FILE_NULL) {
100 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
101 return -EINVAL;
102 }
103 if (fd->Declaration.Semantic) {
104 name = tgsi_sname_to_c_sname(fd->Semantic.Name);
105 sid = fd->Semantic.Index;
106 }
107 v = c_shader_vector_new(ts->shader, file, name, sid);
108 if (v == NULL) {
109 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
110 return -ENOMEM;
111 }
112 ts->v[fd->Declaration.File][i] = v;
113 }
114 return 0;
115 }
116
117 static int ntransform_immediate(struct tgsi_shader *ts)
118 {
119 struct tgsi_full_immediate *fd = &ts->parser.FullToken.FullImmediate;
120 struct c_vector *v;
121 unsigned file;
122 unsigned name;
123
124 if (fd->Immediate.DataType != TGSI_IMM_FLOAT32) {
125 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
126 return -EINVAL;
127 }
128 name = C_SEMANTIC_GENERIC;
129 file = C_FILE_IMMEDIATE;
130 v = c_shader_vector_new(ts->shader, file, name, 0);
131 if (v == NULL) {
132 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
133 return -ENOMEM;
134 }
135 v->channel[0]->value = fd->u[0].Uint;
136 v->channel[1]->value = fd->u[1].Uint;
137 v->channel[2]->value = fd->u[2].Uint;
138 v->channel[3]->value = fd->u[3].Uint;
139 ts->v[TGSI_FILE_IMMEDIATE][0] = v;
140 return 0;
141 }
142
143 static int ntransform_instruction(struct tgsi_shader *ts)
144 {
145 struct tgsi_full_instruction *fi = &ts->parser.FullToken.FullInstruction;
146 struct c_shader *shader = ts->shader;
147 struct c_instruction instruction;
148 unsigned opcode;
149 int i, r;
150
151 if (fi->Instruction.NumDstRegs > 1) {
152 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
153 return -EINVAL;
154 }
155 if (fi->Instruction.Saturate) {
156 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
157 return -EINVAL;
158 }
159 if (fi->Instruction.Predicate) {
160 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
161 return -EINVAL;
162 }
163 if (fi->Instruction.Label) {
164 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
165 return -EINVAL;
166 }
167 if (fi->Instruction.Texture) {
168 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
169 return -EINVAL;
170 }
171 for (i = 0; i < fi->Instruction.NumSrcRegs; i++) {
172 if (fi->Src[i].Register.Indirect ||
173 fi->Src[i].Register.Dimension ||
174 fi->Src[i].Register.Absolute) {
175 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
176 return -EINVAL;
177 }
178 }
179 for (i = 0; i < fi->Instruction.NumDstRegs; i++) {
180 if (fi->Dst[i].Register.Indirect || fi->Dst[i].Register.Dimension) {
181 fprintf(stderr, "%s %d unsupported\n", __func__, __LINE__);
182 return -EINVAL;
183 }
184 }
185 r = tgsi_opcode_to_c_opcode(fi->Instruction.Opcode, &opcode);
186 if (r) {
187 fprintf(stderr, "%s:%d unsupported\n", __func__, __LINE__);
188 return r;
189 }
190 if (opcode == C_OPCODE_END) {
191 return c_node_cfg_link(ts->node, &shader->end);
192 }
193 /* FIXME add flow instruction handling */
194 memset(&instruction, 0, sizeof(struct c_instruction));
195 instruction.opcode = opcode;
196 instruction.ninput = fi->Instruction.NumSrcRegs;
197 instruction.write_mask = fi->Dst[0].Register.WriteMask;
198 for (i = 0; i < fi->Instruction.NumSrcRegs; i++) {
199 instruction.input[i].vector = ts->v[fi->Src[i].Register.File][fi->Src[i].Register.Index];
200 instruction.input[i].swizzle[0] = fi->Src[i].Register.SwizzleX;
201 instruction.input[i].swizzle[1] = fi->Src[i].Register.SwizzleY;
202 instruction.input[i].swizzle[2] = fi->Src[i].Register.SwizzleZ;
203 instruction.input[i].swizzle[3] = fi->Src[i].Register.SwizzleW;
204 }
205 instruction.output.vector = ts->v[fi->Dst[0].Register.File][fi->Dst[0].Register.Index];
206 instruction.output.swizzle[0] = (fi->Dst[0].Register.WriteMask & 0x1) ? C_SWIZZLE_X : C_SWIZZLE_D;
207 instruction.output.swizzle[1] = (fi->Dst[0].Register.WriteMask & 0x2) ? C_SWIZZLE_Y : C_SWIZZLE_D;
208 instruction.output.swizzle[2] = (fi->Dst[0].Register.WriteMask & 0x4) ? C_SWIZZLE_Z : C_SWIZZLE_D;
209 instruction.output.swizzle[3] = (fi->Dst[0].Register.WriteMask & 0x8) ? C_SWIZZLE_W : C_SWIZZLE_D;
210 return c_node_add_new_instruction(ts->node, &instruction);
211 }
212
213 int c_shader_from_tgsi(struct c_shader *shader, unsigned type,
214 const struct tgsi_token *tokens)
215 {
216 struct tgsi_shader ts;
217 int r = 0;
218
219 c_shader_init(shader, type);
220 r = tgsi_shader_init(&ts, tokens, shader);
221 if (r)
222 goto out_err;
223 ts.shader = shader;
224 ts.node = &shader->entry;
225 while (!tgsi_parse_end_of_tokens(&ts.parser)) {
226 tgsi_parse_token(&ts.parser);
227 switch (ts.parser.FullToken.Token.Type) {
228 case TGSI_TOKEN_TYPE_IMMEDIATE:
229 r = ntransform_immediate(&ts);
230 if (r)
231 goto out_err;
232 break;
233 case TGSI_TOKEN_TYPE_DECLARATION:
234 r = ntransform_declaration(&ts);
235 if (r)
236 goto out_err;
237 break;
238 case TGSI_TOKEN_TYPE_INSTRUCTION:
239 r = ntransform_instruction(&ts);
240 if (r)
241 goto out_err;
242 break;
243 default:
244 r = -EINVAL;
245 goto out_err;
246 }
247 }
248 tgsi_shader_destroy(&ts);
249 return 0;
250 out_err:
251 c_shader_destroy(shader);
252 tgsi_shader_destroy(&ts);
253 return r;
254 }
255
256 static unsigned tgsi_file_to_c_file(unsigned file)
257 {
258 switch (file) {
259 case TGSI_FILE_CONSTANT:
260 return C_FILE_CONSTANT;
261 case TGSI_FILE_INPUT:
262 return C_FILE_INPUT;
263 case TGSI_FILE_OUTPUT:
264 return C_FILE_OUTPUT;
265 case TGSI_FILE_TEMPORARY:
266 return C_FILE_TEMPORARY;
267 case TGSI_FILE_SAMPLER:
268 return C_FILE_SAMPLER;
269 case TGSI_FILE_ADDRESS:
270 return C_FILE_ADDRESS;
271 case TGSI_FILE_IMMEDIATE:
272 return C_FILE_IMMEDIATE;
273 case TGSI_FILE_LOOP:
274 return C_FILE_LOOP;
275 case TGSI_FILE_PREDICATE:
276 return C_FILE_PREDICATE;
277 case TGSI_FILE_SYSTEM_VALUE:
278 return C_FILE_SYSTEM_VALUE;
279 case TGSI_FILE_NULL:
280 return C_FILE_NULL;
281 default:
282 fprintf(stderr, "%s:%d unsupported file %d\n", __func__, __LINE__, file);
283 return C_FILE_NULL;
284 }
285 }
286
287 static unsigned tgsi_sname_to_c_sname(unsigned sname)
288 {
289 switch (sname) {
290 case TGSI_SEMANTIC_POSITION:
291 return C_SEMANTIC_POSITION;
292 case TGSI_SEMANTIC_COLOR:
293 return C_SEMANTIC_COLOR;
294 case TGSI_SEMANTIC_BCOLOR:
295 return C_SEMANTIC_BCOLOR;
296 case TGSI_SEMANTIC_FOG:
297 return C_SEMANTIC_FOG;
298 case TGSI_SEMANTIC_PSIZE:
299 return C_SEMANTIC_PSIZE;
300 case TGSI_SEMANTIC_GENERIC:
301 return C_SEMANTIC_GENERIC;
302 case TGSI_SEMANTIC_NORMAL:
303 return C_SEMANTIC_NORMAL;
304 case TGSI_SEMANTIC_FACE:
305 return C_SEMANTIC_FACE;
306 case TGSI_SEMANTIC_EDGEFLAG:
307 return C_SEMANTIC_EDGEFLAG;
308 case TGSI_SEMANTIC_PRIMID:
309 return C_SEMANTIC_PRIMID;
310 case TGSI_SEMANTIC_INSTANCEID:
311 return C_SEMANTIC_INSTANCEID;
312 default:
313 return C_SEMANTIC_GENERIC;
314 }
315 }
316
317 static int tgsi_opcode_to_c_opcode(unsigned opcode, unsigned *copcode)
318 {
319 switch (opcode) {
320 case TGSI_OPCODE_MOV:
321 *copcode = C_OPCODE_MOV;
322 return 0;
323 case TGSI_OPCODE_MUL:
324 *copcode = C_OPCODE_MUL;
325 return 0;
326 case TGSI_OPCODE_MAD:
327 *copcode = C_OPCODE_MAD;
328 return 0;
329 case TGSI_OPCODE_END:
330 *copcode = C_OPCODE_END;
331 return 0;
332 case TGSI_OPCODE_ARL:
333 *copcode = C_OPCODE_ARL;
334 return 0;
335 case TGSI_OPCODE_LIT:
336 *copcode = C_OPCODE_LIT;
337 return 0;
338 case TGSI_OPCODE_RCP:
339 *copcode = C_OPCODE_RCP;
340 return 0;
341 case TGSI_OPCODE_RSQ:
342 *copcode = C_OPCODE_RSQ;
343 return 0;
344 case TGSI_OPCODE_EXP:
345 *copcode = C_OPCODE_EXP;
346 return 0;
347 case TGSI_OPCODE_LOG:
348 *copcode = C_OPCODE_LOG;
349 return 0;
350 case TGSI_OPCODE_ADD:
351 *copcode = C_OPCODE_ADD;
352 return 0;
353 case TGSI_OPCODE_DP3:
354 *copcode = C_OPCODE_DP3;
355 return 0;
356 case TGSI_OPCODE_DP4:
357 *copcode = C_OPCODE_DP4;
358 return 0;
359 case TGSI_OPCODE_DST:
360 *copcode = C_OPCODE_DST;
361 return 0;
362 case TGSI_OPCODE_MIN:
363 *copcode = C_OPCODE_MIN;
364 return 0;
365 case TGSI_OPCODE_MAX:
366 *copcode = C_OPCODE_MAX;
367 return 0;
368 case TGSI_OPCODE_SLT:
369 *copcode = C_OPCODE_SLT;
370 return 0;
371 case TGSI_OPCODE_SGE:
372 *copcode = C_OPCODE_SGE;
373 return 0;
374 case TGSI_OPCODE_SUB:
375 *copcode = C_OPCODE_SUB;
376 return 0;
377 case TGSI_OPCODE_LRP:
378 *copcode = C_OPCODE_LRP;
379 return 0;
380 case TGSI_OPCODE_CND:
381 *copcode = C_OPCODE_CND;
382 return 0;
383 case TGSI_OPCODE_DP2A:
384 *copcode = C_OPCODE_DP2A;
385 return 0;
386 case TGSI_OPCODE_FRC:
387 *copcode = C_OPCODE_FRC;
388 return 0;
389 case TGSI_OPCODE_CLAMP:
390 *copcode = C_OPCODE_CLAMP;
391 return 0;
392 case TGSI_OPCODE_FLR:
393 *copcode = C_OPCODE_FLR;
394 return 0;
395 case TGSI_OPCODE_ROUND:
396 *copcode = C_OPCODE_ROUND;
397 return 0;
398 case TGSI_OPCODE_EX2:
399 *copcode = C_OPCODE_EX2;
400 return 0;
401 case TGSI_OPCODE_LG2:
402 *copcode = C_OPCODE_LG2;
403 return 0;
404 case TGSI_OPCODE_POW:
405 *copcode = C_OPCODE_POW;
406 return 0;
407 case TGSI_OPCODE_XPD:
408 *copcode = C_OPCODE_XPD;
409 return 0;
410 case TGSI_OPCODE_ABS:
411 *copcode = C_OPCODE_ABS;
412 return 0;
413 case TGSI_OPCODE_RCC:
414 *copcode = C_OPCODE_RCC;
415 return 0;
416 case TGSI_OPCODE_DPH:
417 *copcode = C_OPCODE_DPH;
418 return 0;
419 case TGSI_OPCODE_COS:
420 *copcode = C_OPCODE_COS;
421 return 0;
422 case TGSI_OPCODE_DDX:
423 *copcode = C_OPCODE_DDX;
424 return 0;
425 case TGSI_OPCODE_DDY:
426 *copcode = C_OPCODE_DDY;
427 return 0;
428 case TGSI_OPCODE_KILP:
429 *copcode = C_OPCODE_KILP;
430 return 0;
431 case TGSI_OPCODE_PK2H:
432 *copcode = C_OPCODE_PK2H;
433 return 0;
434 case TGSI_OPCODE_PK2US:
435 *copcode = C_OPCODE_PK2US;
436 return 0;
437 case TGSI_OPCODE_PK4B:
438 *copcode = C_OPCODE_PK4B;
439 return 0;
440 case TGSI_OPCODE_PK4UB:
441 *copcode = C_OPCODE_PK4UB;
442 return 0;
443 case TGSI_OPCODE_RFL:
444 *copcode = C_OPCODE_RFL;
445 return 0;
446 case TGSI_OPCODE_SEQ:
447 *copcode = C_OPCODE_SEQ;
448 return 0;
449 case TGSI_OPCODE_SFL:
450 *copcode = C_OPCODE_SFL;
451 return 0;
452 case TGSI_OPCODE_SGT:
453 *copcode = C_OPCODE_SGT;
454 return 0;
455 case TGSI_OPCODE_SIN:
456 *copcode = C_OPCODE_SIN;
457 return 0;
458 case TGSI_OPCODE_SLE:
459 *copcode = C_OPCODE_SLE;
460 return 0;
461 case TGSI_OPCODE_SNE:
462 *copcode = C_OPCODE_SNE;
463 return 0;
464 case TGSI_OPCODE_STR:
465 *copcode = C_OPCODE_STR;
466 return 0;
467 case TGSI_OPCODE_TEX:
468 *copcode = C_OPCODE_TEX;
469 return 0;
470 case TGSI_OPCODE_TXD:
471 *copcode = C_OPCODE_TXD;
472 return 0;
473 case TGSI_OPCODE_TXP:
474 *copcode = C_OPCODE_TXP;
475 return 0;
476 case TGSI_OPCODE_UP2H:
477 *copcode = C_OPCODE_UP2H;
478 return 0;
479 case TGSI_OPCODE_UP2US:
480 *copcode = C_OPCODE_UP2US;
481 return 0;
482 case TGSI_OPCODE_UP4B:
483 *copcode = C_OPCODE_UP4B;
484 return 0;
485 case TGSI_OPCODE_UP4UB:
486 *copcode = C_OPCODE_UP4UB;
487 return 0;
488 case TGSI_OPCODE_X2D:
489 *copcode = C_OPCODE_X2D;
490 return 0;
491 case TGSI_OPCODE_ARA:
492 *copcode = C_OPCODE_ARA;
493 return 0;
494 case TGSI_OPCODE_ARR:
495 *copcode = C_OPCODE_ARR;
496 return 0;
497 case TGSI_OPCODE_BRA:
498 *copcode = C_OPCODE_BRA;
499 return 0;
500 case TGSI_OPCODE_CAL:
501 *copcode = C_OPCODE_CAL;
502 return 0;
503 case TGSI_OPCODE_RET:
504 *copcode = C_OPCODE_RET;
505 return 0;
506 case TGSI_OPCODE_SSG:
507 *copcode = C_OPCODE_SSG;
508 return 0;
509 case TGSI_OPCODE_CMP:
510 *copcode = C_OPCODE_CMP;
511 return 0;
512 case TGSI_OPCODE_SCS:
513 *copcode = C_OPCODE_SCS;
514 return 0;
515 case TGSI_OPCODE_TXB:
516 *copcode = C_OPCODE_TXB;
517 return 0;
518 case TGSI_OPCODE_NRM:
519 *copcode = C_OPCODE_NRM;
520 return 0;
521 case TGSI_OPCODE_DIV:
522 *copcode = C_OPCODE_DIV;
523 return 0;
524 case TGSI_OPCODE_DP2:
525 *copcode = C_OPCODE_DP2;
526 return 0;
527 case TGSI_OPCODE_TXL:
528 *copcode = C_OPCODE_TXL;
529 return 0;
530 case TGSI_OPCODE_BRK:
531 *copcode = C_OPCODE_BRK;
532 return 0;
533 case TGSI_OPCODE_IF:
534 *copcode = C_OPCODE_IF;
535 return 0;
536 case TGSI_OPCODE_BGNFOR:
537 *copcode = C_OPCODE_BGNFOR;
538 return 0;
539 case TGSI_OPCODE_REP:
540 *copcode = C_OPCODE_REP;
541 return 0;
542 case TGSI_OPCODE_ELSE:
543 *copcode = C_OPCODE_ELSE;
544 return 0;
545 case TGSI_OPCODE_ENDIF:
546 *copcode = C_OPCODE_ENDIF;
547 return 0;
548 case TGSI_OPCODE_ENDFOR:
549 *copcode = C_OPCODE_ENDFOR;
550 return 0;
551 case TGSI_OPCODE_ENDREP:
552 *copcode = C_OPCODE_ENDREP;
553 return 0;
554 case TGSI_OPCODE_PUSHA:
555 *copcode = C_OPCODE_PUSHA;
556 return 0;
557 case TGSI_OPCODE_POPA:
558 *copcode = C_OPCODE_POPA;
559 return 0;
560 case TGSI_OPCODE_CEIL:
561 *copcode = C_OPCODE_CEIL;
562 return 0;
563 case TGSI_OPCODE_I2F:
564 *copcode = C_OPCODE_I2F;
565 return 0;
566 case TGSI_OPCODE_NOT:
567 *copcode = C_OPCODE_NOT;
568 return 0;
569 case TGSI_OPCODE_TRUNC:
570 *copcode = C_OPCODE_TRUNC;
571 return 0;
572 case TGSI_OPCODE_SHL:
573 *copcode = C_OPCODE_SHL;
574 return 0;
575 case TGSI_OPCODE_AND:
576 *copcode = C_OPCODE_AND;
577 return 0;
578 case TGSI_OPCODE_OR:
579 *copcode = C_OPCODE_OR;
580 return 0;
581 case TGSI_OPCODE_MOD:
582 *copcode = C_OPCODE_MOD;
583 return 0;
584 case TGSI_OPCODE_XOR:
585 *copcode = C_OPCODE_XOR;
586 return 0;
587 case TGSI_OPCODE_SAD:
588 *copcode = C_OPCODE_SAD;
589 return 0;
590 case TGSI_OPCODE_TXF:
591 *copcode = C_OPCODE_TXF;
592 return 0;
593 case TGSI_OPCODE_TXQ:
594 *copcode = C_OPCODE_TXQ;
595 return 0;
596 case TGSI_OPCODE_CONT:
597 *copcode = C_OPCODE_CONT;
598 return 0;
599 case TGSI_OPCODE_EMIT:
600 *copcode = C_OPCODE_EMIT;
601 return 0;
602 case TGSI_OPCODE_ENDPRIM:
603 *copcode = C_OPCODE_ENDPRIM;
604 return 0;
605 case TGSI_OPCODE_BGNLOOP:
606 *copcode = C_OPCODE_BGNLOOP;
607 return 0;
608 case TGSI_OPCODE_BGNSUB:
609 *copcode = C_OPCODE_BGNSUB;
610 return 0;
611 case TGSI_OPCODE_ENDLOOP:
612 *copcode = C_OPCODE_ENDLOOP;
613 return 0;
614 case TGSI_OPCODE_ENDSUB:
615 *copcode = C_OPCODE_ENDSUB;
616 return 0;
617 case TGSI_OPCODE_NOP:
618 *copcode = C_OPCODE_NOP;
619 return 0;
620 case TGSI_OPCODE_NRM4:
621 *copcode = C_OPCODE_NRM4;
622 return 0;
623 case TGSI_OPCODE_CALLNZ:
624 *copcode = C_OPCODE_CALLNZ;
625 return 0;
626 case TGSI_OPCODE_IFC:
627 *copcode = C_OPCODE_IFC;
628 return 0;
629 case TGSI_OPCODE_BREAKC:
630 *copcode = C_OPCODE_BREAKC;
631 return 0;
632 case TGSI_OPCODE_KIL:
633 *copcode = C_OPCODE_KIL;
634 return 0;
635 case TGSI_OPCODE_F2I:
636 *copcode = C_OPCODE_F2I;
637 return 0;
638 case TGSI_OPCODE_IDIV:
639 *copcode = C_OPCODE_IDIV;
640 return 0;
641 case TGSI_OPCODE_IMAX:
642 *copcode = C_OPCODE_IMAX;
643 return 0;
644 case TGSI_OPCODE_IMIN:
645 *copcode = C_OPCODE_IMIN;
646 return 0;
647 case TGSI_OPCODE_INEG:
648 *copcode = C_OPCODE_INEG;
649 return 0;
650 case TGSI_OPCODE_ISGE:
651 *copcode = C_OPCODE_ISGE;
652 return 0;
653 case TGSI_OPCODE_ISHR:
654 *copcode = C_OPCODE_ISHR;
655 return 0;
656 case TGSI_OPCODE_ISLT:
657 *copcode = C_OPCODE_ISLT;
658 return 0;
659 case TGSI_OPCODE_F2U:
660 *copcode = C_OPCODE_F2U;
661 return 0;
662 case TGSI_OPCODE_U2F:
663 *copcode = C_OPCODE_U2F;
664 return 0;
665 case TGSI_OPCODE_UADD:
666 *copcode = C_OPCODE_UADD;
667 return 0;
668 case TGSI_OPCODE_UDIV:
669 *copcode = C_OPCODE_UDIV;
670 return 0;
671 case TGSI_OPCODE_UMAD:
672 *copcode = C_OPCODE_UMAD;
673 return 0;
674 case TGSI_OPCODE_UMAX:
675 *copcode = C_OPCODE_UMAX;
676 return 0;
677 case TGSI_OPCODE_UMIN:
678 *copcode = C_OPCODE_UMIN;
679 return 0;
680 case TGSI_OPCODE_UMOD:
681 *copcode = C_OPCODE_UMOD;
682 return 0;
683 case TGSI_OPCODE_UMUL:
684 *copcode = C_OPCODE_UMUL;
685 return 0;
686 case TGSI_OPCODE_USEQ:
687 *copcode = C_OPCODE_USEQ;
688 return 0;
689 case TGSI_OPCODE_USGE:
690 *copcode = C_OPCODE_USGE;
691 return 0;
692 case TGSI_OPCODE_USHR:
693 *copcode = C_OPCODE_USHR;
694 return 0;
695 case TGSI_OPCODE_USLT:
696 *copcode = C_OPCODE_USLT;
697 return 0;
698 case TGSI_OPCODE_USNE:
699 *copcode = C_OPCODE_USNE;
700 return 0;
701 case TGSI_OPCODE_SWITCH:
702 *copcode = C_OPCODE_SWITCH;
703 return 0;
704 case TGSI_OPCODE_CASE:
705 *copcode = C_OPCODE_CASE;
706 return 0;
707 case TGSI_OPCODE_DEFAULT:
708 *copcode = C_OPCODE_DEFAULT;
709 return 0;
710 case TGSI_OPCODE_ENDSWITCH:
711 *copcode = C_OPCODE_ENDSWITCH;
712 return 0;
713 default:
714 fprintf(stderr, "%s:%d unsupported opcode %d\n", __func__, __LINE__, opcode);
715 return -EINVAL;
716 }
717 }