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