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