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