i965: Use SENDC on the first render target write on gen6.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_disasm.c
1 /*
2 * Copyright © 2008 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <getopt.h>
27 #include <unistd.h>
28 #include <stdarg.h>
29
30 #include "main/mtypes.h"
31
32 #include "brw_context.h"
33 #include "brw_defines.h"
34
35 struct {
36 char *name;
37 int nsrc;
38 int ndst;
39 } opcode[128] = {
40 [BRW_OPCODE_MOV] = { .name = "mov", .nsrc = 1, .ndst = 1 },
41 [BRW_OPCODE_FRC] = { .name = "frc", .nsrc = 1, .ndst = 1 },
42 [BRW_OPCODE_RNDU] = { .name = "rndu", .nsrc = 1, .ndst = 1 },
43 [BRW_OPCODE_RNDD] = { .name = "rndd", .nsrc = 1, .ndst = 1 },
44 [BRW_OPCODE_RNDE] = { .name = "rnde", .nsrc = 1, .ndst = 1 },
45 [BRW_OPCODE_RNDZ] = { .name = "rndz", .nsrc = 1, .ndst = 1 },
46 [BRW_OPCODE_NOT] = { .name = "not", .nsrc = 1, .ndst = 1 },
47 [BRW_OPCODE_LZD] = { .name = "lzd", .nsrc = 1, .ndst = 1 },
48
49 [BRW_OPCODE_MUL] = { .name = "mul", .nsrc = 2, .ndst = 1 },
50 [BRW_OPCODE_MAC] = { .name = "mac", .nsrc = 2, .ndst = 1 },
51 [BRW_OPCODE_MACH] = { .name = "mach", .nsrc = 2, .ndst = 1 },
52 [BRW_OPCODE_LINE] = { .name = "line", .nsrc = 2, .ndst = 1 },
53 [BRW_OPCODE_PLN] = { .name = "pln", .nsrc = 2, .ndst = 1 },
54 [BRW_OPCODE_SAD2] = { .name = "sad2", .nsrc = 2, .ndst = 1 },
55 [BRW_OPCODE_SADA2] = { .name = "sada2", .nsrc = 2, .ndst = 1 },
56 [BRW_OPCODE_DP4] = { .name = "dp4", .nsrc = 2, .ndst = 1 },
57 [BRW_OPCODE_DPH] = { .name = "dph", .nsrc = 2, .ndst = 1 },
58 [BRW_OPCODE_DP3] = { .name = "dp3", .nsrc = 2, .ndst = 1 },
59 [BRW_OPCODE_DP2] = { .name = "dp2", .nsrc = 2, .ndst = 1 },
60 [BRW_OPCODE_MATH] = { .name = "math", .nsrc = 2, .ndst = 1 },
61
62 [BRW_OPCODE_AVG] = { .name = "avg", .nsrc = 2, .ndst = 1 },
63 [BRW_OPCODE_ADD] = { .name = "add", .nsrc = 2, .ndst = 1 },
64 [BRW_OPCODE_SEL] = { .name = "sel", .nsrc = 2, .ndst = 1 },
65 [BRW_OPCODE_AND] = { .name = "and", .nsrc = 2, .ndst = 1 },
66 [BRW_OPCODE_OR] = { .name = "or", .nsrc = 2, .ndst = 1 },
67 [BRW_OPCODE_XOR] = { .name = "xor", .nsrc = 2, .ndst = 1 },
68 [BRW_OPCODE_SHR] = { .name = "shr", .nsrc = 2, .ndst = 1 },
69 [BRW_OPCODE_SHL] = { .name = "shl", .nsrc = 2, .ndst = 1 },
70 [BRW_OPCODE_ASR] = { .name = "asr", .nsrc = 2, .ndst = 1 },
71 [BRW_OPCODE_CMP] = { .name = "cmp", .nsrc = 2, .ndst = 1 },
72 [BRW_OPCODE_CMPN] = { .name = "cmpn", .nsrc = 2, .ndst = 1 },
73
74 [BRW_OPCODE_SEND] = { .name = "send", .nsrc = 1, .ndst = 1 },
75 [BRW_OPCODE_SENDC] = { .name = "sendc", .nsrc = 1, .ndst = 1 },
76 [BRW_OPCODE_NOP] = { .name = "nop", .nsrc = 0, .ndst = 0 },
77 [BRW_OPCODE_JMPI] = { .name = "jmpi", .nsrc = 1, .ndst = 0 },
78 [BRW_OPCODE_IF] = { .name = "if", .nsrc = 2, .ndst = 0 },
79 [BRW_OPCODE_IFF] = { .name = "iff", .nsrc = 2, .ndst = 1 },
80 [BRW_OPCODE_WHILE] = { .name = "while", .nsrc = 2, .ndst = 0 },
81 [BRW_OPCODE_ELSE] = { .name = "else", .nsrc = 2, .ndst = 0 },
82 [BRW_OPCODE_BREAK] = { .name = "break", .nsrc = 2, .ndst = 0 },
83 [BRW_OPCODE_CONTINUE] = { .name = "cont", .nsrc = 1, .ndst = 0 },
84 [BRW_OPCODE_HALT] = { .name = "halt", .nsrc = 1, .ndst = 0 },
85 [BRW_OPCODE_MSAVE] = { .name = "msave", .nsrc = 1, .ndst = 1 },
86 [BRW_OPCODE_PUSH] = { .name = "push", .nsrc = 1, .ndst = 1 },
87 [BRW_OPCODE_MRESTORE] = { .name = "mrest", .nsrc = 1, .ndst = 1 },
88 [BRW_OPCODE_POP] = { .name = "pop", .nsrc = 2, .ndst = 0 },
89 [BRW_OPCODE_WAIT] = { .name = "wait", .nsrc = 1, .ndst = 0 },
90 [BRW_OPCODE_DO] = { .name = "do", .nsrc = 0, .ndst = 0 },
91 [BRW_OPCODE_ENDIF] = { .name = "endif", .nsrc = 2, .ndst = 0 },
92 };
93
94 char *conditional_modifier[16] = {
95 [BRW_CONDITIONAL_NONE] = "",
96 [BRW_CONDITIONAL_Z] = ".e",
97 [BRW_CONDITIONAL_NZ] = ".ne",
98 [BRW_CONDITIONAL_G] = ".g",
99 [BRW_CONDITIONAL_GE] = ".ge",
100 [BRW_CONDITIONAL_L] = ".l",
101 [BRW_CONDITIONAL_LE] = ".le",
102 [BRW_CONDITIONAL_R] = ".r",
103 [BRW_CONDITIONAL_O] = ".o",
104 [BRW_CONDITIONAL_U] = ".u",
105 };
106
107 char *negate[2] = {
108 [0] = "",
109 [1] = "-",
110 };
111
112 char *_abs[2] = {
113 [0] = "",
114 [1] = "(abs)",
115 };
116
117 char *vert_stride[16] = {
118 [0] = "0",
119 [1] = "1",
120 [2] = "2",
121 [3] = "4",
122 [4] = "8",
123 [5] = "16",
124 [6] = "32",
125 [15] = "VxH",
126 };
127
128 char *width[8] = {
129 [0] = "1",
130 [1] = "2",
131 [2] = "4",
132 [3] = "8",
133 [4] = "16",
134 };
135
136 char *horiz_stride[4] = {
137 [0] = "0",
138 [1] = "1",
139 [2] = "2",
140 [3] = "4"
141 };
142
143 char *chan_sel[4] = {
144 [0] = "x",
145 [1] = "y",
146 [2] = "z",
147 [3] = "w",
148 };
149
150 char *dest_condmod[16] = {
151 };
152
153 char *debug_ctrl[2] = {
154 [0] = "",
155 [1] = ".breakpoint"
156 };
157
158 char *saturate[2] = {
159 [0] = "",
160 [1] = ".sat"
161 };
162
163 char *accwr[2] = {
164 [0] = "",
165 [1] = "AccWrEnable"
166 };
167
168 char *wectrl[2] = {
169 [0] = "WE_normal",
170 [1] = "WE_all"
171 };
172
173 char *exec_size[8] = {
174 [0] = "1",
175 [1] = "2",
176 [2] = "4",
177 [3] = "8",
178 [4] = "16",
179 [5] = "32"
180 };
181
182 char *pred_inv[2] = {
183 [0] = "+",
184 [1] = "-"
185 };
186
187 char *pred_ctrl_align16[16] = {
188 [1] = "",
189 [2] = ".x",
190 [3] = ".y",
191 [4] = ".z",
192 [5] = ".w",
193 [6] = ".any4h",
194 [7] = ".all4h",
195 };
196
197 char *pred_ctrl_align1[16] = {
198 [1] = "",
199 [2] = ".anyv",
200 [3] = ".allv",
201 [4] = ".any2h",
202 [5] = ".all2h",
203 [6] = ".any4h",
204 [7] = ".all4h",
205 [8] = ".any8h",
206 [9] = ".all8h",
207 [10] = ".any16h",
208 [11] = ".all16h",
209 };
210
211 char *thread_ctrl[4] = {
212 [0] = "",
213 [2] = "switch"
214 };
215
216 char *compr_ctrl[4] = {
217 [0] = "",
218 [1] = "sechalf",
219 [2] = "compr",
220 [3] = "compr4",
221 };
222
223 char *dep_ctrl[4] = {
224 [0] = "",
225 [1] = "NoDDClr",
226 [2] = "NoDDChk",
227 [3] = "NoDDClr,NoDDChk",
228 };
229
230 char *mask_ctrl[4] = {
231 [0] = "",
232 [1] = "nomask",
233 };
234
235 char *access_mode[2] = {
236 [0] = "align1",
237 [1] = "align16",
238 };
239
240 char *reg_encoding[8] = {
241 [0] = "UD",
242 [1] = "D",
243 [2] = "UW",
244 [3] = "W",
245 [4] = "UB",
246 [5] = "B",
247 [7] = "F"
248 };
249
250 int reg_type_size[8] = {
251 [0] = 4,
252 [1] = 4,
253 [2] = 2,
254 [3] = 2,
255 [4] = 1,
256 [5] = 1,
257 [7] = 4
258 };
259
260 char *imm_encoding[8] = {
261 [0] = "UD",
262 [1] = "D",
263 [2] = "UW",
264 [3] = "W",
265 [5] = "VF",
266 [6] = "V",
267 [7] = "F"
268 };
269
270 char *reg_file[4] = {
271 [0] = "A",
272 [1] = "g",
273 [2] = "m",
274 [3] = "imm",
275 };
276
277 char *writemask[16] = {
278 [0x0] = ".",
279 [0x1] = ".x",
280 [0x2] = ".y",
281 [0x3] = ".xy",
282 [0x4] = ".z",
283 [0x5] = ".xz",
284 [0x6] = ".yz",
285 [0x7] = ".xyz",
286 [0x8] = ".w",
287 [0x9] = ".xw",
288 [0xa] = ".yw",
289 [0xb] = ".xyw",
290 [0xc] = ".zw",
291 [0xd] = ".xzw",
292 [0xe] = ".yzw",
293 [0xf] = "",
294 };
295
296 char *end_of_thread[2] = {
297 [0] = "",
298 [1] = "EOT"
299 };
300
301 char *target_function[16] = {
302 [BRW_MESSAGE_TARGET_NULL] = "null",
303 [BRW_MESSAGE_TARGET_MATH] = "math",
304 [BRW_MESSAGE_TARGET_SAMPLER] = "sampler",
305 [BRW_MESSAGE_TARGET_GATEWAY] = "gateway",
306 [BRW_MESSAGE_TARGET_DATAPORT_READ] = "read",
307 [BRW_MESSAGE_TARGET_DATAPORT_WRITE] = "write",
308 [BRW_MESSAGE_TARGET_URB] = "urb",
309 [BRW_MESSAGE_TARGET_THREAD_SPAWNER] = "thread_spawner"
310 };
311
312 char *math_function[16] = {
313 [BRW_MATH_FUNCTION_INV] = "inv",
314 [BRW_MATH_FUNCTION_LOG] = "log",
315 [BRW_MATH_FUNCTION_EXP] = "exp",
316 [BRW_MATH_FUNCTION_SQRT] = "sqrt",
317 [BRW_MATH_FUNCTION_RSQ] = "rsq",
318 [BRW_MATH_FUNCTION_SIN] = "sin",
319 [BRW_MATH_FUNCTION_COS] = "cos",
320 [BRW_MATH_FUNCTION_SINCOS] = "sincos",
321 [BRW_MATH_FUNCTION_TAN] = "tan",
322 [BRW_MATH_FUNCTION_POW] = "pow",
323 [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
324 [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intmod",
325 [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intdiv",
326 };
327
328 char *math_saturate[2] = {
329 [0] = "",
330 [1] = "sat"
331 };
332
333 char *math_signed[2] = {
334 [0] = "",
335 [1] = "signed"
336 };
337
338 char *math_scalar[2] = {
339 [0] = "",
340 [1] = "scalar"
341 };
342
343 char *math_precision[2] = {
344 [0] = "",
345 [1] = "partial_precision"
346 };
347
348 char *urb_opcode[2] = {
349 [0] = "urb_write",
350 [1] = "ff_sync",
351 };
352
353 char *urb_swizzle[4] = {
354 [BRW_URB_SWIZZLE_NONE] = "",
355 [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave",
356 [BRW_URB_SWIZZLE_TRANSPOSE] = "transpose",
357 };
358
359 char *urb_allocate[2] = {
360 [0] = "",
361 [1] = "allocate"
362 };
363
364 char *urb_used[2] = {
365 [0] = "",
366 [1] = "used"
367 };
368
369 char *urb_complete[2] = {
370 [0] = "",
371 [1] = "complete"
372 };
373
374 char *sampler_target_format[4] = {
375 [0] = "F",
376 [2] = "UD",
377 [3] = "D"
378 };
379
380
381 static int column;
382
383 static int string (FILE *file, char *string)
384 {
385 fputs (string, file);
386 column += strlen (string);
387 return 0;
388 }
389
390 static int format (FILE *f, char *format, ...)
391 {
392 char buf[1024];
393 va_list args;
394 va_start (args, format);
395
396 vsnprintf (buf, sizeof (buf) - 1, format, args);
397 va_end (args);
398 string (f, buf);
399 return 0;
400 }
401
402 static int newline (FILE *f)
403 {
404 putc ('\n', f);
405 column = 0;
406 return 0;
407 }
408
409 static int pad (FILE *f, int c)
410 {
411 do
412 string (f, " ");
413 while (column < c);
414 return 0;
415 }
416
417 static int control (FILE *file, char *name, char *ctrl[], GLuint id, int *space)
418 {
419 if (!ctrl[id]) {
420 fprintf (file, "*** invalid %s value %d ",
421 name, id);
422 return 1;
423 }
424 if (ctrl[id][0])
425 {
426 if (space && *space)
427 string (file, " ");
428 string (file, ctrl[id]);
429 if (space)
430 *space = 1;
431 }
432 return 0;
433 }
434
435 static int print_opcode (FILE *file, int id)
436 {
437 if (!opcode[id].name) {
438 format (file, "*** invalid opcode value %d ", id);
439 return 1;
440 }
441 string (file, opcode[id].name);
442 return 0;
443 }
444
445 static int reg (FILE *file, GLuint _reg_file, GLuint _reg_nr)
446 {
447 int err = 0;
448
449 /* Clear the Compr4 instruction compression bit. */
450 if (_reg_file == BRW_MESSAGE_REGISTER_FILE)
451 _reg_nr &= ~(1 << 7);
452
453 if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
454 switch (_reg_nr & 0xf0) {
455 case BRW_ARF_NULL:
456 string (file, "null");
457 return -1;
458 case BRW_ARF_ADDRESS:
459 format (file, "a%d", _reg_nr & 0x0f);
460 break;
461 case BRW_ARF_ACCUMULATOR:
462 format (file, "acc%d", _reg_nr & 0x0f);
463 break;
464 case BRW_ARF_MASK:
465 format (file, "mask%d", _reg_nr & 0x0f);
466 break;
467 case BRW_ARF_MASK_STACK:
468 format (file, "msd%d", _reg_nr & 0x0f);
469 break;
470 case BRW_ARF_STATE:
471 format (file, "sr%d", _reg_nr & 0x0f);
472 break;
473 case BRW_ARF_CONTROL:
474 format (file, "cr%d", _reg_nr & 0x0f);
475 break;
476 case BRW_ARF_NOTIFICATION_COUNT:
477 format (file, "n%d", _reg_nr & 0x0f);
478 break;
479 case BRW_ARF_IP:
480 string (file, "ip");
481 return -1;
482 break;
483 default:
484 format (file, "ARF%d", _reg_nr);
485 break;
486 }
487 } else {
488 err |= control (file, "src reg file", reg_file, _reg_file, NULL);
489 format (file, "%d", _reg_nr);
490 }
491 return err;
492 }
493
494 static int dest (FILE *file, struct brw_instruction *inst)
495 {
496 int err = 0;
497
498 if (inst->header.access_mode == BRW_ALIGN_1)
499 {
500 if (inst->bits1.da1.dest_address_mode == BRW_ADDRESS_DIRECT)
501 {
502 err |= reg (file, inst->bits1.da1.dest_reg_file, inst->bits1.da1.dest_reg_nr);
503 if (err == -1)
504 return 0;
505 if (inst->bits1.da1.dest_subreg_nr)
506 format (file, ".%d", inst->bits1.da1.dest_subreg_nr /
507 reg_type_size[inst->bits1.da1.dest_reg_type]);
508 format (file, "<%d>", inst->bits1.da1.dest_horiz_stride);
509 err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da1.dest_reg_type, NULL);
510 }
511 else
512 {
513 string (file, "g[a0");
514 if (inst->bits1.ia1.dest_subreg_nr)
515 format (file, ".%d", inst->bits1.ia1.dest_subreg_nr /
516 reg_type_size[inst->bits1.ia1.dest_reg_type]);
517 if (inst->bits1.ia1.dest_indirect_offset)
518 format (file, " %d", inst->bits1.ia1.dest_indirect_offset);
519 string (file, "]");
520 format (file, "<%d>", inst->bits1.ia1.dest_horiz_stride);
521 err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.ia1.dest_reg_type, NULL);
522 }
523 }
524 else
525 {
526 if (inst->bits1.da16.dest_address_mode == BRW_ADDRESS_DIRECT)
527 {
528 err |= reg (file, inst->bits1.da16.dest_reg_file, inst->bits1.da16.dest_reg_nr);
529 if (err == -1)
530 return 0;
531 if (inst->bits1.da16.dest_subreg_nr)
532 format (file, ".%d", inst->bits1.da16.dest_subreg_nr /
533 reg_type_size[inst->bits1.da16.dest_reg_type]);
534 string (file, "<1>");
535 err |= control (file, "writemask", writemask, inst->bits1.da16.dest_writemask, NULL);
536 err |= control (file, "dest reg encoding", reg_encoding, inst->bits1.da16.dest_reg_type, NULL);
537 }
538 else
539 {
540 err = 1;
541 string (file, "Indirect align16 address mode not supported");
542 }
543 }
544
545 return 0;
546 }
547
548 static int src_align1_region (FILE *file,
549 GLuint _vert_stride, GLuint _width, GLuint _horiz_stride)
550 {
551 int err = 0;
552 string (file, "<");
553 err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
554 string (file, ",");
555 err |= control (file, "width", width, _width, NULL);
556 string (file, ",");
557 err |= control (file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
558 string (file, ">");
559 return err;
560 }
561
562 static int src_da1 (FILE *file, GLuint type, GLuint _reg_file,
563 GLuint _vert_stride, GLuint _width, GLuint _horiz_stride,
564 GLuint reg_num, GLuint sub_reg_num, GLuint __abs, GLuint _negate)
565 {
566 int err = 0;
567 err |= control (file, "negate", negate, _negate, NULL);
568 err |= control (file, "abs", _abs, __abs, NULL);
569
570 err |= reg (file, _reg_file, reg_num);
571 if (err == -1)
572 return 0;
573 if (sub_reg_num)
574 format (file, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
575 src_align1_region (file, _vert_stride, _width, _horiz_stride);
576 err |= control (file, "src reg encoding", reg_encoding, type, NULL);
577 return err;
578 }
579
580 static int src_ia1 (FILE *file,
581 GLuint type,
582 GLuint _reg_file,
583 GLint _addr_imm,
584 GLuint _addr_subreg_nr,
585 GLuint _negate,
586 GLuint __abs,
587 GLuint _addr_mode,
588 GLuint _horiz_stride,
589 GLuint _width,
590 GLuint _vert_stride)
591 {
592 int err = 0;
593 err |= control (file, "negate", negate, _negate, NULL);
594 err |= control (file, "abs", _abs, __abs, NULL);
595
596 string (file, "g[a0");
597 if (_addr_subreg_nr)
598 format (file, ".%d", _addr_subreg_nr);
599 if (_addr_imm)
600 format (file, " %d", _addr_imm);
601 string (file, "]");
602 src_align1_region (file, _vert_stride, _width, _horiz_stride);
603 err |= control (file, "src reg encoding", reg_encoding, type, NULL);
604 return err;
605 }
606
607 static int src_da16 (FILE *file,
608 GLuint _reg_type,
609 GLuint _reg_file,
610 GLuint _vert_stride,
611 GLuint _reg_nr,
612 GLuint _subreg_nr,
613 GLuint __abs,
614 GLuint _negate,
615 GLuint swz_x,
616 GLuint swz_y,
617 GLuint swz_z,
618 GLuint swz_w)
619 {
620 int err = 0;
621 err |= control (file, "negate", negate, _negate, NULL);
622 err |= control (file, "abs", _abs, __abs, NULL);
623
624 err |= reg (file, _reg_file, _reg_nr);
625 if (err == -1)
626 return 0;
627 if (_subreg_nr)
628 /* bit4 for subreg number byte addressing. Make this same meaning as
629 in da1 case, so output looks consistent. */
630 format (file, ".%d", 16 / reg_type_size[_reg_type]);
631 string (file, "<");
632 err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
633 string (file, ",4,1>");
634 /*
635 * Three kinds of swizzle display:
636 * identity - nothing printed
637 * 1->all - print the single channel
638 * 1->1 - print the mapping
639 */
640 if (swz_x == BRW_CHANNEL_X &&
641 swz_y == BRW_CHANNEL_Y &&
642 swz_z == BRW_CHANNEL_Z &&
643 swz_w == BRW_CHANNEL_W)
644 {
645 ;
646 }
647 else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
648 {
649 string (file, ".");
650 err |= control (file, "channel select", chan_sel, swz_x, NULL);
651 }
652 else
653 {
654 string (file, ".");
655 err |= control (file, "channel select", chan_sel, swz_x, NULL);
656 err |= control (file, "channel select", chan_sel, swz_y, NULL);
657 err |= control (file, "channel select", chan_sel, swz_z, NULL);
658 err |= control (file, "channel select", chan_sel, swz_w, NULL);
659 }
660 err |= control (file, "src da16 reg type", reg_encoding, _reg_type, NULL);
661 return err;
662 }
663
664
665 static int imm (FILE *file, GLuint type, struct brw_instruction *inst) {
666 switch (type) {
667 case BRW_REGISTER_TYPE_UD:
668 format (file, "0x%08xUD", inst->bits3.ud);
669 break;
670 case BRW_REGISTER_TYPE_D:
671 format (file, "%dD", inst->bits3.d);
672 break;
673 case BRW_REGISTER_TYPE_UW:
674 format (file, "0x%04xUW", (uint16_t) inst->bits3.ud);
675 break;
676 case BRW_REGISTER_TYPE_W:
677 format (file, "%dW", (int16_t) inst->bits3.d);
678 break;
679 case BRW_REGISTER_TYPE_UB:
680 format (file, "0x%02xUB", (int8_t) inst->bits3.ud);
681 break;
682 case BRW_REGISTER_TYPE_VF:
683 format (file, "Vector Float");
684 break;
685 case BRW_REGISTER_TYPE_V:
686 format (file, "0x%08xV", inst->bits3.ud);
687 break;
688 case BRW_REGISTER_TYPE_F:
689 format (file, "%-gF", inst->bits3.f);
690 }
691 return 0;
692 }
693
694 static int src0 (FILE *file, struct brw_instruction *inst)
695 {
696 if (inst->bits1.da1.src0_reg_file == BRW_IMMEDIATE_VALUE)
697 return imm (file, inst->bits1.da1.src0_reg_type,
698 inst);
699 else if (inst->header.access_mode == BRW_ALIGN_1)
700 {
701 if (inst->bits2.da1.src0_address_mode == BRW_ADDRESS_DIRECT)
702 {
703 return src_da1 (file,
704 inst->bits1.da1.src0_reg_type,
705 inst->bits1.da1.src0_reg_file,
706 inst->bits2.da1.src0_vert_stride,
707 inst->bits2.da1.src0_width,
708 inst->bits2.da1.src0_horiz_stride,
709 inst->bits2.da1.src0_reg_nr,
710 inst->bits2.da1.src0_subreg_nr,
711 inst->bits2.da1.src0_abs,
712 inst->bits2.da1.src0_negate);
713 }
714 else
715 {
716 return src_ia1 (file,
717 inst->bits1.ia1.src0_reg_type,
718 inst->bits1.ia1.src0_reg_file,
719 inst->bits2.ia1.src0_indirect_offset,
720 inst->bits2.ia1.src0_subreg_nr,
721 inst->bits2.ia1.src0_negate,
722 inst->bits2.ia1.src0_abs,
723 inst->bits2.ia1.src0_address_mode,
724 inst->bits2.ia1.src0_horiz_stride,
725 inst->bits2.ia1.src0_width,
726 inst->bits2.ia1.src0_vert_stride);
727 }
728 }
729 else
730 {
731 if (inst->bits2.da16.src0_address_mode == BRW_ADDRESS_DIRECT)
732 {
733 return src_da16 (file,
734 inst->bits1.da16.src0_reg_type,
735 inst->bits1.da16.src0_reg_file,
736 inst->bits2.da16.src0_vert_stride,
737 inst->bits2.da16.src0_reg_nr,
738 inst->bits2.da16.src0_subreg_nr,
739 inst->bits2.da16.src0_abs,
740 inst->bits2.da16.src0_negate,
741 inst->bits2.da16.src0_swz_x,
742 inst->bits2.da16.src0_swz_y,
743 inst->bits2.da16.src0_swz_z,
744 inst->bits2.da16.src0_swz_w);
745 }
746 else
747 {
748 string (file, "Indirect align16 address mode not supported");
749 return 1;
750 }
751 }
752 }
753
754 static int src1 (FILE *file, struct brw_instruction *inst)
755 {
756 if (inst->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE)
757 return imm (file, inst->bits1.da1.src1_reg_type,
758 inst);
759 else if (inst->header.access_mode == BRW_ALIGN_1)
760 {
761 if (inst->bits3.da1.src1_address_mode == BRW_ADDRESS_DIRECT)
762 {
763 return src_da1 (file,
764 inst->bits1.da1.src1_reg_type,
765 inst->bits1.da1.src1_reg_file,
766 inst->bits3.da1.src1_vert_stride,
767 inst->bits3.da1.src1_width,
768 inst->bits3.da1.src1_horiz_stride,
769 inst->bits3.da1.src1_reg_nr,
770 inst->bits3.da1.src1_subreg_nr,
771 inst->bits3.da1.src1_abs,
772 inst->bits3.da1.src1_negate);
773 }
774 else
775 {
776 return src_ia1 (file,
777 inst->bits1.ia1.src1_reg_type,
778 inst->bits1.ia1.src1_reg_file,
779 inst->bits3.ia1.src1_indirect_offset,
780 inst->bits3.ia1.src1_subreg_nr,
781 inst->bits3.ia1.src1_negate,
782 inst->bits3.ia1.src1_abs,
783 inst->bits3.ia1.src1_address_mode,
784 inst->bits3.ia1.src1_horiz_stride,
785 inst->bits3.ia1.src1_width,
786 inst->bits3.ia1.src1_vert_stride);
787 }
788 }
789 else
790 {
791 if (inst->bits3.da16.src1_address_mode == BRW_ADDRESS_DIRECT)
792 {
793 return src_da16 (file,
794 inst->bits1.da16.src1_reg_type,
795 inst->bits1.da16.src1_reg_file,
796 inst->bits3.da16.src1_vert_stride,
797 inst->bits3.da16.src1_reg_nr,
798 inst->bits3.da16.src1_subreg_nr,
799 inst->bits3.da16.src1_abs,
800 inst->bits3.da16.src1_negate,
801 inst->bits3.da16.src1_swz_x,
802 inst->bits3.da16.src1_swz_y,
803 inst->bits3.da16.src1_swz_z,
804 inst->bits3.da16.src1_swz_w);
805 }
806 else
807 {
808 string (file, "Indirect align16 address mode not supported");
809 return 1;
810 }
811 }
812 }
813
814 int esize[6] = {
815 [0] = 1,
816 [1] = 2,
817 [2] = 4,
818 [3] = 8,
819 [4] = 16,
820 [5] = 32,
821 };
822
823 static int qtr_ctrl(FILE *file, struct brw_instruction *inst)
824 {
825 int qtr_ctl = inst->header.compression_control;
826 int exec_size = esize[inst->header.execution_size];
827
828 if (exec_size == 8) {
829 switch (qtr_ctl) {
830 case 0:
831 string (file, " 1Q");
832 break;
833 case 1:
834 string (file, " 2Q");
835 break;
836 case 2:
837 string (file, " 3Q");
838 break;
839 case 3:
840 string (file, " 4Q");
841 break;
842 }
843 } else if (exec_size == 16){
844 if (qtr_ctl < 2)
845 string (file, " 1H");
846 else
847 string (file, " 2H");
848 }
849 return 0;
850 }
851
852 int brw_disasm (FILE *file, struct brw_instruction *inst, int gen)
853 {
854 int err = 0;
855 int space = 0;
856
857 if (inst->header.predicate_control) {
858 string (file, "(");
859 err |= control (file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
860 string (file, "f0");
861 if (inst->bits2.da1.flag_reg_nr)
862 format (file, ".%d", inst->bits2.da1.flag_reg_nr);
863 if (inst->header.access_mode == BRW_ALIGN_1)
864 err |= control (file, "predicate control align1", pred_ctrl_align1,
865 inst->header.predicate_control, NULL);
866 else
867 err |= control (file, "predicate control align16", pred_ctrl_align16,
868 inst->header.predicate_control, NULL);
869 string (file, ") ");
870 }
871
872 err |= print_opcode (file, inst->header.opcode);
873 err |= control (file, "saturate", saturate, inst->header.saturate, NULL);
874 err |= control (file, "debug control", debug_ctrl, inst->header.debug_control, NULL);
875
876 if (inst->header.opcode == BRW_OPCODE_MATH) {
877 string (file, " ");
878 err |= control (file, "function", math_function,
879 inst->header.destreg__conditionalmod, NULL);
880 } else if (inst->header.opcode != BRW_OPCODE_SEND &&
881 inst->header.opcode != BRW_OPCODE_SENDC)
882 err |= control (file, "conditional modifier", conditional_modifier,
883 inst->header.destreg__conditionalmod, NULL);
884
885 if (inst->header.opcode != BRW_OPCODE_NOP) {
886 string (file, "(");
887 err |= control (file, "execution size", exec_size, inst->header.execution_size, NULL);
888 string (file, ")");
889 }
890
891 if (inst->header.opcode == BRW_OPCODE_SEND && gen < 6)
892 format (file, " %d", inst->header.destreg__conditionalmod);
893
894 if (opcode[inst->header.opcode].ndst > 0) {
895 pad (file, 16);
896 err |= dest (file, inst);
897 } else if (gen >= 6 && (inst->header.opcode == BRW_OPCODE_IF ||
898 inst->header.opcode == BRW_OPCODE_ELSE ||
899 inst->header.opcode == BRW_OPCODE_ENDIF)) {
900 format (file, " %d", inst->bits1.branch_gen6.jump_count);
901 }
902
903 if (opcode[inst->header.opcode].nsrc > 0) {
904 pad (file, 32);
905 err |= src0 (file, inst);
906 }
907 if (opcode[inst->header.opcode].nsrc > 1) {
908 pad (file, 48);
909 err |= src1 (file, inst);
910 }
911
912 if (inst->header.opcode == BRW_OPCODE_SEND ||
913 inst->header.opcode == BRW_OPCODE_SENDC) {
914 int target;
915
916 if (gen >= 6)
917 target = inst->header.destreg__conditionalmod;
918 else if (gen == 5)
919 target = inst->bits2.send_gen5.sfid;
920 else
921 target = inst->bits3.generic.msg_target;
922
923 newline (file);
924 pad (file, 16);
925 space = 0;
926 err |= control (file, "target function", target_function,
927 target, &space);
928
929 switch (target) {
930 case BRW_MESSAGE_TARGET_MATH:
931 err |= control (file, "math function", math_function,
932 inst->bits3.math.function, &space);
933 err |= control (file, "math saturate", math_saturate,
934 inst->bits3.math.saturate, &space);
935 err |= control (file, "math signed", math_signed,
936 inst->bits3.math.int_type, &space);
937 err |= control (file, "math scalar", math_scalar,
938 inst->bits3.math.data_type, &space);
939 err |= control (file, "math precision", math_precision,
940 inst->bits3.math.precision, &space);
941 break;
942 case BRW_MESSAGE_TARGET_SAMPLER:
943 if (gen >= 5) {
944 format (file, " (%d, %d, %d, %d)",
945 inst->bits3.sampler_gen5.binding_table_index,
946 inst->bits3.sampler_gen5.sampler,
947 inst->bits3.sampler_gen5.msg_type,
948 inst->bits3.sampler_gen5.simd_mode);
949 } else if (0 /* FINISHME: is_g4x */) {
950 format (file, " (%d, %d)",
951 inst->bits3.sampler_g4x.binding_table_index,
952 inst->bits3.sampler_g4x.sampler);
953 } else {
954 format (file, " (%d, %d, ",
955 inst->bits3.sampler.binding_table_index,
956 inst->bits3.sampler.sampler);
957 err |= control (file, "sampler target format",
958 sampler_target_format,
959 inst->bits3.sampler.return_format, NULL);
960 string (file, ")");
961 }
962 break;
963 case BRW_MESSAGE_TARGET_DATAPORT_READ:
964 if (gen >= 6) {
965 format (file, " (%d, %d, %d, %d, %d, %d)",
966 inst->bits3.dp_render_cache.binding_table_index,
967 inst->bits3.dp_render_cache.msg_control,
968 inst->bits3.dp_render_cache.msg_type,
969 inst->bits3.dp_render_cache.send_commit_msg,
970 inst->bits3.dp_render_cache.msg_length,
971 inst->bits3.dp_render_cache.response_length);
972 } else if (gen >= 5) {
973 format (file, " (%d, %d, %d)",
974 inst->bits3.dp_read_gen5.binding_table_index,
975 inst->bits3.dp_read_gen5.msg_control,
976 inst->bits3.dp_read_gen5.msg_type);
977 } else {
978 format (file, " (%d, %d, %d)",
979 inst->bits3.dp_read.binding_table_index,
980 inst->bits3.dp_read.msg_control,
981 inst->bits3.dp_read.msg_type);
982 }
983 break;
984 case BRW_MESSAGE_TARGET_DATAPORT_WRITE:
985 if (gen >= 6) {
986 format (file, " (%d, %d, %d, %d, %d, %d)",
987 inst->bits3.dp_render_cache.binding_table_index,
988 inst->bits3.dp_render_cache.msg_control,
989 inst->bits3.dp_render_cache.msg_type,
990 inst->bits3.dp_render_cache.send_commit_msg,
991 inst->bits3.dp_render_cache.msg_length,
992 inst->bits3.dp_render_cache.response_length);
993 } else {
994 format (file, " (%d, %d, %d, %d)",
995 inst->bits3.dp_write.binding_table_index,
996 (inst->bits3.dp_write.pixel_scoreboard_clear << 3) |
997 inst->bits3.dp_write.msg_control,
998 inst->bits3.dp_write.msg_type,
999 inst->bits3.dp_write.send_commit_msg);
1000 }
1001 break;
1002 case BRW_MESSAGE_TARGET_URB:
1003 if (gen >= 5) {
1004 format (file, " %d", inst->bits3.urb_gen5.offset);
1005 } else {
1006 format (file, " %d", inst->bits3.urb.offset);
1007 }
1008
1009 space = 1;
1010 if (gen >= 5) {
1011 err |= control (file, "urb opcode", urb_opcode,
1012 inst->bits3.urb_gen5.opcode, &space);
1013 }
1014 err |= control (file, "urb swizzle", urb_swizzle,
1015 inst->bits3.urb.swizzle_control, &space);
1016 err |= control (file, "urb allocate", urb_allocate,
1017 inst->bits3.urb.allocate, &space);
1018 err |= control (file, "urb used", urb_used,
1019 inst->bits3.urb.used, &space);
1020 err |= control (file, "urb complete", urb_complete,
1021 inst->bits3.urb.complete, &space);
1022 if (gen >= 5) {
1023 format (file, " mlen %d, rlen %d\n",
1024 inst->bits3.urb_gen5.msg_length,
1025 inst->bits3.urb_gen5.response_length);
1026 }
1027 break;
1028 case BRW_MESSAGE_TARGET_THREAD_SPAWNER:
1029 break;
1030 default:
1031 format (file, "unsupported target %d", target);
1032 break;
1033 }
1034 if (space)
1035 string (file, " ");
1036 if (gen >= 5) {
1037 format (file, "mlen %d",
1038 inst->bits3.generic_gen5.msg_length);
1039 format (file, " rlen %d",
1040 inst->bits3.generic_gen5.response_length);
1041 } else {
1042 format (file, "mlen %d",
1043 inst->bits3.generic.msg_length);
1044 format (file, " rlen %d",
1045 inst->bits3.generic.response_length);
1046 }
1047 }
1048 pad (file, 64);
1049 if (inst->header.opcode != BRW_OPCODE_NOP) {
1050 string (file, "{");
1051 space = 1;
1052 err |= control(file, "access mode", access_mode, inst->header.access_mode, &space);
1053 if (gen >= 6)
1054 err |= control (file, "write enable control", wectrl, inst->header.mask_control, &space);
1055 else
1056 err |= control (file, "mask control", mask_ctrl, inst->header.mask_control, &space);
1057 err |= control (file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);
1058
1059 if (gen >= 6)
1060 err |= qtr_ctrl (file, inst);
1061 else {
1062 if (inst->header.compression_control == BRW_COMPRESSION_COMPRESSED &&
1063 opcode[inst->header.opcode].ndst > 0 &&
1064 inst->bits1.da1.dest_reg_file == BRW_MESSAGE_REGISTER_FILE &&
1065 inst->bits1.da1.dest_reg_nr & (1 << 7)) {
1066 format (file, " compr4");
1067 } else {
1068 err |= control (file, "compression control", compr_ctrl,
1069 inst->header.compression_control, &space);
1070 }
1071 }
1072
1073 err |= control (file, "thread control", thread_ctrl, inst->header.thread_control, &space);
1074 if (gen >= 6)
1075 err |= control (file, "acc write control", accwr, inst->header.acc_wr_control, &space);
1076 if (inst->header.opcode == BRW_OPCODE_SEND ||
1077 inst->header.opcode == BRW_OPCODE_SENDC)
1078 err |= control (file, "end of thread", end_of_thread,
1079 inst->bits3.generic.end_of_thread, &space);
1080 if (space)
1081 string (file, " ");
1082 string (file, "}");
1083 }
1084 string (file, ";");
1085 newline (file);
1086 return err;
1087 }