Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / drivers / r600 / r600_shader.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 "pipe/p_shader_tokens.h"
24 #include "tgsi/tgsi_parse.h"
25 #include "tgsi/tgsi_scan.h"
26 #include "tgsi/tgsi_dump.h"
27 #include "util/u_format.h"
28 #include "r600_pipe.h"
29 #include "r600_asm.h"
30 #include "r600_sq.h"
31 #include "r600_opcodes.h"
32 #include "r600d.h"
33 #include <stdio.h>
34 #include <errno.h>
35
36 static void r600_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader)
37 {
38 struct r600_pipe_state *rstate = &shader->rstate;
39 struct r600_shader *rshader = &shader->shader;
40 unsigned spi_vs_out_id[10];
41 unsigned i, tmp;
42
43 /* clear previous register */
44 rstate->nregs = 0;
45
46 /* so far never got proper semantic id from tgsi */
47 /* FIXME better to move this in config things so they get emited
48 * only one time per cs
49 */
50 for (i = 0; i < 10; i++) {
51 spi_vs_out_id[i] = 0;
52 }
53 for (i = 0; i < 32; i++) {
54 tmp = i << ((i & 3) * 8);
55 spi_vs_out_id[i / 4] |= tmp;
56 }
57 for (i = 0; i < 10; i++) {
58 r600_pipe_state_add_reg(rstate,
59 R_028614_SPI_VS_OUT_ID_0 + i * 4,
60 spi_vs_out_id[i], 0xFFFFFFFF, NULL);
61 }
62
63 r600_pipe_state_add_reg(rstate,
64 R_0286C4_SPI_VS_OUT_CONFIG,
65 S_0286C4_VS_EXPORT_COUNT(rshader->noutput - 2),
66 0xFFFFFFFF, NULL);
67 r600_pipe_state_add_reg(rstate,
68 R_028868_SQ_PGM_RESOURCES_VS,
69 S_028868_NUM_GPRS(rshader->bc.ngpr) |
70 S_028868_STACK_SIZE(rshader->bc.nstack),
71 0xFFFFFFFF, NULL);
72 r600_pipe_state_add_reg(rstate,
73 R_0288D0_SQ_PGM_CF_OFFSET_VS,
74 0x00000000, 0xFFFFFFFF, NULL);
75 r600_pipe_state_add_reg(rstate,
76 R_028858_SQ_PGM_START_VS,
77 r600_bo_offset(shader->bo) >> 8, 0xFFFFFFFF, shader->bo);
78
79 r600_pipe_state_add_reg(rstate,
80 R_03E200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF,
81 0xFFFFFFFF, NULL);
82
83 }
84
85 int r600_find_vs_semantic_index(struct r600_shader *vs,
86 struct r600_shader *ps, int id)
87 {
88 struct r600_shader_io *input = &ps->input[id];
89
90 for (int i = 0; i < vs->noutput; i++) {
91 if (input->name == vs->output[i].name &&
92 input->sid == vs->output[i].sid) {
93 return i - 1;
94 }
95 }
96 return 0;
97 }
98
99 static void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader)
100 {
101 struct r600_pipe_state *rstate = &shader->rstate;
102 struct r600_shader *rshader = &shader->shader;
103 unsigned i, exports_ps, num_cout, spi_ps_in_control_0, spi_input_z, spi_ps_in_control_1;
104 int pos_index = -1, face_index = -1;
105
106 rstate->nregs = 0;
107
108 for (i = 0; i < rshader->ninput; i++) {
109 if (rshader->input[i].name == TGSI_SEMANTIC_POSITION)
110 pos_index = i;
111 if (rshader->input[i].name == TGSI_SEMANTIC_FACE)
112 face_index = i;
113 }
114
115 for (i = 0; i < rshader->noutput; i++) {
116 if (rshader->output[i].name == TGSI_SEMANTIC_POSITION)
117 r600_pipe_state_add_reg(rstate,
118 R_02880C_DB_SHADER_CONTROL,
119 S_02880C_Z_EXPORT_ENABLE(1),
120 S_02880C_Z_EXPORT_ENABLE(1), NULL);
121 if (rshader->output[i].name == TGSI_SEMANTIC_STENCIL)
122 r600_pipe_state_add_reg(rstate,
123 R_02880C_DB_SHADER_CONTROL,
124 S_02880C_STENCIL_REF_EXPORT_ENABLE(1),
125 S_02880C_STENCIL_REF_EXPORT_ENABLE(1), NULL);
126 }
127
128 exports_ps = 0;
129 num_cout = 0;
130 for (i = 0; i < rshader->noutput; i++) {
131 if (rshader->output[i].name == TGSI_SEMANTIC_POSITION || rshader->output[i].name == TGSI_SEMANTIC_STENCIL)
132 exports_ps |= 1;
133 else if (rshader->output[i].name == TGSI_SEMANTIC_COLOR) {
134 num_cout++;
135 }
136 }
137 exports_ps |= S_028854_EXPORT_COLORS(num_cout);
138 if (!exports_ps) {
139 /* always at least export 1 component per pixel */
140 exports_ps = 2;
141 }
142
143 spi_ps_in_control_0 = S_0286CC_NUM_INTERP(rshader->ninput) |
144 S_0286CC_PERSP_GRADIENT_ENA(1);
145 spi_input_z = 0;
146 if (pos_index != -1) {
147 spi_ps_in_control_0 |= (S_0286CC_POSITION_ENA(1) |
148 S_0286CC_POSITION_CENTROID(rshader->input[pos_index].centroid) |
149 S_0286CC_POSITION_ADDR(rshader->input[pos_index].gpr) |
150 S_0286CC_BARYC_SAMPLE_CNTL(1));
151 spi_input_z |= 1;
152 }
153
154 spi_ps_in_control_1 = 0;
155 if (face_index != -1) {
156 spi_ps_in_control_1 |= S_0286D0_FRONT_FACE_ENA(1) |
157 S_0286D0_FRONT_FACE_ADDR(rshader->input[face_index].gpr);
158 }
159
160 r600_pipe_state_add_reg(rstate, R_0286CC_SPI_PS_IN_CONTROL_0, spi_ps_in_control_0, 0xFFFFFFFF, NULL);
161 r600_pipe_state_add_reg(rstate, R_0286D0_SPI_PS_IN_CONTROL_1, spi_ps_in_control_1, 0xFFFFFFFF, NULL);
162 r600_pipe_state_add_reg(rstate, R_0286D8_SPI_INPUT_Z, spi_input_z, 0xFFFFFFFF, NULL);
163 r600_pipe_state_add_reg(rstate,
164 R_028840_SQ_PGM_START_PS,
165 r600_bo_offset(shader->bo) >> 8, 0xFFFFFFFF, shader->bo);
166 r600_pipe_state_add_reg(rstate,
167 R_028850_SQ_PGM_RESOURCES_PS,
168 S_028868_NUM_GPRS(rshader->bc.ngpr) |
169 S_028868_STACK_SIZE(rshader->bc.nstack),
170 0xFFFFFFFF, NULL);
171 r600_pipe_state_add_reg(rstate,
172 R_028854_SQ_PGM_EXPORTS_PS,
173 exports_ps, 0xFFFFFFFF, NULL);
174 r600_pipe_state_add_reg(rstate,
175 R_0288CC_SQ_PGM_CF_OFFSET_PS,
176 0x00000000, 0xFFFFFFFF, NULL);
177
178 if (rshader->uses_kill) {
179 /* only set some bits here, the other bits are set in the dsa state */
180 r600_pipe_state_add_reg(rstate,
181 R_02880C_DB_SHADER_CONTROL,
182 S_02880C_KILL_ENABLE(1),
183 S_02880C_KILL_ENABLE(1), NULL);
184 }
185 r600_pipe_state_add_reg(rstate,
186 R_03E200_SQ_LOOP_CONST_0, 0x01000FFF,
187 0xFFFFFFFF, NULL);
188 }
189
190 int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *shader)
191 {
192 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
193 struct r600_shader *rshader = &shader->shader;
194 void *ptr;
195
196 /* copy new shader */
197 if (shader->bo == NULL) {
198 shader->bo = r600_bo(rctx->radeon, rshader->bc.ndw * 4, 4096, 0, 0);
199 if (shader->bo == NULL) {
200 return -ENOMEM;
201 }
202 ptr = r600_bo_map(rctx->radeon, shader->bo, 0, NULL);
203 memcpy(ptr, rshader->bc.bytecode, rshader->bc.ndw * 4);
204 r600_bo_unmap(rctx->radeon, shader->bo);
205 }
206 /* build state */
207 switch (rshader->processor_type) {
208 case TGSI_PROCESSOR_VERTEX:
209 if (rshader->family >= CHIP_CEDAR) {
210 evergreen_pipe_shader_vs(ctx, shader);
211 } else {
212 r600_pipe_shader_vs(ctx, shader);
213 }
214 break;
215 case TGSI_PROCESSOR_FRAGMENT:
216 if (rshader->family >= CHIP_CEDAR) {
217 evergreen_pipe_shader_ps(ctx, shader);
218 } else {
219 r600_pipe_shader_ps(ctx, shader);
220 }
221 break;
222 default:
223 return -EINVAL;
224 }
225 return 0;
226 }
227
228 int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader, u32 **literals);
229 int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, const struct tgsi_token *tokens)
230 {
231 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
232 u32 *literals;
233 int r;
234
235 //fprintf(stderr, "--------------------------------------------------------------\n");
236 //tgsi_dump(tokens, 0);
237 shader->shader.family = r600_get_family(rctx->radeon);
238 r = r600_shader_from_tgsi(tokens, &shader->shader, &literals);
239 if (r) {
240 R600_ERR("translation from TGSI failed !\n");
241 return r;
242 }
243 r = r600_bc_build(&shader->shader.bc);
244 free(literals);
245 if (r) {
246 R600_ERR("building bytecode failed !\n");
247 return r;
248 }
249 //r600_bc_dump(&shader->shader.bc);
250 //fprintf(stderr, "______________________________________________________________\n");
251 return r600_pipe_shader(ctx, shader);
252 }
253
254 void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader)
255 {
256 struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
257
258 r600_bo_reference(rctx->radeon, &shader->bo, NULL);
259 r600_bc_clear(&shader->shader.bc);
260 }
261
262 /*
263 * tgsi -> r600 shader
264 */
265 struct r600_shader_tgsi_instruction;
266
267 struct r600_shader_ctx {
268 struct tgsi_shader_info info;
269 struct tgsi_parse_context parse;
270 const struct tgsi_token *tokens;
271 unsigned type;
272 unsigned file_offset[TGSI_FILE_COUNT];
273 unsigned temp_reg;
274 struct r600_shader_tgsi_instruction *inst_info;
275 struct r600_bc *bc;
276 struct r600_shader *shader;
277 u32 *literals;
278 u32 nliterals;
279 u32 max_driver_temp_used;
280 /* needed for evergreen interpolation */
281 boolean input_centroid;
282 boolean input_linear;
283 boolean input_perspective;
284 int num_interp_gpr;
285 };
286
287 struct r600_shader_tgsi_instruction {
288 unsigned tgsi_opcode;
289 unsigned is_op3;
290 unsigned r600_opcode;
291 int (*process)(struct r600_shader_ctx *ctx);
292 };
293
294 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[], eg_shader_tgsi_instruction[];
295 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx *ctx);
296
297 static int tgsi_is_supported(struct r600_shader_ctx *ctx)
298 {
299 struct tgsi_full_instruction *i = &ctx->parse.FullToken.FullInstruction;
300 int j;
301
302 if (i->Instruction.NumDstRegs > 1) {
303 R600_ERR("too many dst (%d)\n", i->Instruction.NumDstRegs);
304 return -EINVAL;
305 }
306 if (i->Instruction.Predicate) {
307 R600_ERR("predicate unsupported\n");
308 return -EINVAL;
309 }
310 #if 0
311 if (i->Instruction.Label) {
312 R600_ERR("label unsupported\n");
313 return -EINVAL;
314 }
315 #endif
316 for (j = 0; j < i->Instruction.NumSrcRegs; j++) {
317 if (i->Src[j].Register.Dimension) {
318 R600_ERR("unsupported src %d (dimension %d)\n", j,
319 i->Src[j].Register.Dimension);
320 return -EINVAL;
321 }
322 }
323 for (j = 0; j < i->Instruction.NumDstRegs; j++) {
324 if (i->Dst[j].Register.Dimension) {
325 R600_ERR("unsupported dst (dimension)\n");
326 return -EINVAL;
327 }
328 }
329 return 0;
330 }
331
332 static int evergreen_interp_alu(struct r600_shader_ctx *ctx, int input)
333 {
334 int i, r;
335 struct r600_bc_alu alu;
336 int gpr = 0, base_chan = 0;
337 int ij_index = 0;
338
339 if (ctx->shader->input[input].interpolate == TGSI_INTERPOLATE_PERSPECTIVE) {
340 ij_index = 0;
341 if (ctx->shader->input[input].centroid)
342 ij_index++;
343 } else if (ctx->shader->input[input].interpolate == TGSI_INTERPOLATE_LINEAR) {
344 ij_index = 0;
345 /* if we have perspective add one */
346 if (ctx->input_perspective) {
347 ij_index++;
348 /* if we have perspective centroid */
349 if (ctx->input_centroid)
350 ij_index++;
351 }
352 if (ctx->shader->input[input].centroid)
353 ij_index++;
354 }
355
356 /* work out gpr and base_chan from index */
357 gpr = ij_index / 2;
358 base_chan = (2 * (ij_index % 2)) + 1;
359
360 for (i = 0; i < 8; i++) {
361 memset(&alu, 0, sizeof(struct r600_bc_alu));
362
363 if (i < 4)
364 alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_ZW;
365 else
366 alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INTERP_XY;
367
368 if ((i > 1) && (i < 6)) {
369 alu.dst.sel = ctx->shader->input[input].gpr;
370 alu.dst.write = 1;
371 }
372
373 alu.dst.chan = i % 4;
374
375 alu.src[0].sel = gpr;
376 alu.src[0].chan = (base_chan - (i % 2));
377
378 alu.src[1].sel = V_SQ_ALU_SRC_PARAM_BASE + ctx->shader->input[input].lds_pos;
379
380 alu.bank_swizzle_force = SQ_ALU_VEC_210;
381 if ((i % 4) == 3)
382 alu.last = 1;
383 r = r600_bc_add_alu(ctx->bc, &alu);
384 if (r)
385 return r;
386 }
387 return 0;
388 }
389
390
391 static int tgsi_declaration(struct r600_shader_ctx *ctx)
392 {
393 struct tgsi_full_declaration *d = &ctx->parse.FullToken.FullDeclaration;
394 unsigned i;
395
396 switch (d->Declaration.File) {
397 case TGSI_FILE_INPUT:
398 i = ctx->shader->ninput++;
399 ctx->shader->input[i].name = d->Semantic.Name;
400 ctx->shader->input[i].sid = d->Semantic.Index;
401 ctx->shader->input[i].interpolate = d->Declaration.Interpolate;
402 ctx->shader->input[i].centroid = d->Declaration.Centroid;
403 ctx->shader->input[i].gpr = ctx->file_offset[TGSI_FILE_INPUT] + i;
404 if (ctx->type == TGSI_PROCESSOR_FRAGMENT && ctx->bc->chiprev == CHIPREV_EVERGREEN) {
405 /* turn input into interpolate on EG */
406 if (ctx->shader->input[i].name != TGSI_SEMANTIC_POSITION) {
407 if (ctx->shader->input[i].interpolate > 0) {
408 ctx->shader->input[i].lds_pos = ctx->shader->nlds++;
409 evergreen_interp_alu(ctx, i);
410 }
411 }
412 }
413 break;
414 case TGSI_FILE_OUTPUT:
415 i = ctx->shader->noutput++;
416 ctx->shader->output[i].name = d->Semantic.Name;
417 ctx->shader->output[i].sid = d->Semantic.Index;
418 ctx->shader->output[i].gpr = ctx->file_offset[TGSI_FILE_OUTPUT] + i;
419 ctx->shader->output[i].interpolate = d->Declaration.Interpolate;
420 break;
421 case TGSI_FILE_CONSTANT:
422 case TGSI_FILE_TEMPORARY:
423 case TGSI_FILE_SAMPLER:
424 case TGSI_FILE_ADDRESS:
425 break;
426 default:
427 R600_ERR("unsupported file %d declaration\n", d->Declaration.File);
428 return -EINVAL;
429 }
430 return 0;
431 }
432
433 static int r600_get_temp(struct r600_shader_ctx *ctx)
434 {
435 return ctx->temp_reg + ctx->max_driver_temp_used++;
436 }
437
438 /*
439 * for evergreen we need to scan the shader to find the number of GPRs we need to
440 * reserve for interpolation.
441 *
442 * we need to know if we are going to emit
443 * any centroid inputs
444 * if perspective and linear are required
445 */
446 static int evergreen_gpr_count(struct r600_shader_ctx *ctx)
447 {
448 int i;
449 int num_baryc;
450
451 ctx->input_linear = FALSE;
452 ctx->input_perspective = FALSE;
453 ctx->input_centroid = FALSE;
454 ctx->num_interp_gpr = 1;
455
456 /* any centroid inputs */
457 for (i = 0; i < ctx->info.num_inputs; i++) {
458 /* skip position/face */
459 if (ctx->info.input_semantic_name[i] == TGSI_SEMANTIC_POSITION ||
460 ctx->info.input_semantic_name[i] == TGSI_SEMANTIC_FACE)
461 continue;
462 if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_LINEAR)
463 ctx->input_linear = TRUE;
464 if (ctx->info.input_interpolate[i] == TGSI_INTERPOLATE_PERSPECTIVE)
465 ctx->input_perspective = TRUE;
466 if (ctx->info.input_centroid[i])
467 ctx->input_centroid = TRUE;
468 }
469
470 num_baryc = 0;
471 /* ignoring sample for now */
472 if (ctx->input_perspective)
473 num_baryc++;
474 if (ctx->input_linear)
475 num_baryc++;
476 if (ctx->input_centroid)
477 num_baryc *= 2;
478
479 ctx->num_interp_gpr += (num_baryc + 1) >> 1;
480
481 /* TODO PULL MODEL and LINE STIPPLE, FIXED PT POS */
482 return ctx->num_interp_gpr;
483 }
484
485 int r600_shader_from_tgsi(const struct tgsi_token *tokens, struct r600_shader *shader, u32 **literals)
486 {
487 struct tgsi_full_immediate *immediate;
488 struct r600_shader_ctx ctx;
489 struct r600_bc_output output[32];
490 unsigned output_done, noutput;
491 unsigned opcode;
492 int i, r = 0, pos0;
493
494 ctx.bc = &shader->bc;
495 ctx.shader = shader;
496 r = r600_bc_init(ctx.bc, shader->family);
497 if (r)
498 return r;
499 ctx.tokens = tokens;
500 tgsi_scan_shader(tokens, &ctx.info);
501 tgsi_parse_init(&ctx.parse, tokens);
502 ctx.type = ctx.parse.FullHeader.Processor.Processor;
503 shader->processor_type = ctx.type;
504 ctx.bc->type = shader->processor_type;
505
506 /* register allocations */
507 /* Values [0,127] correspond to GPR[0..127].
508 * Values [128,159] correspond to constant buffer bank 0
509 * Values [160,191] correspond to constant buffer bank 1
510 * Values [256,511] correspond to cfile constants c[0..255].
511 * Other special values are shown in the list below.
512 * 244 ALU_SRC_1_DBL_L: special constant 1.0 double-float, LSW. (RV670+)
513 * 245 ALU_SRC_1_DBL_M: special constant 1.0 double-float, MSW. (RV670+)
514 * 246 ALU_SRC_0_5_DBL_L: special constant 0.5 double-float, LSW. (RV670+)
515 * 247 ALU_SRC_0_5_DBL_M: special constant 0.5 double-float, MSW. (RV670+)
516 * 248 SQ_ALU_SRC_0: special constant 0.0.
517 * 249 SQ_ALU_SRC_1: special constant 1.0 float.
518 * 250 SQ_ALU_SRC_1_INT: special constant 1 integer.
519 * 251 SQ_ALU_SRC_M_1_INT: special constant -1 integer.
520 * 252 SQ_ALU_SRC_0_5: special constant 0.5 float.
521 * 253 SQ_ALU_SRC_LITERAL: literal constant.
522 * 254 SQ_ALU_SRC_PV: previous vector result.
523 * 255 SQ_ALU_SRC_PS: previous scalar result.
524 */
525 for (i = 0; i < TGSI_FILE_COUNT; i++) {
526 ctx.file_offset[i] = 0;
527 }
528 if (ctx.type == TGSI_PROCESSOR_VERTEX) {
529 ctx.file_offset[TGSI_FILE_INPUT] = 1;
530 if (ctx.bc->chiprev == CHIPREV_EVERGREEN) {
531 r600_bc_add_cfinst(ctx.bc, EG_V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS);
532 } else {
533 r600_bc_add_cfinst(ctx.bc, V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS);
534 }
535 }
536 if (ctx.type == TGSI_PROCESSOR_FRAGMENT && ctx.bc->chiprev == CHIPREV_EVERGREEN) {
537 ctx.file_offset[TGSI_FILE_INPUT] = evergreen_gpr_count(&ctx);
538 }
539 ctx.file_offset[TGSI_FILE_OUTPUT] = ctx.file_offset[TGSI_FILE_INPUT] +
540 ctx.info.file_count[TGSI_FILE_INPUT];
541 ctx.file_offset[TGSI_FILE_TEMPORARY] = ctx.file_offset[TGSI_FILE_OUTPUT] +
542 ctx.info.file_count[TGSI_FILE_OUTPUT];
543
544 ctx.file_offset[TGSI_FILE_CONSTANT] = 128;
545
546 ctx.file_offset[TGSI_FILE_IMMEDIATE] = V_SQ_ALU_SRC_LITERAL;
547 ctx.temp_reg = ctx.file_offset[TGSI_FILE_TEMPORARY] +
548 ctx.info.file_count[TGSI_FILE_TEMPORARY];
549
550 ctx.nliterals = 0;
551 ctx.literals = NULL;
552
553 while (!tgsi_parse_end_of_tokens(&ctx.parse)) {
554 tgsi_parse_token(&ctx.parse);
555 switch (ctx.parse.FullToken.Token.Type) {
556 case TGSI_TOKEN_TYPE_IMMEDIATE:
557 immediate = &ctx.parse.FullToken.FullImmediate;
558 ctx.literals = realloc(ctx.literals, (ctx.nliterals + 1) * 16);
559 if(ctx.literals == NULL) {
560 r = -ENOMEM;
561 goto out_err;
562 }
563 ctx.literals[ctx.nliterals * 4 + 0] = immediate->u[0].Uint;
564 ctx.literals[ctx.nliterals * 4 + 1] = immediate->u[1].Uint;
565 ctx.literals[ctx.nliterals * 4 + 2] = immediate->u[2].Uint;
566 ctx.literals[ctx.nliterals * 4 + 3] = immediate->u[3].Uint;
567 ctx.nliterals++;
568 break;
569 case TGSI_TOKEN_TYPE_DECLARATION:
570 r = tgsi_declaration(&ctx);
571 if (r)
572 goto out_err;
573 break;
574 case TGSI_TOKEN_TYPE_INSTRUCTION:
575 r = tgsi_is_supported(&ctx);
576 if (r)
577 goto out_err;
578 ctx.max_driver_temp_used = 0;
579 /* reserve first tmp for everyone */
580 r600_get_temp(&ctx);
581 opcode = ctx.parse.FullToken.FullInstruction.Instruction.Opcode;
582 if (ctx.bc->chiprev == CHIPREV_EVERGREEN)
583 ctx.inst_info = &eg_shader_tgsi_instruction[opcode];
584 else
585 ctx.inst_info = &r600_shader_tgsi_instruction[opcode];
586 r = ctx.inst_info->process(&ctx);
587 if (r)
588 goto out_err;
589 break;
590 default:
591 R600_ERR("unsupported token type %d\n", ctx.parse.FullToken.Token.Type);
592 r = -EINVAL;
593 goto out_err;
594 }
595 }
596 /* export output */
597 noutput = shader->noutput;
598 for (i = 0, pos0 = 0; i < noutput; i++) {
599 memset(&output[i], 0, sizeof(struct r600_bc_output));
600 output[i].gpr = shader->output[i].gpr;
601 output[i].elem_size = 3;
602 output[i].swizzle_x = 0;
603 output[i].swizzle_y = 1;
604 output[i].swizzle_z = 2;
605 output[i].swizzle_w = 3;
606 output[i].barrier = i == 0;
607 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
608 output[i].array_base = i - pos0;
609 output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
610 switch (ctx.type) {
611 case TGSI_PROCESSOR_VERTEX:
612 if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
613 output[i].array_base = 60;
614 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
615 /* position doesn't count in array_base */
616 pos0++;
617 }
618 if (shader->output[i].name == TGSI_SEMANTIC_PSIZE) {
619 output[i].array_base = 61;
620 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_POS;
621 /* position doesn't count in array_base */
622 pos0++;
623 }
624 break;
625 case TGSI_PROCESSOR_FRAGMENT:
626 if (shader->output[i].name == TGSI_SEMANTIC_COLOR) {
627 output[i].array_base = shader->output[i].sid;
628 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
629 } else if (shader->output[i].name == TGSI_SEMANTIC_POSITION) {
630 output[i].array_base = 61;
631 output[i].swizzle_x = 2;
632 output[i].swizzle_y = 7;
633 output[i].swizzle_z = output[i].swizzle_w = 7;
634 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
635 } else if (shader->output[i].name == TGSI_SEMANTIC_STENCIL) {
636 output[i].array_base = 61;
637 output[i].swizzle_x = 7;
638 output[i].swizzle_y = 1;
639 output[i].swizzle_z = output[i].swizzle_w = 7;
640 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
641 } else {
642 R600_ERR("unsupported fragment output name %d\n", shader->output[i].name);
643 r = -EINVAL;
644 goto out_err;
645 }
646 break;
647 default:
648 R600_ERR("unsupported processor type %d\n", ctx.type);
649 r = -EINVAL;
650 goto out_err;
651 }
652 }
653 /* add fake param output for vertex shader if no param is exported */
654 if (ctx.type == TGSI_PROCESSOR_VERTEX) {
655 for (i = 0, pos0 = 0; i < noutput; i++) {
656 if (output[i].type == V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM) {
657 pos0 = 1;
658 break;
659 }
660 }
661 if (!pos0) {
662 memset(&output[i], 0, sizeof(struct r600_bc_output));
663 output[i].gpr = 0;
664 output[i].elem_size = 3;
665 output[i].swizzle_x = 0;
666 output[i].swizzle_y = 1;
667 output[i].swizzle_z = 2;
668 output[i].swizzle_w = 3;
669 output[i].barrier = 1;
670 output[i].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PARAM;
671 output[i].array_base = 0;
672 output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
673 noutput++;
674 }
675 }
676 /* add fake pixel export */
677 if (ctx.type == TGSI_PROCESSOR_FRAGMENT && !noutput) {
678 memset(&output[0], 0, sizeof(struct r600_bc_output));
679 output[0].gpr = 0;
680 output[0].elem_size = 3;
681 output[0].swizzle_x = 7;
682 output[0].swizzle_y = 7;
683 output[0].swizzle_z = 7;
684 output[0].swizzle_w = 7;
685 output[0].barrier = 1;
686 output[0].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
687 output[0].array_base = 0;
688 output[0].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT);
689 noutput++;
690 }
691 /* set export done on last export of each type */
692 for (i = noutput - 1, output_done = 0; i >= 0; i--) {
693 if (i == (noutput - 1)) {
694 output[i].end_of_program = 1;
695 }
696 if (!(output_done & (1 << output[i].type))) {
697 output_done |= (1 << output[i].type);
698 output[i].inst = BC_INST(ctx.bc, V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE);
699 }
700 }
701 /* add output to bytecode */
702 for (i = 0; i < noutput; i++) {
703 r = r600_bc_add_output(ctx.bc, &output[i]);
704 if (r)
705 goto out_err;
706 }
707 *literals = ctx.literals;
708 tgsi_parse_free(&ctx.parse);
709 return 0;
710 out_err:
711 free(ctx.literals);
712 tgsi_parse_free(&ctx.parse);
713 return r;
714 }
715
716 static int tgsi_unsupported(struct r600_shader_ctx *ctx)
717 {
718 R600_ERR("%d tgsi opcode unsupported\n", ctx->inst_info->tgsi_opcode);
719 return -EINVAL;
720 }
721
722 static int tgsi_end(struct r600_shader_ctx *ctx)
723 {
724 return 0;
725 }
726
727 static int tgsi_src(struct r600_shader_ctx *ctx,
728 const struct tgsi_full_src_register *tgsi_src,
729 struct r600_bc_alu_src *r600_src)
730 {
731 memset(r600_src, 0, sizeof(struct r600_bc_alu_src));
732 r600_src->neg = tgsi_src->Register.Negate;
733 r600_src->abs = tgsi_src->Register.Absolute;
734 if (tgsi_src->Register.File == TGSI_FILE_IMMEDIATE) {
735 int index;
736 if((tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleY) &&
737 (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleZ) &&
738 (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleW)) {
739
740 index = tgsi_src->Register.Index * 4 + tgsi_src->Register.SwizzleX;
741 r600_bc_special_constants(ctx->literals[index], &r600_src->sel, &r600_src->neg);
742 if (r600_src->sel != V_SQ_ALU_SRC_LITERAL)
743 return 0;
744 }
745 index = tgsi_src->Register.Index;
746 r600_src->sel = V_SQ_ALU_SRC_LITERAL;
747 r600_src->value = ctx->literals + index * 4;
748 } else {
749 if (tgsi_src->Register.Indirect)
750 r600_src->rel = V_SQ_REL_RELATIVE;
751 r600_src->sel = tgsi_src->Register.Index;
752 r600_src->sel += ctx->file_offset[tgsi_src->Register.File];
753 }
754 return 0;
755 }
756
757 static int tgsi_dst(struct r600_shader_ctx *ctx,
758 const struct tgsi_full_dst_register *tgsi_dst,
759 unsigned swizzle,
760 struct r600_bc_alu_dst *r600_dst)
761 {
762 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
763
764 r600_dst->sel = tgsi_dst->Register.Index;
765 r600_dst->sel += ctx->file_offset[tgsi_dst->Register.File];
766 r600_dst->chan = swizzle;
767 r600_dst->write = 1;
768 if (tgsi_dst->Register.Indirect)
769 r600_dst->rel = V_SQ_REL_RELATIVE;
770 if (inst->Instruction.Saturate) {
771 r600_dst->clamp = 1;
772 }
773 return 0;
774 }
775
776 static unsigned tgsi_chan(const struct tgsi_full_src_register *tgsi_src, unsigned swizzle)
777 {
778 switch (swizzle) {
779 case 0:
780 return tgsi_src->Register.SwizzleX;
781 case 1:
782 return tgsi_src->Register.SwizzleY;
783 case 2:
784 return tgsi_src->Register.SwizzleZ;
785 case 3:
786 return tgsi_src->Register.SwizzleW;
787 default:
788 return 0;
789 }
790 }
791
792 static int tgsi_split_constant(struct r600_shader_ctx *ctx, struct r600_bc_alu_src r600_src[3])
793 {
794 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
795 struct r600_bc_alu alu;
796 int i, j, k, nconst, r;
797
798 for (i = 0, nconst = 0; i < inst->Instruction.NumSrcRegs; i++) {
799 if (inst->Src[i].Register.File == TGSI_FILE_CONSTANT) {
800 nconst++;
801 }
802 r = tgsi_src(ctx, &inst->Src[i], &r600_src[i]);
803 if (r) {
804 return r;
805 }
806 }
807 for (i = 0, j = nconst - 1; i < inst->Instruction.NumSrcRegs; i++) {
808 if (j > 0 && inst->Src[i].Register.File == TGSI_FILE_CONSTANT) {
809 int treg = r600_get_temp(ctx);
810 for (k = 0; k < 4; k++) {
811 memset(&alu, 0, sizeof(struct r600_bc_alu));
812 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
813 alu.src[0].sel = r600_src[i].sel;
814 alu.src[0].chan = k;
815 alu.src[0].rel = r600_src[i].rel;
816 alu.dst.sel = treg;
817 alu.dst.chan = k;
818 alu.dst.write = 1;
819 if (k == 3)
820 alu.last = 1;
821 r = r600_bc_add_alu(ctx->bc, &alu);
822 if (r)
823 return r;
824 }
825 r600_src[i].sel = treg;
826 r600_src[i].rel =0;
827 j--;
828 }
829 }
830 return 0;
831 }
832
833 /* need to move any immediate into a temp - for trig functions which use literal for PI stuff */
834 static int tgsi_split_literal_constant(struct r600_shader_ctx *ctx, struct r600_bc_alu_src r600_src[3])
835 {
836 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
837 struct r600_bc_alu alu;
838 int i, j, k, nliteral, r;
839
840 for (i = 0, nliteral = 0; i < inst->Instruction.NumSrcRegs; i++) {
841 if (r600_src[i].sel == V_SQ_ALU_SRC_LITERAL) {
842 nliteral++;
843 }
844 }
845 for (i = 0, j = nliteral - 1; i < inst->Instruction.NumSrcRegs; i++) {
846 if (j > 0 && r600_src[i].sel == V_SQ_ALU_SRC_LITERAL) {
847 int treg = r600_get_temp(ctx);
848 for (k = 0; k < 4; k++) {
849 memset(&alu, 0, sizeof(struct r600_bc_alu));
850 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
851 alu.src[0].sel = r600_src[i].sel;
852 alu.src[0].chan = k;
853 alu.src[0].value = r600_src[i].value;
854 alu.dst.sel = treg;
855 alu.dst.chan = k;
856 alu.dst.write = 1;
857 if (k == 3)
858 alu.last = 1;
859 r = r600_bc_add_alu(ctx->bc, &alu);
860 if (r)
861 return r;
862 }
863 r600_src[i].sel = treg;
864 j--;
865 }
866 }
867 return 0;
868 }
869
870 static int tgsi_last_instruction(unsigned writemask)
871 {
872 int i, lasti = 0;
873
874 for (i = 0; i < 4; i++) {
875 if (writemask & (1 << i)) {
876 lasti = i;
877 }
878 }
879 return lasti;
880 }
881
882 static int tgsi_op2_s(struct r600_shader_ctx *ctx, int swap)
883 {
884 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
885 struct r600_bc_alu_src r600_src[3];
886 struct r600_bc_alu alu;
887 int i, j, r;
888 int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask);
889
890 r = tgsi_split_constant(ctx, r600_src);
891 if (r)
892 return r;
893 r = tgsi_split_literal_constant(ctx, r600_src);
894 if (r)
895 return r;
896 for (i = 0; i < lasti + 1; i++) {
897 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
898 continue;
899
900 memset(&alu, 0, sizeof(struct r600_bc_alu));
901 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
902 if (r)
903 return r;
904
905 alu.inst = ctx->inst_info->r600_opcode;
906 if (!swap) {
907 for (j = 0; j < inst->Instruction.NumSrcRegs; j++) {
908 alu.src[j] = r600_src[j];
909 alu.src[j].chan = tgsi_chan(&inst->Src[j], i);
910 }
911 } else {
912 alu.src[0] = r600_src[1];
913 alu.src[0].chan = tgsi_chan(&inst->Src[1], i);
914
915 alu.src[1] = r600_src[0];
916 alu.src[1].chan = tgsi_chan(&inst->Src[0], i);
917 }
918 /* handle some special cases */
919 switch (ctx->inst_info->tgsi_opcode) {
920 case TGSI_OPCODE_SUB:
921 alu.src[1].neg = 1;
922 break;
923 case TGSI_OPCODE_ABS:
924 alu.src[0].abs = 1;
925 break;
926 default:
927 break;
928 }
929 if (i == lasti) {
930 alu.last = 1;
931 }
932 r = r600_bc_add_alu(ctx->bc, &alu);
933 if (r)
934 return r;
935 }
936 return 0;
937 }
938
939 static int tgsi_op2(struct r600_shader_ctx *ctx)
940 {
941 return tgsi_op2_s(ctx, 0);
942 }
943
944 static int tgsi_op2_swap(struct r600_shader_ctx *ctx)
945 {
946 return tgsi_op2_s(ctx, 1);
947 }
948
949 /*
950 * r600 - trunc to -PI..PI range
951 * r700 - normalize by dividing by 2PI
952 * see fdo bug 27901
953 */
954 static int tgsi_setup_trig(struct r600_shader_ctx *ctx,
955 struct r600_bc_alu_src r600_src[3])
956 {
957 static float half_inv_pi = 1.0 /(3.1415926535 * 2);
958 static float double_pi = 3.1415926535 * 2;
959 static float neg_pi = -3.1415926535;
960
961 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
962 int r;
963 struct r600_bc_alu alu;
964
965 r = tgsi_split_constant(ctx, r600_src);
966 if (r)
967 return r;
968 r = tgsi_split_literal_constant(ctx, r600_src);
969 if (r)
970 return r;
971
972 memset(&alu, 0, sizeof(struct r600_bc_alu));
973 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
974 alu.is_op3 = 1;
975
976 alu.dst.chan = 0;
977 alu.dst.sel = ctx->temp_reg;
978 alu.dst.write = 1;
979
980 alu.src[0] = r600_src[0];
981 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
982
983 alu.src[1].sel = V_SQ_ALU_SRC_LITERAL;
984 alu.src[1].chan = 0;
985 alu.src[1].value = (uint32_t *)&half_inv_pi;
986 alu.src[2].sel = V_SQ_ALU_SRC_0_5;
987 alu.src[2].chan = 1;
988 alu.last = 1;
989 r = r600_bc_add_alu(ctx->bc, &alu);
990 if (r)
991 return r;
992
993 memset(&alu, 0, sizeof(struct r600_bc_alu));
994 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT);
995
996 alu.dst.chan = 0;
997 alu.dst.sel = ctx->temp_reg;
998 alu.dst.write = 1;
999
1000 alu.src[0].sel = ctx->temp_reg;
1001 alu.src[0].chan = 0;
1002 alu.last = 1;
1003 r = r600_bc_add_alu(ctx->bc, &alu);
1004 if (r)
1005 return r;
1006
1007 memset(&alu, 0, sizeof(struct r600_bc_alu));
1008 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
1009 alu.is_op3 = 1;
1010
1011 alu.dst.chan = 0;
1012 alu.dst.sel = ctx->temp_reg;
1013 alu.dst.write = 1;
1014
1015 alu.src[0].sel = ctx->temp_reg;
1016 alu.src[0].chan = 0;
1017
1018 alu.src[1].sel = V_SQ_ALU_SRC_LITERAL;
1019 alu.src[1].chan = 0;
1020 alu.src[2].sel = V_SQ_ALU_SRC_LITERAL;
1021 alu.src[2].chan = 1;
1022
1023 if (ctx->bc->chiprev == CHIPREV_R600) {
1024 alu.src[1].value = (uint32_t *)&double_pi;
1025 alu.src[2].value = (uint32_t *)&neg_pi;
1026 } else {
1027 alu.src[1].sel = V_SQ_ALU_SRC_1;
1028 alu.src[2].sel = V_SQ_ALU_SRC_0_5;
1029 alu.src[2].neg = 1;
1030 }
1031
1032 alu.last = 1;
1033 r = r600_bc_add_alu(ctx->bc, &alu);
1034 if (r)
1035 return r;
1036 return 0;
1037 }
1038
1039 static int tgsi_trig(struct r600_shader_ctx *ctx)
1040 {
1041 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1042 struct r600_bc_alu_src r600_src[3];
1043 struct r600_bc_alu alu;
1044 int i, r;
1045 int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask);
1046
1047 r = tgsi_setup_trig(ctx, r600_src);
1048 if (r)
1049 return r;
1050
1051 memset(&alu, 0, sizeof(struct r600_bc_alu));
1052 alu.inst = ctx->inst_info->r600_opcode;
1053 alu.dst.chan = 0;
1054 alu.dst.sel = ctx->temp_reg;
1055 alu.dst.write = 1;
1056
1057 alu.src[0].sel = ctx->temp_reg;
1058 alu.src[0].chan = 0;
1059 alu.last = 1;
1060 r = r600_bc_add_alu(ctx->bc, &alu);
1061 if (r)
1062 return r;
1063
1064 /* replicate result */
1065 for (i = 0; i < lasti + 1; i++) {
1066 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1067 continue;
1068
1069 memset(&alu, 0, sizeof(struct r600_bc_alu));
1070 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1071
1072 alu.src[0].sel = ctx->temp_reg;
1073 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1074 if (r)
1075 return r;
1076 if (i == lasti)
1077 alu.last = 1;
1078 r = r600_bc_add_alu(ctx->bc, &alu);
1079 if (r)
1080 return r;
1081 }
1082 return 0;
1083 }
1084
1085 static int tgsi_scs(struct r600_shader_ctx *ctx)
1086 {
1087 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1088 struct r600_bc_alu_src r600_src[3];
1089 struct r600_bc_alu alu;
1090 int r;
1091
1092 /* We'll only need the trig stuff if we are going to write to the
1093 * X or Y components of the destination vector.
1094 */
1095 if (likely(inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XY)) {
1096 r = tgsi_setup_trig(ctx, r600_src);
1097 if (r)
1098 return r;
1099 }
1100
1101 /* dst.x = COS */
1102 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_X) {
1103 memset(&alu, 0, sizeof(struct r600_bc_alu));
1104 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS);
1105 r = tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst);
1106 if (r)
1107 return r;
1108
1109 alu.src[0].sel = ctx->temp_reg;
1110 alu.src[0].chan = 0;
1111 alu.last = 1;
1112 r = r600_bc_add_alu(ctx->bc, &alu);
1113 if (r)
1114 return r;
1115 }
1116
1117 /* dst.y = SIN */
1118 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Y) {
1119 memset(&alu, 0, sizeof(struct r600_bc_alu));
1120 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN);
1121 r = tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst);
1122 if (r)
1123 return r;
1124
1125 alu.src[0].sel = ctx->temp_reg;
1126 alu.src[0].chan = 0;
1127 alu.last = 1;
1128 r = r600_bc_add_alu(ctx->bc, &alu);
1129 if (r)
1130 return r;
1131 }
1132
1133 /* dst.z = 0.0; */
1134 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_Z) {
1135 memset(&alu, 0, sizeof(struct r600_bc_alu));
1136
1137 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1138
1139 r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst);
1140 if (r)
1141 return r;
1142
1143 alu.src[0].sel = V_SQ_ALU_SRC_0;
1144 alu.src[0].chan = 0;
1145
1146 alu.last = 1;
1147
1148 r = r600_bc_add_alu(ctx->bc, &alu);
1149 if (r)
1150 return r;
1151 }
1152
1153 /* dst.w = 1.0; */
1154 if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) {
1155 memset(&alu, 0, sizeof(struct r600_bc_alu));
1156
1157 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1158
1159 r = tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst);
1160 if (r)
1161 return r;
1162
1163 alu.src[0].sel = V_SQ_ALU_SRC_1;
1164 alu.src[0].chan = 0;
1165
1166 alu.last = 1;
1167
1168 r = r600_bc_add_alu(ctx->bc, &alu);
1169 if (r)
1170 return r;
1171 }
1172
1173 return 0;
1174 }
1175
1176 static int tgsi_kill(struct r600_shader_ctx *ctx)
1177 {
1178 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1179 struct r600_bc_alu alu;
1180 int i, r;
1181
1182 for (i = 0; i < 4; i++) {
1183 memset(&alu, 0, sizeof(struct r600_bc_alu));
1184 alu.inst = ctx->inst_info->r600_opcode;
1185
1186 alu.dst.chan = i;
1187
1188 alu.src[0].sel = V_SQ_ALU_SRC_0;
1189
1190 if (ctx->inst_info->tgsi_opcode == TGSI_OPCODE_KILP) {
1191 alu.src[1].sel = V_SQ_ALU_SRC_1;
1192 alu.src[1].neg = 1;
1193 } else {
1194 r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]);
1195 if (r)
1196 return r;
1197 alu.src[1].chan = tgsi_chan(&inst->Src[0], i);
1198 }
1199 if (i == 3) {
1200 alu.last = 1;
1201 }
1202 r = r600_bc_add_alu(ctx->bc, &alu);
1203 if (r)
1204 return r;
1205 }
1206
1207 /* kill must be last in ALU */
1208 ctx->bc->force_add_cf = 1;
1209 ctx->shader->uses_kill = TRUE;
1210 return 0;
1211 }
1212
1213 static int tgsi_lit(struct r600_shader_ctx *ctx)
1214 {
1215 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1216 struct r600_bc_alu alu;
1217 struct r600_bc_alu_src r600_src[3];
1218 int r;
1219
1220 r = tgsi_split_constant(ctx, r600_src);
1221 if (r)
1222 return r;
1223 r = tgsi_split_literal_constant(ctx, r600_src);
1224 if (r)
1225 return r;
1226
1227 /* dst.x, <- 1.0 */
1228 memset(&alu, 0, sizeof(struct r600_bc_alu));
1229 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1230 alu.src[0].sel = V_SQ_ALU_SRC_1; /*1.0*/
1231 alu.src[0].chan = 0;
1232 r = tgsi_dst(ctx, &inst->Dst[0], 0, &alu.dst);
1233 if (r)
1234 return r;
1235 alu.dst.write = (inst->Dst[0].Register.WriteMask >> 0) & 1;
1236 r = r600_bc_add_alu(ctx->bc, &alu);
1237 if (r)
1238 return r;
1239
1240 /* dst.y = max(src.x, 0.0) */
1241 memset(&alu, 0, sizeof(struct r600_bc_alu));
1242 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX);
1243 alu.src[0] = r600_src[0];
1244 alu.src[1].sel = V_SQ_ALU_SRC_0; /*0.0*/
1245 alu.src[1].chan = 0;
1246 r = tgsi_dst(ctx, &inst->Dst[0], 1, &alu.dst);
1247 if (r)
1248 return r;
1249 alu.dst.write = (inst->Dst[0].Register.WriteMask >> 1) & 1;
1250 r = r600_bc_add_alu(ctx->bc, &alu);
1251 if (r)
1252 return r;
1253
1254 /* dst.w, <- 1.0 */
1255 memset(&alu, 0, sizeof(struct r600_bc_alu));
1256 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1257 alu.src[0].sel = V_SQ_ALU_SRC_1;
1258 alu.src[0].chan = 0;
1259 r = tgsi_dst(ctx, &inst->Dst[0], 3, &alu.dst);
1260 if (r)
1261 return r;
1262 alu.dst.write = (inst->Dst[0].Register.WriteMask >> 3) & 1;
1263 alu.last = 1;
1264 r = r600_bc_add_alu(ctx->bc, &alu);
1265 if (r)
1266 return r;
1267
1268 if (inst->Dst[0].Register.WriteMask & (1 << 2))
1269 {
1270 int chan;
1271 int sel;
1272
1273 /* dst.z = log(src.y) */
1274 memset(&alu, 0, sizeof(struct r600_bc_alu));
1275 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED);
1276 alu.src[0] = r600_src[0];
1277 alu.src[0].chan = tgsi_chan(&inst->Src[0], 1);
1278 r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst);
1279 if (r)
1280 return r;
1281 alu.last = 1;
1282 r = r600_bc_add_alu(ctx->bc, &alu);
1283 if (r)
1284 return r;
1285
1286 chan = alu.dst.chan;
1287 sel = alu.dst.sel;
1288
1289 /* tmp.x = amd MUL_LIT(src.w, dst.z, src.x ) */
1290 memset(&alu, 0, sizeof(struct r600_bc_alu));
1291 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MUL_LIT);
1292 alu.src[0] = r600_src[0];
1293 alu.src[0].chan = tgsi_chan(&inst->Src[0], 3);
1294 alu.src[1].sel = sel;
1295 alu.src[1].chan = chan;
1296
1297 alu.src[2] = r600_src[0];
1298 alu.src[2].chan = tgsi_chan(&inst->Src[0], 0);
1299 alu.dst.sel = ctx->temp_reg;
1300 alu.dst.chan = 0;
1301 alu.dst.write = 1;
1302 alu.is_op3 = 1;
1303 alu.last = 1;
1304 r = r600_bc_add_alu(ctx->bc, &alu);
1305 if (r)
1306 return r;
1307
1308 /* dst.z = exp(tmp.x) */
1309 memset(&alu, 0, sizeof(struct r600_bc_alu));
1310 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE);
1311 alu.src[0].sel = ctx->temp_reg;
1312 alu.src[0].chan = 0;
1313 r = tgsi_dst(ctx, &inst->Dst[0], 2, &alu.dst);
1314 if (r)
1315 return r;
1316 alu.last = 1;
1317 r = r600_bc_add_alu(ctx->bc, &alu);
1318 if (r)
1319 return r;
1320 }
1321 return 0;
1322 }
1323
1324 static int tgsi_rsq(struct r600_shader_ctx *ctx)
1325 {
1326 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1327 struct r600_bc_alu alu;
1328 int i, r;
1329
1330 memset(&alu, 0, sizeof(struct r600_bc_alu));
1331
1332 /* FIXME:
1333 * For state trackers other than OpenGL, we'll want to use
1334 * _RECIPSQRT_IEEE instead.
1335 */
1336 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_CLAMPED);
1337
1338 for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
1339 r = tgsi_src(ctx, &inst->Src[i], &alu.src[i]);
1340 if (r)
1341 return r;
1342 alu.src[i].chan = tgsi_chan(&inst->Src[i], 0);
1343 alu.src[i].abs = 1;
1344 }
1345 alu.dst.sel = ctx->temp_reg;
1346 alu.dst.write = 1;
1347 alu.last = 1;
1348 r = r600_bc_add_alu(ctx->bc, &alu);
1349 if (r)
1350 return r;
1351 /* replicate result */
1352 return tgsi_helper_tempx_replicate(ctx);
1353 }
1354
1355 static int tgsi_helper_tempx_replicate(struct r600_shader_ctx *ctx)
1356 {
1357 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1358 struct r600_bc_alu alu;
1359 int i, r;
1360
1361 for (i = 0; i < 4; i++) {
1362 memset(&alu, 0, sizeof(struct r600_bc_alu));
1363 alu.src[0].sel = ctx->temp_reg;
1364 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1365 alu.dst.chan = i;
1366 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1367 if (r)
1368 return r;
1369 alu.dst.write = (inst->Dst[0].Register.WriteMask >> i) & 1;
1370 if (i == 3)
1371 alu.last = 1;
1372 r = r600_bc_add_alu(ctx->bc, &alu);
1373 if (r)
1374 return r;
1375 }
1376 return 0;
1377 }
1378
1379 static int tgsi_trans_srcx_replicate(struct r600_shader_ctx *ctx)
1380 {
1381 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1382 struct r600_bc_alu alu;
1383 int i, r;
1384
1385 memset(&alu, 0, sizeof(struct r600_bc_alu));
1386 alu.inst = ctx->inst_info->r600_opcode;
1387 for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
1388 r = tgsi_src(ctx, &inst->Src[i], &alu.src[i]);
1389 if (r)
1390 return r;
1391 alu.src[i].chan = tgsi_chan(&inst->Src[i], 0);
1392 }
1393 alu.dst.sel = ctx->temp_reg;
1394 alu.dst.write = 1;
1395 alu.last = 1;
1396 r = r600_bc_add_alu(ctx->bc, &alu);
1397 if (r)
1398 return r;
1399 /* replicate result */
1400 return tgsi_helper_tempx_replicate(ctx);
1401 }
1402
1403 static int tgsi_pow(struct r600_shader_ctx *ctx)
1404 {
1405 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1406 struct r600_bc_alu alu;
1407 int r;
1408
1409 /* LOG2(a) */
1410 memset(&alu, 0, sizeof(struct r600_bc_alu));
1411 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE);
1412 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
1413 if (r)
1414 return r;
1415 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
1416 alu.dst.sel = ctx->temp_reg;
1417 alu.dst.write = 1;
1418 alu.last = 1;
1419 r = r600_bc_add_alu(ctx->bc, &alu);
1420 if (r)
1421 return r;
1422 /* b * LOG2(a) */
1423 memset(&alu, 0, sizeof(struct r600_bc_alu));
1424 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
1425 r = tgsi_src(ctx, &inst->Src[1], &alu.src[0]);
1426 if (r)
1427 return r;
1428 alu.src[0].chan = tgsi_chan(&inst->Src[1], 0);
1429 alu.src[1].sel = ctx->temp_reg;
1430 alu.dst.sel = ctx->temp_reg;
1431 alu.dst.write = 1;
1432 alu.last = 1;
1433 r = r600_bc_add_alu(ctx->bc, &alu);
1434 if (r)
1435 return r;
1436 /* POW(a,b) = EXP2(b * LOG2(a))*/
1437 memset(&alu, 0, sizeof(struct r600_bc_alu));
1438 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE);
1439 alu.src[0].sel = ctx->temp_reg;
1440 alu.dst.sel = ctx->temp_reg;
1441 alu.dst.write = 1;
1442 alu.last = 1;
1443 r = r600_bc_add_alu(ctx->bc, &alu);
1444 if (r)
1445 return r;
1446 return tgsi_helper_tempx_replicate(ctx);
1447 }
1448
1449 static int tgsi_ssg(struct r600_shader_ctx *ctx)
1450 {
1451 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1452 struct r600_bc_alu alu;
1453 struct r600_bc_alu_src r600_src[3];
1454 int i, r;
1455
1456 r = tgsi_split_constant(ctx, r600_src);
1457 if (r)
1458 return r;
1459 r = tgsi_split_literal_constant(ctx, r600_src);
1460 if (r)
1461 return r;
1462
1463 /* tmp = (src > 0 ? 1 : src) */
1464 for (i = 0; i < 4; i++) {
1465 memset(&alu, 0, sizeof(struct r600_bc_alu));
1466 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT);
1467 alu.is_op3 = 1;
1468
1469 alu.dst.sel = ctx->temp_reg;
1470 alu.dst.chan = i;
1471
1472 alu.src[0] = r600_src[0];
1473 alu.src[0].chan = tgsi_chan(&inst->Src[0], i);
1474
1475 alu.src[1].sel = V_SQ_ALU_SRC_1;
1476
1477 alu.src[2] = r600_src[0];
1478 alu.src[2].chan = tgsi_chan(&inst->Src[0], i);
1479 if (i == 3)
1480 alu.last = 1;
1481 r = r600_bc_add_alu(ctx->bc, &alu);
1482 if (r)
1483 return r;
1484 }
1485
1486 /* dst = (-tmp > 0 ? -1 : tmp) */
1487 for (i = 0; i < 4; i++) {
1488 memset(&alu, 0, sizeof(struct r600_bc_alu));
1489 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGT);
1490 alu.is_op3 = 1;
1491 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1492 if (r)
1493 return r;
1494
1495 alu.src[0].sel = ctx->temp_reg;
1496 alu.src[0].chan = i;
1497 alu.src[0].neg = 1;
1498
1499 alu.src[1].sel = V_SQ_ALU_SRC_1;
1500 alu.src[1].neg = 1;
1501
1502 alu.src[2].sel = ctx->temp_reg;
1503 alu.src[2].chan = i;
1504
1505 if (i == 3)
1506 alu.last = 1;
1507 r = r600_bc_add_alu(ctx->bc, &alu);
1508 if (r)
1509 return r;
1510 }
1511 return 0;
1512 }
1513
1514 static int tgsi_helper_copy(struct r600_shader_ctx *ctx, struct tgsi_full_instruction *inst)
1515 {
1516 struct r600_bc_alu alu;
1517 int i, r;
1518
1519 for (i = 0; i < 4; i++) {
1520 memset(&alu, 0, sizeof(struct r600_bc_alu));
1521 if (!(inst->Dst[0].Register.WriteMask & (1 << i))) {
1522 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP);
1523 alu.dst.chan = i;
1524 } else {
1525 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1526 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1527 if (r)
1528 return r;
1529 alu.src[0].sel = ctx->temp_reg;
1530 alu.src[0].chan = i;
1531 }
1532 if (i == 3) {
1533 alu.last = 1;
1534 }
1535 r = r600_bc_add_alu(ctx->bc, &alu);
1536 if (r)
1537 return r;
1538 }
1539 return 0;
1540 }
1541
1542 static int tgsi_op3(struct r600_shader_ctx *ctx)
1543 {
1544 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1545 struct r600_bc_alu_src r600_src[3];
1546 struct r600_bc_alu alu;
1547 int i, j, r;
1548 int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask);
1549
1550 r = tgsi_split_constant(ctx, r600_src);
1551 if (r)
1552 return r;
1553 r = tgsi_split_literal_constant(ctx, r600_src);
1554 if (r)
1555 return r;
1556 for (i = 0; i < lasti + 1; i++) {
1557 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1558 continue;
1559
1560 memset(&alu, 0, sizeof(struct r600_bc_alu));
1561 alu.inst = ctx->inst_info->r600_opcode;
1562 for (j = 0; j < inst->Instruction.NumSrcRegs; j++) {
1563 alu.src[j] = r600_src[j];
1564 alu.src[j].chan = tgsi_chan(&inst->Src[j], i);
1565 }
1566
1567 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1568 if (r)
1569 return r;
1570
1571 alu.dst.chan = i;
1572 alu.dst.write = 1;
1573 alu.is_op3 = 1;
1574 if (i == lasti) {
1575 alu.last = 1;
1576 }
1577 r = r600_bc_add_alu(ctx->bc, &alu);
1578 if (r)
1579 return r;
1580 }
1581 return 0;
1582 }
1583
1584 static int tgsi_dp(struct r600_shader_ctx *ctx)
1585 {
1586 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1587 struct r600_bc_alu_src r600_src[3];
1588 struct r600_bc_alu alu;
1589 int i, j, r;
1590
1591 r = tgsi_split_constant(ctx, r600_src);
1592 if (r)
1593 return r;
1594 r = tgsi_split_literal_constant(ctx, r600_src);
1595 if (r)
1596 return r;
1597 for (i = 0; i < 4; i++) {
1598 memset(&alu, 0, sizeof(struct r600_bc_alu));
1599 alu.inst = ctx->inst_info->r600_opcode;
1600 for (j = 0; j < inst->Instruction.NumSrcRegs; j++) {
1601 alu.src[j] = r600_src[j];
1602 alu.src[j].chan = tgsi_chan(&inst->Src[j], i);
1603 }
1604
1605 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1606 if (r)
1607 return r;
1608
1609 alu.dst.chan = i;
1610 alu.dst.write = (inst->Dst[0].Register.WriteMask >> i) & 1;
1611 /* handle some special cases */
1612 switch (ctx->inst_info->tgsi_opcode) {
1613 case TGSI_OPCODE_DP2:
1614 if (i > 1) {
1615 alu.src[0].sel = alu.src[1].sel = V_SQ_ALU_SRC_0;
1616 alu.src[0].chan = alu.src[1].chan = 0;
1617 }
1618 break;
1619 case TGSI_OPCODE_DP3:
1620 if (i > 2) {
1621 alu.src[0].sel = alu.src[1].sel = V_SQ_ALU_SRC_0;
1622 alu.src[0].chan = alu.src[1].chan = 0;
1623 }
1624 break;
1625 case TGSI_OPCODE_DPH:
1626 if (i == 3) {
1627 alu.src[0].sel = V_SQ_ALU_SRC_1;
1628 alu.src[0].chan = 0;
1629 alu.src[0].neg = 0;
1630 }
1631 break;
1632 default:
1633 break;
1634 }
1635 if (i == 3) {
1636 alu.last = 1;
1637 }
1638 r = r600_bc_add_alu(ctx->bc, &alu);
1639 if (r)
1640 return r;
1641 }
1642 return 0;
1643 }
1644
1645 static int tgsi_tex(struct r600_shader_ctx *ctx)
1646 {
1647 static float one_point_five = 1.5f;
1648 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1649 struct r600_bc_tex tex;
1650 struct r600_bc_alu alu;
1651 unsigned src_gpr;
1652 int r, i;
1653 int opcode;
1654 boolean src_not_temp =
1655 inst->Src[0].Register.File != TGSI_FILE_TEMPORARY &&
1656 inst->Src[0].Register.File != TGSI_FILE_INPUT;
1657
1658 src_gpr = ctx->file_offset[inst->Src[0].Register.File] + inst->Src[0].Register.Index;
1659
1660 if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) {
1661 /* Add perspective divide */
1662 memset(&alu, 0, sizeof(struct r600_bc_alu));
1663 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE);
1664 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
1665 if (r)
1666 return r;
1667
1668 alu.src[0].chan = tgsi_chan(&inst->Src[0], 3);
1669 alu.dst.sel = ctx->temp_reg;
1670 alu.dst.chan = 3;
1671 alu.last = 1;
1672 alu.dst.write = 1;
1673 r = r600_bc_add_alu(ctx->bc, &alu);
1674 if (r)
1675 return r;
1676
1677 for (i = 0; i < 3; i++) {
1678 memset(&alu, 0, sizeof(struct r600_bc_alu));
1679 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
1680 alu.src[0].sel = ctx->temp_reg;
1681 alu.src[0].chan = 3;
1682 r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]);
1683 if (r)
1684 return r;
1685 alu.src[1].chan = tgsi_chan(&inst->Src[0], i);
1686 alu.dst.sel = ctx->temp_reg;
1687 alu.dst.chan = i;
1688 alu.dst.write = 1;
1689 r = r600_bc_add_alu(ctx->bc, &alu);
1690 if (r)
1691 return r;
1692 }
1693 memset(&alu, 0, sizeof(struct r600_bc_alu));
1694 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1695 alu.src[0].sel = V_SQ_ALU_SRC_1;
1696 alu.src[0].chan = 0;
1697 alu.dst.sel = ctx->temp_reg;
1698 alu.dst.chan = 3;
1699 alu.last = 1;
1700 alu.dst.write = 1;
1701 r = r600_bc_add_alu(ctx->bc, &alu);
1702 if (r)
1703 return r;
1704 src_not_temp = FALSE;
1705 src_gpr = ctx->temp_reg;
1706 }
1707
1708 if (inst->Texture.Texture == TGSI_TEXTURE_CUBE) {
1709 int src_chan, src2_chan;
1710
1711 /* tmp1.xyzw = CUBE(R0.zzxy, R0.yxzz) */
1712 for (i = 0; i < 4; i++) {
1713 memset(&alu, 0, sizeof(struct r600_bc_alu));
1714 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE);
1715 switch (i) {
1716 case 0:
1717 src_chan = 2;
1718 src2_chan = 1;
1719 break;
1720 case 1:
1721 src_chan = 2;
1722 src2_chan = 0;
1723 break;
1724 case 2:
1725 src_chan = 0;
1726 src2_chan = 2;
1727 break;
1728 case 3:
1729 src_chan = 1;
1730 src2_chan = 2;
1731 break;
1732 default:
1733 assert(0);
1734 src_chan = 0;
1735 src2_chan = 0;
1736 break;
1737 }
1738 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
1739 if (r)
1740 return r;
1741 alu.src[0].chan = tgsi_chan(&inst->Src[0], src_chan);
1742 r = tgsi_src(ctx, &inst->Src[0], &alu.src[1]);
1743 if (r)
1744 return r;
1745 alu.src[1].chan = tgsi_chan(&inst->Src[0], src2_chan);
1746 alu.dst.sel = ctx->temp_reg;
1747 alu.dst.chan = i;
1748 if (i == 3)
1749 alu.last = 1;
1750 alu.dst.write = 1;
1751 r = r600_bc_add_alu(ctx->bc, &alu);
1752 if (r)
1753 return r;
1754 }
1755
1756 /* tmp1.z = RCP_e(|tmp1.z|) */
1757 memset(&alu, 0, sizeof(struct r600_bc_alu));
1758 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE);
1759 alu.src[0].sel = ctx->temp_reg;
1760 alu.src[0].chan = 2;
1761 alu.src[0].abs = 1;
1762 alu.dst.sel = ctx->temp_reg;
1763 alu.dst.chan = 2;
1764 alu.dst.write = 1;
1765 alu.last = 1;
1766 r = r600_bc_add_alu(ctx->bc, &alu);
1767 if (r)
1768 return r;
1769
1770 /* MULADD R0.x, R0.x, PS1, (0x3FC00000, 1.5f).x
1771 * MULADD R0.y, R0.y, PS1, (0x3FC00000, 1.5f).x
1772 * muladd has no writemask, have to use another temp
1773 */
1774 memset(&alu, 0, sizeof(struct r600_bc_alu));
1775 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
1776 alu.is_op3 = 1;
1777
1778 alu.src[0].sel = ctx->temp_reg;
1779 alu.src[0].chan = 0;
1780 alu.src[1].sel = ctx->temp_reg;
1781 alu.src[1].chan = 2;
1782
1783 alu.src[2].sel = V_SQ_ALU_SRC_LITERAL;
1784 alu.src[2].chan = 0;
1785
1786 alu.dst.sel = ctx->temp_reg;
1787 alu.dst.chan = 0;
1788 alu.dst.write = 1;
1789
1790 r = r600_bc_add_alu(ctx->bc, &alu);
1791 if (r)
1792 return r;
1793
1794 memset(&alu, 0, sizeof(struct r600_bc_alu));
1795 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
1796 alu.is_op3 = 1;
1797
1798 alu.src[0].sel = ctx->temp_reg;
1799 alu.src[0].chan = 1;
1800 alu.src[1].sel = ctx->temp_reg;
1801 alu.src[1].chan = 2;
1802
1803 alu.src[2].sel = V_SQ_ALU_SRC_LITERAL;
1804 alu.src[2].chan = 0;
1805 alu.src[2].value = (u32*)&one_point_five;
1806
1807 alu.dst.sel = ctx->temp_reg;
1808 alu.dst.chan = 1;
1809 alu.dst.write = 1;
1810
1811 alu.last = 1;
1812 r = r600_bc_add_alu(ctx->bc, &alu);
1813 if (r)
1814 return r;
1815
1816 src_not_temp = FALSE;
1817 src_gpr = ctx->temp_reg;
1818 }
1819
1820 if (src_not_temp) {
1821 for (i = 0; i < 4; i++) {
1822 memset(&alu, 0, sizeof(struct r600_bc_alu));
1823 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
1824 alu.src[0].sel = src_gpr;
1825 alu.src[0].chan = tgsi_chan(&inst->Src[0], i);
1826 alu.dst.sel = ctx->temp_reg;
1827 alu.dst.chan = i;
1828 if (i == 3)
1829 alu.last = 1;
1830 alu.dst.write = 1;
1831 r = r600_bc_add_alu(ctx->bc, &alu);
1832 if (r)
1833 return r;
1834 }
1835 src_gpr = ctx->temp_reg;
1836 }
1837
1838 opcode = ctx->inst_info->r600_opcode;
1839 if (opcode == SQ_TEX_INST_SAMPLE &&
1840 (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D))
1841 opcode = SQ_TEX_INST_SAMPLE_C;
1842
1843 memset(&tex, 0, sizeof(struct r600_bc_tex));
1844 tex.inst = opcode;
1845 tex.sampler_id = ctx->file_offset[inst->Src[1].Register.File] + inst->Src[1].Register.Index;
1846 tex.resource_id = tex.sampler_id;
1847 tex.src_gpr = src_gpr;
1848 tex.dst_gpr = ctx->file_offset[inst->Dst[0].Register.File] + inst->Dst[0].Register.Index;
1849 tex.dst_sel_x = (inst->Dst[0].Register.WriteMask & 1) ? 0 : 7;
1850 tex.dst_sel_y = (inst->Dst[0].Register.WriteMask & 2) ? 1 : 7;
1851 tex.dst_sel_z = (inst->Dst[0].Register.WriteMask & 4) ? 2 : 7;
1852 tex.dst_sel_w = (inst->Dst[0].Register.WriteMask & 8) ? 3 : 7;
1853 tex.src_sel_x = 0;
1854 tex.src_sel_y = 1;
1855 tex.src_sel_z = 2;
1856 tex.src_sel_w = 3;
1857
1858 if (inst->Texture.Texture == TGSI_TEXTURE_CUBE) {
1859 tex.src_sel_x = 1;
1860 tex.src_sel_y = 0;
1861 tex.src_sel_z = 3;
1862 tex.src_sel_w = 1;
1863 }
1864
1865 if (inst->Texture.Texture != TGSI_TEXTURE_RECT) {
1866 tex.coord_type_x = 1;
1867 tex.coord_type_y = 1;
1868 tex.coord_type_z = 1;
1869 tex.coord_type_w = 1;
1870 }
1871
1872 if (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D)
1873 tex.src_sel_w = 2;
1874
1875 r = r600_bc_add_tex(ctx->bc, &tex);
1876 if (r)
1877 return r;
1878
1879 /* add shadow ambient support - gallium doesn't do it yet */
1880 return 0;
1881 }
1882
1883 static int tgsi_lrp(struct r600_shader_ctx *ctx)
1884 {
1885 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
1886 struct r600_bc_alu_src r600_src[3];
1887 struct r600_bc_alu alu;
1888 int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask);
1889 unsigned i;
1890 int r;
1891
1892 r = tgsi_split_constant(ctx, r600_src);
1893 if (r)
1894 return r;
1895 r = tgsi_split_literal_constant(ctx, r600_src);
1896 if (r)
1897 return r;
1898
1899 /* optimize if it's just an equal balance */
1900 if(r600_src[0].sel == V_SQ_ALU_SRC_0_5) {
1901 for (i = 0; i < lasti + 1; i++) {
1902 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1903 continue;
1904
1905 memset(&alu, 0, sizeof(struct r600_bc_alu));
1906 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD);
1907 alu.src[0] = r600_src[1];
1908 alu.src[0].chan = tgsi_chan(&inst->Src[1], i);
1909 alu.src[1] = r600_src[2];
1910 alu.src[1].chan = tgsi_chan(&inst->Src[2], i);
1911 alu.omod = 3;
1912 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1913 if (r)
1914 return r;
1915
1916 alu.dst.chan = i;
1917 if (i == lasti) {
1918 alu.last = 1;
1919 }
1920 r = r600_bc_add_alu(ctx->bc, &alu);
1921 if (r)
1922 return r;
1923 }
1924 return 0;
1925 }
1926
1927 /* 1 - src0 */
1928 for (i = 0; i < lasti + 1; i++) {
1929 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1930 continue;
1931
1932 memset(&alu, 0, sizeof(struct r600_bc_alu));
1933 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD);
1934 alu.src[0].sel = V_SQ_ALU_SRC_1;
1935 alu.src[0].chan = 0;
1936 alu.src[1] = r600_src[0];
1937 alu.src[1].chan = tgsi_chan(&inst->Src[0], i);
1938 alu.src[1].neg = 1;
1939 alu.dst.sel = ctx->temp_reg;
1940 alu.dst.chan = i;
1941 if (i == lasti) {
1942 alu.last = 1;
1943 }
1944 alu.dst.write = 1;
1945 r = r600_bc_add_alu(ctx->bc, &alu);
1946 if (r)
1947 return r;
1948 }
1949
1950 /* (1 - src0) * src2 */
1951 for (i = 0; i < lasti + 1; i++) {
1952 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1953 continue;
1954
1955 memset(&alu, 0, sizeof(struct r600_bc_alu));
1956 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
1957 alu.src[0].sel = ctx->temp_reg;
1958 alu.src[0].chan = i;
1959 alu.src[1] = r600_src[2];
1960 alu.src[1].chan = tgsi_chan(&inst->Src[2], i);
1961 alu.dst.sel = ctx->temp_reg;
1962 alu.dst.chan = i;
1963 if (i == lasti) {
1964 alu.last = 1;
1965 }
1966 alu.dst.write = 1;
1967 r = r600_bc_add_alu(ctx->bc, &alu);
1968 if (r)
1969 return r;
1970 }
1971
1972 /* src0 * src1 + (1 - src0) * src2 */
1973 for (i = 0; i < lasti + 1; i++) {
1974 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
1975 continue;
1976
1977 memset(&alu, 0, sizeof(struct r600_bc_alu));
1978 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
1979 alu.is_op3 = 1;
1980 alu.src[0] = r600_src[0];
1981 alu.src[0].chan = tgsi_chan(&inst->Src[0], i);
1982 alu.src[1] = r600_src[1];
1983 alu.src[1].chan = tgsi_chan(&inst->Src[1], i);
1984 alu.src[2].sel = ctx->temp_reg;
1985 alu.src[2].chan = i;
1986
1987 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
1988 if (r)
1989 return r;
1990
1991 alu.dst.chan = i;
1992 if (i == lasti) {
1993 alu.last = 1;
1994 }
1995 r = r600_bc_add_alu(ctx->bc, &alu);
1996 if (r)
1997 return r;
1998 }
1999 return 0;
2000 }
2001
2002 static int tgsi_cmp(struct r600_shader_ctx *ctx)
2003 {
2004 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2005 struct r600_bc_alu_src r600_src[3];
2006 struct r600_bc_alu alu;
2007 int i, r;
2008 int lasti = tgsi_last_instruction(inst->Dst[0].Register.WriteMask);
2009
2010 r = tgsi_split_constant(ctx, r600_src);
2011 if (r)
2012 return r;
2013 r = tgsi_split_literal_constant(ctx, r600_src);
2014 if (r)
2015 return r;
2016
2017 for (i = 0; i < lasti + 1; i++) {
2018 if (!(inst->Dst[0].Register.WriteMask & (1 << i)))
2019 continue;
2020
2021 memset(&alu, 0, sizeof(struct r600_bc_alu));
2022 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_CNDGE);
2023 alu.src[0] = r600_src[0];
2024 alu.src[0].chan = tgsi_chan(&inst->Src[0], i);
2025
2026 alu.src[1] = r600_src[2];
2027 alu.src[1].chan = tgsi_chan(&inst->Src[2], i);
2028
2029 alu.src[2] = r600_src[1];
2030 alu.src[2].chan = tgsi_chan(&inst->Src[1], i);
2031
2032 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
2033 if (r)
2034 return r;
2035
2036 alu.dst.chan = i;
2037 alu.dst.write = 1;
2038 alu.is_op3 = 1;
2039 if (i == lasti)
2040 alu.last = 1;
2041 r = r600_bc_add_alu(ctx->bc, &alu);
2042 if (r)
2043 return r;
2044 }
2045 return 0;
2046 }
2047
2048 static int tgsi_xpd(struct r600_shader_ctx *ctx)
2049 {
2050 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2051 struct r600_bc_alu_src r600_src[3];
2052 struct r600_bc_alu alu;
2053 uint32_t use_temp = 0;
2054 int i, r;
2055
2056 if (inst->Dst[0].Register.WriteMask != 0xf)
2057 use_temp = 1;
2058
2059 r = tgsi_split_constant(ctx, r600_src);
2060 if (r)
2061 return r;
2062 r = tgsi_split_literal_constant(ctx, r600_src);
2063 if (r)
2064 return r;
2065
2066 for (i = 0; i < 4; i++) {
2067 memset(&alu, 0, sizeof(struct r600_bc_alu));
2068 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
2069
2070 alu.src[0] = r600_src[0];
2071 switch (i) {
2072 case 0:
2073 alu.src[0].chan = tgsi_chan(&inst->Src[0], 2);
2074 break;
2075 case 1:
2076 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2077 break;
2078 case 2:
2079 alu.src[0].chan = tgsi_chan(&inst->Src[0], 1);
2080 break;
2081 case 3:
2082 alu.src[0].sel = V_SQ_ALU_SRC_0;
2083 alu.src[0].chan = i;
2084 }
2085
2086 alu.src[1] = r600_src[1];
2087 switch (i) {
2088 case 0:
2089 alu.src[1].chan = tgsi_chan(&inst->Src[1], 1);
2090 break;
2091 case 1:
2092 alu.src[1].chan = tgsi_chan(&inst->Src[1], 2);
2093 break;
2094 case 2:
2095 alu.src[1].chan = tgsi_chan(&inst->Src[1], 0);
2096 break;
2097 case 3:
2098 alu.src[1].sel = V_SQ_ALU_SRC_0;
2099 alu.src[1].chan = i;
2100 }
2101
2102 alu.dst.sel = ctx->temp_reg;
2103 alu.dst.chan = i;
2104 alu.dst.write = 1;
2105
2106 if (i == 3)
2107 alu.last = 1;
2108 r = r600_bc_add_alu(ctx->bc, &alu);
2109 if (r)
2110 return r;
2111 }
2112
2113 for (i = 0; i < 4; i++) {
2114 memset(&alu, 0, sizeof(struct r600_bc_alu));
2115 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD);
2116
2117 alu.src[0] = r600_src[0];
2118 switch (i) {
2119 case 0:
2120 alu.src[0].chan = tgsi_chan(&inst->Src[0], 1);
2121 break;
2122 case 1:
2123 alu.src[0].chan = tgsi_chan(&inst->Src[0], 2);
2124 break;
2125 case 2:
2126 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2127 break;
2128 case 3:
2129 alu.src[0].sel = V_SQ_ALU_SRC_0;
2130 alu.src[0].chan = i;
2131 }
2132
2133 alu.src[1] = r600_src[1];
2134 switch (i) {
2135 case 0:
2136 alu.src[1].chan = tgsi_chan(&inst->Src[1], 2);
2137 break;
2138 case 1:
2139 alu.src[1].chan = tgsi_chan(&inst->Src[1], 0);
2140 break;
2141 case 2:
2142 alu.src[1].chan = tgsi_chan(&inst->Src[1], 1);
2143 break;
2144 case 3:
2145 alu.src[1].sel = V_SQ_ALU_SRC_0;
2146 alu.src[1].chan = i;
2147 }
2148
2149 alu.src[2].sel = ctx->temp_reg;
2150 alu.src[2].neg = 1;
2151 alu.src[2].chan = i;
2152
2153 if (use_temp)
2154 alu.dst.sel = ctx->temp_reg;
2155 else {
2156 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
2157 if (r)
2158 return r;
2159 }
2160 alu.dst.chan = i;
2161 alu.dst.write = 1;
2162 alu.is_op3 = 1;
2163 if (i == 3)
2164 alu.last = 1;
2165 r = r600_bc_add_alu(ctx->bc, &alu);
2166 if (r)
2167 return r;
2168 }
2169 if (use_temp)
2170 return tgsi_helper_copy(ctx, inst);
2171 return 0;
2172 }
2173
2174 static int tgsi_exp(struct r600_shader_ctx *ctx)
2175 {
2176 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2177 struct r600_bc_alu_src r600_src[3] = { { 0 } };
2178 struct r600_bc_alu alu;
2179 int r;
2180
2181 /* result.x = 2^floor(src); */
2182 if (inst->Dst[0].Register.WriteMask & 1) {
2183 memset(&alu, 0, sizeof(struct r600_bc_alu));
2184
2185 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR);
2186 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2187 if (r)
2188 return r;
2189
2190 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2191
2192 alu.dst.sel = ctx->temp_reg;
2193 alu.dst.chan = 0;
2194 alu.dst.write = 1;
2195 alu.last = 1;
2196 r = r600_bc_add_alu(ctx->bc, &alu);
2197 if (r)
2198 return r;
2199
2200 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE);
2201 alu.src[0].sel = ctx->temp_reg;
2202 alu.src[0].chan = 0;
2203
2204 alu.dst.sel = ctx->temp_reg;
2205 alu.dst.chan = 0;
2206 alu.dst.write = 1;
2207 alu.last = 1;
2208 r = r600_bc_add_alu(ctx->bc, &alu);
2209 if (r)
2210 return r;
2211 }
2212
2213 /* result.y = tmp - floor(tmp); */
2214 if ((inst->Dst[0].Register.WriteMask >> 1) & 1) {
2215 memset(&alu, 0, sizeof(struct r600_bc_alu));
2216
2217 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT);
2218 alu.src[0] = r600_src[0];
2219 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2220 if (r)
2221 return r;
2222 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2223
2224 alu.dst.sel = ctx->temp_reg;
2225 // r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
2226 // if (r)
2227 // return r;
2228 alu.dst.write = 1;
2229 alu.dst.chan = 1;
2230
2231 alu.last = 1;
2232
2233 r = r600_bc_add_alu(ctx->bc, &alu);
2234 if (r)
2235 return r;
2236 }
2237
2238 /* result.z = RoughApprox2ToX(tmp);*/
2239 if ((inst->Dst[0].Register.WriteMask >> 2) & 0x1) {
2240 memset(&alu, 0, sizeof(struct r600_bc_alu));
2241 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE);
2242 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2243 if (r)
2244 return r;
2245 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2246
2247 alu.dst.sel = ctx->temp_reg;
2248 alu.dst.write = 1;
2249 alu.dst.chan = 2;
2250
2251 alu.last = 1;
2252
2253 r = r600_bc_add_alu(ctx->bc, &alu);
2254 if (r)
2255 return r;
2256 }
2257
2258 /* result.w = 1.0;*/
2259 if ((inst->Dst[0].Register.WriteMask >> 3) & 0x1) {
2260 memset(&alu, 0, sizeof(struct r600_bc_alu));
2261
2262 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
2263 alu.src[0].sel = V_SQ_ALU_SRC_1;
2264 alu.src[0].chan = 0;
2265
2266 alu.dst.sel = ctx->temp_reg;
2267 alu.dst.chan = 3;
2268 alu.dst.write = 1;
2269 alu.last = 1;
2270 r = r600_bc_add_alu(ctx->bc, &alu);
2271 if (r)
2272 return r;
2273 }
2274 return tgsi_helper_copy(ctx, inst);
2275 }
2276
2277 static int tgsi_log(struct r600_shader_ctx *ctx)
2278 {
2279 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2280 struct r600_bc_alu alu;
2281 int r;
2282
2283 /* result.x = floor(log2(src)); */
2284 if (inst->Dst[0].Register.WriteMask & 1) {
2285 memset(&alu, 0, sizeof(struct r600_bc_alu));
2286
2287 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE);
2288 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2289 if (r)
2290 return r;
2291
2292 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2293
2294 alu.dst.sel = ctx->temp_reg;
2295 alu.dst.chan = 0;
2296 alu.dst.write = 1;
2297 alu.last = 1;
2298 r = r600_bc_add_alu(ctx->bc, &alu);
2299 if (r)
2300 return r;
2301
2302 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR);
2303 alu.src[0].sel = ctx->temp_reg;
2304 alu.src[0].chan = 0;
2305
2306 alu.dst.sel = ctx->temp_reg;
2307 alu.dst.chan = 0;
2308 alu.dst.write = 1;
2309 alu.last = 1;
2310
2311 r = r600_bc_add_alu(ctx->bc, &alu);
2312 if (r)
2313 return r;
2314 }
2315
2316 /* result.y = src.x / (2 ^ floor(log2(src.x))); */
2317 if ((inst->Dst[0].Register.WriteMask >> 1) & 1) {
2318 memset(&alu, 0, sizeof(struct r600_bc_alu));
2319
2320 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE);
2321 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2322 if (r)
2323 return r;
2324
2325 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2326
2327 alu.dst.sel = ctx->temp_reg;
2328 alu.dst.chan = 1;
2329 alu.dst.write = 1;
2330 alu.last = 1;
2331
2332 r = r600_bc_add_alu(ctx->bc, &alu);
2333 if (r)
2334 return r;
2335
2336 memset(&alu, 0, sizeof(struct r600_bc_alu));
2337
2338 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR);
2339 alu.src[0].sel = ctx->temp_reg;
2340 alu.src[0].chan = 1;
2341
2342 alu.dst.sel = ctx->temp_reg;
2343 alu.dst.chan = 1;
2344 alu.dst.write = 1;
2345 alu.last = 1;
2346
2347 r = r600_bc_add_alu(ctx->bc, &alu);
2348 if (r)
2349 return r;
2350
2351 memset(&alu, 0, sizeof(struct r600_bc_alu));
2352
2353 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE);
2354 alu.src[0].sel = ctx->temp_reg;
2355 alu.src[0].chan = 1;
2356
2357 alu.dst.sel = ctx->temp_reg;
2358 alu.dst.chan = 1;
2359 alu.dst.write = 1;
2360 alu.last = 1;
2361
2362 r = r600_bc_add_alu(ctx->bc, &alu);
2363 if (r)
2364 return r;
2365
2366 memset(&alu, 0, sizeof(struct r600_bc_alu));
2367
2368 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE);
2369 alu.src[0].sel = ctx->temp_reg;
2370 alu.src[0].chan = 1;
2371
2372 alu.dst.sel = ctx->temp_reg;
2373 alu.dst.chan = 1;
2374 alu.dst.write = 1;
2375 alu.last = 1;
2376
2377 r = r600_bc_add_alu(ctx->bc, &alu);
2378 if (r)
2379 return r;
2380
2381 memset(&alu, 0, sizeof(struct r600_bc_alu));
2382
2383 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
2384
2385 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2386 if (r)
2387 return r;
2388
2389 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2390
2391 alu.src[1].sel = ctx->temp_reg;
2392 alu.src[1].chan = 1;
2393
2394 alu.dst.sel = ctx->temp_reg;
2395 alu.dst.chan = 1;
2396 alu.dst.write = 1;
2397 alu.last = 1;
2398
2399 r = r600_bc_add_alu(ctx->bc, &alu);
2400 if (r)
2401 return r;
2402 }
2403
2404 /* result.z = log2(src);*/
2405 if ((inst->Dst[0].Register.WriteMask >> 2) & 1) {
2406 memset(&alu, 0, sizeof(struct r600_bc_alu));
2407
2408 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE);
2409 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2410 if (r)
2411 return r;
2412
2413 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2414
2415 alu.dst.sel = ctx->temp_reg;
2416 alu.dst.write = 1;
2417 alu.dst.chan = 2;
2418 alu.last = 1;
2419
2420 r = r600_bc_add_alu(ctx->bc, &alu);
2421 if (r)
2422 return r;
2423 }
2424
2425 /* result.w = 1.0; */
2426 if ((inst->Dst[0].Register.WriteMask >> 3) & 1) {
2427 memset(&alu, 0, sizeof(struct r600_bc_alu));
2428
2429 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV);
2430 alu.src[0].sel = V_SQ_ALU_SRC_1;
2431 alu.src[0].chan = 0;
2432
2433 alu.dst.sel = ctx->temp_reg;
2434 alu.dst.chan = 3;
2435 alu.dst.write = 1;
2436 alu.last = 1;
2437
2438 r = r600_bc_add_alu(ctx->bc, &alu);
2439 if (r)
2440 return r;
2441 }
2442
2443 return tgsi_helper_copy(ctx, inst);
2444 }
2445
2446 static int tgsi_eg_arl(struct r600_shader_ctx *ctx)
2447 {
2448 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2449 struct r600_bc_alu alu;
2450 int r;
2451 memset(&alu, 0, sizeof(struct r600_bc_alu));
2452
2453 switch (inst->Instruction.Opcode) {
2454 case TGSI_OPCODE_ARL:
2455 alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT_FLOOR;
2456 break;
2457 case TGSI_OPCODE_ARR:
2458 alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT;
2459 break;
2460 default:
2461 assert(0);
2462 return -1;
2463 }
2464
2465 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2466 if (r)
2467 return r;
2468 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2469 alu.last = 1;
2470 alu.dst.chan = 0;
2471 alu.dst.sel = ctx->temp_reg;
2472 alu.dst.write = 1;
2473 r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU));
2474 if (r)
2475 return r;
2476 memset(&alu, 0, sizeof(struct r600_bc_alu));
2477 alu.inst = EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_INT;
2478 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2479 if (r)
2480 return r;
2481 alu.src[0].sel = ctx->temp_reg;
2482 alu.src[0].chan = 0;
2483 alu.last = 1;
2484 r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU));
2485 if (r)
2486 return r;
2487 return 0;
2488 }
2489 static int tgsi_r600_arl(struct r600_shader_ctx *ctx)
2490 {
2491 /* TODO from r600c, ar values don't persist between clauses */
2492 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2493 struct r600_bc_alu alu;
2494 int r;
2495 memset(&alu, 0, sizeof(struct r600_bc_alu));
2496
2497 switch (inst->Instruction.Opcode) {
2498 case TGSI_OPCODE_ARL:
2499 alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR;
2500 break;
2501 case TGSI_OPCODE_ARR:
2502 alu.inst = V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA;
2503 break;
2504 default:
2505 assert(0);
2506 return -1;
2507 }
2508
2509
2510 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2511 if (r)
2512 return r;
2513 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2514
2515 alu.last = 1;
2516
2517 r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU));
2518 if (r)
2519 return r;
2520 ctx->bc->cf_last->r6xx_uses_waterfall = 1;
2521 return 0;
2522 }
2523
2524 static int tgsi_opdst(struct r600_shader_ctx *ctx)
2525 {
2526 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2527 struct r600_bc_alu alu;
2528 int i, r = 0;
2529
2530 for (i = 0; i < 4; i++) {
2531 memset(&alu, 0, sizeof(struct r600_bc_alu));
2532
2533 alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL);
2534 r = tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
2535 if (r)
2536 return r;
2537
2538 if (i == 0 || i == 3) {
2539 alu.src[0].sel = V_SQ_ALU_SRC_1;
2540 } else {
2541 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2542 if (r)
2543 return r;
2544 alu.src[0].chan = tgsi_chan(&inst->Src[0], i);
2545 }
2546
2547 if (i == 0 || i == 2) {
2548 alu.src[1].sel = V_SQ_ALU_SRC_1;
2549 } else {
2550 r = tgsi_src(ctx, &inst->Src[1], &alu.src[1]);
2551 if (r)
2552 return r;
2553 alu.src[1].chan = tgsi_chan(&inst->Src[1], i);
2554 }
2555 if (i == 3)
2556 alu.last = 1;
2557 r = r600_bc_add_alu(ctx->bc, &alu);
2558 if (r)
2559 return r;
2560 }
2561 return 0;
2562 }
2563
2564 static int emit_logic_pred(struct r600_shader_ctx *ctx, int opcode)
2565 {
2566 struct tgsi_full_instruction *inst = &ctx->parse.FullToken.FullInstruction;
2567 struct r600_bc_alu alu;
2568 int r;
2569
2570 memset(&alu, 0, sizeof(struct r600_bc_alu));
2571 alu.inst = opcode;
2572 alu.predicate = 1;
2573
2574 alu.dst.sel = ctx->temp_reg;
2575 alu.dst.write = 1;
2576 alu.dst.chan = 0;
2577
2578 r = tgsi_src(ctx, &inst->Src[0], &alu.src[0]);
2579 if (r)
2580 return r;
2581 alu.src[0].chan = tgsi_chan(&inst->Src[0], 0);
2582 alu.src[1].sel = V_SQ_ALU_SRC_0;
2583 alu.src[1].chan = 0;
2584
2585 alu.last = 1;
2586
2587 r = r600_bc_add_alu_type(ctx->bc, &alu, CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE));
2588 if (r)
2589 return r;
2590 return 0;
2591 }
2592
2593 static int pops(struct r600_shader_ctx *ctx, int pops)
2594 {
2595 int alu_pop = 3;
2596 if (ctx->bc->cf_last) {
2597 if (ctx->bc->cf_last->inst == CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU) << 3)
2598 alu_pop = 0;
2599 else if (ctx->bc->cf_last->inst == CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER) << 3)
2600 alu_pop = 1;
2601 }
2602 alu_pop += pops;
2603 if (alu_pop == 1) {
2604 ctx->bc->cf_last->inst = CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER) << 3;
2605 ctx->bc->force_add_cf = 1;
2606 } else if (alu_pop == 2) {
2607 ctx->bc->cf_last->inst = CTX_INST(V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER) << 3;
2608 ctx->bc->force_add_cf = 1;
2609 } else {
2610 r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_POP));
2611 ctx->bc->cf_last->pop_count = pops;
2612 ctx->bc->cf_last->cf_addr = ctx->bc->cf_last->id + 2;
2613 }
2614 return 0;
2615 }
2616
2617 static inline void callstack_decrease_current(struct r600_shader_ctx *ctx, unsigned reason)
2618 {
2619 switch(reason) {
2620 case FC_PUSH_VPM:
2621 ctx->bc->callstack[ctx->bc->call_sp].current--;
2622 break;
2623 case FC_PUSH_WQM:
2624 case FC_LOOP:
2625 ctx->bc->callstack[ctx->bc->call_sp].current -= 4;
2626 break;
2627 case FC_REP:
2628 /* TOODO : for 16 vp asic should -= 2; */
2629 ctx->bc->callstack[ctx->bc->call_sp].current --;
2630 break;
2631 }
2632 }
2633
2634 static inline void callstack_check_depth(struct r600_shader_ctx *ctx, unsigned reason, unsigned check_max_only)
2635 {
2636 if (check_max_only) {
2637 int diff;
2638 switch (reason) {
2639 case FC_PUSH_VPM:
2640 diff = 1;
2641 break;
2642 case FC_PUSH_WQM:
2643 diff = 4;
2644 break;
2645 default:
2646 assert(0);
2647 diff = 0;
2648 }
2649 if ((ctx->bc->callstack[ctx->bc->call_sp].current + diff) >
2650 ctx->bc->callstack[ctx->bc->call_sp].max) {
2651 ctx->bc->callstack[ctx->bc->call_sp].max =
2652 ctx->bc->callstack[ctx->bc->call_sp].current + diff;
2653 }
2654 return;
2655 }
2656 switch (reason) {
2657 case FC_PUSH_VPM:
2658 ctx->bc->callstack[ctx->bc->call_sp].current++;
2659 break;
2660 case FC_PUSH_WQM:
2661 case FC_LOOP:
2662 ctx->bc->callstack[ctx->bc->call_sp].current += 4;
2663 break;
2664 case FC_REP:
2665 ctx->bc->callstack[ctx->bc->call_sp].current++;
2666 break;
2667 }
2668
2669 if ((ctx->bc->callstack[ctx->bc->call_sp].current) >
2670 ctx->bc->callstack[ctx->bc->call_sp].max) {
2671 ctx->bc->callstack[ctx->bc->call_sp].max =
2672 ctx->bc->callstack[ctx->bc->call_sp].current;
2673 }
2674 }
2675
2676 static void fc_set_mid(struct r600_shader_ctx *ctx, int fc_sp)
2677 {
2678 struct r600_cf_stack_entry *sp = &ctx->bc->fc_stack[fc_sp];
2679
2680 sp->mid = (struct r600_bc_cf **)realloc((void *)sp->mid,
2681 sizeof(struct r600_bc_cf *) * (sp->num_mid + 1));
2682 sp->mid[sp->num_mid] = ctx->bc->cf_last;
2683 sp->num_mid++;
2684 }
2685
2686 static void fc_pushlevel(struct r600_shader_ctx *ctx, int type)
2687 {
2688 ctx->bc->fc_sp++;
2689 ctx->bc->fc_stack[ctx->bc->fc_sp].type = type;
2690 ctx->bc->fc_stack[ctx->bc->fc_sp].start = ctx->bc->cf_last;
2691 }
2692
2693 static void fc_poplevel(struct r600_shader_ctx *ctx)
2694 {
2695 struct r600_cf_stack_entry *sp = &ctx->bc->fc_stack[ctx->bc->fc_sp];
2696 if (sp->mid) {
2697 free(sp->mid);
2698 sp->mid = NULL;
2699 }
2700 sp->num_mid = 0;
2701 sp->start = NULL;
2702 sp->type = 0;
2703 ctx->bc->fc_sp--;
2704 }
2705
2706 #if 0
2707 static int emit_return(struct r600_shader_ctx *ctx)
2708 {
2709 r600_bc_add_cfinst(ctx->bc, V_SQ_CF_WORD1_SQ_CF_INST_RETURN);
2710 return 0;
2711 }
2712
2713 static int emit_jump_to_offset(struct r600_shader_ctx *ctx, int pops, int offset)
2714 {
2715
2716 r600_bc_add_cfinst(ctx->bc, V_SQ_CF_WORD1_SQ_CF_INST_JUMP);
2717 ctx->bc->cf_last->pop_count = pops;
2718 /* TODO work out offset */
2719 return 0;
2720 }
2721
2722 static int emit_setret_in_loop_flag(struct r600_shader_ctx *ctx, unsigned flag_value)
2723 {
2724 return 0;
2725 }
2726
2727 static void emit_testflag(struct r600_shader_ctx *ctx)
2728 {
2729
2730 }
2731
2732 static void emit_return_on_flag(struct r600_shader_ctx *ctx, unsigned ifidx)
2733 {
2734 emit_testflag(ctx);
2735 emit_jump_to_offset(ctx, 1, 4);
2736 emit_setret_in_loop_flag(ctx, V_SQ_ALU_SRC_0);
2737 pops(ctx, ifidx + 1);
2738 emit_return(ctx);
2739 }
2740
2741 static void break_loop_on_flag(struct r600_shader_ctx *ctx, unsigned fc_sp)
2742 {
2743 emit_testflag(ctx);
2744
2745 r600_bc_add_cfinst(ctx->bc, ctx->inst_info->r600_opcode);
2746 ctx->bc->cf_last->pop_count = 1;
2747
2748 fc_set_mid(ctx, fc_sp);
2749
2750 pops(ctx, 1);
2751 }
2752 #endif
2753
2754 static int tgsi_if(struct r600_shader_ctx *ctx)
2755 {
2756 emit_logic_pred(ctx, CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE));
2757
2758 r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_JUMP));
2759
2760 fc_pushlevel(ctx, FC_IF);
2761
2762 callstack_check_depth(ctx, FC_PUSH_VPM, 0);
2763 return 0;
2764 }
2765
2766 static int tgsi_else(struct r600_shader_ctx *ctx)
2767 {
2768 r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_ELSE));
2769 ctx->bc->cf_last->pop_count = 1;
2770
2771 fc_set_mid(ctx, ctx->bc->fc_sp);
2772 ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id;
2773 return 0;
2774 }
2775
2776 static int tgsi_endif(struct r600_shader_ctx *ctx)
2777 {
2778 pops(ctx, 1);
2779 if (ctx->bc->fc_stack[ctx->bc->fc_sp].type != FC_IF) {
2780 R600_ERR("if/endif unbalanced in shader\n");
2781 return -1;
2782 }
2783
2784 if (ctx->bc->fc_stack[ctx->bc->fc_sp].mid == NULL) {
2785 ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id + 2;
2786 ctx->bc->fc_stack[ctx->bc->fc_sp].start->pop_count = 1;
2787 } else {
2788 ctx->bc->fc_stack[ctx->bc->fc_sp].mid[0]->cf_addr = ctx->bc->cf_last->id + 2;
2789 }
2790 fc_poplevel(ctx);
2791
2792 callstack_decrease_current(ctx, FC_PUSH_VPM);
2793 return 0;
2794 }
2795
2796 static int tgsi_bgnloop(struct r600_shader_ctx *ctx)
2797 {
2798 r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL));
2799
2800 fc_pushlevel(ctx, FC_LOOP);
2801
2802 /* check stack depth */
2803 callstack_check_depth(ctx, FC_LOOP, 0);
2804 return 0;
2805 }
2806
2807 static int tgsi_endloop(struct r600_shader_ctx *ctx)
2808 {
2809 int i;
2810
2811 r600_bc_add_cfinst(ctx->bc, CTX_INST(V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END));
2812
2813 if (ctx->bc->fc_stack[ctx->bc->fc_sp].type != FC_LOOP) {
2814 R600_ERR("loop/endloop in shader code are not paired.\n");
2815 return -EINVAL;
2816 }
2817
2818 /* fixup loop pointers - from r600isa
2819 LOOP END points to CF after LOOP START,
2820 LOOP START point to CF after LOOP END
2821 BRK/CONT point to LOOP END CF
2822 */
2823 ctx->bc->cf_last->cf_addr = ctx->bc->fc_stack[ctx->bc->fc_sp].start->id + 2;
2824
2825 ctx->bc->fc_stack[ctx->bc->fc_sp].start->cf_addr = ctx->bc->cf_last->id + 2;
2826
2827 for (i = 0; i < ctx->bc->fc_stack[ctx->bc->fc_sp].num_mid; i++) {
2828 ctx->bc->fc_stack[ctx->bc->fc_sp].mid[i]->cf_addr = ctx->bc->cf_last->id;
2829 }
2830 /* TODO add LOOPRET support */
2831 fc_poplevel(ctx);
2832 callstack_decrease_current(ctx, FC_LOOP);
2833 return 0;
2834 }
2835
2836 static int tgsi_loop_brk_cont(struct r600_shader_ctx *ctx)
2837 {
2838 unsigned int fscp;
2839
2840 for (fscp = ctx->bc->fc_sp; fscp > 0; fscp--)
2841 {
2842 if (FC_LOOP == ctx->bc->fc_stack[fscp].type)
2843 break;
2844 }
2845
2846 if (fscp == 0) {
2847 R600_ERR("Break not inside loop/endloop pair\n");
2848 return -EINVAL;
2849 }
2850
2851 r600_bc_add_cfinst(ctx->bc, ctx->inst_info->r600_opcode);
2852 ctx->bc->cf_last->pop_count = 1;
2853
2854 fc_set_mid(ctx, fscp);
2855
2856 pops(ctx, 1);
2857 callstack_check_depth(ctx, FC_PUSH_VPM, 1);
2858 return 0;
2859 }
2860
2861 static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[] = {
2862 {TGSI_OPCODE_ARL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_r600_arl},
2863 {TGSI_OPCODE_MOV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
2864 {TGSI_OPCODE_LIT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit},
2865
2866 /* FIXME:
2867 * For state trackers other than OpenGL, we'll want to use
2868 * _RECIP_IEEE instead.
2869 */
2870 {TGSI_OPCODE_RCP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_CLAMPED, tgsi_trans_srcx_replicate},
2871
2872 {TGSI_OPCODE_RSQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_rsq},
2873 {TGSI_OPCODE_EXP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp},
2874 {TGSI_OPCODE_LOG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_log},
2875 {TGSI_OPCODE_MUL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2},
2876 {TGSI_OPCODE_ADD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2},
2877 {TGSI_OPCODE_DP3, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
2878 {TGSI_OPCODE_DP4, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
2879 {TGSI_OPCODE_DST, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_opdst},
2880 {TGSI_OPCODE_MIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN, tgsi_op2},
2881 {TGSI_OPCODE_MAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX, tgsi_op2},
2882 {TGSI_OPCODE_SLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2_swap},
2883 {TGSI_OPCODE_SGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2},
2884 {TGSI_OPCODE_MAD, 1, V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD, tgsi_op3},
2885 {TGSI_OPCODE_SUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2},
2886 {TGSI_OPCODE_LRP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lrp},
2887 {TGSI_OPCODE_CND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2888 /* gap */
2889 {20, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2890 {TGSI_OPCODE_DP2A, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2891 /* gap */
2892 {22, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2893 {23, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2894 {TGSI_OPCODE_FRC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT, tgsi_op2},
2895 {TGSI_OPCODE_CLAMP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2896 {TGSI_OPCODE_FLR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR, tgsi_op2},
2897 {TGSI_OPCODE_ROUND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2898 {TGSI_OPCODE_EX2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE, tgsi_trans_srcx_replicate},
2899 {TGSI_OPCODE_LG2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE, tgsi_trans_srcx_replicate},
2900 {TGSI_OPCODE_POW, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_pow},
2901 {TGSI_OPCODE_XPD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_xpd},
2902 /* gap */
2903 {32, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2904 {TGSI_OPCODE_ABS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
2905 {TGSI_OPCODE_RCC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2906 {TGSI_OPCODE_DPH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
2907 {TGSI_OPCODE_COS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS, tgsi_trig},
2908 {TGSI_OPCODE_DDX, 0, SQ_TEX_INST_GET_GRADIENTS_H, tgsi_tex},
2909 {TGSI_OPCODE_DDY, 0, SQ_TEX_INST_GET_GRADIENTS_V, tgsi_tex},
2910 {TGSI_OPCODE_KILP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* predicated kill */
2911 {TGSI_OPCODE_PK2H, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2912 {TGSI_OPCODE_PK2US, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2913 {TGSI_OPCODE_PK4B, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2914 {TGSI_OPCODE_PK4UB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2915 {TGSI_OPCODE_RFL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2916 {TGSI_OPCODE_SEQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE, tgsi_op2},
2917 {TGSI_OPCODE_SFL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2918 {TGSI_OPCODE_SGT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2},
2919 {TGSI_OPCODE_SIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN, tgsi_trig},
2920 {TGSI_OPCODE_SLE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2_swap},
2921 {TGSI_OPCODE_SNE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE, tgsi_op2},
2922 {TGSI_OPCODE_STR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2923 {TGSI_OPCODE_TEX, 0, SQ_TEX_INST_SAMPLE, tgsi_tex},
2924 {TGSI_OPCODE_TXD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2925 {TGSI_OPCODE_TXP, 0, SQ_TEX_INST_SAMPLE, tgsi_tex},
2926 {TGSI_OPCODE_UP2H, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2927 {TGSI_OPCODE_UP2US, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2928 {TGSI_OPCODE_UP4B, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2929 {TGSI_OPCODE_UP4UB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2930 {TGSI_OPCODE_X2D, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2931 {TGSI_OPCODE_ARA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2932 {TGSI_OPCODE_ARR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_r600_arl},
2933 {TGSI_OPCODE_BRA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2934 {TGSI_OPCODE_CAL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2935 {TGSI_OPCODE_RET, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2936 {TGSI_OPCODE_SSG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_ssg},
2937 {TGSI_OPCODE_CMP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_cmp},
2938 {TGSI_OPCODE_SCS, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_scs},
2939 {TGSI_OPCODE_TXB, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex},
2940 {TGSI_OPCODE_NRM, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2941 {TGSI_OPCODE_DIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2942 {TGSI_OPCODE_DP2, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
2943 {TGSI_OPCODE_TXL, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex},
2944 {TGSI_OPCODE_BRK, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK, tgsi_loop_brk_cont},
2945 {TGSI_OPCODE_IF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_if},
2946 /* gap */
2947 {75, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2948 {76, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2949 {TGSI_OPCODE_ELSE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_else},
2950 {TGSI_OPCODE_ENDIF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endif},
2951 /* gap */
2952 {79, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2953 {80, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2954 {TGSI_OPCODE_PUSHA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2955 {TGSI_OPCODE_POPA, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2956 {TGSI_OPCODE_CEIL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2957 {TGSI_OPCODE_I2F, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2958 {TGSI_OPCODE_NOT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2959 {TGSI_OPCODE_TRUNC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC, tgsi_trans_srcx_replicate},
2960 {TGSI_OPCODE_SHL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2961 /* gap */
2962 {88, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2963 {TGSI_OPCODE_AND, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2964 {TGSI_OPCODE_OR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2965 {TGSI_OPCODE_MOD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2966 {TGSI_OPCODE_XOR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2967 {TGSI_OPCODE_SAD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2968 {TGSI_OPCODE_TXF, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2969 {TGSI_OPCODE_TXQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2970 {TGSI_OPCODE_CONT, 0, V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE, tgsi_loop_brk_cont},
2971 {TGSI_OPCODE_EMIT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2972 {TGSI_OPCODE_ENDPRIM, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2973 {TGSI_OPCODE_BGNLOOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_bgnloop},
2974 {TGSI_OPCODE_BGNSUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2975 {TGSI_OPCODE_ENDLOOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop},
2976 {TGSI_OPCODE_ENDSUB, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2977 /* gap */
2978 {103, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2979 {104, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2980 {105, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2981 {106, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2982 {TGSI_OPCODE_NOP, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2983 /* gap */
2984 {108, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2985 {109, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2986 {110, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2987 {111, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2988 {TGSI_OPCODE_NRM4, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2989 {TGSI_OPCODE_CALLNZ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2990 {TGSI_OPCODE_IFC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2991 {TGSI_OPCODE_BREAKC, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2992 {TGSI_OPCODE_KIL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* conditional kill */
2993 {TGSI_OPCODE_END, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_end}, /* aka HALT */
2994 /* gap */
2995 {118, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2996 {TGSI_OPCODE_F2I, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2997 {TGSI_OPCODE_IDIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2998 {TGSI_OPCODE_IMAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
2999 {TGSI_OPCODE_IMIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3000 {TGSI_OPCODE_INEG, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3001 {TGSI_OPCODE_ISGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3002 {TGSI_OPCODE_ISHR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3003 {TGSI_OPCODE_ISLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3004 {TGSI_OPCODE_F2U, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3005 {TGSI_OPCODE_U2F, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3006 {TGSI_OPCODE_UADD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3007 {TGSI_OPCODE_UDIV, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3008 {TGSI_OPCODE_UMAD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3009 {TGSI_OPCODE_UMAX, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3010 {TGSI_OPCODE_UMIN, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3011 {TGSI_OPCODE_UMOD, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3012 {TGSI_OPCODE_UMUL, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3013 {TGSI_OPCODE_USEQ, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3014 {TGSI_OPCODE_USGE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3015 {TGSI_OPCODE_USHR, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3016 {TGSI_OPCODE_USLT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3017 {TGSI_OPCODE_USNE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3018 {TGSI_OPCODE_SWITCH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3019 {TGSI_OPCODE_CASE, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3020 {TGSI_OPCODE_DEFAULT, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3021 {TGSI_OPCODE_ENDSWITCH, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3022 {TGSI_OPCODE_LAST, 0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3023 };
3024
3025 static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = {
3026 {TGSI_OPCODE_ARL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_eg_arl},
3027 {TGSI_OPCODE_MOV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
3028 {TGSI_OPCODE_LIT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lit},
3029 {TGSI_OPCODE_RCP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE, tgsi_trans_srcx_replicate},
3030 {TGSI_OPCODE_RSQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE, tgsi_trans_srcx_replicate},
3031 {TGSI_OPCODE_EXP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_exp},
3032 {TGSI_OPCODE_LOG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3033 {TGSI_OPCODE_MUL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL, tgsi_op2},
3034 {TGSI_OPCODE_ADD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2},
3035 {TGSI_OPCODE_DP3, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
3036 {TGSI_OPCODE_DP4, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
3037 {TGSI_OPCODE_DST, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_opdst},
3038 {TGSI_OPCODE_MIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN, tgsi_op2},
3039 {TGSI_OPCODE_MAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX, tgsi_op2},
3040 {TGSI_OPCODE_SLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2_swap},
3041 {TGSI_OPCODE_SGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2},
3042 {TGSI_OPCODE_MAD, 1, EG_V_SQ_ALU_WORD1_OP3_SQ_OP3_INST_MULADD, tgsi_op3},
3043 {TGSI_OPCODE_SUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD, tgsi_op2},
3044 {TGSI_OPCODE_LRP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_lrp},
3045 {TGSI_OPCODE_CND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3046 /* gap */
3047 {20, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3048 {TGSI_OPCODE_DP2A, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3049 /* gap */
3050 {22, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3051 {23, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3052 {TGSI_OPCODE_FRC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT, tgsi_op2},
3053 {TGSI_OPCODE_CLAMP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3054 {TGSI_OPCODE_FLR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR, tgsi_op2},
3055 {TGSI_OPCODE_ROUND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3056 {TGSI_OPCODE_EX2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE, tgsi_trans_srcx_replicate},
3057 {TGSI_OPCODE_LG2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE, tgsi_trans_srcx_replicate},
3058 {TGSI_OPCODE_POW, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_pow},
3059 {TGSI_OPCODE_XPD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_xpd},
3060 /* gap */
3061 {32, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3062 {TGSI_OPCODE_ABS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV, tgsi_op2},
3063 {TGSI_OPCODE_RCC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3064 {TGSI_OPCODE_DPH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
3065 {TGSI_OPCODE_COS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS, tgsi_trig},
3066 {TGSI_OPCODE_DDX, 0, SQ_TEX_INST_GET_GRADIENTS_H, tgsi_tex},
3067 {TGSI_OPCODE_DDY, 0, SQ_TEX_INST_GET_GRADIENTS_V, tgsi_tex},
3068 {TGSI_OPCODE_KILP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* predicated kill */
3069 {TGSI_OPCODE_PK2H, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3070 {TGSI_OPCODE_PK2US, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3071 {TGSI_OPCODE_PK4B, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3072 {TGSI_OPCODE_PK4UB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3073 {TGSI_OPCODE_RFL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3074 {TGSI_OPCODE_SEQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE, tgsi_op2},
3075 {TGSI_OPCODE_SFL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3076 {TGSI_OPCODE_SGT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT, tgsi_op2},
3077 {TGSI_OPCODE_SIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN, tgsi_trig},
3078 {TGSI_OPCODE_SLE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE, tgsi_op2_swap},
3079 {TGSI_OPCODE_SNE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE, tgsi_op2},
3080 {TGSI_OPCODE_STR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3081 {TGSI_OPCODE_TEX, 0, SQ_TEX_INST_SAMPLE, tgsi_tex},
3082 {TGSI_OPCODE_TXD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3083 {TGSI_OPCODE_TXP, 0, SQ_TEX_INST_SAMPLE, tgsi_tex},
3084 {TGSI_OPCODE_UP2H, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3085 {TGSI_OPCODE_UP2US, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3086 {TGSI_OPCODE_UP4B, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3087 {TGSI_OPCODE_UP4UB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3088 {TGSI_OPCODE_X2D, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3089 {TGSI_OPCODE_ARA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3090 {TGSI_OPCODE_ARR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_eg_arl},
3091 {TGSI_OPCODE_BRA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3092 {TGSI_OPCODE_CAL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3093 {TGSI_OPCODE_RET, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3094 {TGSI_OPCODE_SSG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_ssg},
3095 {TGSI_OPCODE_CMP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_cmp},
3096 {TGSI_OPCODE_SCS, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_scs},
3097 {TGSI_OPCODE_TXB, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex},
3098 {TGSI_OPCODE_NRM, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3099 {TGSI_OPCODE_DIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3100 {TGSI_OPCODE_DP2, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4, tgsi_dp},
3101 {TGSI_OPCODE_TXL, 0, SQ_TEX_INST_SAMPLE_L, tgsi_tex},
3102 {TGSI_OPCODE_BRK, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK, tgsi_loop_brk_cont},
3103 {TGSI_OPCODE_IF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_if},
3104 /* gap */
3105 {75, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3106 {76, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3107 {TGSI_OPCODE_ELSE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_else},
3108 {TGSI_OPCODE_ENDIF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endif},
3109 /* gap */
3110 {79, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3111 {80, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3112 {TGSI_OPCODE_PUSHA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3113 {TGSI_OPCODE_POPA, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3114 {TGSI_OPCODE_CEIL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3115 {TGSI_OPCODE_I2F, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3116 {TGSI_OPCODE_NOT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3117 {TGSI_OPCODE_TRUNC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC, tgsi_trans_srcx_replicate},
3118 {TGSI_OPCODE_SHL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3119 /* gap */
3120 {88, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3121 {TGSI_OPCODE_AND, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3122 {TGSI_OPCODE_OR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3123 {TGSI_OPCODE_MOD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3124 {TGSI_OPCODE_XOR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3125 {TGSI_OPCODE_SAD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3126 {TGSI_OPCODE_TXF, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3127 {TGSI_OPCODE_TXQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3128 {TGSI_OPCODE_CONT, 0, EG_V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE, tgsi_loop_brk_cont},
3129 {TGSI_OPCODE_EMIT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3130 {TGSI_OPCODE_ENDPRIM, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3131 {TGSI_OPCODE_BGNLOOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_bgnloop},
3132 {TGSI_OPCODE_BGNSUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3133 {TGSI_OPCODE_ENDLOOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop},
3134 {TGSI_OPCODE_ENDSUB, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3135 /* gap */
3136 {103, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3137 {104, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3138 {105, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3139 {106, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3140 {TGSI_OPCODE_NOP, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3141 /* gap */
3142 {108, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3143 {109, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3144 {110, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3145 {111, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3146 {TGSI_OPCODE_NRM4, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3147 {TGSI_OPCODE_CALLNZ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3148 {TGSI_OPCODE_IFC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3149 {TGSI_OPCODE_BREAKC, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3150 {TGSI_OPCODE_KIL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT, tgsi_kill}, /* conditional kill */
3151 {TGSI_OPCODE_END, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_end}, /* aka HALT */
3152 /* gap */
3153 {118, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3154 {TGSI_OPCODE_F2I, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3155 {TGSI_OPCODE_IDIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3156 {TGSI_OPCODE_IMAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3157 {TGSI_OPCODE_IMIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3158 {TGSI_OPCODE_INEG, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3159 {TGSI_OPCODE_ISGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3160 {TGSI_OPCODE_ISHR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3161 {TGSI_OPCODE_ISLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3162 {TGSI_OPCODE_F2U, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3163 {TGSI_OPCODE_U2F, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3164 {TGSI_OPCODE_UADD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3165 {TGSI_OPCODE_UDIV, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3166 {TGSI_OPCODE_UMAD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3167 {TGSI_OPCODE_UMAX, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3168 {TGSI_OPCODE_UMIN, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3169 {TGSI_OPCODE_UMOD, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3170 {TGSI_OPCODE_UMUL, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3171 {TGSI_OPCODE_USEQ, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3172 {TGSI_OPCODE_USGE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3173 {TGSI_OPCODE_USHR, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3174 {TGSI_OPCODE_USLT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3175 {TGSI_OPCODE_USNE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3176 {TGSI_OPCODE_SWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3177 {TGSI_OPCODE_CASE, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3178 {TGSI_OPCODE_DEFAULT, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3179 {TGSI_OPCODE_ENDSWITCH, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3180 {TGSI_OPCODE_LAST, 0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
3181 };