1 /*
2 * Copyright © 2008 Keith Packard
3 * Copyright © 2014 Intel Corporation
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "elk_disasm.h"
30 #include "elk_disasm_info.h"
31 #include "elk_eu_defines.h"
32 #include "elk_eu.h"
33 #include "elk_inst.h"
34 #include "elk_isa_info.h"
35 #include "elk_reg.h"
36 #include "elk_shader.h"
37 #include "util/half_float.h"
38
39 bool
elk_has_jip(const struct intel_device_info * devinfo,enum elk_opcode opcode)40 elk_has_jip(const struct intel_device_info *devinfo, enum elk_opcode opcode)
41 {
42 if (devinfo->ver < 6)
43 return false;
44
45 return opcode == ELK_OPCODE_IF ||
46 opcode == ELK_OPCODE_ELSE ||
47 opcode == ELK_OPCODE_ENDIF ||
48 opcode == ELK_OPCODE_WHILE ||
49 opcode == ELK_OPCODE_BREAK ||
50 opcode == ELK_OPCODE_CONTINUE ||
51 opcode == ELK_OPCODE_HALT;
52 }
53
54 bool
elk_has_uip(const struct intel_device_info * devinfo,enum elk_opcode opcode)55 elk_has_uip(const struct intel_device_info *devinfo, enum elk_opcode opcode)
56 {
57 if (devinfo->ver < 6)
58 return false;
59
60 return (devinfo->ver >= 7 && opcode == ELK_OPCODE_IF) ||
61 (devinfo->ver >= 8 && opcode == ELK_OPCODE_ELSE) ||
62 opcode == ELK_OPCODE_BREAK ||
63 opcode == ELK_OPCODE_CONTINUE ||
64 opcode == ELK_OPCODE_HALT;
65 }
66
67 bool
elk_has_branch_ctrl(const struct intel_device_info * devinfo,enum elk_opcode opcode)68 elk_has_branch_ctrl(const struct intel_device_info *devinfo, enum elk_opcode opcode)
69 {
70 if (devinfo->ver < 8)
71 return false;
72
73 switch (opcode) {
74 case ELK_OPCODE_IF:
75 case ELK_OPCODE_ELSE:
76 case ELK_OPCODE_GOTO:
77 case ELK_OPCODE_BREAK:
78 case ELK_OPCODE_CALL:
79 case ELK_OPCODE_CALLA:
80 case ELK_OPCODE_CONTINUE:
81 case ELK_OPCODE_ENDIF:
82 case ELK_OPCODE_HALT:
83 case ELK_OPCODE_JMPI:
84 case ELK_OPCODE_RET:
85 case ELK_OPCODE_WHILE:
86 case ELK_OPCODE_BRC:
87 case ELK_OPCODE_BRD:
88 /* TODO: "join" should also be here if added */
89 return true;
90 default:
91 return false;
92 }
93 }
94
95 static bool
is_logic_instruction(unsigned opcode)96 is_logic_instruction(unsigned opcode)
97 {
98 return opcode == ELK_OPCODE_AND ||
99 opcode == ELK_OPCODE_NOT ||
100 opcode == ELK_OPCODE_OR ||
101 opcode == ELK_OPCODE_XOR;
102 }
103
104 static bool
is_send(unsigned opcode)105 is_send(unsigned opcode)
106 {
107 return opcode == ELK_OPCODE_SEND ||
108 opcode == ELK_OPCODE_SENDC;
109 }
110
111 const char *const elk_conditional_modifier[16] = {
112 [ELK_CONDITIONAL_NONE] = "",
113 [ELK_CONDITIONAL_Z] = ".z",
114 [ELK_CONDITIONAL_NZ] = ".nz",
115 [ELK_CONDITIONAL_G] = ".g",
116 [ELK_CONDITIONAL_GE] = ".ge",
117 [ELK_CONDITIONAL_L] = ".l",
118 [ELK_CONDITIONAL_LE] = ".le",
119 [ELK_CONDITIONAL_R] = ".r",
120 [ELK_CONDITIONAL_O] = ".o",
121 [ELK_CONDITIONAL_U] = ".u",
122 };
123
124 static const char *const m_negate[2] = {
125 [0] = "",
126 [1] = "-",
127 };
128
129 static const char *const _abs[2] = {
130 [0] = "",
131 [1] = "(abs)",
132 };
133
134 static const char *const m_bitnot[2] = { "", "~" };
135
136 static const char *const vert_stride[16] = {
137 [0] = "0",
138 [1] = "1",
139 [2] = "2",
140 [3] = "4",
141 [4] = "8",
142 [5] = "16",
143 [6] = "32",
144 [15] = "VxH",
145 };
146
147 static const char *const width[8] = {
148 [0] = "1",
149 [1] = "2",
150 [2] = "4",
151 [3] = "8",
152 [4] = "16",
153 };
154
155 static const char *const horiz_stride[4] = {
156 [0] = "0",
157 [1] = "1",
158 [2] = "2",
159 [3] = "4"
160 };
161
162 static const char *const chan_sel[4] = {
163 [0] = "x",
164 [1] = "y",
165 [2] = "z",
166 [3] = "w",
167 };
168
169 static const char *const debug_ctrl[2] = {
170 [0] = "",
171 [1] = ".breakpoint"
172 };
173
174 static const char *const saturate[2] = {
175 [0] = "",
176 [1] = ".sat"
177 };
178
179 static const char *const cmpt_ctrl[2] = {
180 [0] = "",
181 [1] = "compacted"
182 };
183
184 static const char *const accwr[2] = {
185 [0] = "",
186 [1] = "AccWrEnable"
187 };
188
189 static const char *const branch_ctrl[2] = {
190 [0] = "",
191 [1] = "BranchCtrl"
192 };
193
194 static const char *const wectrl[2] = {
195 [0] = "",
196 [1] = "WE_all"
197 };
198
199 static const char *const exec_size[8] = {
200 [0] = "1",
201 [1] = "2",
202 [2] = "4",
203 [3] = "8",
204 [4] = "16",
205 [5] = "32"
206 };
207
208 static const char *const pred_inv[2] = {
209 [0] = "+",
210 [1] = "-"
211 };
212
213 const char *const elk_pred_ctrl_align16[16] = {
214 [1] = "",
215 [2] = ".x",
216 [3] = ".y",
217 [4] = ".z",
218 [5] = ".w",
219 [6] = ".any4h",
220 [7] = ".all4h",
221 };
222
223 static const char *const pred_ctrl_align1[16] = {
224 [ELK_PREDICATE_NORMAL] = "",
225 [ELK_PREDICATE_ALIGN1_ANYV] = ".anyv",
226 [ELK_PREDICATE_ALIGN1_ALLV] = ".allv",
227 [ELK_PREDICATE_ALIGN1_ANY2H] = ".any2h",
228 [ELK_PREDICATE_ALIGN1_ALL2H] = ".all2h",
229 [ELK_PREDICATE_ALIGN1_ANY4H] = ".any4h",
230 [ELK_PREDICATE_ALIGN1_ALL4H] = ".all4h",
231 [ELK_PREDICATE_ALIGN1_ANY8H] = ".any8h",
232 [ELK_PREDICATE_ALIGN1_ALL8H] = ".all8h",
233 [ELK_PREDICATE_ALIGN1_ANY16H] = ".any16h",
234 [ELK_PREDICATE_ALIGN1_ALL16H] = ".all16h",
235 [ELK_PREDICATE_ALIGN1_ANY32H] = ".any32h",
236 [ELK_PREDICATE_ALIGN1_ALL32H] = ".all32h",
237 };
238
239 static const char *const thread_ctrl[4] = {
240 [ELK_THREAD_NORMAL] = "",
241 [ELK_THREAD_ATOMIC] = "atomic",
242 [ELK_THREAD_SWITCH] = "switch",
243 };
244
245 static const char *const compr_ctrl[4] = {
246 [0] = "",
247 [1] = "sechalf",
248 [2] = "compr",
249 [3] = "compr4",
250 };
251
252 static const char *const dep_ctrl[4] = {
253 [0] = "",
254 [1] = "NoDDClr",
255 [2] = "NoDDChk",
256 [3] = "NoDDClr,NoDDChk",
257 };
258
259 static const char *const mask_ctrl[4] = {
260 [0] = "",
261 [1] = "nomask",
262 };
263
264 static const char *const access_mode[2] = {
265 [0] = "align1",
266 [1] = "align16",
267 };
268
269 static const char *const reg_file[4] = {
270 [0] = "A",
271 [1] = "g",
272 [2] = "m",
273 [3] = "imm",
274 };
275
276 static const char *const 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 static const char *const end_of_thread[2] = {
296 [0] = "",
297 [1] = "EOT"
298 };
299
300 /* SFIDs on Gfx4-5 */
301 static const char *const gfx4_sfid[16] = {
302 [ELK_SFID_NULL] = "null",
303 [ELK_SFID_MATH] = "math",
304 [ELK_SFID_SAMPLER] = "sampler",
305 [ELK_SFID_MESSAGE_GATEWAY] = "gateway",
306 [ELK_SFID_DATAPORT_READ] = "read",
307 [ELK_SFID_DATAPORT_WRITE] = "write",
308 [ELK_SFID_URB] = "urb",
309 [ELK_SFID_THREAD_SPAWNER] = "thread_spawner",
310 [ELK_SFID_VME] = "vme",
311 };
312
313 static const char *const gfx6_sfid[16] = {
314 [ELK_SFID_NULL] = "null",
315 [ELK_SFID_MATH] = "math",
316 [ELK_SFID_SAMPLER] = "sampler",
317 [ELK_SFID_MESSAGE_GATEWAY] = "gateway",
318 [ELK_SFID_URB] = "urb",
319 [ELK_SFID_THREAD_SPAWNER] = "thread_spawner",
320 [GFX6_SFID_DATAPORT_SAMPLER_CACHE] = "dp_sampler",
321 [GFX6_SFID_DATAPORT_RENDER_CACHE] = "render",
322 [GFX6_SFID_DATAPORT_CONSTANT_CACHE] = "const",
323 [GFX7_SFID_DATAPORT_DATA_CACHE] = "data",
324 [GFX7_SFID_PIXEL_INTERPOLATOR] = "pixel interp",
325 [HSW_SFID_DATAPORT_DATA_CACHE_1] = "dp data 1",
326 [HSW_SFID_CRE] = "cre",
327 };
328
329 static const char *const gfx7_gateway_subfuncid[8] = {
330 [ELK_MESSAGE_GATEWAY_SFID_OPEN_GATEWAY] = "open",
331 [ELK_MESSAGE_GATEWAY_SFID_CLOSE_GATEWAY] = "close",
332 [ELK_MESSAGE_GATEWAY_SFID_FORWARD_MSG] = "forward msg",
333 [ELK_MESSAGE_GATEWAY_SFID_GET_TIMESTAMP] = "get timestamp",
334 [ELK_MESSAGE_GATEWAY_SFID_BARRIER_MSG] = "barrier msg",
335 [ELK_MESSAGE_GATEWAY_SFID_UPDATE_GATEWAY_STATE] = "update state",
336 [ELK_MESSAGE_GATEWAY_SFID_MMIO_READ_WRITE] = "mmio read/write",
337 };
338
339 static const char *const gfx4_dp_read_port_msg_type[4] = {
340 [0b00] = "OWord Block Read",
341 [0b01] = "OWord Dual Block Read",
342 [0b10] = "Media Block Read",
343 [0b11] = "DWord Scattered Read",
344 };
345
346 static const char *const g45_dp_read_port_msg_type[8] = {
347 [0b000] = "OWord Block Read",
348 [0b010] = "OWord Dual Block Read",
349 [0b100] = "Media Block Read",
350 [0b110] = "DWord Scattered Read",
351 [0b001] = "Render Target UNORM Read",
352 [0b011] = "AVC Loop Filter Read",
353 };
354
355 static const char *const dp_write_port_msg_type[8] = {
356 [0b000] = "OWord block write",
357 [0b001] = "OWord dual block write",
358 [0b010] = "media block write",
359 [0b011] = "DWord scattered write",
360 [0b100] = "RT write",
361 [0b101] = "streamed VB write",
362 [0b110] = "RT UNORM write", /* G45+ */
363 [0b111] = "flush render cache",
364 };
365
366 static const char *const dp_rc_msg_type_gfx6[16] = {
367 [ELK_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ] = "OWORD block read",
368 [GFX6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ] = "RT UNORM read",
369 [GFX6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ] = "OWORD dual block read",
370 [GFX6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ] = "media block read",
371 [GFX6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ] =
372 "OWORD unaligned block read",
373 [GFX6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ] = "DWORD scattered read",
374 [GFX6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE] = "DWORD atomic write",
375 [GFX6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE] = "OWORD block write",
376 [GFX6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE] =
377 "OWORD dual block write",
378 [GFX6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE] = "media block write",
379 [GFX6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE] =
380 "DWORD scattered write",
381 [GFX6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE] = "RT write",
382 [GFX6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE] = "streamed VB write",
383 [GFX6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE] = "RT UNORM write",
384 };
385
386 static const char *const dp_rc_msg_type_gfx7[16] = {
387 [GFX7_DATAPORT_RC_MEDIA_BLOCK_READ] = "media block read",
388 [GFX7_DATAPORT_RC_TYPED_SURFACE_READ] = "typed surface read",
389 [GFX7_DATAPORT_RC_TYPED_ATOMIC_OP] = "typed atomic op",
390 [GFX7_DATAPORT_RC_MEMORY_FENCE] = "memory fence",
391 [GFX7_DATAPORT_RC_MEDIA_BLOCK_WRITE] = "media block write",
392 [GFX7_DATAPORT_RC_RENDER_TARGET_WRITE] = "RT write",
393 [GFX7_DATAPORT_RC_TYPED_SURFACE_WRITE] = "typed surface write"
394 };
395
396 static const char *const *
dp_rc_msg_type(const struct intel_device_info * devinfo)397 dp_rc_msg_type(const struct intel_device_info *devinfo)
398 {
399 return (devinfo->ver >= 7 ? dp_rc_msg_type_gfx7 :
400 devinfo->ver >= 6 ? dp_rc_msg_type_gfx6 :
401 dp_write_port_msg_type);
402 }
403
404 static const char *const m_rt_write_subtype[] = {
405 [0b000] = "SIMD16",
406 [0b001] = "SIMD16/RepData",
407 [0b010] = "SIMD8/DualSrcLow",
408 [0b011] = "SIMD8/DualSrcHigh",
409 [0b100] = "SIMD8",
410 [0b101] = "SIMD8/ImageWrite", /* Gfx6+ */
411 [0b111] = "SIMD16/RepData-111", /* no idea how this is different than 1 */
412 };
413
414 static const char *const dp_dc0_msg_type_gfx7[16] = {
415 [GFX7_DATAPORT_DC_OWORD_BLOCK_READ] = "DC OWORD block read",
416 [GFX7_DATAPORT_DC_UNALIGNED_OWORD_BLOCK_READ] =
417 "DC unaligned OWORD block read",
418 [GFX7_DATAPORT_DC_OWORD_DUAL_BLOCK_READ] = "DC OWORD dual block read",
419 [GFX7_DATAPORT_DC_DWORD_SCATTERED_READ] = "DC DWORD scattered read",
420 [GFX7_DATAPORT_DC_BYTE_SCATTERED_READ] = "DC byte scattered read",
421 [GFX7_DATAPORT_DC_UNTYPED_SURFACE_READ] = "DC untyped surface read",
422 [GFX7_DATAPORT_DC_UNTYPED_ATOMIC_OP] = "DC untyped atomic",
423 [GFX7_DATAPORT_DC_MEMORY_FENCE] = "DC mfence",
424 [GFX7_DATAPORT_DC_OWORD_BLOCK_WRITE] = "DC OWORD block write",
425 [GFX7_DATAPORT_DC_OWORD_DUAL_BLOCK_WRITE] = "DC OWORD dual block write",
426 [GFX7_DATAPORT_DC_DWORD_SCATTERED_WRITE] = "DC DWORD scatterd write",
427 [GFX7_DATAPORT_DC_BYTE_SCATTERED_WRITE] = "DC byte scattered write",
428 [GFX7_DATAPORT_DC_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
429 };
430
431 static const char *const dp_oword_block_rw[8] = {
432 [ELK_DATAPORT_OWORD_BLOCK_1_OWORDLOW] = "1-low",
433 [ELK_DATAPORT_OWORD_BLOCK_1_OWORDHIGH] = "1-high",
434 [ELK_DATAPORT_OWORD_BLOCK_2_OWORDS] = "2",
435 [ELK_DATAPORT_OWORD_BLOCK_4_OWORDS] = "4",
436 [ELK_DATAPORT_OWORD_BLOCK_8_OWORDS] = "8",
437 };
438
439 static const char *const dp_dc1_msg_type_hsw[32] = {
440 [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ] = "untyped surface read",
441 [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP] = "DC untyped atomic op",
442 [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2] =
443 "DC untyped 4x2 atomic op",
444 [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_READ] = "DC media block read",
445 [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ] = "DC typed surface read",
446 [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP] = "DC typed atomic",
447 [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2] = "DC typed 4x2 atomic op",
448 [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
449 [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_WRITE] = "DC media block write",
450 [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP] = "DC atomic counter op",
451 [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2] =
452 "DC 4x2 atomic counter op",
453 [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE] = "DC typed surface write",
454 [GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ] = "DC A64 untyped surface read",
455 [GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP] = "DC A64 untyped atomic op",
456 [GFX8_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_READ] = "DC A64 oword block read",
457 [GFX8_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_WRITE] = "DC A64 oword block write",
458 [GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE] = "DC A64 untyped surface write",
459 [GFX8_DATAPORT_DC_PORT1_A64_SCATTERED_WRITE] = "DC A64 scattered write",
460 };
461
462 static const char *const aop[16] = {
463 [ELK_AOP_AND] = "and",
464 [ELK_AOP_OR] = "or",
465 [ELK_AOP_XOR] = "xor",
466 [ELK_AOP_MOV] = "mov",
467 [ELK_AOP_INC] = "inc",
468 [ELK_AOP_DEC] = "dec",
469 [ELK_AOP_ADD] = "add",
470 [ELK_AOP_SUB] = "sub",
471 [ELK_AOP_REVSUB] = "revsub",
472 [ELK_AOP_IMAX] = "imax",
473 [ELK_AOP_IMIN] = "imin",
474 [ELK_AOP_UMAX] = "umax",
475 [ELK_AOP_UMIN] = "umin",
476 [ELK_AOP_CMPWR] = "cmpwr",
477 [ELK_AOP_PREDEC] = "predec",
478 };
479
480 static const char * const pixel_interpolator_msg_types[4] = {
481 [GFX7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET] = "per_message_offset",
482 [GFX7_PIXEL_INTERPOLATOR_LOC_SAMPLE] = "sample_position",
483 [GFX7_PIXEL_INTERPOLATOR_LOC_CENTROID] = "centroid",
484 [GFX7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET] = "per_slot_offset",
485 };
486
487 static const char *const math_function[16] = {
488 [ELK_MATH_FUNCTION_INV] = "inv",
489 [ELK_MATH_FUNCTION_LOG] = "log",
490 [ELK_MATH_FUNCTION_EXP] = "exp",
491 [ELK_MATH_FUNCTION_SQRT] = "sqrt",
492 [ELK_MATH_FUNCTION_RSQ] = "rsq",
493 [ELK_MATH_FUNCTION_SIN] = "sin",
494 [ELK_MATH_FUNCTION_COS] = "cos",
495 [ELK_MATH_FUNCTION_SINCOS] = "sincos",
496 [ELK_MATH_FUNCTION_FDIV] = "fdiv",
497 [ELK_MATH_FUNCTION_POW] = "pow",
498 [ELK_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
499 [ELK_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intdiv",
500 [ELK_MATH_FUNCTION_INT_DIV_REMAINDER] = "intmod",
501 [GFX8_MATH_FUNCTION_INVM] = "invm",
502 [GFX8_MATH_FUNCTION_RSQRTM] = "rsqrtm",
503 };
504
505 static const char *const math_saturate[2] = {
506 [0] = "",
507 [1] = "sat"
508 };
509
510 static const char *const math_signed[2] = {
511 [0] = "",
512 [1] = "signed"
513 };
514
515 static const char *const math_scalar[2] = {
516 [0] = "",
517 [1] = "scalar"
518 };
519
520 static const char *const math_precision[2] = {
521 [0] = "",
522 [1] = "partial_precision"
523 };
524
525 static const char *const gfx5_urb_opcode[] = {
526 [0] = "urb_write",
527 [1] = "ff_sync",
528 };
529
530 static const char *const gfx7_urb_opcode[] = {
531 [ELK_URB_OPCODE_WRITE_HWORD] = "write HWord",
532 [ELK_URB_OPCODE_WRITE_OWORD] = "write OWord",
533 [ELK_URB_OPCODE_READ_HWORD] = "read HWord",
534 [ELK_URB_OPCODE_READ_OWORD] = "read OWord",
535 [GFX7_URB_OPCODE_ATOMIC_MOV] = "atomic mov", /* Gfx7+ */
536 [GFX7_URB_OPCODE_ATOMIC_INC] = "atomic inc", /* Gfx7+ */
537 [GFX8_URB_OPCODE_ATOMIC_ADD] = "atomic add", /* Gfx8+ */
538 [GFX8_URB_OPCODE_SIMD8_WRITE] = "SIMD8 write", /* Gfx8+ */
539 [GFX8_URB_OPCODE_SIMD8_READ] = "SIMD8 read", /* Gfx8+ */
540 /* [9-15] - reserved */
541 };
542
543 static const char *const urb_swizzle[4] = {
544 [ELK_URB_SWIZZLE_NONE] = "",
545 [ELK_URB_SWIZZLE_INTERLEAVE] = "interleave",
546 [ELK_URB_SWIZZLE_TRANSPOSE] = "transpose",
547 };
548
549 static const char *const urb_allocate[2] = {
550 [0] = "",
551 [1] = "allocate"
552 };
553
554 static const char *const urb_used[2] = {
555 [0] = "",
556 [1] = "used"
557 };
558
559 static const char *const urb_complete[2] = {
560 [0] = "",
561 [1] = "complete"
562 };
563
564 static const char *const gfx5_sampler_msg_type[] = {
565 [GFX5_SAMPLER_MESSAGE_SAMPLE] = "sample",
566 [GFX5_SAMPLER_MESSAGE_SAMPLE_BIAS] = "sample_b",
567 [GFX5_SAMPLER_MESSAGE_SAMPLE_LOD] = "sample_l",
568 [GFX5_SAMPLER_MESSAGE_SAMPLE_COMPARE] = "sample_c",
569 [GFX5_SAMPLER_MESSAGE_SAMPLE_DERIVS] = "sample_d",
570 [GFX5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE] = "sample_b_c",
571 [GFX5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE] = "sample_l_c",
572 [GFX5_SAMPLER_MESSAGE_SAMPLE_LD] = "ld",
573 [GFX7_SAMPLER_MESSAGE_SAMPLE_GATHER4] = "gather4",
574 [GFX5_SAMPLER_MESSAGE_LOD] = "lod",
575 [GFX5_SAMPLER_MESSAGE_SAMPLE_RESINFO] = "resinfo",
576 [GFX6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO] = "sampleinfo",
577 [GFX7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C] = "gather4_c",
578 [GFX7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO] = "gather4_po",
579 [GFX7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C] = "gather4_po_c",
580 [HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE] = "sample_d_c",
581 [GFX7_SAMPLER_MESSAGE_SAMPLE_LD_MCS] = "ld_mcs",
582 [GFX7_SAMPLER_MESSAGE_SAMPLE_LD2DMS] = "ld2dms",
583 [GFX7_SAMPLER_MESSAGE_SAMPLE_LD2DSS] = "ld2dss",
584 };
585
586 static const char *const gfx5_sampler_simd_mode[7] = {
587 [ELK_SAMPLER_SIMD_MODE_SIMD4X2] = "SIMD4x2",
588 [ELK_SAMPLER_SIMD_MODE_SIMD8] = "SIMD8",
589 [ELK_SAMPLER_SIMD_MODE_SIMD16] = "SIMD16",
590 [ELK_SAMPLER_SIMD_MODE_SIMD32_64] = "SIMD32/64",
591 };
592
593 static const char *const sampler_target_format[4] = {
594 [0] = "F",
595 [2] = "UD",
596 [3] = "D"
597 };
598
599 static int column;
600
601 static int
string(FILE * file,const char * string)602 string(FILE *file, const char *string)
603 {
604 fputs(string, file);
605 column += strlen(string);
606 return 0;
607 }
608
609 static int
610 format(FILE *f, const char *format, ...) PRINTFLIKE(2, 3);
611
612 static int
format(FILE * f,const char * format,...)613 format(FILE *f, const char *format, ...)
614 {
615 char buf[1024];
616 va_list args;
617 va_start(args, format);
618
619 vsnprintf(buf, sizeof(buf) - 1, format, args);
620 va_end(args);
621 string(f, buf);
622 return 0;
623 }
624
625 static int
newline(FILE * f)626 newline(FILE *f)
627 {
628 putc('\n', f);
629 column = 0;
630 return 0;
631 }
632
633 static int
pad(FILE * f,int c)634 pad(FILE *f, int c)
635 {
636 do
637 string(f, " ");
638 while (column < c);
639 return 0;
640 }
641
642 static int
control(FILE * file,const char * name,const char * const ctrl[],unsigned id,int * space)643 control(FILE *file, const char *name, const char *const ctrl[],
644 unsigned id, int *space)
645 {
646 if (!ctrl[id]) {
647 fprintf(file, "*** invalid %s value %d ", name, id);
648 return 1;
649 }
650 if (ctrl[id][0]) {
651 if (space && *space)
652 string(file, " ");
653 string(file, ctrl[id]);
654 if (space)
655 *space = 1;
656 }
657 return 0;
658 }
659
660 static int
print_opcode(FILE * file,const struct elk_isa_info * isa,enum elk_opcode id)661 print_opcode(FILE *file, const struct elk_isa_info *isa,
662 enum elk_opcode id)
663 {
664 const struct elk_opcode_desc *desc = elk_opcode_desc(isa, id);
665 if (!desc) {
666 format(file, "*** invalid opcode value %d ", id);
667 return 1;
668 }
669 string(file, desc->name);
670 return 0;
671 }
672
673 static int
reg(FILE * file,unsigned _reg_file,unsigned _reg_nr)674 reg(FILE *file, unsigned _reg_file, unsigned _reg_nr)
675 {
676 int err = 0;
677
678 /* Clear the Compr4 instruction compression bit. */
679 if (_reg_file == ELK_MESSAGE_REGISTER_FILE)
680 _reg_nr &= ~ELK_MRF_COMPR4;
681
682 if (_reg_file == ELK_ARCHITECTURE_REGISTER_FILE) {
683 switch (_reg_nr & 0xf0) {
684 case ELK_ARF_NULL:
685 string(file, "null");
686 break;
687 case ELK_ARF_ADDRESS:
688 format(file, "a%d", _reg_nr & 0x0f);
689 break;
690 case ELK_ARF_ACCUMULATOR:
691 format(file, "acc%d", _reg_nr & 0x0f);
692 break;
693 case ELK_ARF_FLAG:
694 format(file, "f%d", _reg_nr & 0x0f);
695 break;
696 case ELK_ARF_MASK:
697 format(file, "mask%d", _reg_nr & 0x0f);
698 break;
699 case ELK_ARF_MASK_STACK:
700 format(file, "ms%d", _reg_nr & 0x0f);
701 break;
702 case ELK_ARF_MASK_STACK_DEPTH:
703 format(file, "msd%d", _reg_nr & 0x0f);
704 break;
705 case ELK_ARF_STATE:
706 format(file, "sr%d", _reg_nr & 0x0f);
707 break;
708 case ELK_ARF_CONTROL:
709 format(file, "cr%d", _reg_nr & 0x0f);
710 break;
711 case ELK_ARF_NOTIFICATION_COUNT:
712 format(file, "n%d", _reg_nr & 0x0f);
713 break;
714 case ELK_ARF_IP:
715 string(file, "ip");
716 return -1;
717 break;
718 case ELK_ARF_TDR:
719 format(file, "tdr0");
720 return -1;
721 case ELK_ARF_TIMESTAMP:
722 format(file, "tm%d", _reg_nr & 0x0f);
723 break;
724 default:
725 format(file, "ARF%d", _reg_nr);
726 break;
727 }
728 } else {
729 err |= control(file, "src reg file", reg_file, _reg_file, NULL);
730 format(file, "%d", _reg_nr);
731 }
732 return err;
733 }
734
735 static int
dest(FILE * file,const struct elk_isa_info * isa,const elk_inst * inst)736 dest(FILE *file, const struct elk_isa_info *isa, const elk_inst *inst)
737 {
738 const struct intel_device_info *devinfo = isa->devinfo;
739 enum elk_reg_type type = elk_inst_dst_type(devinfo, inst);
740 unsigned elem_size = elk_reg_type_to_size(type);
741 int err = 0;
742
743 if (elk_inst_access_mode(devinfo, inst) == ELK_ALIGN_1) {
744 if (elk_inst_dst_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
745 err |= reg(file, elk_inst_dst_reg_file(devinfo, inst),
746 elk_inst_dst_da_reg_nr(devinfo, inst));
747 if (err == -1)
748 return 0;
749 if (elk_inst_dst_da1_subreg_nr(devinfo, inst))
750 format(file, ".%"PRIu64, elk_inst_dst_da1_subreg_nr(devinfo, inst) /
751 elem_size);
752 string(file, "<");
753 err |= control(file, "horiz stride", horiz_stride,
754 elk_inst_dst_hstride(devinfo, inst), NULL);
755 string(file, ">");
756 string(file, elk_reg_type_to_letters(type));
757 } else {
758 string(file, "g[a0");
759 if (elk_inst_dst_ia_subreg_nr(devinfo, inst))
760 format(file, ".%"PRIu64, elk_inst_dst_ia_subreg_nr(devinfo, inst) /
761 elem_size);
762 if (elk_inst_dst_ia1_addr_imm(devinfo, inst))
763 format(file, " %d", elk_inst_dst_ia1_addr_imm(devinfo, inst));
764 string(file, "]<");
765 err |= control(file, "horiz stride", horiz_stride,
766 elk_inst_dst_hstride(devinfo, inst), NULL);
767 string(file, ">");
768 string(file, elk_reg_type_to_letters(type));
769 }
770 } else {
771 if (elk_inst_dst_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
772 err |= reg(file, elk_inst_dst_reg_file(devinfo, inst),
773 elk_inst_dst_da_reg_nr(devinfo, inst));
774 if (err == -1)
775 return 0;
776 if (elk_inst_dst_da16_subreg_nr(devinfo, inst))
777 format(file, ".%u", 16 / elem_size);
778 string(file, "<1>");
779 err |= control(file, "writemask", writemask,
780 elk_inst_da16_writemask(devinfo, inst), NULL);
781 string(file, elk_reg_type_to_letters(type));
782 } else {
783 err = 1;
784 string(file, "Indirect align16 address mode not supported");
785 }
786 }
787
788 return 0;
789 }
790
791 static int
dest_3src(FILE * file,const struct intel_device_info * devinfo,const elk_inst * inst)792 dest_3src(FILE *file, const struct intel_device_info *devinfo,
793 const elk_inst *inst)
794 {
795 bool is_align1 = elk_inst_3src_access_mode(devinfo, inst) == ELK_ALIGN_1;
796 int err = 0;
797 uint32_t reg_file;
798 unsigned subreg_nr;
799 enum elk_reg_type type;
800
801 if (is_align1)
802 return 0;
803
804 if (devinfo->ver == 6 && elk_inst_3src_a16_dst_reg_file(devinfo, inst))
805 reg_file = ELK_MESSAGE_REGISTER_FILE;
806 else
807 reg_file = ELK_GENERAL_REGISTER_FILE;
808
809 err |= reg(file, reg_file, elk_inst_3src_dst_reg_nr(devinfo, inst));
810 if (err == -1)
811 return 0;
812
813 type = elk_inst_3src_a16_dst_type(devinfo, inst);
814 subreg_nr = elk_inst_3src_a16_dst_subreg_nr(devinfo, inst) * 4;
815 subreg_nr /= elk_reg_type_to_size(type);
816
817 if (subreg_nr)
818 format(file, ".%u", subreg_nr);
819 string(file, "<1>");
820
821 if (!is_align1) {
822 err |= control(file, "writemask", writemask,
823 elk_inst_3src_a16_dst_writemask(devinfo, inst), NULL);
824 }
825 string(file, elk_reg_type_to_letters(type));
826
827 return 0;
828 }
829
830 static int
src_align1_region(FILE * file,unsigned _vert_stride,unsigned _width,unsigned _horiz_stride)831 src_align1_region(FILE *file,
832 unsigned _vert_stride, unsigned _width,
833 unsigned _horiz_stride)
834 {
835 int err = 0;
836 string(file, "<");
837 err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
838 string(file, ",");
839 err |= control(file, "width", width, _width, NULL);
840 string(file, ",");
841 err |= control(file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
842 string(file, ">");
843 return err;
844 }
845
846 static int
src_da1(FILE * file,const struct intel_device_info * devinfo,unsigned opcode,enum elk_reg_type type,unsigned _reg_file,unsigned _vert_stride,unsigned _width,unsigned _horiz_stride,unsigned reg_num,unsigned sub_reg_num,unsigned __abs,unsigned _negate)847 src_da1(FILE *file,
848 const struct intel_device_info *devinfo,
849 unsigned opcode,
850 enum elk_reg_type type, unsigned _reg_file,
851 unsigned _vert_stride, unsigned _width, unsigned _horiz_stride,
852 unsigned reg_num, unsigned sub_reg_num, unsigned __abs,
853 unsigned _negate)
854 {
855 int err = 0;
856
857 if (devinfo->ver >= 8 && is_logic_instruction(opcode))
858 err |= control(file, "bitnot", m_bitnot, _negate, NULL);
859 else
860 err |= control(file, "negate", m_negate, _negate, NULL);
861
862 err |= control(file, "abs", _abs, __abs, NULL);
863
864 err |= reg(file, _reg_file, reg_num);
865 if (err == -1)
866 return 0;
867 if (sub_reg_num) {
868 unsigned elem_size = elk_reg_type_to_size(type);
869 format(file, ".%d", sub_reg_num / elem_size); /* use formal style like spec */
870 }
871 src_align1_region(file, _vert_stride, _width, _horiz_stride);
872 string(file, elk_reg_type_to_letters(type));
873 return err;
874 }
875
876 static int
src_ia1(FILE * file,const struct intel_device_info * devinfo,unsigned opcode,enum elk_reg_type type,int _addr_imm,unsigned _addr_subreg_nr,unsigned _negate,unsigned __abs,unsigned _horiz_stride,unsigned _width,unsigned _vert_stride)877 src_ia1(FILE *file,
878 const struct intel_device_info *devinfo,
879 unsigned opcode,
880 enum elk_reg_type type,
881 int _addr_imm,
882 unsigned _addr_subreg_nr,
883 unsigned _negate,
884 unsigned __abs,
885 unsigned _horiz_stride, unsigned _width, unsigned _vert_stride)
886 {
887 int err = 0;
888
889 if (devinfo->ver >= 8 && is_logic_instruction(opcode))
890 err |= control(file, "bitnot", m_bitnot, _negate, NULL);
891 else
892 err |= control(file, "negate", m_negate, _negate, NULL);
893
894 err |= control(file, "abs", _abs, __abs, NULL);
895
896 string(file, "g[a0");
897 if (_addr_subreg_nr)
898 format(file, ".%d", _addr_subreg_nr);
899 if (_addr_imm)
900 format(file, " %d", _addr_imm);
901 string(file, "]");
902 src_align1_region(file, _vert_stride, _width, _horiz_stride);
903 string(file, elk_reg_type_to_letters(type));
904 return err;
905 }
906
907 static int
src_swizzle(FILE * file,unsigned swiz)908 src_swizzle(FILE *file, unsigned swiz)
909 {
910 unsigned x = ELK_GET_SWZ(swiz, ELK_CHANNEL_X);
911 unsigned y = ELK_GET_SWZ(swiz, ELK_CHANNEL_Y);
912 unsigned z = ELK_GET_SWZ(swiz, ELK_CHANNEL_Z);
913 unsigned w = ELK_GET_SWZ(swiz, ELK_CHANNEL_W);
914 int err = 0;
915
916 if (x == y && x == z && x == w) {
917 string(file, ".");
918 err |= control(file, "channel select", chan_sel, x, NULL);
919 } else if (swiz != ELK_SWIZZLE_XYZW) {
920 string(file, ".");
921 err |= control(file, "channel select", chan_sel, x, NULL);
922 err |= control(file, "channel select", chan_sel, y, NULL);
923 err |= control(file, "channel select", chan_sel, z, NULL);
924 err |= control(file, "channel select", chan_sel, w, NULL);
925 }
926 return err;
927 }
928
929 static int
src_da16(FILE * file,const struct intel_device_info * devinfo,unsigned opcode,enum elk_reg_type type,unsigned _reg_file,unsigned _vert_stride,unsigned _reg_nr,unsigned _subreg_nr,unsigned __abs,unsigned _negate,unsigned swz_x,unsigned swz_y,unsigned swz_z,unsigned swz_w)930 src_da16(FILE *file,
931 const struct intel_device_info *devinfo,
932 unsigned opcode,
933 enum elk_reg_type type,
934 unsigned _reg_file,
935 unsigned _vert_stride,
936 unsigned _reg_nr,
937 unsigned _subreg_nr,
938 unsigned __abs,
939 unsigned _negate,
940 unsigned swz_x, unsigned swz_y, unsigned swz_z, unsigned swz_w)
941 {
942 int err = 0;
943
944 if (devinfo->ver >= 8 && is_logic_instruction(opcode))
945 err |= control(file, "bitnot", m_bitnot, _negate, NULL);
946 else
947 err |= control(file, "negate", m_negate, _negate, NULL);
948
949 err |= control(file, "abs", _abs, __abs, NULL);
950
951 err |= reg(file, _reg_file, _reg_nr);
952 if (err == -1)
953 return 0;
954 if (_subreg_nr) {
955 unsigned elem_size = elk_reg_type_to_size(type);
956
957 /* bit4 for subreg number byte addressing. Make this same meaning as
958 in da1 case, so output looks consistent. */
959 format(file, ".%d", 16 / elem_size);
960 }
961 string(file, "<");
962 err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
963 string(file, ">");
964 err |= src_swizzle(file, ELK_SWIZZLE4(swz_x, swz_y, swz_z, swz_w));
965 string(file, elk_reg_type_to_letters(type));
966 return err;
967 }
968
969 static enum elk_vertical_stride
vstride_from_align1_3src_vstride(const struct intel_device_info * devinfo,enum gfx10_align1_3src_vertical_stride vstride)970 vstride_from_align1_3src_vstride(const struct intel_device_info *devinfo,
971 enum gfx10_align1_3src_vertical_stride vstride)
972 {
973 switch (vstride) {
974 case ELK_ALIGN1_3SRC_VERTICAL_STRIDE_0: return ELK_VERTICAL_STRIDE_0;
975 case ELK_ALIGN1_3SRC_VERTICAL_STRIDE_2: return ELK_VERTICAL_STRIDE_2;
976 case ELK_ALIGN1_3SRC_VERTICAL_STRIDE_4: return ELK_VERTICAL_STRIDE_4;
977 case ELK_ALIGN1_3SRC_VERTICAL_STRIDE_8: return ELK_VERTICAL_STRIDE_8;
978 default:
979 unreachable("not reached");
980 }
981 }
982
983 static enum elk_horizontal_stride
hstride_from_align1_3src_hstride(enum gfx10_align1_3src_src_horizontal_stride hstride)984 hstride_from_align1_3src_hstride(enum gfx10_align1_3src_src_horizontal_stride hstride)
985 {
986 switch (hstride) {
987 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_0: return ELK_HORIZONTAL_STRIDE_0;
988 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_1: return ELK_HORIZONTAL_STRIDE_1;
989 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_2: return ELK_HORIZONTAL_STRIDE_2;
990 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_4: return ELK_HORIZONTAL_STRIDE_4;
991 default:
992 unreachable("not reached");
993 }
994 }
995
996 static enum elk_vertical_stride
vstride_from_align1_3src_hstride(enum gfx10_align1_3src_src_horizontal_stride hstride)997 vstride_from_align1_3src_hstride(enum gfx10_align1_3src_src_horizontal_stride hstride)
998 {
999 switch (hstride) {
1000 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_0: return ELK_VERTICAL_STRIDE_0;
1001 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_1: return ELK_VERTICAL_STRIDE_1;
1002 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_2: return ELK_VERTICAL_STRIDE_2;
1003 case ELK_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_4: return ELK_VERTICAL_STRIDE_4;
1004 default:
1005 unreachable("not reached");
1006 }
1007 }
1008
1009 /* From "GFX10 Regioning Rules for Align1 Ternary Operations" in the
1010 * "Register Region Restrictions" documentation
1011 */
1012 static enum elk_width
implied_width(enum elk_vertical_stride _vert_stride,enum elk_horizontal_stride _horiz_stride)1013 implied_width(enum elk_vertical_stride _vert_stride,
1014 enum elk_horizontal_stride _horiz_stride)
1015 {
1016 /* "1. Width is 1 when Vertical and Horizontal Strides are both zero." */
1017 if (_vert_stride == ELK_VERTICAL_STRIDE_0 &&
1018 _horiz_stride == ELK_HORIZONTAL_STRIDE_0) {
1019 return ELK_WIDTH_1;
1020
1021 /* "2. Width is equal to vertical stride when Horizontal Stride is zero." */
1022 } else if (_horiz_stride == ELK_HORIZONTAL_STRIDE_0) {
1023 switch (_vert_stride) {
1024 case ELK_VERTICAL_STRIDE_1: return ELK_WIDTH_1;
1025 case ELK_VERTICAL_STRIDE_2: return ELK_WIDTH_2;
1026 case ELK_VERTICAL_STRIDE_4: return ELK_WIDTH_4;
1027 case ELK_VERTICAL_STRIDE_8: return ELK_WIDTH_8;
1028 case ELK_VERTICAL_STRIDE_0:
1029 default:
1030 unreachable("not reached");
1031 }
1032
1033 } else {
1034 /* FINISHME: Implement these: */
1035
1036 /* "3. Width is equal to Vertical Stride/Horizontal Stride when both
1037 * Strides are non-zero.
1038 *
1039 * 4. Vertical Stride must not be zero if Horizontal Stride is non-zero.
1040 * This implies Vertical Stride is always greater than Horizontal
1041 * Stride."
1042 *
1043 * Given these statements and the knowledge that the stride and width
1044 * values are encoded in logarithmic form, we can perform the division
1045 * by just subtracting.
1046 */
1047 return _vert_stride - _horiz_stride;
1048 }
1049 }
1050
1051 static int
src0_3src(FILE * file,const struct intel_device_info * devinfo,const elk_inst * inst)1052 src0_3src(FILE *file, const struct intel_device_info *devinfo,
1053 const elk_inst *inst)
1054 {
1055 int err = 0;
1056 unsigned reg_nr, subreg_nr;
1057 enum elk_reg_file _file;
1058 enum elk_reg_type type;
1059 enum elk_vertical_stride _vert_stride;
1060 enum elk_width _width;
1061 enum elk_horizontal_stride _horiz_stride;
1062 bool is_scalar_region;
1063 bool is_align1 = elk_inst_3src_access_mode(devinfo, inst) == ELK_ALIGN_1;
1064
1065 if (is_align1)
1066 return 0;
1067
1068 _file = ELK_GENERAL_REGISTER_FILE;
1069 reg_nr = elk_inst_3src_src0_reg_nr(devinfo, inst);
1070 subreg_nr = elk_inst_3src_a16_src0_subreg_nr(devinfo, inst) * 4;
1071 type = elk_inst_3src_a16_src_type(devinfo, inst);
1072
1073 if (elk_inst_3src_a16_src0_rep_ctrl(devinfo, inst)) {
1074 _vert_stride = ELK_VERTICAL_STRIDE_0;
1075 _width = ELK_WIDTH_1;
1076 _horiz_stride = ELK_HORIZONTAL_STRIDE_0;
1077 } else {
1078 _vert_stride = ELK_VERTICAL_STRIDE_4;
1079 _width = ELK_WIDTH_4;
1080 _horiz_stride = ELK_HORIZONTAL_STRIDE_1;
1081 }
1082
1083 is_scalar_region = _vert_stride == ELK_VERTICAL_STRIDE_0 &&
1084 _width == ELK_WIDTH_1 &&
1085 _horiz_stride == ELK_HORIZONTAL_STRIDE_0;
1086
1087 subreg_nr /= elk_reg_type_to_size(type);
1088
1089 err |= control(file, "negate", m_negate,
1090 elk_inst_3src_src0_negate(devinfo, inst), NULL);
1091 err |= control(file, "abs", _abs, elk_inst_3src_src0_abs(devinfo, inst), NULL);
1092
1093 err |= reg(file, _file, reg_nr);
1094 if (err == -1)
1095 return 0;
1096 if (subreg_nr || is_scalar_region)
1097 format(file, ".%d", subreg_nr);
1098 src_align1_region(file, _vert_stride, _width, _horiz_stride);
1099 if (!is_scalar_region && !is_align1)
1100 err |= src_swizzle(file, elk_inst_3src_a16_src0_swizzle(devinfo, inst));
1101 string(file, elk_reg_type_to_letters(type));
1102 return err;
1103 }
1104
1105 static int
src1_3src(FILE * file,const struct intel_device_info * devinfo,const elk_inst * inst)1106 src1_3src(FILE *file, const struct intel_device_info *devinfo,
1107 const elk_inst *inst)
1108 {
1109 int err = 0;
1110 unsigned reg_nr, subreg_nr;
1111 enum elk_reg_file _file;
1112 enum elk_reg_type type;
1113 enum elk_vertical_stride _vert_stride;
1114 enum elk_width _width;
1115 enum elk_horizontal_stride _horiz_stride;
1116 bool is_scalar_region;
1117 bool is_align1 = elk_inst_3src_access_mode(devinfo, inst) == ELK_ALIGN_1;
1118
1119 if (is_align1)
1120 return 0;
1121
1122 _file = ELK_GENERAL_REGISTER_FILE;
1123 reg_nr = elk_inst_3src_src1_reg_nr(devinfo, inst);
1124 subreg_nr = elk_inst_3src_a16_src1_subreg_nr(devinfo, inst) * 4;
1125 type = elk_inst_3src_a16_src_type(devinfo, inst);
1126
1127 if (elk_inst_3src_a16_src1_rep_ctrl(devinfo, inst)) {
1128 _vert_stride = ELK_VERTICAL_STRIDE_0;
1129 _width = ELK_WIDTH_1;
1130 _horiz_stride = ELK_HORIZONTAL_STRIDE_0;
1131 } else {
1132 _vert_stride = ELK_VERTICAL_STRIDE_4;
1133 _width = ELK_WIDTH_4;
1134 _horiz_stride = ELK_HORIZONTAL_STRIDE_1;
1135 }
1136
1137 is_scalar_region = _vert_stride == ELK_VERTICAL_STRIDE_0 &&
1138 _width == ELK_WIDTH_1 &&
1139 _horiz_stride == ELK_HORIZONTAL_STRIDE_0;
1140
1141 subreg_nr /= elk_reg_type_to_size(type);
1142
1143 err |= control(file, "negate", m_negate,
1144 elk_inst_3src_src1_negate(devinfo, inst), NULL);
1145 err |= control(file, "abs", _abs, elk_inst_3src_src1_abs(devinfo, inst), NULL);
1146
1147 err |= reg(file, _file, reg_nr);
1148 if (err == -1)
1149 return 0;
1150 if (subreg_nr || is_scalar_region)
1151 format(file, ".%d", subreg_nr);
1152 src_align1_region(file, _vert_stride, _width, _horiz_stride);
1153 if (!is_scalar_region && !is_align1)
1154 err |= src_swizzle(file, elk_inst_3src_a16_src1_swizzle(devinfo, inst));
1155 string(file, elk_reg_type_to_letters(type));
1156 return err;
1157 }
1158
1159 static int
src2_3src(FILE * file,const struct intel_device_info * devinfo,const elk_inst * inst)1160 src2_3src(FILE *file, const struct intel_device_info *devinfo,
1161 const elk_inst *inst)
1162 {
1163 int err = 0;
1164 unsigned reg_nr, subreg_nr;
1165 enum elk_reg_file _file;
1166 enum elk_reg_type type;
1167 enum elk_vertical_stride _vert_stride;
1168 enum elk_width _width;
1169 enum elk_horizontal_stride _horiz_stride;
1170 bool is_scalar_region;
1171 bool is_align1 = elk_inst_3src_access_mode(devinfo, inst) == ELK_ALIGN_1;
1172
1173 if (is_align1)
1174 return 0;
1175
1176 _file = ELK_GENERAL_REGISTER_FILE;
1177 reg_nr = elk_inst_3src_src2_reg_nr(devinfo, inst);
1178 subreg_nr = elk_inst_3src_a16_src2_subreg_nr(devinfo, inst) * 4;
1179 type = elk_inst_3src_a16_src_type(devinfo, inst);
1180
1181 if (elk_inst_3src_a16_src2_rep_ctrl(devinfo, inst)) {
1182 _vert_stride = ELK_VERTICAL_STRIDE_0;
1183 _width = ELK_WIDTH_1;
1184 _horiz_stride = ELK_HORIZONTAL_STRIDE_0;
1185 } else {
1186 _vert_stride = ELK_VERTICAL_STRIDE_4;
1187 _width = ELK_WIDTH_4;
1188 _horiz_stride = ELK_HORIZONTAL_STRIDE_1;
1189 }
1190
1191 is_scalar_region = _vert_stride == ELK_VERTICAL_STRIDE_0 &&
1192 _width == ELK_WIDTH_1 &&
1193 _horiz_stride == ELK_HORIZONTAL_STRIDE_0;
1194
1195 subreg_nr /= elk_reg_type_to_size(type);
1196
1197 err |= control(file, "negate", m_negate,
1198 elk_inst_3src_src2_negate(devinfo, inst), NULL);
1199 err |= control(file, "abs", _abs, elk_inst_3src_src2_abs(devinfo, inst), NULL);
1200
1201 err |= reg(file, _file, reg_nr);
1202 if (err == -1)
1203 return 0;
1204 if (subreg_nr || is_scalar_region)
1205 format(file, ".%d", subreg_nr);
1206 src_align1_region(file, _vert_stride, _width, _horiz_stride);
1207 if (!is_scalar_region && !is_align1)
1208 err |= src_swizzle(file, elk_inst_3src_a16_src2_swizzle(devinfo, inst));
1209 string(file, elk_reg_type_to_letters(type));
1210 return err;
1211 }
1212
1213 static int
imm(FILE * file,const struct elk_isa_info * isa,enum elk_reg_type type,const elk_inst * inst)1214 imm(FILE *file, const struct elk_isa_info *isa, enum elk_reg_type type,
1215 const elk_inst *inst)
1216 {
1217 const struct intel_device_info *devinfo = isa->devinfo;
1218
1219 switch (type) {
1220 case ELK_REGISTER_TYPE_UQ:
1221 format(file, "0x%016"PRIx64"UQ", elk_inst_imm_uq(devinfo, inst));
1222 break;
1223 case ELK_REGISTER_TYPE_Q:
1224 format(file, "0x%016"PRIx64"Q", elk_inst_imm_uq(devinfo, inst));
1225 break;
1226 case ELK_REGISTER_TYPE_UD:
1227 format(file, "0x%08xUD", elk_inst_imm_ud(devinfo, inst));
1228 break;
1229 case ELK_REGISTER_TYPE_D:
1230 format(file, "%dD", elk_inst_imm_d(devinfo, inst));
1231 break;
1232 case ELK_REGISTER_TYPE_UW:
1233 format(file, "0x%04xUW", (uint16_t) elk_inst_imm_ud(devinfo, inst));
1234 break;
1235 case ELK_REGISTER_TYPE_W:
1236 format(file, "%dW", (int16_t) elk_inst_imm_d(devinfo, inst));
1237 break;
1238 case ELK_REGISTER_TYPE_UV:
1239 format(file, "0x%08xUV", elk_inst_imm_ud(devinfo, inst));
1240 break;
1241 case ELK_REGISTER_TYPE_VF:
1242 format(file, "0x%"PRIx64"VF", elk_inst_bits(inst, 127, 96));
1243 pad(file, 48);
1244 format(file, "/* [%-gF, %-gF, %-gF, %-gF]VF */",
1245 elk_vf_to_float(elk_inst_imm_ud(devinfo, inst)),
1246 elk_vf_to_float(elk_inst_imm_ud(devinfo, inst) >> 8),
1247 elk_vf_to_float(elk_inst_imm_ud(devinfo, inst) >> 16),
1248 elk_vf_to_float(elk_inst_imm_ud(devinfo, inst) >> 24));
1249 break;
1250 case ELK_REGISTER_TYPE_V:
1251 format(file, "0x%08xV", elk_inst_imm_ud(devinfo, inst));
1252 break;
1253 case ELK_REGISTER_TYPE_F:
1254 /* The DIM instruction's src0 uses an F type but contains a
1255 * 64-bit immediate
1256 */
1257 if (elk_inst_opcode(isa, inst) == ELK_OPCODE_DIM) {
1258 format(file, "0x%"PRIx64"F", elk_inst_bits(inst, 127, 64));
1259 pad(file, 48);
1260 format(file, "/* %-gF */", elk_inst_imm_df(devinfo, inst));
1261 } else {
1262 format(file, "0x%"PRIx64"F", elk_inst_bits(inst, 127, 96));
1263 pad(file, 48);
1264 format(file, " /* %-gF */", elk_inst_imm_f(devinfo, inst));
1265 }
1266 break;
1267 case ELK_REGISTER_TYPE_DF:
1268 format(file, "0x%016"PRIx64"DF", elk_inst_imm_uq(devinfo, inst));
1269 pad(file, 48);
1270 format(file, "/* %-gDF */", elk_inst_imm_df(devinfo, inst));
1271 break;
1272 case ELK_REGISTER_TYPE_HF:
1273 format(file, "0x%04xHF",
1274 (uint16_t) elk_inst_imm_ud(devinfo, inst));
1275 pad(file, 48);
1276 format(file, "/* %-gHF */",
1277 _mesa_half_to_float((uint16_t) elk_inst_imm_ud(devinfo, inst)));
1278 break;
1279 case ELK_REGISTER_TYPE_NF:
1280 case ELK_REGISTER_TYPE_UB:
1281 case ELK_REGISTER_TYPE_B:
1282 format(file, "*** invalid immediate type %d ", type);
1283 }
1284 return 0;
1285 }
1286
1287 static int
src_send_desc_ia(FILE * file,const struct intel_device_info * devinfo,unsigned _addr_subreg_nr)1288 src_send_desc_ia(FILE *file,
1289 const struct intel_device_info *devinfo,
1290 unsigned _addr_subreg_nr)
1291 {
1292 string(file, "a0");
1293 if (_addr_subreg_nr)
1294 format(file, ".%d", _addr_subreg_nr);
1295 format(file, "<0>UD");
1296
1297 return 0;
1298 }
1299
1300 static int
src0(FILE * file,const struct elk_isa_info * isa,const elk_inst * inst)1301 src0(FILE *file, const struct elk_isa_info *isa, const elk_inst *inst)
1302 {
1303 const struct intel_device_info *devinfo = isa->devinfo;
1304
1305 if (elk_inst_src0_reg_file(devinfo, inst) == ELK_IMMEDIATE_VALUE) {
1306 return imm(file, isa, elk_inst_src0_type(devinfo, inst), inst);
1307 } else if (elk_inst_access_mode(devinfo, inst) == ELK_ALIGN_1) {
1308 if (elk_inst_src0_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
1309 return src_da1(file,
1310 devinfo,
1311 elk_inst_opcode(isa, inst),
1312 elk_inst_src0_type(devinfo, inst),
1313 elk_inst_src0_reg_file(devinfo, inst),
1314 elk_inst_src0_vstride(devinfo, inst),
1315 elk_inst_src0_width(devinfo, inst),
1316 elk_inst_src0_hstride(devinfo, inst),
1317 elk_inst_src0_da_reg_nr(devinfo, inst),
1318 elk_inst_src0_da1_subreg_nr(devinfo, inst),
1319 elk_inst_src0_abs(devinfo, inst),
1320 elk_inst_src0_negate(devinfo, inst));
1321 } else {
1322 return src_ia1(file,
1323 devinfo,
1324 elk_inst_opcode(isa, inst),
1325 elk_inst_src0_type(devinfo, inst),
1326 elk_inst_src0_ia1_addr_imm(devinfo, inst),
1327 elk_inst_src0_ia_subreg_nr(devinfo, inst),
1328 elk_inst_src0_negate(devinfo, inst),
1329 elk_inst_src0_abs(devinfo, inst),
1330 elk_inst_src0_hstride(devinfo, inst),
1331 elk_inst_src0_width(devinfo, inst),
1332 elk_inst_src0_vstride(devinfo, inst));
1333 }
1334 } else {
1335 if (elk_inst_src0_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
1336 return src_da16(file,
1337 devinfo,
1338 elk_inst_opcode(isa, inst),
1339 elk_inst_src0_type(devinfo, inst),
1340 elk_inst_src0_reg_file(devinfo, inst),
1341 elk_inst_src0_vstride(devinfo, inst),
1342 elk_inst_src0_da_reg_nr(devinfo, inst),
1343 elk_inst_src0_da16_subreg_nr(devinfo, inst),
1344 elk_inst_src0_abs(devinfo, inst),
1345 elk_inst_src0_negate(devinfo, inst),
1346 elk_inst_src0_da16_swiz_x(devinfo, inst),
1347 elk_inst_src0_da16_swiz_y(devinfo, inst),
1348 elk_inst_src0_da16_swiz_z(devinfo, inst),
1349 elk_inst_src0_da16_swiz_w(devinfo, inst));
1350 } else {
1351 string(file, "Indirect align16 address mode not supported");
1352 return 1;
1353 }
1354 }
1355 }
1356
1357 static int
src1(FILE * file,const struct elk_isa_info * isa,const elk_inst * inst)1358 src1(FILE *file, const struct elk_isa_info *isa, const elk_inst *inst)
1359 {
1360 const struct intel_device_info *devinfo = isa->devinfo;
1361
1362 if (elk_inst_src1_reg_file(devinfo, inst) == ELK_IMMEDIATE_VALUE) {
1363 return imm(file, isa, elk_inst_src1_type(devinfo, inst), inst);
1364 } else if (elk_inst_access_mode(devinfo, inst) == ELK_ALIGN_1) {
1365 if (elk_inst_src1_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
1366 return src_da1(file,
1367 devinfo,
1368 elk_inst_opcode(isa, inst),
1369 elk_inst_src1_type(devinfo, inst),
1370 elk_inst_src1_reg_file(devinfo, inst),
1371 elk_inst_src1_vstride(devinfo, inst),
1372 elk_inst_src1_width(devinfo, inst),
1373 elk_inst_src1_hstride(devinfo, inst),
1374 elk_inst_src1_da_reg_nr(devinfo, inst),
1375 elk_inst_src1_da1_subreg_nr(devinfo, inst),
1376 elk_inst_src1_abs(devinfo, inst),
1377 elk_inst_src1_negate(devinfo, inst));
1378 } else {
1379 return src_ia1(file,
1380 devinfo,
1381 elk_inst_opcode(isa, inst),
1382 elk_inst_src1_type(devinfo, inst),
1383 elk_inst_src1_ia1_addr_imm(devinfo, inst),
1384 elk_inst_src1_ia_subreg_nr(devinfo, inst),
1385 elk_inst_src1_negate(devinfo, inst),
1386 elk_inst_src1_abs(devinfo, inst),
1387 elk_inst_src1_hstride(devinfo, inst),
1388 elk_inst_src1_width(devinfo, inst),
1389 elk_inst_src1_vstride(devinfo, inst));
1390 }
1391 } else {
1392 if (elk_inst_src1_address_mode(devinfo, inst) == ELK_ADDRESS_DIRECT) {
1393 return src_da16(file,
1394 devinfo,
1395 elk_inst_opcode(isa, inst),
1396 elk_inst_src1_type(devinfo, inst),
1397 elk_inst_src1_reg_file(devinfo, inst),
1398 elk_inst_src1_vstride(devinfo, inst),
1399 elk_inst_src1_da_reg_nr(devinfo, inst),
1400 elk_inst_src1_da16_subreg_nr(devinfo, inst),
1401 elk_inst_src1_abs(devinfo, inst),
1402 elk_inst_src1_negate(devinfo, inst),
1403 elk_inst_src1_da16_swiz_x(devinfo, inst),
1404 elk_inst_src1_da16_swiz_y(devinfo, inst),
1405 elk_inst_src1_da16_swiz_z(devinfo, inst),
1406 elk_inst_src1_da16_swiz_w(devinfo, inst));
1407 } else {
1408 string(file, "Indirect align16 address mode not supported");
1409 return 1;
1410 }
1411 }
1412 }
1413
1414 static int
qtr_ctrl(FILE * file,const struct intel_device_info * devinfo,const elk_inst * inst)1415 qtr_ctrl(FILE *file, const struct intel_device_info *devinfo,
1416 const elk_inst *inst)
1417 {
1418 int qtr_ctl = elk_inst_qtr_control(devinfo, inst);
1419 int exec_size = 1 << elk_inst_exec_size(devinfo, inst);
1420 const unsigned nib_ctl =
1421 devinfo->ver < 7 ? 0 : elk_inst_nib_control(devinfo, inst);
1422
1423 if (exec_size < 8 || nib_ctl) {
1424 format(file, " %dN", qtr_ctl * 2 + nib_ctl + 1);
1425 } else if (exec_size == 8) {
1426 switch (qtr_ctl) {
1427 case 0:
1428 string(file, " 1Q");
1429 break;
1430 case 1:
1431 string(file, " 2Q");
1432 break;
1433 case 2:
1434 string(file, " 3Q");
1435 break;
1436 case 3:
1437 string(file, " 4Q");
1438 break;
1439 }
1440 } else if (exec_size == 16) {
1441 if (qtr_ctl < 2)
1442 string(file, " 1H");
1443 else
1444 string(file, " 2H");
1445 }
1446 return 0;
1447 }
1448
1449 static bool
inst_has_type(const struct elk_isa_info * isa,const elk_inst * inst,enum elk_reg_type type)1450 inst_has_type(const struct elk_isa_info *isa,
1451 const elk_inst *inst,
1452 enum elk_reg_type type)
1453 {
1454 const struct intel_device_info *devinfo = isa->devinfo;
1455 const unsigned num_sources = elk_num_sources_from_inst(isa, inst);
1456
1457 if (elk_inst_dst_type(devinfo, inst) == type)
1458 return true;
1459
1460 if (num_sources >= 3) {
1461 return elk_inst_3src_a16_src_type(devinfo, inst) == type;
1462 } else if (num_sources == 2) {
1463 return elk_inst_src0_type(devinfo, inst) == type ||
1464 elk_inst_src1_type(devinfo, inst) == type;
1465 } else {
1466 return elk_inst_src0_type(devinfo, inst) == type;
1467 }
1468 }
1469
1470 #if MESA_DEBUG
1471 static __attribute__((__unused__)) int
elk_disassemble_imm(const struct elk_isa_info * isa,uint32_t dw3,uint32_t dw2,uint32_t dw1,uint32_t dw0)1472 elk_disassemble_imm(const struct elk_isa_info *isa,
1473 uint32_t dw3, uint32_t dw2, uint32_t dw1, uint32_t dw0)
1474 {
1475 elk_inst inst;
1476 inst.data[0] = (((uint64_t) dw1) << 32) | ((uint64_t) dw0);
1477 inst.data[1] = (((uint64_t) dw3) << 32) | ((uint64_t) dw2);
1478 return elk_disassemble_inst(stderr, isa, &inst, false, 0, NULL);
1479 }
1480 #endif
1481
1482 static void
write_label(FILE * file,const struct intel_device_info * devinfo,const struct elk_label * root_label,int offset,int jump)1483 write_label(FILE *file, const struct intel_device_info *devinfo,
1484 const struct elk_label *root_label,
1485 int offset, int jump)
1486 {
1487 if (root_label != NULL) {
1488 int to_bytes_scale = sizeof(elk_inst) / elk_jump_scale(devinfo);
1489 const struct elk_label *label =
1490 elk_find_label(root_label, offset + jump * to_bytes_scale);
1491 if (label != NULL) {
1492 format(file, " LABEL%d", label->number);
1493 }
1494 }
1495 }
1496
1497 static void
lsc_disassemble_ex_desc(const struct intel_device_info * devinfo,uint32_t imm_desc,uint32_t imm_ex_desc,FILE * file)1498 lsc_disassemble_ex_desc(const struct intel_device_info *devinfo,
1499 uint32_t imm_desc,
1500 uint32_t imm_ex_desc,
1501 FILE *file)
1502 {
1503 const unsigned addr_type = lsc_msg_desc_addr_type(devinfo, imm_desc);
1504 switch (addr_type) {
1505 case LSC_ADDR_SURFTYPE_FLAT:
1506 format(file, " base_offset %u ",
1507 lsc_flat_ex_desc_base_offset(devinfo, imm_ex_desc));
1508 break;
1509 case LSC_ADDR_SURFTYPE_BSS:
1510 case LSC_ADDR_SURFTYPE_SS:
1511 format(file, " surface_state_index %u ",
1512 lsc_bss_ex_desc_index(devinfo, imm_ex_desc));
1513 break;
1514 case LSC_ADDR_SURFTYPE_BTI:
1515 format(file, " BTI %u ",
1516 lsc_bti_ex_desc_index(devinfo, imm_ex_desc));
1517 format(file, " base_offset %u ",
1518 lsc_bti_ex_desc_base_offset(devinfo, imm_ex_desc));
1519 break;
1520 default:
1521 format(file, "unsupported address surface type %d", addr_type);
1522 break;
1523 }
1524 }
1525
1526 int
elk_disassemble_inst(FILE * file,const struct elk_isa_info * isa,const elk_inst * inst,bool is_compacted,int offset,const struct elk_label * root_label)1527 elk_disassemble_inst(FILE *file, const struct elk_isa_info *isa,
1528 const elk_inst *inst, bool is_compacted,
1529 int offset, const struct elk_label *root_label)
1530 {
1531 const struct intel_device_info *devinfo = isa->devinfo;
1532
1533 int err = 0;
1534 int space = 0;
1535
1536 const enum elk_opcode opcode = elk_inst_opcode(isa, inst);
1537 const struct elk_opcode_desc *desc = elk_opcode_desc(isa, opcode);
1538
1539 if (elk_inst_pred_control(devinfo, inst)) {
1540 string(file, "(");
1541 err |= control(file, "predicate inverse", pred_inv,
1542 elk_inst_pred_inv(devinfo, inst), NULL);
1543 format(file, "f%"PRIu64".%"PRIu64,
1544 devinfo->ver >= 7 ? elk_inst_flag_reg_nr(devinfo, inst) : 0,
1545 elk_inst_flag_subreg_nr(devinfo, inst));
1546 if (elk_inst_access_mode(devinfo, inst) == ELK_ALIGN_1) {
1547 err |= control(file, "predicate control align1", pred_ctrl_align1,
1548 elk_inst_pred_control(devinfo, inst), NULL);
1549 } else {
1550 err |= control(file, "predicate control align16", elk_pred_ctrl_align16,
1551 elk_inst_pred_control(devinfo, inst), NULL);
1552 }
1553 string(file, ") ");
1554 }
1555
1556 err |= print_opcode(file, isa, opcode);
1557
1558 if (!is_send(opcode))
1559 err |= control(file, "saturate", saturate, elk_inst_saturate(devinfo, inst),
1560 NULL);
1561
1562 err |= control(file, "debug control", debug_ctrl,
1563 elk_inst_debug_control(devinfo, inst), NULL);
1564
1565 if (opcode == ELK_OPCODE_MATH) {
1566 string(file, " ");
1567 err |= control(file, "function", math_function,
1568 elk_inst_math_function(devinfo, inst), NULL);
1569
1570 } else if (!is_send(opcode)) {
1571 err |= control(file, "conditional modifier", elk_conditional_modifier,
1572 elk_inst_cond_modifier(devinfo, inst), NULL);
1573
1574 /* If we're using the conditional modifier, print which flags reg is
1575 * used for it. Note that on gfx6+, the embedded-condition SEL and
1576 * control flow doesn't update flags.
1577 */
1578 if (elk_inst_cond_modifier(devinfo, inst) &&
1579 (devinfo->ver < 6 || (opcode != ELK_OPCODE_SEL &&
1580 opcode != ELK_OPCODE_CSEL &&
1581 opcode != ELK_OPCODE_IF &&
1582 opcode != ELK_OPCODE_WHILE))) {
1583 format(file, ".f%"PRIu64".%"PRIu64,
1584 devinfo->ver >= 7 ? elk_inst_flag_reg_nr(devinfo, inst) : 0,
1585 elk_inst_flag_subreg_nr(devinfo, inst));
1586 }
1587 }
1588
1589 if (opcode != ELK_OPCODE_NOP && opcode != ELK_OPCODE_NENOP) {
1590 string(file, "(");
1591 err |= control(file, "execution size", exec_size,
1592 elk_inst_exec_size(devinfo, inst), NULL);
1593 string(file, ")");
1594 }
1595
1596 if (opcode == ELK_OPCODE_SEND && devinfo->ver < 6)
1597 format(file, " %"PRIu64, elk_inst_base_mrf(devinfo, inst));
1598
1599 if (elk_has_uip(devinfo, opcode)) {
1600 /* Instructions that have UIP also have JIP. */
1601 pad(file, 16);
1602 string(file, "JIP: ");
1603 write_label(file, devinfo, root_label, offset, elk_inst_jip(devinfo, inst));
1604
1605 pad(file, 38);
1606 string(file, "UIP: ");
1607 write_label(file, devinfo, root_label, offset, elk_inst_uip(devinfo, inst));
1608 } else if (elk_has_jip(devinfo, opcode)) {
1609 int jip;
1610 if (devinfo->ver >= 7) {
1611 jip = elk_inst_jip(devinfo, inst);
1612 } else {
1613 jip = elk_inst_gfx6_jump_count(devinfo, inst);
1614 }
1615
1616 pad(file, 16);
1617 string(file, "JIP: ");
1618 write_label(file, devinfo, root_label, offset, jip);
1619 } else if (devinfo->ver < 6 && (opcode == ELK_OPCODE_BREAK ||
1620 opcode == ELK_OPCODE_CONTINUE ||
1621 opcode == ELK_OPCODE_ELSE)) {
1622 pad(file, 16);
1623 format(file, "Jump: %d", elk_inst_gfx4_jump_count(devinfo, inst));
1624 pad(file, 32);
1625 format(file, "Pop: %"PRIu64, elk_inst_gfx4_pop_count(devinfo, inst));
1626 } else if (devinfo->ver < 6 && (opcode == ELK_OPCODE_IF ||
1627 opcode == ELK_OPCODE_IFF ||
1628 opcode == ELK_OPCODE_HALT ||
1629 opcode == ELK_OPCODE_WHILE)) {
1630 pad(file, 16);
1631 format(file, "Jump: %d", elk_inst_gfx4_jump_count(devinfo, inst));
1632 } else if (devinfo->ver < 6 && opcode == ELK_OPCODE_ENDIF) {
1633 pad(file, 16);
1634 format(file, "Pop: %"PRIu64, elk_inst_gfx4_pop_count(devinfo, inst));
1635 } else if (opcode == ELK_OPCODE_JMPI) {
1636 pad(file, 16);
1637 err |= src1(file, isa, inst);
1638 } else if (desc && desc->nsrc == 3) {
1639 pad(file, 16);
1640 err |= dest_3src(file, devinfo, inst);
1641
1642 pad(file, 32);
1643 err |= src0_3src(file, devinfo, inst);
1644
1645 pad(file, 48);
1646 err |= src1_3src(file, devinfo, inst);
1647
1648 pad(file, 64);
1649 err |= src2_3src(file, devinfo, inst);
1650 } else if (desc) {
1651 if (desc->ndst > 0) {
1652 pad(file, 16);
1653 err |= dest(file, isa, inst);
1654 }
1655
1656 if (desc->nsrc > 0) {
1657 pad(file, 32);
1658 err |= src0(file, isa, inst);
1659 }
1660
1661 if (desc->nsrc > 1) {
1662 pad(file, 48);
1663 err |= src1(file, isa, inst);
1664 }
1665 }
1666
1667 if (is_send(opcode)) {
1668 enum elk_message_target sfid = elk_inst_sfid(devinfo, inst);
1669
1670 bool has_imm_desc = false, has_imm_ex_desc = false;
1671 uint32_t imm_desc = 0, imm_ex_desc = 0;
1672 {
1673 if (elk_inst_src1_reg_file(devinfo, inst) != ELK_IMMEDIATE_VALUE) {
1674 /* show the indirect descriptor source */
1675 pad(file, 48);
1676 err |= src1(file, isa, inst);
1677 pad(file, 64);
1678 } else {
1679 has_imm_desc = true;
1680 imm_desc = elk_inst_send_desc(devinfo, inst);
1681 pad(file, 48);
1682 }
1683
1684 /* Print message descriptor as immediate source */
1685 fprintf(file, "0x%08"PRIx64, inst->data[1] >> 32);
1686 }
1687
1688 newline(file);
1689 pad(file, 16);
1690 space = 0;
1691
1692 fprintf(file, " ");
1693 err |= control(file, "SFID", devinfo->ver >= 6 ? gfx6_sfid : gfx4_sfid,
1694 sfid, &space);
1695 string(file, " MsgDesc:");
1696
1697 if (!has_imm_desc) {
1698 format(file, " indirect");
1699 } else {
1700 bool unsupported = false;
1701 switch (sfid) {
1702 case ELK_SFID_MATH:
1703 err |= control(file, "math function", math_function,
1704 elk_inst_math_msg_function(devinfo, inst), &space);
1705 err |= control(file, "math saturate", math_saturate,
1706 elk_inst_math_msg_saturate(devinfo, inst), &space);
1707 err |= control(file, "math signed", math_signed,
1708 elk_inst_math_msg_signed_int(devinfo, inst), &space);
1709 err |= control(file, "math scalar", math_scalar,
1710 elk_inst_math_msg_data_type(devinfo, inst), &space);
1711 err |= control(file, "math precision", math_precision,
1712 elk_inst_math_msg_precision(devinfo, inst), &space);
1713 break;
1714 case ELK_SFID_SAMPLER:
1715 if (devinfo->ver >= 5) {
1716 err |= control(file, "sampler message", gfx5_sampler_msg_type,
1717 elk_sampler_desc_msg_type(devinfo, imm_desc),
1718 &space);
1719 err |= control(file, "sampler simd mode", gfx5_sampler_simd_mode,
1720 elk_sampler_desc_simd_mode(devinfo, imm_desc),
1721 &space);
1722 if (devinfo->ver >= 8 &&
1723 elk_sampler_desc_return_format(devinfo, imm_desc)) {
1724 string(file, " HP");
1725 }
1726 format(file, " Surface = %u Sampler = %u",
1727 elk_sampler_desc_binding_table_index(devinfo, imm_desc),
1728 elk_sampler_desc_sampler(devinfo, imm_desc));
1729 } else {
1730 format(file, " (bti %u, sampler %u, msg_type %u, ",
1731 elk_sampler_desc_binding_table_index(devinfo, imm_desc),
1732 elk_sampler_desc_sampler(devinfo, imm_desc),
1733 elk_sampler_desc_msg_type(devinfo, imm_desc));
1734 if (devinfo->verx10 != 45) {
1735 err |= control(file, "sampler target format",
1736 sampler_target_format,
1737 elk_sampler_desc_return_format(devinfo, imm_desc),
1738 NULL);
1739 }
1740 string(file, ")");
1741 }
1742 break;
1743 case GFX6_SFID_DATAPORT_SAMPLER_CACHE:
1744 case GFX6_SFID_DATAPORT_CONSTANT_CACHE:
1745 /* aka ELK_SFID_DATAPORT_READ on Gfx4-5 */
1746 if (devinfo->ver >= 6) {
1747 format(file, " (bti %u, msg_ctrl %u, msg_type %u, write_commit %u)",
1748 elk_dp_desc_binding_table_index(devinfo, imm_desc),
1749 elk_dp_desc_msg_control(devinfo, imm_desc),
1750 elk_dp_desc_msg_type(devinfo, imm_desc),
1751 devinfo->ver >= 7 ? 0u :
1752 elk_dp_write_desc_write_commit(devinfo, imm_desc));
1753 } else {
1754 bool is_965 = devinfo->verx10 == 40;
1755 err |= control(file, "DP read message type",
1756 is_965 ? gfx4_dp_read_port_msg_type :
1757 g45_dp_read_port_msg_type,
1758 elk_dp_read_desc_msg_type(devinfo, imm_desc),
1759 &space);
1760
1761 format(file, " MsgCtrl = 0x%u",
1762 elk_dp_read_desc_msg_control(devinfo, imm_desc));
1763
1764 format(file, " Surface = %u",
1765 elk_dp_desc_binding_table_index(devinfo, imm_desc));
1766 }
1767 break;
1768
1769 case GFX6_SFID_DATAPORT_RENDER_CACHE: {
1770 /* aka ELK_SFID_DATAPORT_WRITE on Gfx4-5 */
1771 unsigned msg_type = elk_fb_write_desc_msg_type(devinfo, imm_desc);
1772
1773 err |= control(file, "DP rc message type",
1774 dp_rc_msg_type(devinfo), msg_type, &space);
1775
1776 bool is_rt_write = msg_type ==
1777 (devinfo->ver >= 6 ? GFX6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE
1778 : ELK_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE);
1779
1780 if (is_rt_write) {
1781 err |= control(file, "RT message type", m_rt_write_subtype,
1782 elk_inst_rt_message_type(devinfo, inst), &space);
1783 if (devinfo->ver >= 6 && elk_inst_rt_slot_group(devinfo, inst))
1784 string(file, " Hi");
1785 if (elk_fb_write_desc_last_render_target(devinfo, imm_desc))
1786 string(file, " LastRT");
1787 if (devinfo->ver < 7 &&
1788 elk_fb_write_desc_write_commit(devinfo, imm_desc))
1789 string(file, " WriteCommit");
1790 } else {
1791 format(file, " MsgCtrl = 0x%u",
1792 elk_fb_write_desc_msg_control(devinfo, imm_desc));
1793 }
1794
1795 format(file, " Surface = %u",
1796 elk_fb_desc_binding_table_index(devinfo, imm_desc));
1797 break;
1798 }
1799
1800 case ELK_SFID_URB: {
1801 unsigned urb_opcode = elk_inst_urb_opcode(devinfo, inst);
1802
1803 format(file, " offset %"PRIu64, elk_inst_urb_global_offset(devinfo, inst));
1804
1805 space = 1;
1806
1807 err |= control(file, "urb opcode",
1808 devinfo->ver >= 7 ? gfx7_urb_opcode
1809 : gfx5_urb_opcode,
1810 urb_opcode, &space);
1811
1812 if (devinfo->ver >= 7 &&
1813 elk_inst_urb_per_slot_offset(devinfo, inst)) {
1814 string(file, " per-slot");
1815 }
1816
1817 if (urb_opcode == GFX8_URB_OPCODE_SIMD8_WRITE ||
1818 urb_opcode == GFX8_URB_OPCODE_SIMD8_READ) {
1819 if (elk_inst_urb_channel_mask_present(devinfo, inst))
1820 string(file, " masked");
1821 } else {
1822 err |= control(file, "urb swizzle", urb_swizzle,
1823 elk_inst_urb_swizzle_control(devinfo, inst),
1824 &space);
1825 }
1826
1827 if (devinfo->ver < 7) {
1828 err |= control(file, "urb allocate", urb_allocate,
1829 elk_inst_urb_allocate(devinfo, inst), &space);
1830 err |= control(file, "urb used", urb_used,
1831 elk_inst_urb_used(devinfo, inst), &space);
1832 }
1833 if (devinfo->ver < 8) {
1834 err |= control(file, "urb complete", urb_complete,
1835 elk_inst_urb_complete(devinfo, inst), &space);
1836 }
1837 break;
1838 }
1839 case ELK_SFID_THREAD_SPAWNER:
1840 break;
1841
1842 case ELK_SFID_MESSAGE_GATEWAY:
1843 format(file, " (%s)",
1844 gfx7_gateway_subfuncid[elk_inst_gateway_subfuncid(devinfo, inst)]);
1845 break;
1846
1847 case GFX7_SFID_DATAPORT_DATA_CACHE:
1848 if (devinfo->ver >= 7) {
1849 format(file, " (");
1850 space = 0;
1851
1852 err |= control(file, "DP DC0 message type",
1853 dp_dc0_msg_type_gfx7,
1854 elk_dp_desc_msg_type(devinfo, imm_desc), &space);
1855
1856 format(file, ", bti %u, ",
1857 elk_dp_desc_binding_table_index(devinfo, imm_desc));
1858
1859 switch (elk_inst_dp_msg_type(devinfo, inst)) {
1860 case GFX7_DATAPORT_DC_UNTYPED_ATOMIC_OP:
1861 control(file, "atomic op", aop,
1862 elk_dp_desc_msg_control(devinfo, imm_desc) & 0xf,
1863 &space);
1864 break;
1865 case GFX7_DATAPORT_DC_OWORD_BLOCK_READ:
1866 case GFX7_DATAPORT_DC_OWORD_BLOCK_WRITE: {
1867 unsigned msg_ctrl = elk_dp_desc_msg_control(devinfo, imm_desc);
1868 assert(dp_oword_block_rw[msg_ctrl & 7]);
1869 format(file, "owords = %s, aligned = %d",
1870 dp_oword_block_rw[msg_ctrl & 7], (msg_ctrl >> 3) & 3);
1871 break;
1872 }
1873 default:
1874 format(file, "%u",
1875 elk_dp_desc_msg_control(devinfo, imm_desc));
1876 }
1877 format(file, ")");
1878 } else {
1879 unsupported = true;
1880 }
1881 break;
1882
1883 case HSW_SFID_DATAPORT_DATA_CACHE_1: {
1884 if (devinfo->ver >= 7) {
1885 format(file, " (");
1886 space = 0;
1887
1888 unsigned msg_ctrl = elk_dp_desc_msg_control(devinfo, imm_desc);
1889
1890 err |= control(file, "DP DC1 message type",
1891 dp_dc1_msg_type_hsw,
1892 elk_dp_desc_msg_type(devinfo, imm_desc), &space);
1893
1894 format(file, ", Surface = %u, ",
1895 elk_dp_desc_binding_table_index(devinfo, imm_desc));
1896
1897 switch (elk_inst_dp_msg_type(devinfo, inst)) {
1898 case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP:
1899 case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP:
1900 case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP:
1901 format(file, "SIMD%d,", (msg_ctrl & (1 << 4)) ? 8 : 16);
1902 FALLTHROUGH;
1903 case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2:
1904 case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2:
1905 case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2:
1906 case GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP:
1907 control(file, "atomic op", aop, msg_ctrl & 0xf, &space);
1908 break;
1909 case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ:
1910 case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE:
1911 case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ:
1912 case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE:
1913 case GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE:
1914 case GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ: {
1915 static const char *simd_modes[] = { "4x2", "16", "8" };
1916 format(file, "SIMD%s, Mask = 0x%x",
1917 simd_modes[msg_ctrl >> 4], msg_ctrl & 0xf);
1918 break;
1919 }
1920 case GFX8_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_WRITE:
1921 case GFX8_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_READ:
1922 assert(dp_oword_block_rw[msg_ctrl & 7]);
1923 format(file, "owords = %s, aligned = %d",
1924 dp_oword_block_rw[msg_ctrl & 7], (msg_ctrl >> 3) & 3);
1925 break;
1926 default:
1927 format(file, "0x%x", msg_ctrl);
1928 }
1929 format(file, ")");
1930 } else {
1931 unsupported = true;
1932 }
1933 break;
1934 }
1935
1936 case GFX7_SFID_PIXEL_INTERPOLATOR:
1937 if (devinfo->ver >= 7) {
1938 format(file, " (%s, %s, 0x%02"PRIx64")",
1939 elk_inst_pi_nopersp(devinfo, inst) ? "linear" : "persp",
1940 pixel_interpolator_msg_types[elk_inst_pi_message_type(devinfo, inst)],
1941 elk_inst_pi_message_data(devinfo, inst));
1942 } else {
1943 unsupported = true;
1944 }
1945 break;
1946
1947 default:
1948 unsupported = true;
1949 break;
1950 }
1951
1952 if (unsupported)
1953 format(file, "unsupported shared function ID %d", sfid);
1954
1955 if (space)
1956 string(file, " ");
1957 }
1958 if (has_imm_desc)
1959 format(file, " mlen %u", elk_message_desc_mlen(devinfo, imm_desc));
1960 if (has_imm_ex_desc) {
1961 format(file, " ex_mlen %u",
1962 elk_message_ex_desc_ex_mlen(devinfo, imm_ex_desc));
1963 }
1964 if (has_imm_desc)
1965 format(file, " rlen %u", elk_message_desc_rlen(devinfo, imm_desc));
1966 }
1967 pad(file, 64);
1968 if (opcode != ELK_OPCODE_NOP && opcode != ELK_OPCODE_NENOP) {
1969 string(file, "{");
1970 space = 1;
1971 err |= control(file, "access mode", access_mode,
1972 elk_inst_access_mode(devinfo, inst), &space);
1973 if (devinfo->ver >= 6) {
1974 err |= control(file, "write enable control", wectrl,
1975 elk_inst_mask_control(devinfo, inst), &space);
1976 } else {
1977 err |= control(file, "mask control", mask_ctrl,
1978 elk_inst_mask_control(devinfo, inst), &space);
1979 }
1980
1981 err |= control(file, "dependency control", dep_ctrl,
1982 ((elk_inst_no_dd_check(devinfo, inst) << 1) |
1983 elk_inst_no_dd_clear(devinfo, inst)), &space);
1984
1985 if (devinfo->ver >= 6)
1986 err |= qtr_ctrl(file, devinfo, inst);
1987 else {
1988 if (elk_inst_qtr_control(devinfo, inst) == ELK_COMPRESSION_COMPRESSED &&
1989 desc && desc->ndst > 0 &&
1990 elk_inst_dst_reg_file(devinfo, inst) == ELK_MESSAGE_REGISTER_FILE &&
1991 elk_inst_dst_da_reg_nr(devinfo, inst) & ELK_MRF_COMPR4) {
1992 format(file, " compr4");
1993 } else {
1994 err |= control(file, "compression control", compr_ctrl,
1995 elk_inst_qtr_control(devinfo, inst), &space);
1996 }
1997 }
1998
1999 err |= control(file, "compaction", cmpt_ctrl, is_compacted, &space);
2000 err |= control(file, "thread control", thread_ctrl,
2001 elk_inst_thread_control(devinfo, inst),
2002 &space);
2003 if (elk_has_branch_ctrl(devinfo, opcode)) {
2004 err |= control(file, "branch ctrl", branch_ctrl,
2005 elk_inst_branch_control(devinfo, inst), &space);
2006 } else if (devinfo->ver >= 6) {
2007 err |= control(file, "acc write control", accwr,
2008 elk_inst_acc_wr_control(devinfo, inst), &space);
2009 }
2010 if (is_send(opcode))
2011 err |= control(file, "end of thread", end_of_thread,
2012 elk_inst_eot(devinfo, inst), &space);
2013 if (space)
2014 string(file, " ");
2015 string(file, "}");
2016 }
2017 string(file, ";");
2018 newline(file);
2019 return err;
2020 }
2021
2022 int
elk_disassemble_find_end(const struct elk_isa_info * isa,const void * assembly,int start)2023 elk_disassemble_find_end(const struct elk_isa_info *isa,
2024 const void *assembly, int start)
2025 {
2026 const struct intel_device_info *devinfo = isa->devinfo;
2027 int offset = start;
2028
2029 /* This loop exits when send-with-EOT or when opcode is 0 */
2030 while (true) {
2031 const elk_inst *insn = assembly + offset;
2032
2033 if (elk_inst_cmpt_control(devinfo, insn)) {
2034 offset += 8;
2035 } else {
2036 offset += 16;
2037 }
2038
2039 /* Simplistic, but efficient way to terminate disasm */
2040 uint32_t opcode = elk_inst_opcode(isa, insn);
2041 if (opcode == 0 || (is_send(opcode) && elk_inst_eot(devinfo, insn))) {
2042 break;
2043 }
2044 }
2045
2046 return offset;
2047 }
2048
2049 void
elk_disassemble_with_errors(const struct elk_isa_info * isa,const void * assembly,int start,FILE * out)2050 elk_disassemble_with_errors(const struct elk_isa_info *isa,
2051 const void *assembly, int start, FILE *out)
2052 {
2053 int end = elk_disassemble_find_end(isa, assembly, start);
2054
2055 /* Make a dummy disasm structure that elk_validate_instructions
2056 * can work from.
2057 */
2058 struct elk_disasm_info *elk_disasm_info = elk_disasm_initialize(isa, NULL);
2059 elk_disasm_new_inst_group(elk_disasm_info, start);
2060 elk_disasm_new_inst_group(elk_disasm_info, end);
2061
2062 elk_validate_instructions(isa, assembly, start, end, elk_disasm_info);
2063
2064 void *mem_ctx = ralloc_context(NULL);
2065 const struct elk_label *root_label =
2066 elk_label_assembly(isa, assembly, start, end, mem_ctx);
2067
2068 foreach_list_typed(struct inst_group, group, link,
2069 &elk_disasm_info->group_list) {
2070 struct exec_node *next_node = exec_node_get_next(&group->link);
2071 if (exec_node_is_tail_sentinel(next_node))
2072 break;
2073
2074 struct inst_group *next =
2075 exec_node_data(struct inst_group, next_node, link);
2076
2077 int start_offset = group->offset;
2078 int end_offset = next->offset;
2079
2080 elk_disassemble(isa, assembly, start_offset, end_offset,
2081 root_label, out);
2082
2083 if (group->error) {
2084 fputs(group->error, out);
2085 }
2086 }
2087
2088 ralloc_free(mem_ctx);
2089 ralloc_free(elk_disasm_info);
2090 }
2091