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