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