2e02732834916d1d521d83116427cda38c8ab096
[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 "brw_context.h"
31 #include "brw_defines.h"
32 #include "brw_reg.h"
33 #include "brw_inst.h"
34
35 const struct opcode_desc opcode_descs[128] = {
36 [BRW_OPCODE_MOV] = { .name = "mov", .nsrc = 1, .ndst = 1 },
37 [BRW_OPCODE_FRC] = { .name = "frc", .nsrc = 1, .ndst = 1 },
38 [BRW_OPCODE_RNDU] = { .name = "rndu", .nsrc = 1, .ndst = 1 },
39 [BRW_OPCODE_RNDD] = { .name = "rndd", .nsrc = 1, .ndst = 1 },
40 [BRW_OPCODE_RNDE] = { .name = "rnde", .nsrc = 1, .ndst = 1 },
41 [BRW_OPCODE_RNDZ] = { .name = "rndz", .nsrc = 1, .ndst = 1 },
42 [BRW_OPCODE_NOT] = { .name = "not", .nsrc = 1, .ndst = 1 },
43 [BRW_OPCODE_LZD] = { .name = "lzd", .nsrc = 1, .ndst = 1 },
44 [BRW_OPCODE_F32TO16] = { .name = "f32to16", .nsrc = 1, .ndst = 1 },
45 [BRW_OPCODE_F16TO32] = { .name = "f16to32", .nsrc = 1, .ndst = 1 },
46 [BRW_OPCODE_BFREV] = { .name = "bfrev", .nsrc = 1, .ndst = 1},
47 [BRW_OPCODE_FBH] = { .name = "fbh", .nsrc = 1, .ndst = 1},
48 [BRW_OPCODE_FBL] = { .name = "fbl", .nsrc = 1, .ndst = 1},
49 [BRW_OPCODE_CBIT] = { .name = "cbit", .nsrc = 1, .ndst = 1},
50
51 [BRW_OPCODE_MUL] = { .name = "mul", .nsrc = 2, .ndst = 1 },
52 [BRW_OPCODE_MAC] = { .name = "mac", .nsrc = 2, .ndst = 1 },
53 [BRW_OPCODE_MACH] = { .name = "mach", .nsrc = 2, .ndst = 1 },
54 [BRW_OPCODE_LINE] = { .name = "line", .nsrc = 2, .ndst = 1 },
55 [BRW_OPCODE_PLN] = { .name = "pln", .nsrc = 2, .ndst = 1 },
56 [BRW_OPCODE_MAD] = { .name = "mad", .nsrc = 3, .ndst = 1 },
57 [BRW_OPCODE_LRP] = { .name = "lrp", .nsrc = 3, .ndst = 1 },
58 [BRW_OPCODE_SAD2] = { .name = "sad2", .nsrc = 2, .ndst = 1 },
59 [BRW_OPCODE_SADA2] = { .name = "sada2", .nsrc = 2, .ndst = 1 },
60 [BRW_OPCODE_DP4] = { .name = "dp4", .nsrc = 2, .ndst = 1 },
61 [BRW_OPCODE_DPH] = { .name = "dph", .nsrc = 2, .ndst = 1 },
62 [BRW_OPCODE_DP3] = { .name = "dp3", .nsrc = 2, .ndst = 1 },
63 [BRW_OPCODE_DP2] = { .name = "dp2", .nsrc = 2, .ndst = 1 },
64 [BRW_OPCODE_MATH] = { .name = "math", .nsrc = 2, .ndst = 1 },
65
66 [BRW_OPCODE_AVG] = { .name = "avg", .nsrc = 2, .ndst = 1 },
67 [BRW_OPCODE_ADD] = { .name = "add", .nsrc = 2, .ndst = 1 },
68 [BRW_OPCODE_SEL] = { .name = "sel", .nsrc = 2, .ndst = 1 },
69 [BRW_OPCODE_AND] = { .name = "and", .nsrc = 2, .ndst = 1 },
70 [BRW_OPCODE_OR] = { .name = "or", .nsrc = 2, .ndst = 1 },
71 [BRW_OPCODE_XOR] = { .name = "xor", .nsrc = 2, .ndst = 1 },
72 [BRW_OPCODE_SHR] = { .name = "shr", .nsrc = 2, .ndst = 1 },
73 [BRW_OPCODE_SHL] = { .name = "shl", .nsrc = 2, .ndst = 1 },
74 [BRW_OPCODE_ASR] = { .name = "asr", .nsrc = 2, .ndst = 1 },
75 [BRW_OPCODE_CMP] = { .name = "cmp", .nsrc = 2, .ndst = 1 },
76 [BRW_OPCODE_CMPN] = { .name = "cmpn", .nsrc = 2, .ndst = 1 },
77 [BRW_OPCODE_BFE] = { .name = "bfe", .nsrc = 3, .ndst = 1},
78 [BRW_OPCODE_BFI1] = { .name = "bfi1", .nsrc = 2, .ndst = 1},
79 [BRW_OPCODE_BFI2] = { .name = "bfi2", .nsrc = 3, .ndst = 1},
80 [BRW_OPCODE_ADDC] = { .name = "addc", .nsrc = 2, .ndst = 1},
81 [BRW_OPCODE_SUBB] = { .name = "subb", .nsrc = 2, .ndst = 1},
82
83 [BRW_OPCODE_SEND] = { .name = "send", .nsrc = 1, .ndst = 1 },
84 [BRW_OPCODE_SENDC] = { .name = "sendc", .nsrc = 1, .ndst = 1 },
85 [BRW_OPCODE_NOP] = { .name = "nop", .nsrc = 0, .ndst = 0 },
86 [BRW_OPCODE_JMPI] = { .name = "jmpi", .nsrc = 0, .ndst = 0 },
87 [BRW_OPCODE_IF] = { .name = "if", .nsrc = 2, .ndst = 0 },
88 [BRW_OPCODE_IFF] = { .name = "iff", .nsrc = 2, .ndst = 1 },
89 [BRW_OPCODE_WHILE] = { .name = "while", .nsrc = 2, .ndst = 0 },
90 [BRW_OPCODE_ELSE] = { .name = "else", .nsrc = 2, .ndst = 0 },
91 [BRW_OPCODE_BREAK] = { .name = "break", .nsrc = 2, .ndst = 0 },
92 [BRW_OPCODE_CONTINUE] = { .name = "cont", .nsrc = 1, .ndst = 0 },
93 [BRW_OPCODE_HALT] = { .name = "halt", .nsrc = 1, .ndst = 0 },
94 [BRW_OPCODE_MSAVE] = { .name = "msave", .nsrc = 1, .ndst = 1 },
95 [BRW_OPCODE_PUSH] = { .name = "push", .nsrc = 1, .ndst = 1 },
96 [BRW_OPCODE_MRESTORE] = { .name = "mrest", .nsrc = 1, .ndst = 1 },
97 [BRW_OPCODE_POP] = { .name = "pop", .nsrc = 2, .ndst = 0 },
98 [BRW_OPCODE_WAIT] = { .name = "wait", .nsrc = 1, .ndst = 0 },
99 [BRW_OPCODE_DO] = { .name = "do", .nsrc = 0, .ndst = 0 },
100 [BRW_OPCODE_ENDIF] = { .name = "endif", .nsrc = 2, .ndst = 0 },
101 };
102 static const struct opcode_desc *opcode = opcode_descs;
103
104 const char * const conditional_modifier[16] = {
105 [BRW_CONDITIONAL_NONE] = "",
106 [BRW_CONDITIONAL_Z] = ".e",
107 [BRW_CONDITIONAL_NZ] = ".ne",
108 [BRW_CONDITIONAL_G] = ".g",
109 [BRW_CONDITIONAL_GE] = ".ge",
110 [BRW_CONDITIONAL_L] = ".l",
111 [BRW_CONDITIONAL_LE] = ".le",
112 [BRW_CONDITIONAL_R] = ".r",
113 [BRW_CONDITIONAL_O] = ".o",
114 [BRW_CONDITIONAL_U] = ".u",
115 };
116
117 static const char * const m_negate[2] = {
118 [0] = "",
119 [1] = "-",
120 };
121
122 static const char * const _abs[2] = {
123 [0] = "",
124 [1] = "(abs)",
125 };
126
127 static const char * const vert_stride[16] = {
128 [0] = "0",
129 [1] = "1",
130 [2] = "2",
131 [3] = "4",
132 [4] = "8",
133 [5] = "16",
134 [6] = "32",
135 [15] = "VxH",
136 };
137
138 static const char * const width[8] = {
139 [0] = "1",
140 [1] = "2",
141 [2] = "4",
142 [3] = "8",
143 [4] = "16",
144 };
145
146 static const char * const horiz_stride[4] = {
147 [0] = "0",
148 [1] = "1",
149 [2] = "2",
150 [3] = "4"
151 };
152
153 static const char * const chan_sel[4] = {
154 [0] = "x",
155 [1] = "y",
156 [2] = "z",
157 [3] = "w",
158 };
159
160 static const char * const debug_ctrl[2] = {
161 [0] = "",
162 [1] = ".breakpoint"
163 };
164
165 static const char * const saturate[2] = {
166 [0] = "",
167 [1] = ".sat"
168 };
169
170 static const char * const cmpt_ctrl[2] = {
171 [0] = "",
172 [1] = "compacted"
173 };
174
175 static const char * const accwr[2] = {
176 [0] = "",
177 [1] = "AccWrEnable"
178 };
179
180 static const char * const wectrl[2] = {
181 [0] = "WE_normal",
182 [1] = "WE_all"
183 };
184
185 static const char * const exec_size[8] = {
186 [0] = "1",
187 [1] = "2",
188 [2] = "4",
189 [3] = "8",
190 [4] = "16",
191 [5] = "32"
192 };
193
194 static const char * const pred_inv[2] = {
195 [0] = "+",
196 [1] = "-"
197 };
198
199 static const char * const pred_ctrl_align16[16] = {
200 [1] = "",
201 [2] = ".x",
202 [3] = ".y",
203 [4] = ".z",
204 [5] = ".w",
205 [6] = ".any4h",
206 [7] = ".all4h",
207 };
208
209 static const char * const pred_ctrl_align1[16] = {
210 [1] = "",
211 [2] = ".anyv",
212 [3] = ".allv",
213 [4] = ".any2h",
214 [5] = ".all2h",
215 [6] = ".any4h",
216 [7] = ".all4h",
217 [8] = ".any8h",
218 [9] = ".all8h",
219 [10] = ".any16h",
220 [11] = ".all16h",
221 };
222
223 static const char * const thread_ctrl[4] = {
224 [0] = "",
225 [2] = "switch"
226 };
227
228 static const char * const compr_ctrl[4] = {
229 [0] = "",
230 [1] = "sechalf",
231 [2] = "compr",
232 [3] = "compr4",
233 };
234
235 static const char * const dep_ctrl[4] = {
236 [0] = "",
237 [1] = "NoDDClr",
238 [2] = "NoDDChk",
239 [3] = "NoDDClr,NoDDChk",
240 };
241
242 static const char * const mask_ctrl[4] = {
243 [0] = "",
244 [1] = "nomask",
245 };
246
247 static const char * const access_mode[2] = {
248 [0] = "align1",
249 [1] = "align16",
250 };
251
252 static const char * const reg_encoding[8] = {
253 [0] = "UD",
254 [1] = "D",
255 [2] = "UW",
256 [3] = "W",
257 [4] = "UB",
258 [5] = "B",
259 [7] = "F"
260 };
261
262 static const char * const three_source_reg_encoding[] = {
263 [BRW_3SRC_TYPE_F] = "F",
264 [BRW_3SRC_TYPE_D] = "D",
265 [BRW_3SRC_TYPE_UD] = "UD",
266 };
267
268 const int reg_type_size[8] = {
269 [0] = 4,
270 [1] = 4,
271 [2] = 2,
272 [3] = 2,
273 [4] = 1,
274 [5] = 1,
275 [7] = 4
276 };
277
278 static const char * const reg_file[4] = {
279 [0] = "A",
280 [1] = "g",
281 [2] = "m",
282 [3] = "imm",
283 };
284
285 static const char * const writemask[16] = {
286 [0x0] = ".",
287 [0x1] = ".x",
288 [0x2] = ".y",
289 [0x3] = ".xy",
290 [0x4] = ".z",
291 [0x5] = ".xz",
292 [0x6] = ".yz",
293 [0x7] = ".xyz",
294 [0x8] = ".w",
295 [0x9] = ".xw",
296 [0xa] = ".yw",
297 [0xb] = ".xyw",
298 [0xc] = ".zw",
299 [0xd] = ".xzw",
300 [0xe] = ".yzw",
301 [0xf] = "",
302 };
303
304 static const char * const end_of_thread[2] = {
305 [0] = "",
306 [1] = "EOT"
307 };
308
309 static const char * const target_function[16] = {
310 [BRW_SFID_NULL] = "null",
311 [BRW_SFID_MATH] = "math",
312 [BRW_SFID_SAMPLER] = "sampler",
313 [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
314 [BRW_SFID_DATAPORT_READ] = "read",
315 [BRW_SFID_DATAPORT_WRITE] = "write",
316 [BRW_SFID_URB] = "urb",
317 [BRW_SFID_THREAD_SPAWNER] = "thread_spawner",
318 [BRW_SFID_VME] = "vme",
319 };
320
321 static const char * const target_function_gen6[16] = {
322 [BRW_SFID_NULL] = "null",
323 [BRW_SFID_MATH] = "math",
324 [BRW_SFID_SAMPLER] = "sampler",
325 [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
326 [BRW_SFID_URB] = "urb",
327 [BRW_SFID_THREAD_SPAWNER] = "thread_spawner",
328 [GEN6_SFID_DATAPORT_SAMPLER_CACHE] = "sampler",
329 [GEN6_SFID_DATAPORT_RENDER_CACHE] = "render",
330 [GEN6_SFID_DATAPORT_CONSTANT_CACHE] = "const",
331 [GEN7_SFID_DATAPORT_DATA_CACHE] = "data",
332 [GEN7_SFID_PIXEL_INTERPOLATOR] = "pixel interp",
333 [HSW_SFID_DATAPORT_DATA_CACHE_1] = "dp data 1",
334 [HSW_SFID_CRE] = "cre",
335 };
336
337 static const char * const dp_rc_msg_type_gen6[16] = {
338 [BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ] = "OWORD block read",
339 [GEN6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ] = "RT UNORM read",
340 [GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ] = "OWORD dual block read",
341 [GEN6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ] = "media block read",
342 [GEN6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ] = "OWORD unaligned block read",
343 [GEN6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ] = "DWORD scattered read",
344 [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE] = "DWORD atomic write",
345 [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE] = "OWORD block write",
346 [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE] = "OWORD dual block write",
347 [GEN6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE] = "media block write",
348 [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE] = "DWORD scattered write",
349 [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE] = "RT write",
350 [GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE] = "streamed VB write",
351 [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE] = "RT UNORMc write",
352 };
353
354 static const char *const dp_dc0_msg_type_gen7[16] = {
355 [GEN7_DATAPORT_DC_OWORD_BLOCK_READ] = "DC OWORD block read",
356 [GEN7_DATAPORT_DC_UNALIGNED_OWORD_BLOCK_READ] = "DC unaligned OWORD block read",
357 [GEN7_DATAPORT_DC_OWORD_DUAL_BLOCK_READ] = "DC OWORD dual block read",
358 [GEN7_DATAPORT_DC_DWORD_SCATTERED_READ] = "DC DWORD scattered read",
359 [GEN7_DATAPORT_DC_BYTE_SCATTERED_READ] = "DC byte scattered read",
360 [GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP] = "DC untyped atomic",
361 [GEN7_DATAPORT_DC_MEMORY_FENCE] = "DC mfence",
362 [GEN7_DATAPORT_DC_OWORD_BLOCK_WRITE] = "DC OWORD block write",
363 [GEN7_DATAPORT_DC_OWORD_DUAL_BLOCK_WRITE] = "DC OWORD dual block write",
364 [GEN7_DATAPORT_DC_DWORD_SCATTERED_WRITE] = "DC DWORD scatterd write",
365 [GEN7_DATAPORT_DC_BYTE_SCATTERED_WRITE] = "DC byte scattered write",
366 [GEN7_DATAPORT_DC_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
367 };
368
369 static const char *const dp_dc1_msg_type_hsw[16] = {
370 [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ] = "untyped surface read",
371 [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP] = "DC untyped atomic op",
372 [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2] = "DC untyped 4x2 atomic op",
373 [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_READ] = "DC media block read",
374 [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ] = "DC typed surface read",
375 [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP] = "DC typed atomic",
376 [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2] = "DC typed 4x2 atomic op",
377 [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
378 [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_WRITE] = "DC media block write",
379 [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP] = "DC atomic counter op",
380 [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2] = "DC 4x2 atomic counter op",
381 [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE] = "DC typed surface write",
382 };
383
384 static const char * const aop[16] = {
385 [BRW_AOP_AND] = "and",
386 [BRW_AOP_OR] = "or",
387 [BRW_AOP_XOR] = "xor",
388 [BRW_AOP_MOV] = "mov",
389 [BRW_AOP_INC] = "inc",
390 [BRW_AOP_DEC] = "dec",
391 [BRW_AOP_ADD] = "add",
392 [BRW_AOP_SUB] = "sub",
393 [BRW_AOP_REVSUB] = "revsub",
394 [BRW_AOP_IMAX] = "imax",
395 [BRW_AOP_IMIN] = "imin",
396 [BRW_AOP_UMAX] = "umax",
397 [BRW_AOP_UMIN] = "umin",
398 [BRW_AOP_CMPWR] = "cmpwr",
399 [BRW_AOP_PREDEC] = "predec",
400 };
401
402 static const char * const math_function[16] = {
403 [BRW_MATH_FUNCTION_INV] = "inv",
404 [BRW_MATH_FUNCTION_LOG] = "log",
405 [BRW_MATH_FUNCTION_EXP] = "exp",
406 [BRW_MATH_FUNCTION_SQRT] = "sqrt",
407 [BRW_MATH_FUNCTION_RSQ] = "rsq",
408 [BRW_MATH_FUNCTION_SIN] = "sin",
409 [BRW_MATH_FUNCTION_COS] = "cos",
410 [BRW_MATH_FUNCTION_SINCOS] = "sincos",
411 [BRW_MATH_FUNCTION_FDIV] = "fdiv",
412 [BRW_MATH_FUNCTION_POW] = "pow",
413 [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
414 [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intdiv",
415 [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intmod",
416 };
417
418 static const char * const math_saturate[2] = {
419 [0] = "",
420 [1] = "sat"
421 };
422
423 static const char * const math_signed[2] = {
424 [0] = "",
425 [1] = "signed"
426 };
427
428 static const char * const math_scalar[2] = {
429 [0] = "",
430 [1] = "scalar"
431 };
432
433 static const char * const math_precision[2] = {
434 [0] = "",
435 [1] = "partial_precision"
436 };
437
438 static const char * const urb_opcode[2] = {
439 [0] = "urb_write",
440 [1] = "ff_sync",
441 };
442
443 static const char * const urb_swizzle[4] = {
444 [BRW_URB_SWIZZLE_NONE] = "",
445 [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave",
446 [BRW_URB_SWIZZLE_TRANSPOSE] = "transpose",
447 };
448
449 static const char * const urb_allocate[2] = {
450 [0] = "",
451 [1] = "allocate"
452 };
453
454 static const char * const urb_used[2] = {
455 [0] = "",
456 [1] = "used"
457 };
458
459 static const char * const urb_complete[2] = {
460 [0] = "",
461 [1] = "complete"
462 };
463
464 static const char * const sampler_target_format[4] = {
465 [0] = "F",
466 [2] = "UD",
467 [3] = "D"
468 };
469
470
471 static int column;
472
473 static int string (FILE *file, const char *string)
474 {
475 fputs (string, file);
476 column += strlen (string);
477 return 0;
478 }
479
480 static int format (FILE *f, const char *format, ...)
481 {
482 char buf[1024];
483 va_list args;
484 va_start (args, format);
485
486 vsnprintf (buf, sizeof (buf) - 1, format, args);
487 va_end (args);
488 string (f, buf);
489 return 0;
490 }
491
492 static int newline (FILE *f)
493 {
494 putc ('\n', f);
495 column = 0;
496 return 0;
497 }
498
499 static int pad (FILE *f, int c)
500 {
501 do
502 string (f, " ");
503 while (column < c);
504 return 0;
505 }
506
507 static int control (FILE *file, const char *name, const char * const ctrl[],
508 unsigned id, int *space)
509 {
510 if (!ctrl[id]) {
511 fprintf (file, "*** invalid %s value %d ",
512 name, id);
513 return 1;
514 }
515 if (ctrl[id][0])
516 {
517 if (space && *space)
518 string (file, " ");
519 string (file, ctrl[id]);
520 if (space)
521 *space = 1;
522 }
523 return 0;
524 }
525
526 static int print_opcode (FILE *file, int id)
527 {
528 if (!opcode[id].name) {
529 format (file, "*** invalid opcode value %d ", id);
530 return 1;
531 }
532 string (file, opcode[id].name);
533 return 0;
534 }
535
536 static int reg (FILE *file, unsigned _reg_file, unsigned _reg_nr)
537 {
538 int err = 0;
539
540 /* Clear the Compr4 instruction compression bit. */
541 if (_reg_file == BRW_MESSAGE_REGISTER_FILE)
542 _reg_nr &= ~(1 << 7);
543
544 if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
545 switch (_reg_nr & 0xf0) {
546 case BRW_ARF_NULL:
547 string (file, "null");
548 return -1;
549 case BRW_ARF_ADDRESS:
550 format (file, "a%d", _reg_nr & 0x0f);
551 break;
552 case BRW_ARF_ACCUMULATOR:
553 format (file, "acc%d", _reg_nr & 0x0f);
554 break;
555 case BRW_ARF_FLAG:
556 format (file, "f%d", _reg_nr & 0x0f);
557 break;
558 case BRW_ARF_MASK:
559 format (file, "mask%d", _reg_nr & 0x0f);
560 break;
561 case BRW_ARF_MASK_STACK:
562 format (file, "msd%d", _reg_nr & 0x0f);
563 break;
564 case BRW_ARF_STATE:
565 format (file, "sr%d", _reg_nr & 0x0f);
566 break;
567 case BRW_ARF_CONTROL:
568 format (file, "cr%d", _reg_nr & 0x0f);
569 break;
570 case BRW_ARF_NOTIFICATION_COUNT:
571 format (file, "n%d", _reg_nr & 0x0f);
572 break;
573 case BRW_ARF_IP:
574 string (file, "ip");
575 return -1;
576 break;
577 default:
578 format (file, "ARF%d", _reg_nr);
579 break;
580 }
581 } else {
582 err |= control (file, "src reg file", reg_file, _reg_file, NULL);
583 format (file, "%d", _reg_nr);
584 }
585 return err;
586 }
587
588 static int dest (FILE *file, struct brw_context *brw, brw_inst *inst)
589 {
590 int err = 0;
591
592 if (brw_inst_access_mode(brw, inst) == BRW_ALIGN_1)
593 {
594 if (brw_inst_dst_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
595 {
596 err |= reg (file, brw_inst_dst_reg_file(brw, inst), brw_inst_dst_da_reg_nr(brw, inst));
597 if (err == -1)
598 return 0;
599 if (brw_inst_dst_da1_subreg_nr(brw, inst))
600 format (file, ".%d", brw_inst_dst_da1_subreg_nr(brw, inst) /
601 reg_type_size[brw_inst_dst_reg_type(brw, inst)]);
602 string (file, "<");
603 err |= control (file, "horiz stride", horiz_stride, brw_inst_dst_hstride(brw, inst), NULL);
604 string (file, ">");
605 err |= control (file, "dest reg encoding", reg_encoding, brw_inst_dst_reg_type(brw, inst), NULL);
606 }
607 else
608 {
609 string (file, "g[a0");
610 if (brw_inst_dst_ia_subreg_nr(brw, inst))
611 format (file, ".%d", brw_inst_dst_ia_subreg_nr(brw, inst) /
612 reg_type_size[brw_inst_dst_reg_type(brw, inst)]);
613 if (brw_inst_dst_ia1_addr_imm(brw, inst))
614 format (file, " %d", brw_inst_dst_ia1_addr_imm(brw, inst));
615 string (file, "]<");
616 err |= control (file, "horiz stride", horiz_stride, brw_inst_dst_hstride(brw, inst), NULL);
617 string (file, ">");
618 err |= control (file, "dest reg encoding", reg_encoding, brw_inst_dst_reg_type(brw, inst), NULL);
619 }
620 }
621 else
622 {
623 if (brw_inst_dst_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
624 {
625 err |= reg (file, brw_inst_dst_reg_file(brw, inst), brw_inst_dst_da_reg_nr(brw, inst));
626 if (err == -1)
627 return 0;
628 if (brw_inst_dst_da16_subreg_nr(brw, inst))
629 format (file, ".%d", brw_inst_dst_da16_subreg_nr(brw, inst) /
630 reg_type_size[brw_inst_dst_reg_type(brw, inst)]);
631 string (file, "<1>");
632 err |= control (file, "writemask", writemask, brw_inst_da16_writemask(brw, inst), NULL);
633 err |= control (file, "dest reg encoding", reg_encoding, brw_inst_dst_reg_type(brw, inst), NULL);
634 }
635 else
636 {
637 err = 1;
638 string (file, "Indirect align16 address mode not supported");
639 }
640 }
641
642 return 0;
643 }
644
645 static int dest_3src (FILE *file, struct brw_context *brw, brw_inst *inst)
646 {
647 int err = 0;
648 uint32_t reg_file;
649
650 if (brw->gen == 6 && brw_inst_3src_dst_reg_file(brw, inst))
651 reg_file = BRW_MESSAGE_REGISTER_FILE;
652 else
653 reg_file = BRW_GENERAL_REGISTER_FILE;
654
655 err |= reg (file, reg_file, brw_inst_3src_dst_reg_nr(brw, inst));
656 if (err == -1)
657 return 0;
658 if (brw_inst_3src_dst_subreg_nr(brw, inst))
659 format (file, ".%d", brw_inst_3src_dst_subreg_nr(brw, inst));
660 string (file, "<1>");
661 err |= control (file, "writemask", writemask, brw_inst_3src_dst_writemask(brw, inst), NULL);
662 err |= control (file, "dest reg encoding", three_source_reg_encoding,
663 brw_inst_3src_dst_type(brw, inst), NULL);
664
665 return 0;
666 }
667
668 static int src_align1_region (FILE *file,
669 unsigned _vert_stride, unsigned _width, unsigned _horiz_stride)
670 {
671 int err = 0;
672 string (file, "<");
673 err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
674 string (file, ",");
675 err |= control (file, "width", width, _width, NULL);
676 string (file, ",");
677 err |= control (file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
678 string (file, ">");
679 return err;
680 }
681
682 static int src_da1 (FILE *file, unsigned type, unsigned _reg_file,
683 unsigned _vert_stride, unsigned _width, unsigned _horiz_stride,
684 unsigned reg_num, unsigned sub_reg_num, unsigned __abs, unsigned _negate)
685 {
686 int err = 0;
687 err |= control (file, "negate", m_negate, _negate, NULL);
688 err |= control (file, "abs", _abs, __abs, NULL);
689
690 err |= reg (file, _reg_file, reg_num);
691 if (err == -1)
692 return 0;
693 if (sub_reg_num)
694 format (file, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
695 src_align1_region (file, _vert_stride, _width, _horiz_stride);
696 err |= control (file, "src reg encoding", reg_encoding, type, NULL);
697 return err;
698 }
699
700 static int src_ia1 (FILE *file,
701 unsigned type,
702 unsigned _reg_file,
703 int _addr_imm,
704 unsigned _addr_subreg_nr,
705 unsigned _negate,
706 unsigned __abs,
707 unsigned _addr_mode,
708 unsigned _horiz_stride,
709 unsigned _width,
710 unsigned _vert_stride)
711 {
712 int err = 0;
713 err |= control (file, "negate", m_negate, _negate, NULL);
714 err |= control (file, "abs", _abs, __abs, NULL);
715
716 string (file, "g[a0");
717 if (_addr_subreg_nr)
718 format (file, ".%d", _addr_subreg_nr);
719 if (_addr_imm)
720 format (file, " %d", _addr_imm);
721 string (file, "]");
722 src_align1_region (file, _vert_stride, _width, _horiz_stride);
723 err |= control (file, "src reg encoding", reg_encoding, type, NULL);
724 return err;
725 }
726
727 static int src_da16 (FILE *file,
728 unsigned _reg_type,
729 unsigned _reg_file,
730 unsigned _vert_stride,
731 unsigned _reg_nr,
732 unsigned _subreg_nr,
733 unsigned __abs,
734 unsigned _negate,
735 unsigned swz_x,
736 unsigned swz_y,
737 unsigned swz_z,
738 unsigned swz_w)
739 {
740 int err = 0;
741 err |= control (file, "negate", m_negate, _negate, NULL);
742 err |= control (file, "abs", _abs, __abs, NULL);
743
744 err |= reg (file, _reg_file, _reg_nr);
745 if (err == -1)
746 return 0;
747 if (_subreg_nr)
748 /* bit4 for subreg number byte addressing. Make this same meaning as
749 in da1 case, so output looks consistent. */
750 format (file, ".%d", 16 / reg_type_size[_reg_type]);
751 string (file, "<");
752 err |= control (file, "vert stride", vert_stride, _vert_stride, NULL);
753 string (file, ",4,1>");
754 /*
755 * Three kinds of swizzle display:
756 * identity - nothing printed
757 * 1->all - print the single channel
758 * 1->1 - print the mapping
759 */
760 if (swz_x == BRW_CHANNEL_X &&
761 swz_y == BRW_CHANNEL_Y &&
762 swz_z == BRW_CHANNEL_Z &&
763 swz_w == BRW_CHANNEL_W)
764 {
765 ;
766 }
767 else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
768 {
769 string (file, ".");
770 err |= control (file, "channel select", chan_sel, swz_x, NULL);
771 }
772 else
773 {
774 string (file, ".");
775 err |= control (file, "channel select", chan_sel, swz_x, NULL);
776 err |= control (file, "channel select", chan_sel, swz_y, NULL);
777 err |= control (file, "channel select", chan_sel, swz_z, NULL);
778 err |= control (file, "channel select", chan_sel, swz_w, NULL);
779 }
780 err |= control (file, "src da16 reg type", reg_encoding, _reg_type, NULL);
781 return err;
782 }
783
784 static int src0_3src (FILE *file, struct brw_context *brw, brw_inst *inst)
785 {
786 int err = 0;
787 unsigned swz = brw_inst_3src_src0_swizzle(brw, inst);
788 unsigned swz_x = BRW_GET_SWZ(swz, BRW_CHANNEL_X);
789 unsigned swz_y = BRW_GET_SWZ(swz, BRW_CHANNEL_Y);
790 unsigned swz_z = BRW_GET_SWZ(swz, BRW_CHANNEL_Z);
791 unsigned swz_w = BRW_GET_SWZ(swz, BRW_CHANNEL_W);
792 unsigned src0_subreg_nr = brw_inst_3src_src0_subreg_nr(brw, inst);
793
794 err |= control (file, "negate", m_negate, brw_inst_3src_src0_negate(brw, inst), NULL);
795 err |= control (file, "abs", _abs, brw_inst_3src_src0_abs(brw, inst), NULL);
796
797 err |= reg (file, BRW_GENERAL_REGISTER_FILE, brw_inst_3src_src0_reg_nr(brw, inst));
798 if (err == -1)
799 return 0;
800 if (src0_subreg_nr)
801 format (file, ".%d", src0_subreg_nr);
802 if (brw_inst_3src_src0_rep_ctrl(brw, inst))
803 string (file, "<0,1,0>");
804 else
805 string (file, "<4,4,1>");
806 err |= control (file, "src da16 reg type", three_source_reg_encoding,
807 brw_inst_3src_src_type(brw, inst), NULL);
808 /*
809 * Three kinds of swizzle display:
810 * identity - nothing printed
811 * 1->all - print the single channel
812 * 1->1 - print the mapping
813 */
814 if (swz == BRW_SWIZZLE_XYZW)
815 {
816 ;
817 }
818 else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
819 {
820 string (file, ".");
821 err |= control (file, "channel select", chan_sel, swz_x, NULL);
822 }
823 else
824 {
825 string (file, ".");
826 err |= control (file, "channel select", chan_sel, swz_x, NULL);
827 err |= control (file, "channel select", chan_sel, swz_y, NULL);
828 err |= control (file, "channel select", chan_sel, swz_z, NULL);
829 err |= control (file, "channel select", chan_sel, swz_w, NULL);
830 }
831 return err;
832 }
833
834 static int src1_3src (FILE *file, struct brw_context *brw, brw_inst *inst)
835 {
836 int err = 0;
837 unsigned swz = brw_inst_3src_src1_swizzle(brw, inst);
838 unsigned swz_x = BRW_GET_SWZ(swz, BRW_CHANNEL_X);
839 unsigned swz_y = BRW_GET_SWZ(swz, BRW_CHANNEL_Y);
840 unsigned swz_z = BRW_GET_SWZ(swz, BRW_CHANNEL_Z);
841 unsigned swz_w = BRW_GET_SWZ(swz, BRW_CHANNEL_W);
842 unsigned src1_subreg_nr = brw_inst_3src_src1_subreg_nr(brw, inst);
843
844 err |= control (file, "negate", m_negate, brw_inst_3src_src1_negate(brw, inst), NULL);
845 err |= control (file, "abs", _abs, brw_inst_3src_src1_abs(brw, inst), NULL);
846
847 err |= reg (file, BRW_GENERAL_REGISTER_FILE, brw_inst_3src_src1_reg_nr(brw, inst));
848 if (err == -1)
849 return 0;
850 if (src1_subreg_nr)
851 format (file, ".%d", src1_subreg_nr);
852 if (brw_inst_3src_src1_rep_ctrl(brw, inst))
853 string (file, "<0,1,0>");
854 else
855 string (file, "<4,4,1>");
856 err |= control (file, "src da16 reg type", three_source_reg_encoding,
857 brw_inst_3src_src_type(brw, inst), NULL);
858 /*
859 * Three kinds of swizzle display:
860 * identity - nothing printed
861 * 1->all - print the single channel
862 * 1->1 - print the mapping
863 */
864 if (swz == BRW_SWIZZLE_XYZW)
865 {
866 ;
867 }
868 else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
869 {
870 string (file, ".");
871 err |= control (file, "channel select", chan_sel, swz_x, NULL);
872 }
873 else
874 {
875 string (file, ".");
876 err |= control (file, "channel select", chan_sel, swz_x, NULL);
877 err |= control (file, "channel select", chan_sel, swz_y, NULL);
878 err |= control (file, "channel select", chan_sel, swz_z, NULL);
879 err |= control (file, "channel select", chan_sel, swz_w, NULL);
880 }
881 return err;
882 }
883
884
885 static int src2_3src (FILE *file, struct brw_context *brw, brw_inst *inst)
886 {
887 int err = 0;
888 unsigned swz = brw_inst_3src_src2_swizzle(brw, inst);
889 unsigned swz_x = BRW_GET_SWZ(swz, BRW_CHANNEL_X);
890 unsigned swz_y = BRW_GET_SWZ(swz, BRW_CHANNEL_Y);
891 unsigned swz_z = BRW_GET_SWZ(swz, BRW_CHANNEL_Z);
892 unsigned swz_w = BRW_GET_SWZ(swz, BRW_CHANNEL_W);
893 unsigned src2_subreg_nr = brw_inst_3src_src2_subreg_nr(brw, inst);
894
895 err |= control (file, "negate", m_negate, brw_inst_3src_src2_negate(brw, inst), NULL);
896 err |= control (file, "abs", _abs, brw_inst_3src_src2_abs(brw, inst), NULL);
897
898 err |= reg (file, BRW_GENERAL_REGISTER_FILE, brw_inst_3src_src2_reg_nr(brw, inst));
899 if (err == -1)
900 return 0;
901 if (src2_subreg_nr)
902 format (file, ".%d", src2_subreg_nr);
903 if (brw_inst_3src_src2_rep_ctrl(brw, inst))
904 string (file, "<0,1,0>");
905 else
906 string (file, "<4,4,1>");
907 err |= control (file, "src da16 reg type", three_source_reg_encoding,
908 brw_inst_3src_src_type(brw, inst), NULL);
909 /*
910 * Three kinds of swizzle display:
911 * identity - nothing printed
912 * 1->all - print the single channel
913 * 1->1 - print the mapping
914 */
915 if (swz == BRW_SWIZZLE_XYZW)
916 {
917 ;
918 }
919 else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
920 {
921 string (file, ".");
922 err |= control (file, "channel select", chan_sel, swz_x, NULL);
923 }
924 else
925 {
926 string (file, ".");
927 err |= control (file, "channel select", chan_sel, swz_x, NULL);
928 err |= control (file, "channel select", chan_sel, swz_y, NULL);
929 err |= control (file, "channel select", chan_sel, swz_z, NULL);
930 err |= control (file, "channel select", chan_sel, swz_w, NULL);
931 }
932 return err;
933 }
934
935 static int imm (FILE *file, struct brw_context *brw, unsigned type,
936 brw_inst *inst) {
937 switch (type) {
938 case BRW_HW_REG_TYPE_UD:
939 format (file, "0x%08xUD", brw_inst_imm_ud(brw, inst));
940 break;
941 case BRW_HW_REG_TYPE_D:
942 format (file, "%dD", brw_inst_imm_d(brw, inst));
943 break;
944 case BRW_HW_REG_TYPE_UW:
945 format (file, "0x%04xUW", (uint16_t) brw_inst_imm_ud(brw, inst));
946 break;
947 case BRW_HW_REG_TYPE_W:
948 format (file, "%dW", (int16_t) brw_inst_imm_d(brw, inst));
949 break;
950 case BRW_HW_REG_IMM_TYPE_UV:
951 format (file, "0x%08xUV", brw_inst_imm_ud(brw, inst));
952 break;
953 case BRW_HW_REG_IMM_TYPE_VF:
954 format (file, "Vector Float");
955 break;
956 case BRW_HW_REG_IMM_TYPE_V:
957 format (file, "0x%08xV", brw_inst_imm_ud(brw, inst));
958 break;
959 case BRW_HW_REG_TYPE_F:
960 format (file, "%-gF", brw_inst_imm_f(brw, inst));
961 }
962 return 0;
963 }
964
965 static int src0 (FILE *file, struct brw_context *brw, brw_inst *inst)
966 {
967 if (brw_inst_src0_reg_file(brw, inst) == BRW_IMMEDIATE_VALUE)
968 return imm (file, brw, brw_inst_src0_reg_type(brw, inst), inst);
969 else if (brw_inst_access_mode(brw, inst) == BRW_ALIGN_1)
970 {
971 if (brw_inst_src0_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
972 {
973 return src_da1 (file,
974 brw_inst_src0_reg_type(brw, inst),
975 brw_inst_src0_reg_file(brw, inst),
976 brw_inst_src0_vstride(brw, inst),
977 brw_inst_src0_width(brw, inst),
978 brw_inst_src0_hstride(brw, inst),
979 brw_inst_src0_da_reg_nr(brw, inst),
980 brw_inst_src0_da1_subreg_nr(brw, inst),
981 brw_inst_src0_abs(brw, inst),
982 brw_inst_src0_negate(brw, inst));
983 }
984 else
985 {
986 return src_ia1 (file,
987 brw_inst_src0_reg_type(brw, inst),
988 brw_inst_src0_reg_file(brw, inst),
989 brw_inst_src0_ia1_addr_imm(brw, inst),
990 brw_inst_src0_ia_subreg_nr(brw, inst),
991 brw_inst_src0_negate(brw, inst),
992 brw_inst_src0_abs(brw, inst),
993 brw_inst_src0_address_mode(brw, inst),
994 brw_inst_src0_hstride(brw, inst),
995 brw_inst_src0_width(brw, inst),
996 brw_inst_src0_vstride(brw, inst));
997 }
998 }
999 else
1000 {
1001 if (brw_inst_src0_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
1002 {
1003 return src_da16 (file,
1004 brw_inst_src0_reg_type(brw, inst),
1005 brw_inst_src0_reg_file(brw, inst),
1006 brw_inst_src0_vstride(brw, inst),
1007 brw_inst_src0_da_reg_nr(brw, inst),
1008 brw_inst_src0_da16_subreg_nr(brw, inst),
1009 brw_inst_src0_abs(brw, inst),
1010 brw_inst_src0_negate(brw, inst),
1011 brw_inst_src0_da16_swiz_x(brw, inst),
1012 brw_inst_src0_da16_swiz_y(brw, inst),
1013 brw_inst_src0_da16_swiz_z(brw, inst),
1014 brw_inst_src0_da16_swiz_w(brw, inst));
1015 }
1016 else
1017 {
1018 string (file, "Indirect align16 address mode not supported");
1019 return 1;
1020 }
1021 }
1022 }
1023
1024 static int src1 (FILE *file, struct brw_context *brw, brw_inst *inst)
1025 {
1026 if (brw_inst_src1_reg_file(brw, inst) == BRW_IMMEDIATE_VALUE)
1027 return imm (file, brw, brw_inst_src1_reg_type(brw, inst), inst);
1028 else if (brw_inst_access_mode(brw, inst) == BRW_ALIGN_1)
1029 {
1030 if (brw_inst_src1_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
1031 {
1032 return src_da1 (file,
1033 brw_inst_src1_reg_type(brw, inst),
1034 brw_inst_src1_reg_file(brw, inst),
1035 brw_inst_src1_vstride(brw, inst),
1036 brw_inst_src1_width(brw, inst),
1037 brw_inst_src1_hstride(brw, inst),
1038 brw_inst_src1_da_reg_nr(brw, inst),
1039 brw_inst_src1_da1_subreg_nr(brw, inst),
1040 brw_inst_src1_abs(brw, inst),
1041 brw_inst_src1_negate(brw, inst));
1042 }
1043 else
1044 {
1045 return src_ia1 (file,
1046 brw_inst_src1_reg_type(brw, inst),
1047 brw_inst_src1_reg_file(brw, inst),
1048 brw_inst_src1_ia1_addr_imm(brw, inst),
1049 brw_inst_src1_ia_subreg_nr(brw, inst),
1050 brw_inst_src1_negate(brw, inst),
1051 brw_inst_src1_abs(brw, inst),
1052 brw_inst_src1_address_mode(brw, inst),
1053 brw_inst_src1_hstride(brw, inst),
1054 brw_inst_src1_width(brw, inst),
1055 brw_inst_src1_vstride(brw, inst));
1056 }
1057 }
1058 else
1059 {
1060 if (brw_inst_src1_address_mode(brw, inst) == BRW_ADDRESS_DIRECT)
1061 {
1062 return src_da16 (file,
1063 brw_inst_src1_reg_type(brw, inst),
1064 brw_inst_src1_reg_file(brw, inst),
1065 brw_inst_src1_vstride(brw, inst),
1066 brw_inst_src1_da_reg_nr(brw, inst),
1067 brw_inst_src1_da16_subreg_nr(brw, inst),
1068 brw_inst_src1_abs(brw, inst),
1069 brw_inst_src1_negate(brw, inst),
1070 brw_inst_src1_da16_swiz_x(brw, inst),
1071 brw_inst_src1_da16_swiz_y(brw, inst),
1072 brw_inst_src1_da16_swiz_z(brw, inst),
1073 brw_inst_src1_da16_swiz_w(brw, inst));
1074 }
1075 else
1076 {
1077 string (file, "Indirect align16 address mode not supported");
1078 return 1;
1079 }
1080 }
1081 }
1082
1083 static int qtr_ctrl(FILE *file, struct brw_context *brw, brw_inst *inst)
1084 {
1085 int qtr_ctl = brw_inst_qtr_control(brw, inst);
1086 int exec_size = 1 << brw_inst_exec_size(brw, inst);
1087
1088 if (exec_size == 8) {
1089 switch (qtr_ctl) {
1090 case 0:
1091 string (file, " 1Q");
1092 break;
1093 case 1:
1094 string (file, " 2Q");
1095 break;
1096 case 2:
1097 string (file, " 3Q");
1098 break;
1099 case 3:
1100 string (file, " 4Q");
1101 break;
1102 }
1103 } else if (exec_size == 16){
1104 if (qtr_ctl < 2)
1105 string (file, " 1H");
1106 else
1107 string (file, " 2H");
1108 }
1109 return 0;
1110 }
1111
1112 int
1113 brw_disassemble_inst(FILE *file, struct brw_context *brw, brw_inst *inst,
1114 bool is_compacted)
1115 {
1116 int err = 0;
1117 int space = 0;
1118
1119 if (brw_inst_pred_control(brw, inst)) {
1120 string (file, "(");
1121 err |= control (file, "predicate inverse", pred_inv,
1122 brw_inst_pred_inv(brw, inst), NULL);
1123 format (file, "f%d", brw->gen >= 7 ? brw_inst_flag_reg_nr(brw, inst) : 0);
1124 if (brw_inst_flag_subreg_nr(brw, inst))
1125 format (file, ".%d", brw_inst_flag_subreg_nr(brw, inst));
1126 if (brw_inst_access_mode(brw, inst) == BRW_ALIGN_1)
1127 err |= control (file, "predicate control align1", pred_ctrl_align1,
1128 brw_inst_pred_control(brw, inst), NULL);
1129 else
1130 err |= control (file, "predicate control align16", pred_ctrl_align16,
1131 brw_inst_pred_control(brw, inst), NULL);
1132 string (file, ") ");
1133 }
1134
1135 err |= print_opcode (file, brw_inst_opcode(brw, inst));
1136 err |= control (file, "saturate", saturate, brw_inst_saturate(brw, inst),
1137 NULL);
1138
1139 err |= control (file, "debug control", debug_ctrl,
1140 brw_inst_debug_control(brw, inst), NULL);
1141
1142 if (brw_inst_opcode(brw, inst) == BRW_OPCODE_MATH) {
1143 string (file, " ");
1144 err |= control (file, "function", math_function,
1145 brw_inst_math_function(brw, inst), NULL);
1146 } else if (brw_inst_opcode(brw, inst) != BRW_OPCODE_SEND &&
1147 brw_inst_opcode(brw, inst) != BRW_OPCODE_SENDC) {
1148 err |= control (file, "conditional modifier", conditional_modifier,
1149 brw_inst_cond_modifier(brw, inst), NULL);
1150
1151 /* If we're using the conditional modifier, print which flags reg is
1152 * used for it. Note that on gen6+, the embedded-condition SEL and
1153 * control flow doesn't update flags.
1154 */
1155 if (brw_inst_cond_modifier(brw, inst) &&
1156 (brw->gen < 6 || (brw_inst_opcode(brw, inst) != BRW_OPCODE_SEL &&
1157 brw_inst_opcode(brw, inst) != BRW_OPCODE_IF &&
1158 brw_inst_opcode(brw, inst) != BRW_OPCODE_WHILE))) {
1159 format (file, ".f%d", brw->gen >= 7 ? brw_inst_flag_reg_nr(brw, inst) : 0);
1160 if (brw_inst_flag_subreg_nr(brw, inst))
1161 format (file, ".%d", brw_inst_flag_subreg_nr(brw, inst));
1162 }
1163 }
1164
1165 if (brw_inst_opcode(brw, inst) != BRW_OPCODE_NOP) {
1166 string (file, "(");
1167 err |= control (file, "execution size", exec_size, brw_inst_exec_size(brw, inst), NULL);
1168 string (file, ")");
1169 }
1170
1171 if (brw_inst_opcode(brw, inst) == BRW_OPCODE_SEND && brw->gen < 6)
1172 format (file, " %d", brw_inst_base_mrf(brw, inst));
1173
1174 if (opcode[brw_inst_opcode(brw, inst)].nsrc == 3) {
1175 pad (file, 16);
1176 err |= dest_3src (file, brw, inst);
1177
1178 pad (file, 32);
1179 err |= src0_3src (file, brw, inst);
1180
1181 pad (file, 48);
1182 err |= src1_3src (file, brw, inst);
1183
1184 pad (file, 64);
1185 err |= src2_3src (file, brw, inst);
1186 } else {
1187 if (opcode[brw_inst_opcode(brw, inst)].ndst > 0) {
1188 pad (file, 16);
1189 err |= dest (file, brw, inst);
1190 } else if (brw->gen == 7 && (brw_inst_opcode(brw, inst) == BRW_OPCODE_ELSE ||
1191 brw_inst_opcode(brw, inst) == BRW_OPCODE_ENDIF ||
1192 brw_inst_opcode(brw, inst) == BRW_OPCODE_WHILE)) {
1193 format (file, " %d", brw_inst_jip(brw, inst));
1194 } else if (brw->gen == 6 && (brw_inst_opcode(brw, inst) == BRW_OPCODE_IF ||
1195 brw_inst_opcode(brw, inst) == BRW_OPCODE_ELSE ||
1196 brw_inst_opcode(brw, inst) == BRW_OPCODE_ENDIF ||
1197 brw_inst_opcode(brw, inst) == BRW_OPCODE_WHILE)) {
1198 format (file, " %d", brw_inst_gen6_jump_count(brw, inst));
1199 } else if ((brw->gen >= 6 && (brw_inst_opcode(brw, inst) == BRW_OPCODE_BREAK ||
1200 brw_inst_opcode(brw, inst) == BRW_OPCODE_CONTINUE ||
1201 brw_inst_opcode(brw, inst) == BRW_OPCODE_HALT)) ||
1202 (brw->gen == 7 && brw_inst_opcode(brw, inst) == BRW_OPCODE_IF)) {
1203 format (file, " %d %d", brw_inst_uip(brw, inst), brw_inst_jip(brw, inst));
1204 } else if (brw_inst_opcode(brw, inst) == BRW_OPCODE_JMPI) {
1205 format (file, " %d", brw_inst_imm_d(brw, inst));
1206 }
1207
1208 if (opcode[brw_inst_opcode(brw, inst)].nsrc > 0) {
1209 pad (file, 32);
1210 err |= src0 (file, brw, inst);
1211 }
1212 if (opcode[brw_inst_opcode(brw, inst)].nsrc > 1) {
1213 pad (file, 48);
1214 err |= src1 (file, brw, inst);
1215 }
1216 }
1217
1218 if (brw_inst_opcode(brw, inst) == BRW_OPCODE_SEND ||
1219 brw_inst_opcode(brw, inst) == BRW_OPCODE_SENDC) {
1220 enum brw_message_target target = brw_inst_sfid(brw, inst);
1221
1222 newline (file);
1223 pad (file, 16);
1224 space = 0;
1225
1226 fprintf (file, " ");
1227 if (brw->gen >= 6) {
1228 err |= control (file, "target function", target_function_gen6,
1229 target, &space);
1230 } else {
1231 err |= control (file, "target function", target_function,
1232 target, &space);
1233 }
1234
1235 switch (target) {
1236 case BRW_SFID_MATH:
1237 err |= control (file, "math function", math_function,
1238 brw_inst_math_msg_function(brw, inst), &space);
1239 err |= control (file, "math saturate", math_saturate,
1240 brw_inst_math_msg_saturate(brw, inst), &space);
1241 err |= control (file, "math signed", math_signed,
1242 brw_inst_math_msg_signed_int(brw, inst), &space);
1243 err |= control (file, "math scalar", math_scalar,
1244 brw_inst_math_msg_data_type(brw, inst), &space);
1245 err |= control (file, "math precision", math_precision,
1246 brw_inst_math_msg_precision(brw, inst), &space);
1247 break;
1248 case BRW_SFID_SAMPLER:
1249 if (brw->gen >= 5) {
1250 format (file, " (%d, %d, %d, %d)",
1251 brw_inst_binding_table_index(brw, inst),
1252 brw_inst_sampler(brw, inst),
1253 brw_inst_sampler_msg_type(brw, inst),
1254 brw_inst_sampler_simd_mode(brw, inst));
1255 } else {
1256 format (file, " (%d, %d, %d, ",
1257 brw_inst_binding_table_index(brw, inst),
1258 brw_inst_sampler(brw, inst),
1259 brw_inst_sampler_msg_type(brw, inst));
1260 if (!brw->is_g4x) {
1261 err |= control (file, "sampler target format",
1262 sampler_target_format,
1263 brw_inst_sampler_return_format(brw, inst), NULL);
1264 }
1265 string (file, ")");
1266 }
1267 break;
1268 case BRW_SFID_DATAPORT_READ:
1269 if (brw->gen >= 6) {
1270 format (file, " (%d, %d, %d, %d)",
1271 brw_inst_binding_table_index(brw, inst),
1272 brw_inst_dp_msg_control(brw, inst),
1273 brw_inst_dp_msg_type(brw, inst),
1274 brw->gen >= 7 ? 0 : brw_inst_dp_write_commit(brw, inst));
1275 } else {
1276 format (file, " (%d, %d, %d)",
1277 brw_inst_binding_table_index(brw, inst),
1278 brw_inst_dp_read_msg_control(brw, inst),
1279 brw_inst_dp_read_msg_type(brw, inst));
1280 }
1281 break;
1282
1283 case BRW_SFID_DATAPORT_WRITE:
1284 if (brw->gen >= 7) {
1285 format (file, " (");
1286
1287 err |= control (file, "DP rc message type",
1288 dp_rc_msg_type_gen6,
1289 brw_inst_dp_msg_type(brw, inst), &space);
1290
1291 format (file, ", %d, %d, %d)",
1292 brw_inst_binding_table_index(brw, inst),
1293 brw_inst_dp_msg_control(brw, inst),
1294 brw_inst_dp_msg_type(brw, inst));
1295 } else if (brw->gen == 6) {
1296 format (file, " (");
1297
1298 err |= control (file, "DP rc message type",
1299 dp_rc_msg_type_gen6,
1300 brw_inst_dp_msg_type(brw, inst), &space);
1301
1302 format (file, ", %d, %d, %d, %d)",
1303 brw_inst_binding_table_index(brw, inst),
1304 brw_inst_dp_msg_control(brw, inst),
1305 brw_inst_dp_msg_type(brw, inst),
1306 brw_inst_dp_write_commit(brw, inst));
1307 } else {
1308 format (file, " (%d, %d, %d, %d)",
1309 brw_inst_binding_table_index(brw, inst),
1310 (brw_inst_rt_last(brw, inst) << 3) |
1311 brw_inst_dp_write_msg_control(brw, inst),
1312 brw_inst_dp_write_msg_type(brw, inst),
1313 brw_inst_dp_write_commit(brw, inst));
1314 }
1315 break;
1316
1317 case BRW_SFID_URB:
1318 format (file, " %d", brw_inst_urb_global_offset(brw, inst));
1319
1320 space = 1;
1321 if (brw->gen >= 5) {
1322 err |= control (file, "urb opcode", urb_opcode,
1323 brw_inst_urb_opcode(brw, inst), &space);
1324 }
1325 err |= control (file, "urb swizzle", urb_swizzle,
1326 brw_inst_urb_swizzle_control(brw, inst), &space);
1327 if (brw->gen < 7) {
1328 err |= control (file, "urb allocate", urb_allocate,
1329 brw_inst_urb_allocate(brw, inst), &space);
1330 err |= control (file, "urb used", urb_used,
1331 brw_inst_urb_used(brw, inst), &space);
1332 }
1333 err |= control (file, "urb complete", urb_complete,
1334 brw_inst_urb_complete(brw, inst), &space);
1335 break;
1336 case BRW_SFID_THREAD_SPAWNER:
1337 break;
1338 case GEN7_SFID_DATAPORT_DATA_CACHE:
1339 if (brw->gen >= 7) {
1340 format (file, " (");
1341
1342 err |= control (file, "DP DC0 message type",
1343 dp_dc0_msg_type_gen7,
1344 brw_inst_dp_msg_type(brw, inst), &space);
1345
1346 format (file, ", %d, ", brw_inst_binding_table_index(brw, inst));
1347
1348 switch (brw_inst_dp_msg_type(brw, inst)) {
1349 case GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP:
1350 control (file, "atomic op", aop, brw_inst_imm_ud(brw, inst) >> 8 & 0xf,
1351 &space);
1352 break;
1353 default:
1354 format (file, "%d", brw_inst_dp_msg_control(brw, inst));
1355 }
1356 format (file, ")");
1357 break;
1358 }
1359 /* FALLTHROUGH */
1360
1361 case HSW_SFID_DATAPORT_DATA_CACHE_1:
1362 if (brw->gen >= 7) {
1363 format (file, " (");
1364
1365 err |= control (file, "DP DC1 message type",
1366 dp_dc1_msg_type_hsw,
1367 brw_inst_dp_msg_type(brw, inst), &space);
1368
1369 format (file, ", %d, ",
1370 brw_inst_binding_table_index(brw, inst));
1371
1372 switch (brw_inst_dp_msg_type(brw, inst)) {
1373 case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP:
1374 case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2:
1375 case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP:
1376 case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2:
1377 case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP:
1378 case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2:
1379 control (file, "atomic op", aop,
1380 brw_inst_imm_ud(brw, inst) >> 8 & 0xf, &space);
1381 break;
1382 default:
1383 format (file, "%d", brw_inst_dp_msg_control(brw, inst));
1384 }
1385 format (file, ")");
1386 break;
1387 }
1388 /* FALLTHROUGH */
1389
1390 default:
1391 format (file, "unsupported target %d", target);
1392 break;
1393 }
1394 if (space)
1395 string (file, " ");
1396 format (file, "mlen %d", brw_inst_mlen(brw, inst));
1397 format (file, " rlen %d", brw_inst_rlen(brw, inst));
1398 }
1399 pad (file, 64);
1400 if (brw_inst_opcode(brw, inst) != BRW_OPCODE_NOP) {
1401 string (file, "{");
1402 space = 1;
1403 err |= control(file, "access mode", access_mode, brw_inst_access_mode(brw, inst), &space);
1404 if (brw->gen >= 6)
1405 err |= control (file, "write enable control", wectrl, brw_inst_mask_control(brw, inst), &space);
1406 else
1407 err |= control (file, "mask control", mask_ctrl, brw_inst_mask_control(brw, inst), &space);
1408 err |= control (file, "dependency control", dep_ctrl,
1409 ((brw_inst_no_dd_check(brw, inst) << 1) |
1410 brw_inst_no_dd_clear(brw, inst)), &space);
1411
1412 if (brw->gen >= 6)
1413 err |= qtr_ctrl (file, brw, inst);
1414 else {
1415 if (brw_inst_qtr_control(brw, inst) == BRW_COMPRESSION_COMPRESSED &&
1416 opcode[brw_inst_opcode(brw, inst)].ndst > 0 &&
1417 brw_inst_dst_reg_file(brw, inst) == BRW_MESSAGE_REGISTER_FILE &&
1418 brw_inst_dst_da_reg_nr(brw, inst) & (1 << 7)) {
1419 format (file, " compr4");
1420 } else {
1421 err |= control (file, "compression control", compr_ctrl,
1422 brw_inst_qtr_control(brw, inst), &space);
1423 }
1424 }
1425
1426 err |= control (file, "compaction control", cmpt_ctrl, is_compacted, &space);
1427 err |= control (file, "thread control", thread_ctrl, brw_inst_thread_control(brw, inst), &space);
1428 if (brw->gen >= 6)
1429 err |= control (file, "acc write control", accwr, brw_inst_acc_wr_control(brw, inst), &space);
1430 if (brw_inst_opcode(brw, inst) == BRW_OPCODE_SEND ||
1431 brw_inst_opcode(brw, inst) == BRW_OPCODE_SENDC)
1432 err |= control (file, "end of thread", end_of_thread,
1433 brw_inst_eot(brw, inst), &space);
1434 if (space)
1435 string (file, " ");
1436 string (file, "}");
1437 }
1438 string (file, ";");
1439 newline (file);
1440 return err;
1441 }