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 <string.h>
25 #include <stdarg.h>
26 
27 #include "brw_eu_defines.h"
28 #include "brw_inst.h"
29 #include "brw_shader.h"
30 #include "brw_reg.h"
31 #include "brw_inst.h"
32 #include "brw_eu.h"
33 #include "util/half_float.h"
34 
35 bool
brw_has_jip(const struct gen_device_info * devinfo,enum opcode opcode)36 brw_has_jip(const struct gen_device_info *devinfo, enum opcode opcode)
37 {
38    if (devinfo->gen < 6)
39       return false;
40 
41    return opcode == BRW_OPCODE_IF ||
42           opcode == BRW_OPCODE_ELSE ||
43           opcode == BRW_OPCODE_ENDIF ||
44           opcode == BRW_OPCODE_WHILE ||
45           opcode == BRW_OPCODE_BREAK ||
46           opcode == BRW_OPCODE_CONTINUE ||
47           opcode == BRW_OPCODE_HALT;
48 }
49 
50 bool
brw_has_uip(const struct gen_device_info * devinfo,enum opcode opcode)51 brw_has_uip(const struct gen_device_info *devinfo, enum opcode opcode)
52 {
53    if (devinfo->gen < 6)
54       return false;
55 
56    return (devinfo->gen >= 7 && opcode == BRW_OPCODE_IF) ||
57           (devinfo->gen >= 8 && opcode == BRW_OPCODE_ELSE) ||
58           opcode == BRW_OPCODE_BREAK ||
59           opcode == BRW_OPCODE_CONTINUE ||
60           opcode == BRW_OPCODE_HALT;
61 }
62 
63 static bool
has_branch_ctrl(const struct gen_device_info * devinfo,enum opcode opcode)64 has_branch_ctrl(const struct gen_device_info *devinfo, enum opcode opcode)
65 {
66    if (devinfo->gen < 8)
67       return false;
68 
69    return opcode == BRW_OPCODE_IF ||
70           opcode == BRW_OPCODE_ELSE;
71           /* opcode == BRW_OPCODE_GOTO; */
72 }
73 
74 static bool
is_logic_instruction(unsigned opcode)75 is_logic_instruction(unsigned opcode)
76 {
77    return opcode == BRW_OPCODE_AND ||
78           opcode == BRW_OPCODE_NOT ||
79           opcode == BRW_OPCODE_OR ||
80           opcode == BRW_OPCODE_XOR;
81 }
82 
83 static bool
is_send(unsigned opcode)84 is_send(unsigned opcode)
85 {
86    return opcode == BRW_OPCODE_SEND ||
87           opcode == BRW_OPCODE_SENDC ||
88           opcode == BRW_OPCODE_SENDS ||
89           opcode == BRW_OPCODE_SENDSC;
90 }
91 
92 static bool
is_split_send(UNUSED const struct gen_device_info * devinfo,unsigned opcode)93 is_split_send(UNUSED const struct gen_device_info *devinfo, unsigned opcode)
94 {
95    if (devinfo->gen >= 12)
96       return is_send(opcode);
97    else
98       return opcode == BRW_OPCODE_SENDS ||
99              opcode == BRW_OPCODE_SENDSC;
100 }
101 
102 const char *const conditional_modifier[16] = {
103    [BRW_CONDITIONAL_NONE] = "",
104    [BRW_CONDITIONAL_Z]    = ".z",
105    [BRW_CONDITIONAL_NZ]   = ".nz",
106    [BRW_CONDITIONAL_G]    = ".g",
107    [BRW_CONDITIONAL_GE]   = ".ge",
108    [BRW_CONDITIONAL_L]    = ".l",
109    [BRW_CONDITIONAL_LE]   = ".le",
110    [BRW_CONDITIONAL_R]    = ".r",
111    [BRW_CONDITIONAL_O]    = ".o",
112    [BRW_CONDITIONAL_U]    = ".u",
113 };
114 
115 static const char *const m_negate[2] = {
116    [0] = "",
117    [1] = "-",
118 };
119 
120 static const char *const _abs[2] = {
121    [0] = "",
122    [1] = "(abs)",
123 };
124 
125 static const char *const m_bitnot[2] = { "", "~" };
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 branch_ctrl[2] = {
181    [0] = "",
182    [1] = "BranchCtrl"
183 };
184 
185 static const char *const wectrl[2] = {
186    [0] = "",
187    [1] = "WE_all"
188 };
189 
190 static const char *const exec_size[8] = {
191    [0] = "1",
192    [1] = "2",
193    [2] = "4",
194    [3] = "8",
195    [4] = "16",
196    [5] = "32"
197 };
198 
199 static const char *const pred_inv[2] = {
200    [0] = "+",
201    [1] = "-"
202 };
203 
204 const char *const pred_ctrl_align16[16] = {
205    [1] = "",
206    [2] = ".x",
207    [3] = ".y",
208    [4] = ".z",
209    [5] = ".w",
210    [6] = ".any4h",
211    [7] = ".all4h",
212 };
213 
214 static const char *const pred_ctrl_align1[16] = {
215    [BRW_PREDICATE_NORMAL]        = "",
216    [BRW_PREDICATE_ALIGN1_ANYV]   = ".anyv",
217    [BRW_PREDICATE_ALIGN1_ALLV]   = ".allv",
218    [BRW_PREDICATE_ALIGN1_ANY2H]  = ".any2h",
219    [BRW_PREDICATE_ALIGN1_ALL2H]  = ".all2h",
220    [BRW_PREDICATE_ALIGN1_ANY4H]  = ".any4h",
221    [BRW_PREDICATE_ALIGN1_ALL4H]  = ".all4h",
222    [BRW_PREDICATE_ALIGN1_ANY8H]  = ".any8h",
223    [BRW_PREDICATE_ALIGN1_ALL8H]  = ".all8h",
224    [BRW_PREDICATE_ALIGN1_ANY16H] = ".any16h",
225    [BRW_PREDICATE_ALIGN1_ALL16H] = ".all16h",
226    [BRW_PREDICATE_ALIGN1_ANY32H] = ".any32h",
227    [BRW_PREDICATE_ALIGN1_ALL32H] = ".all32h",
228 };
229 
230 static const char *const thread_ctrl[4] = {
231    [BRW_THREAD_NORMAL] = "",
232    [BRW_THREAD_ATOMIC] = "atomic",
233    [BRW_THREAD_SWITCH] = "switch",
234 };
235 
236 static const char *const compr_ctrl[4] = {
237    [0] = "",
238    [1] = "sechalf",
239    [2] = "compr",
240    [3] = "compr4",
241 };
242 
243 static const char *const dep_ctrl[4] = {
244    [0] = "",
245    [1] = "NoDDClr",
246    [2] = "NoDDChk",
247    [3] = "NoDDClr,NoDDChk",
248 };
249 
250 static const char *const mask_ctrl[4] = {
251    [0] = "",
252    [1] = "nomask",
253 };
254 
255 static const char *const access_mode[2] = {
256    [0] = "align1",
257    [1] = "align16",
258 };
259 
260 static const char *const reg_file[4] = {
261    [0] = "A",
262    [1] = "g",
263    [2] = "m",
264    [3] = "imm",
265 };
266 
267 static const char *const writemask[16] = {
268    [0x0] = ".",
269    [0x1] = ".x",
270    [0x2] = ".y",
271    [0x3] = ".xy",
272    [0x4] = ".z",
273    [0x5] = ".xz",
274    [0x6] = ".yz",
275    [0x7] = ".xyz",
276    [0x8] = ".w",
277    [0x9] = ".xw",
278    [0xa] = ".yw",
279    [0xb] = ".xyw",
280    [0xc] = ".zw",
281    [0xd] = ".xzw",
282    [0xe] = ".yzw",
283    [0xf] = "",
284 };
285 
286 static const char *const end_of_thread[2] = {
287    [0] = "",
288    [1] = "EOT"
289 };
290 
291 /* SFIDs on Gen4-5 */
292 static const char *const gen4_sfid[16] = {
293    [BRW_SFID_NULL]            = "null",
294    [BRW_SFID_MATH]            = "math",
295    [BRW_SFID_SAMPLER]         = "sampler",
296    [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
297    [BRW_SFID_DATAPORT_READ]   = "read",
298    [BRW_SFID_DATAPORT_WRITE]  = "write",
299    [BRW_SFID_URB]             = "urb",
300    [BRW_SFID_THREAD_SPAWNER]  = "thread_spawner",
301    [BRW_SFID_VME]             = "vme",
302 };
303 
304 static const char *const gen6_sfid[16] = {
305    [BRW_SFID_NULL]                     = "null",
306    [BRW_SFID_MATH]                     = "math",
307    [BRW_SFID_SAMPLER]                  = "sampler",
308    [BRW_SFID_MESSAGE_GATEWAY]          = "gateway",
309    [BRW_SFID_URB]                      = "urb",
310    [BRW_SFID_THREAD_SPAWNER]           = "thread_spawner",
311    [GEN6_SFID_DATAPORT_SAMPLER_CACHE]  = "dp_sampler",
312    [GEN6_SFID_DATAPORT_RENDER_CACHE]   = "render",
313    [GEN6_SFID_DATAPORT_CONSTANT_CACHE] = "const",
314    [GEN7_SFID_DATAPORT_DATA_CACHE]     = "data",
315    [GEN7_SFID_PIXEL_INTERPOLATOR]      = "pixel interp",
316    [HSW_SFID_DATAPORT_DATA_CACHE_1]    = "dp data 1",
317    [HSW_SFID_CRE]                      = "cre",
318 };
319 
320 static const char *const gen7_gateway_subfuncid[8] = {
321    [BRW_MESSAGE_GATEWAY_SFID_OPEN_GATEWAY] = "open",
322    [BRW_MESSAGE_GATEWAY_SFID_CLOSE_GATEWAY] = "close",
323    [BRW_MESSAGE_GATEWAY_SFID_FORWARD_MSG] = "forward msg",
324    [BRW_MESSAGE_GATEWAY_SFID_GET_TIMESTAMP] = "get timestamp",
325    [BRW_MESSAGE_GATEWAY_SFID_BARRIER_MSG] = "barrier msg",
326    [BRW_MESSAGE_GATEWAY_SFID_UPDATE_GATEWAY_STATE] = "update state",
327    [BRW_MESSAGE_GATEWAY_SFID_MMIO_READ_WRITE] = "mmio read/write",
328 };
329 
330 static const char *const gen4_dp_read_port_msg_type[4] = {
331    [0b00] = "OWord Block Read",
332    [0b01] = "OWord Dual Block Read",
333    [0b10] = "Media Block Read",
334    [0b11] = "DWord Scattered Read",
335 };
336 
337 static const char *const g45_dp_read_port_msg_type[8] = {
338    [0b000] = "OWord Block Read",
339    [0b010] = "OWord Dual Block Read",
340    [0b100] = "Media Block Read",
341    [0b110] = "DWord Scattered Read",
342    [0b001] = "Render Target UNORM Read",
343    [0b011] = "AVC Loop Filter Read",
344 };
345 
346 static const char *const dp_write_port_msg_type[8] = {
347    [0b000] = "OWord block write",
348    [0b001] = "OWord dual block write",
349    [0b010] = "media block write",
350    [0b011] = "DWord scattered write",
351    [0b100] = "RT write",
352    [0b101] = "streamed VB write",
353    [0b110] = "RT UNORM write", /* G45+ */
354    [0b111] = "flush render cache",
355 };
356 
357 static const char *const dp_rc_msg_type_gen6[16] = {
358    [BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ] = "OWORD block read",
359    [GEN6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ] = "RT UNORM read",
360    [GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ] = "OWORD dual block read",
361    [GEN6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ] = "media block read",
362    [GEN6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ] =
363       "OWORD unaligned block read",
364    [GEN6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ] = "DWORD scattered read",
365    [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE] = "DWORD atomic write",
366    [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE] = "OWORD block write",
367    [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE] =
368       "OWORD dual block write",
369    [GEN6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE] = "media block write",
370    [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE] =
371       "DWORD scattered write",
372    [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE] = "RT write",
373    [GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE] = "streamed VB write",
374    [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE] = "RT UNORM write",
375 };
376 
377 static const char *const dp_rc_msg_type_gen7[16] = {
378    [GEN7_DATAPORT_RC_MEDIA_BLOCK_READ] = "media block read",
379    [GEN7_DATAPORT_RC_TYPED_SURFACE_READ] = "typed surface read",
380    [GEN7_DATAPORT_RC_TYPED_ATOMIC_OP] = "typed atomic op",
381    [GEN7_DATAPORT_RC_MEMORY_FENCE] = "memory fence",
382    [GEN7_DATAPORT_RC_MEDIA_BLOCK_WRITE] = "media block write",
383    [GEN7_DATAPORT_RC_RENDER_TARGET_WRITE] = "RT write",
384    [GEN7_DATAPORT_RC_TYPED_SURFACE_WRITE] = "typed surface write"
385 };
386 
387 static const char *const dp_rc_msg_type_gen9[16] = {
388    [GEN9_DATAPORT_RC_RENDER_TARGET_WRITE] = "RT write",
389    [GEN9_DATAPORT_RC_RENDER_TARGET_READ] = "RT read"
390 };
391 
392 static const char *const *
dp_rc_msg_type(const struct gen_device_info * devinfo)393 dp_rc_msg_type(const struct gen_device_info *devinfo)
394 {
395    return (devinfo->gen >= 9 ? dp_rc_msg_type_gen9 :
396            devinfo->gen >= 7 ? dp_rc_msg_type_gen7 :
397            devinfo->gen >= 6 ? dp_rc_msg_type_gen6 :
398            dp_write_port_msg_type);
399 }
400 
401 static const char *const m_rt_write_subtype[] = {
402    [0b000] = "SIMD16",
403    [0b001] = "SIMD16/RepData",
404    [0b010] = "SIMD8/DualSrcLow",
405    [0b011] = "SIMD8/DualSrcHigh",
406    [0b100] = "SIMD8",
407    [0b101] = "SIMD8/ImageWrite",   /* Gen6+ */
408    [0b111] = "SIMD16/RepData-111", /* no idea how this is different than 1 */
409 };
410 
411 static const char *const dp_dc0_msg_type_gen7[16] = {
412    [GEN7_DATAPORT_DC_OWORD_BLOCK_READ] = "DC OWORD block read",
413    [GEN7_DATAPORT_DC_UNALIGNED_OWORD_BLOCK_READ] =
414       "DC unaligned OWORD block read",
415    [GEN7_DATAPORT_DC_OWORD_DUAL_BLOCK_READ] = "DC OWORD dual block read",
416    [GEN7_DATAPORT_DC_DWORD_SCATTERED_READ] = "DC DWORD scattered read",
417    [GEN7_DATAPORT_DC_BYTE_SCATTERED_READ] = "DC byte scattered read",
418    [GEN7_DATAPORT_DC_UNTYPED_SURFACE_READ] = "DC untyped surface read",
419    [GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP] = "DC untyped atomic",
420    [GEN7_DATAPORT_DC_MEMORY_FENCE] = "DC mfence",
421    [GEN7_DATAPORT_DC_OWORD_BLOCK_WRITE] = "DC OWORD block write",
422    [GEN7_DATAPORT_DC_OWORD_DUAL_BLOCK_WRITE] = "DC OWORD dual block write",
423    [GEN7_DATAPORT_DC_DWORD_SCATTERED_WRITE] = "DC DWORD scatterd write",
424    [GEN7_DATAPORT_DC_BYTE_SCATTERED_WRITE] = "DC byte scattered write",
425    [GEN7_DATAPORT_DC_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
426 };
427 
428 static const char *const dp_dc1_msg_type_hsw[32] = {
429    [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ] = "untyped surface read",
430    [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP] = "DC untyped atomic op",
431    [HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2] =
432       "DC untyped 4x2 atomic op",
433    [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_READ] = "DC media block read",
434    [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ] = "DC typed surface read",
435    [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP] = "DC typed atomic",
436    [HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2] = "DC typed 4x2 atomic op",
437    [HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE] = "DC untyped surface write",
438    [HSW_DATAPORT_DC_PORT1_MEDIA_BLOCK_WRITE] = "DC media block write",
439    [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP] = "DC atomic counter op",
440    [HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2] =
441       "DC 4x2 atomic counter op",
442    [HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE] = "DC typed surface write",
443    [GEN9_DATAPORT_DC_PORT1_A64_SCATTERED_READ] = "DC A64 scattered read",
444    [GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ] = "DC A64 untyped surface read",
445    [GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP] = "DC A64 untyped atomic op",
446    [GEN9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_READ] = "DC A64 oword block read",
447    [GEN9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_WRITE] = "DC A64 oword block write",
448    [GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE] = "DC A64 untyped surface write",
449    [GEN8_DATAPORT_DC_PORT1_A64_SCATTERED_WRITE] = "DC A64 scattered write",
450    [GEN9_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_FLOAT_OP] =
451       "DC untyped atomic float op",
452    [GEN9_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_FLOAT_OP] =
453       "DC A64 untyped atomic float op",
454 };
455 
456 static const char *const aop[16] = {
457    [BRW_AOP_AND]    = "and",
458    [BRW_AOP_OR]     = "or",
459    [BRW_AOP_XOR]    = "xor",
460    [BRW_AOP_MOV]    = "mov",
461    [BRW_AOP_INC]    = "inc",
462    [BRW_AOP_DEC]    = "dec",
463    [BRW_AOP_ADD]    = "add",
464    [BRW_AOP_SUB]    = "sub",
465    [BRW_AOP_REVSUB] = "revsub",
466    [BRW_AOP_IMAX]   = "imax",
467    [BRW_AOP_IMIN]   = "imin",
468    [BRW_AOP_UMAX]   = "umax",
469    [BRW_AOP_UMIN]   = "umin",
470    [BRW_AOP_CMPWR]  = "cmpwr",
471    [BRW_AOP_PREDEC] = "predec",
472 };
473 
474 static const char *const aop_float[4] = {
475    [BRW_AOP_FMAX]   = "fmax",
476    [BRW_AOP_FMIN]   = "fmin",
477    [BRW_AOP_FCMPWR] = "fcmpwr",
478 };
479 
480 static const char * const pixel_interpolator_msg_types[4] = {
481     [GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET] = "per_message_offset",
482     [GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE] = "sample_position",
483     [GEN7_PIXEL_INTERPOLATOR_LOC_CENTROID] = "centroid",
484     [GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET] = "per_slot_offset",
485 };
486 
487 static const char *const math_function[16] = {
488    [BRW_MATH_FUNCTION_INV]    = "inv",
489    [BRW_MATH_FUNCTION_LOG]    = "log",
490    [BRW_MATH_FUNCTION_EXP]    = "exp",
491    [BRW_MATH_FUNCTION_SQRT]   = "sqrt",
492    [BRW_MATH_FUNCTION_RSQ]    = "rsq",
493    [BRW_MATH_FUNCTION_SIN]    = "sin",
494    [BRW_MATH_FUNCTION_COS]    = "cos",
495    [BRW_MATH_FUNCTION_SINCOS] = "sincos",
496    [BRW_MATH_FUNCTION_FDIV]   = "fdiv",
497    [BRW_MATH_FUNCTION_POW]    = "pow",
498    [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
499    [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT]  = "intdiv",
500    [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intmod",
501    [GEN8_MATH_FUNCTION_INVM]  = "invm",
502    [GEN8_MATH_FUNCTION_RSQRTM] = "rsqrtm",
503 };
504 
505 static const char *const sync_function[16] = {
506    [TGL_SYNC_NOP] = "nop",
507    [TGL_SYNC_ALLRD] = "allrd",
508    [TGL_SYNC_ALLWR] = "allwr",
509    [TGL_SYNC_BAR] = "bar",
510    [TGL_SYNC_HOST] = "host",
511 };
512 
513 static const char *const math_saturate[2] = {
514    [0] = "",
515    [1] = "sat"
516 };
517 
518 static const char *const math_signed[2] = {
519    [0] = "",
520    [1] = "signed"
521 };
522 
523 static const char *const math_scalar[2] = {
524    [0] = "",
525    [1] = "scalar"
526 };
527 
528 static const char *const math_precision[2] = {
529    [0] = "",
530    [1] = "partial_precision"
531 };
532 
533 static const char *const gen5_urb_opcode[] = {
534    [0] = "urb_write",
535    [1] = "ff_sync",
536 };
537 
538 static const char *const gen7_urb_opcode[] = {
539    [BRW_URB_OPCODE_WRITE_HWORD] = "write HWord",
540    [BRW_URB_OPCODE_WRITE_OWORD] = "write OWord",
541    [BRW_URB_OPCODE_READ_HWORD] = "read HWord",
542    [BRW_URB_OPCODE_READ_OWORD] = "read OWord",
543    [GEN7_URB_OPCODE_ATOMIC_MOV] = "atomic mov",  /* Gen7+ */
544    [GEN7_URB_OPCODE_ATOMIC_INC] = "atomic inc",  /* Gen7+ */
545    [GEN8_URB_OPCODE_ATOMIC_ADD] = "atomic add",  /* Gen8+ */
546    [GEN8_URB_OPCODE_SIMD8_WRITE] = "SIMD8 write", /* Gen8+ */
547    [GEN8_URB_OPCODE_SIMD8_READ] = "SIMD8 read",  /* Gen8+ */
548    /* [9-15] - reserved */
549 };
550 
551 static const char *const urb_swizzle[4] = {
552    [BRW_URB_SWIZZLE_NONE]       = "",
553    [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave",
554    [BRW_URB_SWIZZLE_TRANSPOSE]  = "transpose",
555 };
556 
557 static const char *const urb_allocate[2] = {
558    [0] = "",
559    [1] = "allocate"
560 };
561 
562 static const char *const urb_used[2] = {
563    [0] = "",
564    [1] = "used"
565 };
566 
567 static const char *const urb_complete[2] = {
568    [0] = "",
569    [1] = "complete"
570 };
571 
572 static const char *const gen5_sampler_msg_type[] = {
573    [GEN5_SAMPLER_MESSAGE_SAMPLE]              = "sample",
574    [GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS]         = "sample_b",
575    [GEN5_SAMPLER_MESSAGE_SAMPLE_LOD]          = "sample_l",
576    [GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE]      = "sample_c",
577    [GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS]       = "sample_d",
578    [GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE] = "sample_b_c",
579    [GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE]  = "sample_l_c",
580    [GEN5_SAMPLER_MESSAGE_SAMPLE_LD]           = "ld",
581    [GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4]      = "gather4",
582    [GEN5_SAMPLER_MESSAGE_LOD]                 = "lod",
583    [GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO]      = "resinfo",
584    [GEN6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO]   = "sampleinfo",
585    [GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C]    = "gather4_c",
586    [GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO]   = "gather4_po",
587    [GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C] = "gather4_po_c",
588    [HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE] = "sample_d_c",
589    [GEN9_SAMPLER_MESSAGE_SAMPLE_LZ]           = "sample_lz",
590    [GEN9_SAMPLER_MESSAGE_SAMPLE_C_LZ]         = "sample_c_lz",
591    [GEN9_SAMPLER_MESSAGE_SAMPLE_LD_LZ]        = "ld_lz",
592    [GEN9_SAMPLER_MESSAGE_SAMPLE_LD2DMS_W]     = "ld2dms_w",
593    [GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS]       = "ld_mcs",
594    [GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS]       = "ld2dms",
595    [GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS]       = "ld2dss",
596 };
597 
598 static const char *const gen5_sampler_simd_mode[4] = {
599    [BRW_SAMPLER_SIMD_MODE_SIMD4X2]   = "SIMD4x2",
600    [BRW_SAMPLER_SIMD_MODE_SIMD8]     = "SIMD8",
601    [BRW_SAMPLER_SIMD_MODE_SIMD16]    = "SIMD16",
602    [BRW_SAMPLER_SIMD_MODE_SIMD32_64] = "SIMD32/64",
603 };
604 
605 static const char *const sampler_target_format[4] = {
606    [0] = "F",
607    [2] = "UD",
608    [3] = "D"
609 };
610 
611 
612 static int column;
613 
614 static int
string(FILE * file,const char * string)615 string(FILE *file, const char *string)
616 {
617    fputs(string, file);
618    column += strlen(string);
619    return 0;
620 }
621 
622 static int
623 format(FILE *f, const char *format, ...) PRINTFLIKE(2, 3);
624 
625 static int
format(FILE * f,const char * format,...)626 format(FILE *f, const char *format, ...)
627 {
628    char buf[1024];
629    va_list args;
630    va_start(args, format);
631 
632    vsnprintf(buf, sizeof(buf) - 1, format, args);
633    va_end(args);
634    string(f, buf);
635    return 0;
636 }
637 
638 static int
newline(FILE * f)639 newline(FILE *f)
640 {
641    putc('\n', f);
642    column = 0;
643    return 0;
644 }
645 
646 static int
pad(FILE * f,int c)647 pad(FILE *f, int c)
648 {
649    do
650       string(f, " ");
651    while (column < c);
652    return 0;
653 }
654 
655 static int
control(FILE * file,const char * name,const char * const ctrl[],unsigned id,int * space)656 control(FILE *file, const char *name, const char *const ctrl[],
657         unsigned id, int *space)
658 {
659    if (!ctrl[id]) {
660       fprintf(file, "*** invalid %s value %d ", name, id);
661       return 1;
662    }
663    if (ctrl[id][0]) {
664       if (space && *space)
665          string(file, " ");
666       string(file, ctrl[id]);
667       if (space)
668          *space = 1;
669    }
670    return 0;
671 }
672 
673 static int
print_opcode(FILE * file,const struct gen_device_info * devinfo,enum opcode id)674 print_opcode(FILE *file, const struct gen_device_info *devinfo,
675              enum opcode id)
676 {
677    const struct opcode_desc *desc = brw_opcode_desc(devinfo, id);
678    if (!desc) {
679       format(file, "*** invalid opcode value %d ", id);
680       return 1;
681    }
682    string(file, desc->name);
683    return 0;
684 }
685 
686 static int
reg(FILE * file,unsigned _reg_file,unsigned _reg_nr)687 reg(FILE *file, unsigned _reg_file, unsigned _reg_nr)
688 {
689    int err = 0;
690 
691    /* Clear the Compr4 instruction compression bit. */
692    if (_reg_file == BRW_MESSAGE_REGISTER_FILE)
693       _reg_nr &= ~BRW_MRF_COMPR4;
694 
695    if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
696       switch (_reg_nr & 0xf0) {
697       case BRW_ARF_NULL:
698          string(file, "null");
699          break;
700       case BRW_ARF_ADDRESS:
701          format(file, "a%d", _reg_nr & 0x0f);
702          break;
703       case BRW_ARF_ACCUMULATOR:
704          format(file, "acc%d", _reg_nr & 0x0f);
705          break;
706       case BRW_ARF_FLAG:
707          format(file, "f%d", _reg_nr & 0x0f);
708          break;
709       case BRW_ARF_MASK:
710          format(file, "mask%d", _reg_nr & 0x0f);
711          break;
712       case BRW_ARF_MASK_STACK:
713          format(file, "ms%d", _reg_nr & 0x0f);
714          break;
715       case BRW_ARF_MASK_STACK_DEPTH:
716          format(file, "msd%d", _reg_nr & 0x0f);
717          break;
718       case BRW_ARF_STATE:
719          format(file, "sr%d", _reg_nr & 0x0f);
720          break;
721       case BRW_ARF_CONTROL:
722          format(file, "cr%d", _reg_nr & 0x0f);
723          break;
724       case BRW_ARF_NOTIFICATION_COUNT:
725          format(file, "n%d", _reg_nr & 0x0f);
726          break;
727       case BRW_ARF_IP:
728          string(file, "ip");
729          return -1;
730          break;
731       case BRW_ARF_TDR:
732          format(file, "tdr0");
733          return -1;
734       case BRW_ARF_TIMESTAMP:
735          format(file, "tm%d", _reg_nr & 0x0f);
736          break;
737       default:
738          format(file, "ARF%d", _reg_nr);
739          break;
740       }
741    } else {
742       err |= control(file, "src reg file", reg_file, _reg_file, NULL);
743       format(file, "%d", _reg_nr);
744    }
745    return err;
746 }
747 
748 static int
dest(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)749 dest(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
750 {
751    enum brw_reg_type type = brw_inst_dst_type(devinfo, inst);
752    unsigned elem_size = brw_reg_type_to_size(type);
753    int err = 0;
754 
755    if (is_split_send(devinfo, brw_inst_opcode(devinfo, inst))) {
756       /* These are fixed for split sends */
757       type = BRW_REGISTER_TYPE_UD;
758       elem_size = 4;
759       if (devinfo->gen >= 12) {
760          err |= reg(file, brw_inst_send_dst_reg_file(devinfo, inst),
761                     brw_inst_dst_da_reg_nr(devinfo, inst));
762          string(file, brw_reg_type_to_letters(type));
763       } else if (brw_inst_dst_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
764          err |= reg(file, brw_inst_send_dst_reg_file(devinfo, inst),
765                     brw_inst_dst_da_reg_nr(devinfo, inst));
766          unsigned subreg_nr = brw_inst_dst_da16_subreg_nr(devinfo, inst);
767          if (subreg_nr)
768             format(file, ".%u", subreg_nr);
769          string(file, brw_reg_type_to_letters(type));
770       } else {
771          string(file, "g[a0");
772          if (brw_inst_dst_ia_subreg_nr(devinfo, inst))
773             format(file, ".%"PRIu64, brw_inst_dst_ia_subreg_nr(devinfo, inst) /
774                    elem_size);
775          if (brw_inst_send_dst_ia16_addr_imm(devinfo, inst))
776             format(file, " %d", brw_inst_send_dst_ia16_addr_imm(devinfo, inst));
777          string(file, "]<");
778          string(file, brw_reg_type_to_letters(type));
779       }
780    } else if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
781       if (brw_inst_dst_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
782          err |= reg(file, brw_inst_dst_reg_file(devinfo, inst),
783                     brw_inst_dst_da_reg_nr(devinfo, inst));
784          if (err == -1)
785             return 0;
786          if (brw_inst_dst_da1_subreg_nr(devinfo, inst))
787             format(file, ".%"PRIu64, brw_inst_dst_da1_subreg_nr(devinfo, inst) /
788                    elem_size);
789          string(file, "<");
790          err |= control(file, "horiz stride", horiz_stride,
791                         brw_inst_dst_hstride(devinfo, inst), NULL);
792          string(file, ">");
793          string(file, brw_reg_type_to_letters(type));
794       } else {
795          string(file, "g[a0");
796          if (brw_inst_dst_ia_subreg_nr(devinfo, inst))
797             format(file, ".%"PRIu64, brw_inst_dst_ia_subreg_nr(devinfo, inst) /
798                    elem_size);
799          if (brw_inst_dst_ia1_addr_imm(devinfo, inst))
800             format(file, " %d", brw_inst_dst_ia1_addr_imm(devinfo, inst));
801          string(file, "]<");
802          err |= control(file, "horiz stride", horiz_stride,
803                         brw_inst_dst_hstride(devinfo, inst), NULL);
804          string(file, ">");
805          string(file, brw_reg_type_to_letters(type));
806       }
807    } else {
808       if (brw_inst_dst_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
809          err |= reg(file, brw_inst_dst_reg_file(devinfo, inst),
810                     brw_inst_dst_da_reg_nr(devinfo, inst));
811          if (err == -1)
812             return 0;
813          if (brw_inst_dst_da16_subreg_nr(devinfo, inst))
814             format(file, ".%u", 16 / elem_size);
815          string(file, "<1>");
816          err |= control(file, "writemask", writemask,
817                         brw_inst_da16_writemask(devinfo, inst), NULL);
818          string(file, brw_reg_type_to_letters(type));
819       } else {
820          err = 1;
821          string(file, "Indirect align16 address mode not supported");
822       }
823    }
824 
825    return 0;
826 }
827 
828 static int
dest_3src(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)829 dest_3src(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
830 {
831    bool is_align1 = brw_inst_3src_access_mode(devinfo, inst) == BRW_ALIGN_1;
832    int err = 0;
833    uint32_t reg_file;
834    unsigned subreg_nr;
835    enum brw_reg_type type;
836 
837    if (devinfo->gen < 10 && is_align1)
838       return 0;
839 
840    if (devinfo->gen == 6 && brw_inst_3src_a16_dst_reg_file(devinfo, inst))
841       reg_file = BRW_MESSAGE_REGISTER_FILE;
842    else if (devinfo->gen >= 12)
843       reg_file = brw_inst_3src_a1_dst_reg_file(devinfo, inst);
844    else if (is_align1 && brw_inst_3src_a1_dst_reg_file(devinfo, inst))
845       reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
846    else
847       reg_file = BRW_GENERAL_REGISTER_FILE;
848 
849    err |= reg(file, reg_file, brw_inst_3src_dst_reg_nr(devinfo, inst));
850    if (err == -1)
851       return 0;
852 
853    if (is_align1) {
854       type = brw_inst_3src_a1_dst_type(devinfo, inst);
855       subreg_nr = brw_inst_3src_a1_dst_subreg_nr(devinfo, inst);
856    } else {
857       type = brw_inst_3src_a16_dst_type(devinfo, inst);
858       subreg_nr = brw_inst_3src_a16_dst_subreg_nr(devinfo, inst) * 4;
859    }
860    subreg_nr /= brw_reg_type_to_size(type);
861 
862    if (subreg_nr)
863       format(file, ".%u", subreg_nr);
864    string(file, "<1>");
865 
866    if (!is_align1) {
867       err |= control(file, "writemask", writemask,
868                      brw_inst_3src_a16_dst_writemask(devinfo, inst), NULL);
869    }
870    string(file, brw_reg_type_to_letters(type));
871 
872    return 0;
873 }
874 
875 static int
src_align1_region(FILE * file,unsigned _vert_stride,unsigned _width,unsigned _horiz_stride)876 src_align1_region(FILE *file,
877                   unsigned _vert_stride, unsigned _width,
878                   unsigned _horiz_stride)
879 {
880    int err = 0;
881    string(file, "<");
882    err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
883    string(file, ",");
884    err |= control(file, "width", width, _width, NULL);
885    string(file, ",");
886    err |= control(file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
887    string(file, ">");
888    return err;
889 }
890 
891 static int
src_da1(FILE * file,const struct gen_device_info * devinfo,unsigned opcode,enum brw_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)892 src_da1(FILE *file,
893         const struct gen_device_info *devinfo,
894         unsigned opcode,
895         enum brw_reg_type type, unsigned _reg_file,
896         unsigned _vert_stride, unsigned _width, unsigned _horiz_stride,
897         unsigned reg_num, unsigned sub_reg_num, unsigned __abs,
898         unsigned _negate)
899 {
900    int err = 0;
901 
902    if (devinfo->gen >= 8 && is_logic_instruction(opcode))
903       err |= control(file, "bitnot", m_bitnot, _negate, NULL);
904    else
905       err |= control(file, "negate", m_negate, _negate, NULL);
906 
907    err |= control(file, "abs", _abs, __abs, NULL);
908 
909    err |= reg(file, _reg_file, reg_num);
910    if (err == -1)
911       return 0;
912    if (sub_reg_num) {
913       unsigned elem_size = brw_reg_type_to_size(type);
914       format(file, ".%d", sub_reg_num / elem_size);   /* use formal style like spec */
915    }
916    src_align1_region(file, _vert_stride, _width, _horiz_stride);
917    string(file, brw_reg_type_to_letters(type));
918    return err;
919 }
920 
921 static int
src_ia1(FILE * file,const struct gen_device_info * devinfo,unsigned opcode,enum brw_reg_type type,int _addr_imm,unsigned _addr_subreg_nr,unsigned _negate,unsigned __abs,unsigned _horiz_stride,unsigned _width,unsigned _vert_stride)922 src_ia1(FILE *file,
923         const struct gen_device_info *devinfo,
924         unsigned opcode,
925         enum brw_reg_type type,
926         int _addr_imm,
927         unsigned _addr_subreg_nr,
928         unsigned _negate,
929         unsigned __abs,
930         unsigned _horiz_stride, unsigned _width, unsigned _vert_stride)
931 {
932    int err = 0;
933 
934    if (devinfo->gen >= 8 && is_logic_instruction(opcode))
935       err |= control(file, "bitnot", m_bitnot, _negate, NULL);
936    else
937       err |= control(file, "negate", m_negate, _negate, NULL);
938 
939    err |= control(file, "abs", _abs, __abs, NULL);
940 
941    string(file, "g[a0");
942    if (_addr_subreg_nr)
943       format(file, ".%d", _addr_subreg_nr);
944    if (_addr_imm)
945       format(file, " %d", _addr_imm);
946    string(file, "]");
947    src_align1_region(file, _vert_stride, _width, _horiz_stride);
948    string(file, brw_reg_type_to_letters(type));
949    return err;
950 }
951 
952 static int
src_swizzle(FILE * file,unsigned swiz)953 src_swizzle(FILE *file, unsigned swiz)
954 {
955    unsigned x = BRW_GET_SWZ(swiz, BRW_CHANNEL_X);
956    unsigned y = BRW_GET_SWZ(swiz, BRW_CHANNEL_Y);
957    unsigned z = BRW_GET_SWZ(swiz, BRW_CHANNEL_Z);
958    unsigned w = BRW_GET_SWZ(swiz, BRW_CHANNEL_W);
959    int err = 0;
960 
961    if (x == y && x == z && x == w) {
962       string(file, ".");
963       err |= control(file, "channel select", chan_sel, x, NULL);
964    } else if (swiz != BRW_SWIZZLE_XYZW) {
965       string(file, ".");
966       err |= control(file, "channel select", chan_sel, x, NULL);
967       err |= control(file, "channel select", chan_sel, y, NULL);
968       err |= control(file, "channel select", chan_sel, z, NULL);
969       err |= control(file, "channel select", chan_sel, w, NULL);
970    }
971    return err;
972 }
973 
974 static int
src_da16(FILE * file,const struct gen_device_info * devinfo,unsigned opcode,enum brw_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)975 src_da16(FILE *file,
976          const struct gen_device_info *devinfo,
977          unsigned opcode,
978          enum brw_reg_type type,
979          unsigned _reg_file,
980          unsigned _vert_stride,
981          unsigned _reg_nr,
982          unsigned _subreg_nr,
983          unsigned __abs,
984          unsigned _negate,
985          unsigned swz_x, unsigned swz_y, unsigned swz_z, unsigned swz_w)
986 {
987    int err = 0;
988 
989    if (devinfo->gen >= 8 && is_logic_instruction(opcode))
990       err |= control(file, "bitnot", m_bitnot, _negate, NULL);
991    else
992       err |= control(file, "negate", m_negate, _negate, NULL);
993 
994    err |= control(file, "abs", _abs, __abs, NULL);
995 
996    err |= reg(file, _reg_file, _reg_nr);
997    if (err == -1)
998       return 0;
999    if (_subreg_nr) {
1000       unsigned elem_size = brw_reg_type_to_size(type);
1001 
1002       /* bit4 for subreg number byte addressing. Make this same meaning as
1003          in da1 case, so output looks consistent. */
1004       format(file, ".%d", 16 / elem_size);
1005    }
1006    string(file, "<");
1007    err |= control(file, "vert stride", vert_stride, _vert_stride, NULL);
1008    string(file, ">");
1009    err |= src_swizzle(file, BRW_SWIZZLE4(swz_x, swz_y, swz_z, swz_w));
1010    string(file, brw_reg_type_to_letters(type));
1011    return err;
1012 }
1013 
1014 static enum brw_vertical_stride
vstride_from_align1_3src_vstride(const struct gen_device_info * devinfo,enum gen10_align1_3src_vertical_stride vstride)1015 vstride_from_align1_3src_vstride(const struct gen_device_info *devinfo,
1016                                  enum gen10_align1_3src_vertical_stride vstride)
1017 {
1018    switch (vstride) {
1019    case BRW_ALIGN1_3SRC_VERTICAL_STRIDE_0: return BRW_VERTICAL_STRIDE_0;
1020    case BRW_ALIGN1_3SRC_VERTICAL_STRIDE_2:
1021       if (devinfo->gen >= 12)
1022          return BRW_VERTICAL_STRIDE_1;
1023       else
1024          return BRW_VERTICAL_STRIDE_2;
1025    case BRW_ALIGN1_3SRC_VERTICAL_STRIDE_4: return BRW_VERTICAL_STRIDE_4;
1026    case BRW_ALIGN1_3SRC_VERTICAL_STRIDE_8: return BRW_VERTICAL_STRIDE_8;
1027    default:
1028       unreachable("not reached");
1029    }
1030 }
1031 
1032 static enum brw_horizontal_stride
hstride_from_align1_3src_hstride(enum gen10_align1_3src_src_horizontal_stride hstride)1033 hstride_from_align1_3src_hstride(enum gen10_align1_3src_src_horizontal_stride hstride)
1034 {
1035    switch (hstride) {
1036    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_0: return BRW_HORIZONTAL_STRIDE_0;
1037    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_1: return BRW_HORIZONTAL_STRIDE_1;
1038    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_2: return BRW_HORIZONTAL_STRIDE_2;
1039    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_4: return BRW_HORIZONTAL_STRIDE_4;
1040    default:
1041       unreachable("not reached");
1042    }
1043 }
1044 
1045 static enum brw_vertical_stride
vstride_from_align1_3src_hstride(enum gen10_align1_3src_src_horizontal_stride hstride)1046 vstride_from_align1_3src_hstride(enum gen10_align1_3src_src_horizontal_stride hstride)
1047 {
1048    switch (hstride) {
1049    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_0: return BRW_VERTICAL_STRIDE_0;
1050    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_1: return BRW_VERTICAL_STRIDE_1;
1051    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_2: return BRW_VERTICAL_STRIDE_2;
1052    case BRW_ALIGN1_3SRC_SRC_HORIZONTAL_STRIDE_4: return BRW_VERTICAL_STRIDE_4;
1053    default:
1054       unreachable("not reached");
1055    }
1056 }
1057 
1058 /* From "GEN10 Regioning Rules for Align1 Ternary Operations" in the
1059  * "Register Region Restrictions" documentation
1060  */
1061 static enum brw_width
implied_width(enum brw_vertical_stride _vert_stride,enum brw_horizontal_stride _horiz_stride)1062 implied_width(enum brw_vertical_stride _vert_stride,
1063               enum brw_horizontal_stride _horiz_stride)
1064 {
1065    /* "1. Width is 1 when Vertical and Horizontal Strides are both zero." */
1066    if (_vert_stride == BRW_VERTICAL_STRIDE_0 &&
1067        _horiz_stride == BRW_HORIZONTAL_STRIDE_0) {
1068       return BRW_WIDTH_1;
1069 
1070    /* "2. Width is equal to vertical stride when Horizontal Stride is zero." */
1071    } else if (_horiz_stride == BRW_HORIZONTAL_STRIDE_0) {
1072       switch (_vert_stride) {
1073       case BRW_VERTICAL_STRIDE_2: return BRW_WIDTH_2;
1074       case BRW_VERTICAL_STRIDE_4: return BRW_WIDTH_4;
1075       case BRW_VERTICAL_STRIDE_8: return BRW_WIDTH_8;
1076       case BRW_VERTICAL_STRIDE_0:
1077       default:
1078          unreachable("not reached");
1079       }
1080 
1081    } else {
1082       /* FINISHME: Implement these: */
1083 
1084       /* "3. Width is equal to Vertical Stride/Horizontal Stride when both
1085        *     Strides are non-zero.
1086        *
1087        *  4. Vertical Stride must not be zero if Horizontal Stride is non-zero.
1088        *     This implies Vertical Stride is always greater than Horizontal
1089        *     Stride."
1090        *
1091        * Given these statements and the knowledge that the stride and width
1092        * values are encoded in logarithmic form, we can perform the division
1093        * by just subtracting.
1094        */
1095       return _vert_stride - _horiz_stride;
1096    }
1097 }
1098 
1099 static int
src0_3src(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1100 src0_3src(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1101 {
1102    int err = 0;
1103    unsigned reg_nr, subreg_nr;
1104    enum brw_reg_file _file;
1105    enum brw_reg_type type;
1106    enum brw_vertical_stride _vert_stride;
1107    enum brw_width _width;
1108    enum brw_horizontal_stride _horiz_stride;
1109    bool is_scalar_region;
1110    bool is_align1 = brw_inst_3src_access_mode(devinfo, inst) == BRW_ALIGN_1;
1111 
1112    if (devinfo->gen < 10 && is_align1)
1113       return 0;
1114 
1115    if (is_align1) {
1116       if (devinfo->gen >= 12 && !brw_inst_3src_a1_src0_is_imm(devinfo, inst)) {
1117          _file = brw_inst_3src_a1_src0_reg_file(devinfo, inst);
1118       } else if (brw_inst_3src_a1_src0_reg_file(devinfo, inst) ==
1119                  BRW_ALIGN1_3SRC_GENERAL_REGISTER_FILE) {
1120          _file = BRW_GENERAL_REGISTER_FILE;
1121       } else if (brw_inst_3src_a1_src0_type(devinfo, inst) ==
1122                  BRW_REGISTER_TYPE_NF) {
1123          _file = BRW_ARCHITECTURE_REGISTER_FILE;
1124       } else {
1125          _file = BRW_IMMEDIATE_VALUE;
1126          uint16_t imm_val = brw_inst_3src_a1_src0_imm(devinfo, inst);
1127          enum brw_reg_type type = brw_inst_3src_a1_src0_type(devinfo, inst);
1128 
1129          if (type == BRW_REGISTER_TYPE_W) {
1130             format(file, "%dW", imm_val);
1131          } else if (type == BRW_REGISTER_TYPE_UW) {
1132             format(file, "0x%04xUW", imm_val);
1133          } else if (type == BRW_REGISTER_TYPE_HF) {
1134             format(file, "0x%04xHF", imm_val);
1135          }
1136          return 0;
1137       }
1138 
1139       reg_nr = brw_inst_3src_src0_reg_nr(devinfo, inst);
1140       subreg_nr = brw_inst_3src_a1_src0_subreg_nr(devinfo, inst);
1141       type = brw_inst_3src_a1_src0_type(devinfo, inst);
1142       _vert_stride = vstride_from_align1_3src_vstride(
1143          devinfo, brw_inst_3src_a1_src0_vstride(devinfo, inst));
1144       _horiz_stride = hstride_from_align1_3src_hstride(
1145                          brw_inst_3src_a1_src0_hstride(devinfo, inst));
1146       _width = implied_width(_vert_stride, _horiz_stride);
1147    } else {
1148       _file = BRW_GENERAL_REGISTER_FILE;
1149       reg_nr = brw_inst_3src_src0_reg_nr(devinfo, inst);
1150       subreg_nr = brw_inst_3src_a16_src0_subreg_nr(devinfo, inst) * 4;
1151       type = brw_inst_3src_a16_src_type(devinfo, inst);
1152 
1153       if (brw_inst_3src_a16_src0_rep_ctrl(devinfo, inst)) {
1154          _vert_stride = BRW_VERTICAL_STRIDE_0;
1155          _width = BRW_WIDTH_1;
1156          _horiz_stride = BRW_HORIZONTAL_STRIDE_0;
1157       } else {
1158          _vert_stride = BRW_VERTICAL_STRIDE_4;
1159          _width = BRW_WIDTH_4;
1160          _horiz_stride = BRW_HORIZONTAL_STRIDE_1;
1161       }
1162    }
1163    is_scalar_region = _vert_stride == BRW_VERTICAL_STRIDE_0 &&
1164                       _width == BRW_WIDTH_1 &&
1165                       _horiz_stride == BRW_HORIZONTAL_STRIDE_0;
1166 
1167    subreg_nr /= brw_reg_type_to_size(type);
1168 
1169    err |= control(file, "negate", m_negate,
1170                   brw_inst_3src_src0_negate(devinfo, inst), NULL);
1171    err |= control(file, "abs", _abs, brw_inst_3src_src0_abs(devinfo, inst), NULL);
1172 
1173    err |= reg(file, _file, reg_nr);
1174    if (err == -1)
1175       return 0;
1176    if (subreg_nr || is_scalar_region)
1177       format(file, ".%d", subreg_nr);
1178    src_align1_region(file, _vert_stride, _width, _horiz_stride);
1179    if (!is_scalar_region && !is_align1)
1180       err |= src_swizzle(file, brw_inst_3src_a16_src0_swizzle(devinfo, inst));
1181    string(file, brw_reg_type_to_letters(type));
1182    return err;
1183 }
1184 
1185 static int
src1_3src(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1186 src1_3src(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1187 {
1188    int err = 0;
1189    unsigned reg_nr, subreg_nr;
1190    enum brw_reg_file _file;
1191    enum brw_reg_type type;
1192    enum brw_vertical_stride _vert_stride;
1193    enum brw_width _width;
1194    enum brw_horizontal_stride _horiz_stride;
1195    bool is_scalar_region;
1196    bool is_align1 = brw_inst_3src_access_mode(devinfo, inst) == BRW_ALIGN_1;
1197 
1198    if (devinfo->gen < 10 && is_align1)
1199       return 0;
1200 
1201    if (is_align1) {
1202       if (devinfo->gen >= 12) {
1203          _file = brw_inst_3src_a1_src1_reg_file(devinfo, inst);
1204       } else if (brw_inst_3src_a1_src1_reg_file(devinfo, inst) ==
1205                  BRW_ALIGN1_3SRC_GENERAL_REGISTER_FILE) {
1206          _file = BRW_GENERAL_REGISTER_FILE;
1207       } else {
1208          _file = BRW_ARCHITECTURE_REGISTER_FILE;
1209       }
1210 
1211       reg_nr = brw_inst_3src_src1_reg_nr(devinfo, inst);
1212       subreg_nr = brw_inst_3src_a1_src1_subreg_nr(devinfo, inst);
1213       type = brw_inst_3src_a1_src1_type(devinfo, inst);
1214 
1215       _vert_stride = vstride_from_align1_3src_vstride(
1216          devinfo, brw_inst_3src_a1_src1_vstride(devinfo, inst));
1217       _horiz_stride = hstride_from_align1_3src_hstride(
1218                          brw_inst_3src_a1_src1_hstride(devinfo, inst));
1219       _width = implied_width(_vert_stride, _horiz_stride);
1220    } else {
1221       _file = BRW_GENERAL_REGISTER_FILE;
1222       reg_nr = brw_inst_3src_src1_reg_nr(devinfo, inst);
1223       subreg_nr = brw_inst_3src_a16_src1_subreg_nr(devinfo, inst) * 4;
1224       type = brw_inst_3src_a16_src_type(devinfo, inst);
1225 
1226       if (brw_inst_3src_a16_src1_rep_ctrl(devinfo, inst)) {
1227          _vert_stride = BRW_VERTICAL_STRIDE_0;
1228          _width = BRW_WIDTH_1;
1229          _horiz_stride = BRW_HORIZONTAL_STRIDE_0;
1230       } else {
1231          _vert_stride = BRW_VERTICAL_STRIDE_4;
1232          _width = BRW_WIDTH_4;
1233          _horiz_stride = BRW_HORIZONTAL_STRIDE_1;
1234       }
1235    }
1236    is_scalar_region = _vert_stride == BRW_VERTICAL_STRIDE_0 &&
1237                       _width == BRW_WIDTH_1 &&
1238                       _horiz_stride == BRW_HORIZONTAL_STRIDE_0;
1239 
1240    subreg_nr /= brw_reg_type_to_size(type);
1241 
1242    err |= control(file, "negate", m_negate,
1243                   brw_inst_3src_src1_negate(devinfo, inst), NULL);
1244    err |= control(file, "abs", _abs, brw_inst_3src_src1_abs(devinfo, inst), NULL);
1245 
1246    err |= reg(file, _file, reg_nr);
1247    if (err == -1)
1248       return 0;
1249    if (subreg_nr || is_scalar_region)
1250       format(file, ".%d", subreg_nr);
1251    src_align1_region(file, _vert_stride, _width, _horiz_stride);
1252    if (!is_scalar_region && !is_align1)
1253       err |= src_swizzle(file, brw_inst_3src_a16_src1_swizzle(devinfo, inst));
1254    string(file, brw_reg_type_to_letters(type));
1255    return err;
1256 }
1257 
1258 static int
src2_3src(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1259 src2_3src(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1260 {
1261    int err = 0;
1262    unsigned reg_nr, subreg_nr;
1263    enum brw_reg_file _file;
1264    enum brw_reg_type type;
1265    enum brw_vertical_stride _vert_stride;
1266    enum brw_width _width;
1267    enum brw_horizontal_stride _horiz_stride;
1268    bool is_scalar_region;
1269    bool is_align1 = brw_inst_3src_access_mode(devinfo, inst) == BRW_ALIGN_1;
1270 
1271    if (devinfo->gen < 10 && is_align1)
1272       return 0;
1273 
1274    if (is_align1) {
1275       if (devinfo->gen >= 12 && !brw_inst_3src_a1_src2_is_imm(devinfo, inst)) {
1276          _file = brw_inst_3src_a1_src2_reg_file(devinfo, inst);
1277       } else if (brw_inst_3src_a1_src2_reg_file(devinfo, inst) ==
1278                  BRW_ALIGN1_3SRC_GENERAL_REGISTER_FILE) {
1279          _file = BRW_GENERAL_REGISTER_FILE;
1280       } else {
1281          _file = BRW_IMMEDIATE_VALUE;
1282          uint16_t imm_val = brw_inst_3src_a1_src2_imm(devinfo, inst);
1283          enum brw_reg_type type = brw_inst_3src_a1_src2_type(devinfo, inst);
1284 
1285          if (type == BRW_REGISTER_TYPE_W) {
1286             format(file, "%dW", imm_val);
1287          } else if (type == BRW_REGISTER_TYPE_UW) {
1288             format(file, "0x%04xUW", imm_val);
1289          } else if (type == BRW_REGISTER_TYPE_HF) {
1290             format(file, "0x%04xHF", imm_val);
1291          }
1292          return 0;
1293       }
1294 
1295       reg_nr = brw_inst_3src_src2_reg_nr(devinfo, inst);
1296       subreg_nr = brw_inst_3src_a1_src2_subreg_nr(devinfo, inst);
1297       type = brw_inst_3src_a1_src2_type(devinfo, inst);
1298       /* FINISHME: No vertical stride on src2. Is using the hstride in place
1299        *           correct? Doesn't seem like it, since there's hstride=1 but
1300        *           no vstride=1.
1301        */
1302       _vert_stride = vstride_from_align1_3src_hstride(
1303                         brw_inst_3src_a1_src2_hstride(devinfo, inst));
1304       _horiz_stride = hstride_from_align1_3src_hstride(
1305                          brw_inst_3src_a1_src2_hstride(devinfo, inst));
1306       _width = implied_width(_vert_stride, _horiz_stride);
1307    } else {
1308       _file = BRW_GENERAL_REGISTER_FILE;
1309       reg_nr = brw_inst_3src_src2_reg_nr(devinfo, inst);
1310       subreg_nr = brw_inst_3src_a16_src2_subreg_nr(devinfo, inst) * 4;
1311       type = brw_inst_3src_a16_src_type(devinfo, inst);
1312 
1313       if (brw_inst_3src_a16_src2_rep_ctrl(devinfo, inst)) {
1314          _vert_stride = BRW_VERTICAL_STRIDE_0;
1315          _width = BRW_WIDTH_1;
1316          _horiz_stride = BRW_HORIZONTAL_STRIDE_0;
1317       } else {
1318          _vert_stride = BRW_VERTICAL_STRIDE_4;
1319          _width = BRW_WIDTH_4;
1320          _horiz_stride = BRW_HORIZONTAL_STRIDE_1;
1321       }
1322    }
1323    is_scalar_region = _vert_stride == BRW_VERTICAL_STRIDE_0 &&
1324                       _width == BRW_WIDTH_1 &&
1325                       _horiz_stride == BRW_HORIZONTAL_STRIDE_0;
1326 
1327    subreg_nr /= brw_reg_type_to_size(type);
1328 
1329    err |= control(file, "negate", m_negate,
1330                   brw_inst_3src_src2_negate(devinfo, inst), NULL);
1331    err |= control(file, "abs", _abs, brw_inst_3src_src2_abs(devinfo, inst), NULL);
1332 
1333    err |= reg(file, _file, reg_nr);
1334    if (err == -1)
1335       return 0;
1336    if (subreg_nr || is_scalar_region)
1337       format(file, ".%d", subreg_nr);
1338    src_align1_region(file, _vert_stride, _width, _horiz_stride);
1339    if (!is_scalar_region && !is_align1)
1340       err |= src_swizzle(file, brw_inst_3src_a16_src2_swizzle(devinfo, inst));
1341    string(file, brw_reg_type_to_letters(type));
1342    return err;
1343 }
1344 
1345 static int
imm(FILE * file,const struct gen_device_info * devinfo,enum brw_reg_type type,const brw_inst * inst)1346 imm(FILE *file, const struct gen_device_info *devinfo, enum brw_reg_type type,
1347     const brw_inst *inst)
1348 {
1349    switch (type) {
1350    case BRW_REGISTER_TYPE_UQ:
1351       format(file, "0x%016"PRIx64"UQ", brw_inst_imm_uq(devinfo, inst));
1352       break;
1353    case BRW_REGISTER_TYPE_Q:
1354       format(file, "0x%016"PRIx64"Q", brw_inst_imm_uq(devinfo, inst));
1355       break;
1356    case BRW_REGISTER_TYPE_UD:
1357       format(file, "0x%08xUD", brw_inst_imm_ud(devinfo, inst));
1358       break;
1359    case BRW_REGISTER_TYPE_D:
1360       format(file, "%dD", brw_inst_imm_d(devinfo, inst));
1361       break;
1362    case BRW_REGISTER_TYPE_UW:
1363       format(file, "0x%04xUW", (uint16_t) brw_inst_imm_ud(devinfo, inst));
1364       break;
1365    case BRW_REGISTER_TYPE_W:
1366       format(file, "%dW", (int16_t) brw_inst_imm_d(devinfo, inst));
1367       break;
1368    case BRW_REGISTER_TYPE_UV:
1369       format(file, "0x%08xUV", brw_inst_imm_ud(devinfo, inst));
1370       break;
1371    case BRW_REGISTER_TYPE_VF:
1372       format(file, "0x%"PRIx64"VF", brw_inst_bits(inst, 127, 96));
1373       pad(file, 48);
1374       format(file, "/* [%-gF, %-gF, %-gF, %-gF]VF */",
1375              brw_vf_to_float(brw_inst_imm_ud(devinfo, inst)),
1376              brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 8),
1377              brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 16),
1378              brw_vf_to_float(brw_inst_imm_ud(devinfo, inst) >> 24));
1379       break;
1380    case BRW_REGISTER_TYPE_V:
1381       format(file, "0x%08xV", brw_inst_imm_ud(devinfo, inst));
1382       break;
1383    case BRW_REGISTER_TYPE_F:
1384       /* The DIM instruction's src0 uses an F type but contains a
1385        * 64-bit immediate
1386        */
1387       if (brw_inst_opcode(devinfo, inst) == BRW_OPCODE_DIM) {
1388          format(file, "0x%"PRIx64"F", brw_inst_bits(inst, 127, 64));
1389          pad(file, 48);
1390          format(file, "/* %-gF */", brw_inst_imm_df(devinfo, inst));
1391       } else {
1392          format(file, "0x%"PRIx64"F", brw_inst_bits(inst, 127, 96));
1393          pad(file, 48);
1394          format(file, " /* %-gF */", brw_inst_imm_f(devinfo, inst));
1395       }
1396       break;
1397    case BRW_REGISTER_TYPE_DF:
1398       format(file, "0x%016"PRIx64"DF", brw_inst_bits(inst, 127, 64));
1399       pad(file, 48);
1400       format(file, "/* %-gDF */", brw_inst_imm_df(devinfo, inst));
1401       break;
1402    case BRW_REGISTER_TYPE_HF:
1403       string(file, "Half Float IMM");
1404       break;
1405    case BRW_REGISTER_TYPE_NF:
1406    case BRW_REGISTER_TYPE_UB:
1407    case BRW_REGISTER_TYPE_B:
1408       format(file, "*** invalid immediate type %d ", type);
1409    }
1410    return 0;
1411 }
1412 
1413 static int
src_sends_da(FILE * file,const struct gen_device_info * devinfo,enum brw_reg_type type,enum brw_reg_file _reg_file,unsigned _reg_nr,unsigned _reg_subnr)1414 src_sends_da(FILE *file,
1415              const struct gen_device_info *devinfo,
1416              enum brw_reg_type type,
1417              enum brw_reg_file _reg_file,
1418              unsigned _reg_nr,
1419              unsigned _reg_subnr)
1420 {
1421    int err = 0;
1422 
1423    err |= reg(file, _reg_file, _reg_nr);
1424    if (err == -1)
1425       return 0;
1426    if (_reg_subnr)
1427       format(file, ".1");
1428    string(file, brw_reg_type_to_letters(type));
1429 
1430    return err;
1431 }
1432 
1433 static int
src_sends_ia(FILE * file,const struct gen_device_info * devinfo,enum brw_reg_type type,int _addr_imm,unsigned _addr_subreg_nr)1434 src_sends_ia(FILE *file,
1435              const struct gen_device_info *devinfo,
1436              enum brw_reg_type type,
1437              int _addr_imm,
1438              unsigned _addr_subreg_nr)
1439 {
1440    string(file, "g[a0");
1441    if (_addr_subreg_nr)
1442       format(file, ".1");
1443    if (_addr_imm)
1444       format(file, " %d", _addr_imm);
1445    string(file, "]");
1446    string(file, brw_reg_type_to_letters(type));
1447 
1448    return 0;
1449 }
1450 
1451 static int
src_send_desc_ia(FILE * file,const struct gen_device_info * devinfo,unsigned _addr_subreg_nr)1452 src_send_desc_ia(FILE *file,
1453                  const struct gen_device_info *devinfo,
1454                  unsigned _addr_subreg_nr)
1455 {
1456    string(file, "a0");
1457    if (_addr_subreg_nr)
1458       format(file, ".%d", _addr_subreg_nr);
1459    format(file, "<0>UD");
1460 
1461    return 0;
1462 }
1463 
1464 static int
src0(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1465 src0(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1466 {
1467    if (is_split_send(devinfo, brw_inst_opcode(devinfo, inst))) {
1468       if (devinfo->gen >= 12) {
1469          return src_sends_da(file,
1470                              devinfo,
1471                              BRW_REGISTER_TYPE_UD,
1472                              brw_inst_send_src0_reg_file(devinfo, inst),
1473                              brw_inst_src0_da_reg_nr(devinfo, inst),
1474                              0);
1475       } else if (brw_inst_send_src0_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
1476          return src_sends_da(file,
1477                              devinfo,
1478                              BRW_REGISTER_TYPE_UD,
1479                              BRW_GENERAL_REGISTER_FILE,
1480                              brw_inst_src0_da_reg_nr(devinfo, inst),
1481                              brw_inst_src0_da16_subreg_nr(devinfo, inst));
1482       } else {
1483          return src_sends_ia(file,
1484                              devinfo,
1485                              BRW_REGISTER_TYPE_UD,
1486                              brw_inst_send_src0_ia16_addr_imm(devinfo, inst),
1487                              brw_inst_src0_ia_subreg_nr(devinfo, inst));
1488       }
1489    } else if (brw_inst_src0_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
1490       return imm(file, devinfo, brw_inst_src0_type(devinfo, inst), inst);
1491    } else if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
1492       if (brw_inst_src0_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
1493          return src_da1(file,
1494                         devinfo,
1495                         brw_inst_opcode(devinfo, inst),
1496                         brw_inst_src0_type(devinfo, inst),
1497                         brw_inst_src0_reg_file(devinfo, inst),
1498                         brw_inst_src0_vstride(devinfo, inst),
1499                         brw_inst_src0_width(devinfo, inst),
1500                         brw_inst_src0_hstride(devinfo, inst),
1501                         brw_inst_src0_da_reg_nr(devinfo, inst),
1502                         brw_inst_src0_da1_subreg_nr(devinfo, inst),
1503                         brw_inst_src0_abs(devinfo, inst),
1504                         brw_inst_src0_negate(devinfo, inst));
1505       } else {
1506          return src_ia1(file,
1507                         devinfo,
1508                         brw_inst_opcode(devinfo, inst),
1509                         brw_inst_src0_type(devinfo, inst),
1510                         brw_inst_src0_ia1_addr_imm(devinfo, inst),
1511                         brw_inst_src0_ia_subreg_nr(devinfo, inst),
1512                         brw_inst_src0_negate(devinfo, inst),
1513                         brw_inst_src0_abs(devinfo, inst),
1514                         brw_inst_src0_hstride(devinfo, inst),
1515                         brw_inst_src0_width(devinfo, inst),
1516                         brw_inst_src0_vstride(devinfo, inst));
1517       }
1518    } else {
1519       if (brw_inst_src0_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
1520          return src_da16(file,
1521                          devinfo,
1522                          brw_inst_opcode(devinfo, inst),
1523                          brw_inst_src0_type(devinfo, inst),
1524                          brw_inst_src0_reg_file(devinfo, inst),
1525                          brw_inst_src0_vstride(devinfo, inst),
1526                          brw_inst_src0_da_reg_nr(devinfo, inst),
1527                          brw_inst_src0_da16_subreg_nr(devinfo, inst),
1528                          brw_inst_src0_abs(devinfo, inst),
1529                          brw_inst_src0_negate(devinfo, inst),
1530                          brw_inst_src0_da16_swiz_x(devinfo, inst),
1531                          brw_inst_src0_da16_swiz_y(devinfo, inst),
1532                          brw_inst_src0_da16_swiz_z(devinfo, inst),
1533                          brw_inst_src0_da16_swiz_w(devinfo, inst));
1534       } else {
1535          string(file, "Indirect align16 address mode not supported");
1536          return 1;
1537       }
1538    }
1539 }
1540 
1541 static int
src1(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1542 src1(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1543 {
1544    if (is_split_send(devinfo, brw_inst_opcode(devinfo, inst))) {
1545       return src_sends_da(file,
1546                           devinfo,
1547                           BRW_REGISTER_TYPE_UD,
1548                           brw_inst_send_src1_reg_file(devinfo, inst),
1549                           brw_inst_send_src1_reg_nr(devinfo, inst),
1550                           0 /* subreg_nr */);
1551    } else if (brw_inst_src1_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
1552       return imm(file, devinfo, brw_inst_src1_type(devinfo, inst), inst);
1553    } else if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
1554       if (brw_inst_src1_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
1555          return src_da1(file,
1556                         devinfo,
1557                         brw_inst_opcode(devinfo, inst),
1558                         brw_inst_src1_type(devinfo, inst),
1559                         brw_inst_src1_reg_file(devinfo, inst),
1560                         brw_inst_src1_vstride(devinfo, inst),
1561                         brw_inst_src1_width(devinfo, inst),
1562                         brw_inst_src1_hstride(devinfo, inst),
1563                         brw_inst_src1_da_reg_nr(devinfo, inst),
1564                         brw_inst_src1_da1_subreg_nr(devinfo, inst),
1565                         brw_inst_src1_abs(devinfo, inst),
1566                         brw_inst_src1_negate(devinfo, inst));
1567       } else {
1568          return src_ia1(file,
1569                         devinfo,
1570                         brw_inst_opcode(devinfo, inst),
1571                         brw_inst_src1_type(devinfo, inst),
1572                         brw_inst_src1_ia1_addr_imm(devinfo, inst),
1573                         brw_inst_src1_ia_subreg_nr(devinfo, inst),
1574                         brw_inst_src1_negate(devinfo, inst),
1575                         brw_inst_src1_abs(devinfo, inst),
1576                         brw_inst_src1_hstride(devinfo, inst),
1577                         brw_inst_src1_width(devinfo, inst),
1578                         brw_inst_src1_vstride(devinfo, inst));
1579       }
1580    } else {
1581       if (brw_inst_src1_address_mode(devinfo, inst) == BRW_ADDRESS_DIRECT) {
1582          return src_da16(file,
1583                          devinfo,
1584                          brw_inst_opcode(devinfo, inst),
1585                          brw_inst_src1_type(devinfo, inst),
1586                          brw_inst_src1_reg_file(devinfo, inst),
1587                          brw_inst_src1_vstride(devinfo, inst),
1588                          brw_inst_src1_da_reg_nr(devinfo, inst),
1589                          brw_inst_src1_da16_subreg_nr(devinfo, inst),
1590                          brw_inst_src1_abs(devinfo, inst),
1591                          brw_inst_src1_negate(devinfo, inst),
1592                          brw_inst_src1_da16_swiz_x(devinfo, inst),
1593                          brw_inst_src1_da16_swiz_y(devinfo, inst),
1594                          brw_inst_src1_da16_swiz_z(devinfo, inst),
1595                          brw_inst_src1_da16_swiz_w(devinfo, inst));
1596       } else {
1597          string(file, "Indirect align16 address mode not supported");
1598          return 1;
1599       }
1600    }
1601 }
1602 
1603 static int
qtr_ctrl(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1604 qtr_ctrl(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1605 {
1606    int qtr_ctl = brw_inst_qtr_control(devinfo, inst);
1607    int exec_size = 1 << brw_inst_exec_size(devinfo, inst);
1608    const unsigned nib_ctl = devinfo->gen < 7 ? 0 :
1609                             brw_inst_nib_control(devinfo, inst);
1610 
1611    if (exec_size < 8 || nib_ctl) {
1612       format(file, " %dN", qtr_ctl * 2 + nib_ctl + 1);
1613    } else if (exec_size == 8) {
1614       switch (qtr_ctl) {
1615       case 0:
1616          string(file, " 1Q");
1617          break;
1618       case 1:
1619          string(file, " 2Q");
1620          break;
1621       case 2:
1622          string(file, " 3Q");
1623          break;
1624       case 3:
1625          string(file, " 4Q");
1626          break;
1627       }
1628    } else if (exec_size == 16) {
1629       if (qtr_ctl < 2)
1630          string(file, " 1H");
1631       else
1632          string(file, " 2H");
1633    }
1634    return 0;
1635 }
1636 
1637 static int
swsb(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst)1638 swsb(FILE *file, const struct gen_device_info *devinfo, const brw_inst *inst)
1639 {
1640    const struct tgl_swsb swsb = tgl_swsb_decode(brw_inst_opcode(devinfo, inst),
1641                                                 brw_inst_swsb(devinfo, inst));
1642    if (swsb.regdist)
1643       format(file, " @%d", swsb.regdist);
1644    if (swsb.mode)
1645       format(file, " $%d%s", swsb.sbid,
1646              (swsb.mode & TGL_SBID_SET ? "" :
1647               swsb.mode & TGL_SBID_DST ? ".dst" : ".src"));
1648    return 0;
1649 }
1650 
1651 #ifdef DEBUG
1652 static __attribute__((__unused__)) int
brw_disassemble_imm(const struct gen_device_info * devinfo,uint32_t dw3,uint32_t dw2,uint32_t dw1,uint32_t dw0)1653 brw_disassemble_imm(const struct gen_device_info *devinfo,
1654                     uint32_t dw3, uint32_t dw2, uint32_t dw1, uint32_t dw0)
1655 {
1656    brw_inst inst;
1657    inst.data[0] = (((uint64_t) dw1) << 32) | ((uint64_t) dw0);
1658    inst.data[1] = (((uint64_t) dw3) << 32) | ((uint64_t) dw2);
1659    return brw_disassemble_inst(stderr, devinfo, &inst, false, 0, NULL);
1660 }
1661 #endif
1662 
1663 static void
write_label(FILE * file,const struct gen_device_info * devinfo,const struct brw_label * root_label,int offset,int jump)1664 write_label(FILE *file, const struct gen_device_info *devinfo,
1665             const struct brw_label *root_label,
1666             int offset, int jump)
1667 {
1668    if (root_label != NULL) {
1669       int to_bytes_scale = sizeof(brw_inst) / brw_jump_scale(devinfo);
1670       const struct brw_label *label =
1671          brw_find_label(root_label, offset + jump * to_bytes_scale);
1672       if (label != NULL) {
1673          format(file, " LABEL%d", label->number);
1674       }
1675    }
1676 }
1677 
1678 int
brw_disassemble_inst(FILE * file,const struct gen_device_info * devinfo,const brw_inst * inst,bool is_compacted,int offset,const struct brw_label * root_label)1679 brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
1680                      const brw_inst *inst, bool is_compacted,
1681                      int offset, const struct brw_label *root_label)
1682 {
1683    int err = 0;
1684    int space = 0;
1685 
1686    const enum opcode opcode = brw_inst_opcode(devinfo, inst);
1687    const struct opcode_desc *desc = brw_opcode_desc(devinfo, opcode);
1688 
1689    if (brw_inst_pred_control(devinfo, inst)) {
1690       string(file, "(");
1691       err |= control(file, "predicate inverse", pred_inv,
1692                      brw_inst_pred_inv(devinfo, inst), NULL);
1693       format(file, "f%"PRIu64".%"PRIu64,
1694              devinfo->gen >= 7 ? brw_inst_flag_reg_nr(devinfo, inst) : 0,
1695              brw_inst_flag_subreg_nr(devinfo, inst));
1696       if (brw_inst_access_mode(devinfo, inst) == BRW_ALIGN_1) {
1697          err |= control(file, "predicate control align1", pred_ctrl_align1,
1698                         brw_inst_pred_control(devinfo, inst), NULL);
1699       } else {
1700          err |= control(file, "predicate control align16", pred_ctrl_align16,
1701                         brw_inst_pred_control(devinfo, inst), NULL);
1702       }
1703       string(file, ") ");
1704    }
1705 
1706    err |= print_opcode(file, devinfo, opcode);
1707 
1708    if (!is_send(opcode))
1709       err |= control(file, "saturate", saturate, brw_inst_saturate(devinfo, inst),
1710                      NULL);
1711 
1712    err |= control(file, "debug control", debug_ctrl,
1713                   brw_inst_debug_control(devinfo, inst), NULL);
1714 
1715    if (opcode == BRW_OPCODE_MATH) {
1716       string(file, " ");
1717       err |= control(file, "function", math_function,
1718                      brw_inst_math_function(devinfo, inst), NULL);
1719 
1720    } else if (opcode == BRW_OPCODE_SYNC) {
1721       string(file, " ");
1722       err |= control(file, "function", sync_function,
1723                      brw_inst_cond_modifier(devinfo, inst), NULL);
1724 
1725    } else if (!is_send(opcode)) {
1726       err |= control(file, "conditional modifier", conditional_modifier,
1727                      brw_inst_cond_modifier(devinfo, inst), NULL);
1728 
1729       /* If we're using the conditional modifier, print which flags reg is
1730        * used for it.  Note that on gen6+, the embedded-condition SEL and
1731        * control flow doesn't update flags.
1732        */
1733       if (brw_inst_cond_modifier(devinfo, inst) &&
1734           (devinfo->gen < 6 || (opcode != BRW_OPCODE_SEL &&
1735                                 opcode != BRW_OPCODE_CSEL &&
1736                                 opcode != BRW_OPCODE_IF &&
1737                                 opcode != BRW_OPCODE_WHILE))) {
1738          format(file, ".f%"PRIu64".%"PRIu64,
1739                 devinfo->gen >= 7 ? brw_inst_flag_reg_nr(devinfo, inst) : 0,
1740                 brw_inst_flag_subreg_nr(devinfo, inst));
1741       }
1742    }
1743 
1744    if (opcode != BRW_OPCODE_NOP && opcode != BRW_OPCODE_NENOP) {
1745       string(file, "(");
1746       err |= control(file, "execution size", exec_size,
1747                      brw_inst_exec_size(devinfo, inst), NULL);
1748       string(file, ")");
1749    }
1750 
1751    if (opcode == BRW_OPCODE_SEND && devinfo->gen < 6)
1752       format(file, " %"PRIu64, brw_inst_base_mrf(devinfo, inst));
1753 
1754    if (brw_has_uip(devinfo, opcode)) {
1755       /* Instructions that have UIP also have JIP. */
1756       pad(file, 16);
1757       string(file, "JIP: ");
1758       write_label(file, devinfo, root_label, offset, brw_inst_jip(devinfo, inst));
1759 
1760       pad(file, 38);
1761       string(file, "UIP: ");
1762       write_label(file, devinfo, root_label, offset, brw_inst_uip(devinfo, inst));
1763    } else if (brw_has_jip(devinfo, opcode)) {
1764       int jip;
1765       if (devinfo->gen >= 7) {
1766          jip = brw_inst_jip(devinfo, inst);
1767       } else {
1768          jip = brw_inst_gen6_jump_count(devinfo, inst);
1769       }
1770 
1771       pad(file, 16);
1772       string(file, "JIP: ");
1773       write_label(file, devinfo, root_label, offset, jip);
1774    } else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_BREAK ||
1775                                    opcode == BRW_OPCODE_CONTINUE ||
1776                                    opcode == BRW_OPCODE_ELSE)) {
1777       pad(file, 16);
1778       format(file, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
1779       pad(file, 32);
1780       format(file, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
1781    } else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_IF ||
1782                                    opcode == BRW_OPCODE_IFF ||
1783                                    opcode == BRW_OPCODE_HALT ||
1784                                    opcode == BRW_OPCODE_WHILE)) {
1785       pad(file, 16);
1786       format(file, "Jump: %d", brw_inst_gen4_jump_count(devinfo, inst));
1787    } else if (devinfo->gen < 6 && opcode == BRW_OPCODE_ENDIF) {
1788       pad(file, 16);
1789       format(file, "Pop: %"PRIu64, brw_inst_gen4_pop_count(devinfo, inst));
1790    } else if (opcode == BRW_OPCODE_JMPI) {
1791       pad(file, 16);
1792       err |= src1(file, devinfo, inst);
1793    } else if (desc && desc->nsrc == 3) {
1794       pad(file, 16);
1795       err |= dest_3src(file, devinfo, inst);
1796 
1797       pad(file, 32);
1798       err |= src0_3src(file, devinfo, inst);
1799 
1800       pad(file, 48);
1801       err |= src1_3src(file, devinfo, inst);
1802 
1803       pad(file, 64);
1804       err |= src2_3src(file, devinfo, inst);
1805    } else if (desc) {
1806       if (desc->ndst > 0) {
1807          pad(file, 16);
1808          err |= dest(file, devinfo, inst);
1809       }
1810 
1811       if (desc->nsrc > 0) {
1812          pad(file, 32);
1813          err |= src0(file, devinfo, inst);
1814       }
1815 
1816       if (desc->nsrc > 1) {
1817          pad(file, 48);
1818          err |= src1(file, devinfo, inst);
1819       }
1820    }
1821 
1822    if (is_send(opcode)) {
1823       enum brw_message_target sfid = brw_inst_sfid(devinfo, inst);
1824 
1825       bool has_imm_desc = false, has_imm_ex_desc = false;
1826       uint32_t imm_desc = 0, imm_ex_desc = 0;
1827       if (is_split_send(devinfo, opcode)) {
1828          pad(file, 64);
1829          if (brw_inst_send_sel_reg32_desc(devinfo, inst)) {
1830             /* show the indirect descriptor source */
1831             err |= src_send_desc_ia(file, devinfo, 0);
1832          } else {
1833             has_imm_desc = true;
1834             imm_desc = brw_inst_send_desc(devinfo, inst);
1835             fprintf(file, "0x%08"PRIx32, imm_desc);
1836          }
1837 
1838          pad(file, 80);
1839          if (brw_inst_send_sel_reg32_ex_desc(devinfo, inst)) {
1840             /* show the indirect descriptor source */
1841             err |= src_send_desc_ia(file, devinfo,
1842                                     brw_inst_send_ex_desc_ia_subreg_nr(devinfo, inst));
1843          } else {
1844             has_imm_ex_desc = true;
1845             imm_ex_desc = brw_inst_sends_ex_desc(devinfo, inst);
1846             fprintf(file, "0x%08"PRIx32, imm_ex_desc);
1847          }
1848       } else {
1849          if (brw_inst_src1_reg_file(devinfo, inst) != BRW_IMMEDIATE_VALUE) {
1850             /* show the indirect descriptor source */
1851             pad(file, 48);
1852             err |= src1(file, devinfo, inst);
1853             pad(file, 64);
1854          } else {
1855             has_imm_desc = true;
1856             imm_desc = brw_inst_send_desc(devinfo, inst);
1857             pad(file, 48);
1858          }
1859 
1860          /* Print message descriptor as immediate source */
1861          fprintf(file, "0x%08"PRIx64, inst->data[1] >> 32);
1862       }
1863 
1864       newline(file);
1865       pad(file, 16);
1866       space = 0;
1867 
1868       fprintf(file, "            ");
1869       err |= control(file, "SFID", devinfo->gen >= 6 ? gen6_sfid : gen4_sfid,
1870                      sfid, &space);
1871       string(file, " MsgDesc:");
1872 
1873       if (!has_imm_desc) {
1874          format(file, " indirect");
1875       } else {
1876          switch (sfid) {
1877          case BRW_SFID_MATH:
1878             err |= control(file, "math function", math_function,
1879                            brw_inst_math_msg_function(devinfo, inst), &space);
1880             err |= control(file, "math saturate", math_saturate,
1881                            brw_inst_math_msg_saturate(devinfo, inst), &space);
1882             err |= control(file, "math signed", math_signed,
1883                            brw_inst_math_msg_signed_int(devinfo, inst), &space);
1884             err |= control(file, "math scalar", math_scalar,
1885                            brw_inst_math_msg_data_type(devinfo, inst), &space);
1886             err |= control(file, "math precision", math_precision,
1887                            brw_inst_math_msg_precision(devinfo, inst), &space);
1888             break;
1889          case BRW_SFID_SAMPLER:
1890             if (devinfo->gen >= 5) {
1891                err |= control(file, "sampler message", gen5_sampler_msg_type,
1892                               brw_sampler_desc_msg_type(devinfo, imm_desc),
1893                               &space);
1894                err |= control(file, "sampler simd mode", gen5_sampler_simd_mode,
1895                               brw_sampler_desc_simd_mode(devinfo, imm_desc),
1896                               &space);
1897                format(file, " Surface = %u Sampler = %u",
1898                       brw_sampler_desc_binding_table_index(devinfo, imm_desc),
1899                       brw_sampler_desc_sampler(devinfo, imm_desc));
1900             } else {
1901                format(file, " (%u, %u, %u, ",
1902                       brw_sampler_desc_binding_table_index(devinfo, imm_desc),
1903                       brw_sampler_desc_sampler(devinfo, imm_desc),
1904                       brw_sampler_desc_msg_type(devinfo, imm_desc));
1905                if (!devinfo->is_g4x) {
1906                   err |= control(file, "sampler target format",
1907                                  sampler_target_format,
1908                                  brw_sampler_desc_return_format(devinfo, imm_desc),
1909                                  NULL);
1910                }
1911                string(file, ")");
1912             }
1913             break;
1914          case GEN6_SFID_DATAPORT_SAMPLER_CACHE:
1915          case GEN6_SFID_DATAPORT_CONSTANT_CACHE:
1916             /* aka BRW_SFID_DATAPORT_READ on Gen4-5 */
1917             if (devinfo->gen >= 6) {
1918                format(file, " (%u, %u, %u, %u)",
1919                       brw_dp_desc_binding_table_index(devinfo, imm_desc),
1920                       brw_dp_desc_msg_control(devinfo, imm_desc),
1921                       brw_dp_desc_msg_type(devinfo, imm_desc),
1922                       devinfo->gen >= 7 ? 0u :
1923                       brw_dp_write_desc_write_commit(devinfo, imm_desc));
1924             } else {
1925                bool is_965 = devinfo->gen == 4 && !devinfo->is_g4x;
1926                err |= control(file, "DP read message type",
1927                               is_965 ? gen4_dp_read_port_msg_type :
1928                                        g45_dp_read_port_msg_type,
1929                               brw_dp_read_desc_msg_type(devinfo, imm_desc),
1930                               &space);
1931 
1932                format(file, " MsgCtrl = 0x%u",
1933                       brw_dp_read_desc_msg_control(devinfo, imm_desc));
1934 
1935                format(file, " Surface = %u",
1936                       brw_dp_desc_binding_table_index(devinfo, imm_desc));
1937             }
1938             break;
1939 
1940          case GEN6_SFID_DATAPORT_RENDER_CACHE: {
1941             /* aka BRW_SFID_DATAPORT_WRITE on Gen4-5 */
1942             unsigned msg_type = brw_dp_write_desc_msg_type(devinfo, imm_desc);
1943 
1944             err |= control(file, "DP rc message type",
1945                            dp_rc_msg_type(devinfo), msg_type, &space);
1946 
1947             bool is_rt_write = msg_type ==
1948                (devinfo->gen >= 6 ? GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE
1949                                   : BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE);
1950 
1951             if (is_rt_write) {
1952                err |= control(file, "RT message type", m_rt_write_subtype,
1953                               brw_inst_rt_message_type(devinfo, inst), &space);
1954                if (devinfo->gen >= 6 && brw_inst_rt_slot_group(devinfo, inst))
1955                   string(file, " Hi");
1956                if (brw_dp_write_desc_last_render_target(devinfo, imm_desc))
1957                   string(file, " LastRT");
1958                if (devinfo->gen < 7 &&
1959                    brw_dp_write_desc_write_commit(devinfo, imm_desc))
1960                   string(file, " WriteCommit");
1961             } else {
1962                format(file, " MsgCtrl = 0x%u",
1963                       brw_dp_write_desc_msg_control(devinfo, imm_desc));
1964             }
1965 
1966             format(file, " Surface = %u",
1967                    brw_dp_desc_binding_table_index(devinfo, imm_desc));
1968             break;
1969          }
1970 
1971          case BRW_SFID_URB: {
1972             unsigned opcode = brw_inst_urb_opcode(devinfo, inst);
1973 
1974             format(file, " %"PRIu64, brw_inst_urb_global_offset(devinfo, inst));
1975 
1976             space = 1;
1977 
1978             err |= control(file, "urb opcode",
1979                            devinfo->gen >= 7 ? gen7_urb_opcode
1980                                              : gen5_urb_opcode,
1981                            opcode, &space);
1982 
1983             if (devinfo->gen >= 7 &&
1984                 brw_inst_urb_per_slot_offset(devinfo, inst)) {
1985                string(file, " per-slot");
1986             }
1987 
1988             if (opcode == GEN8_URB_OPCODE_SIMD8_WRITE ||
1989                 opcode == GEN8_URB_OPCODE_SIMD8_READ) {
1990                if (brw_inst_urb_channel_mask_present(devinfo, inst))
1991                   string(file, " masked");
1992             } else {
1993                err |= control(file, "urb swizzle", urb_swizzle,
1994                               brw_inst_urb_swizzle_control(devinfo, inst),
1995                               &space);
1996             }
1997 
1998             if (devinfo->gen < 7) {
1999                err |= control(file, "urb allocate", urb_allocate,
2000                               brw_inst_urb_allocate(devinfo, inst), &space);
2001                err |= control(file, "urb used", urb_used,
2002                               brw_inst_urb_used(devinfo, inst), &space);
2003             }
2004             if (devinfo->gen < 8) {
2005                err |= control(file, "urb complete", urb_complete,
2006                               brw_inst_urb_complete(devinfo, inst), &space);
2007             }
2008             break;
2009          }
2010          case BRW_SFID_THREAD_SPAWNER:
2011             break;
2012 
2013          case BRW_SFID_MESSAGE_GATEWAY:
2014             format(file, " (%s)",
2015                    gen7_gateway_subfuncid[brw_inst_gateway_subfuncid(devinfo, inst)]);
2016             break;
2017 
2018          case GEN7_SFID_DATAPORT_DATA_CACHE:
2019             if (devinfo->gen >= 7) {
2020                format(file, " (");
2021 
2022                err |= control(file, "DP DC0 message type",
2023                               dp_dc0_msg_type_gen7,
2024                               brw_dp_desc_msg_type(devinfo, imm_desc), &space);
2025 
2026                format(file, ", %u, ",
2027                       brw_dp_desc_binding_table_index(devinfo, imm_desc));
2028 
2029                switch (brw_inst_dp_msg_type(devinfo, inst)) {
2030                case GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP:
2031                   control(file, "atomic op", aop,
2032                           brw_dp_desc_msg_control(devinfo, imm_desc) & 0xf,
2033                           &space);
2034                   break;
2035                default:
2036                   format(file, "%u",
2037                          brw_dp_desc_msg_control(devinfo, imm_desc));
2038                }
2039                format(file, ")");
2040                break;
2041             }
2042             /* FALLTHROUGH */
2043 
2044          case HSW_SFID_DATAPORT_DATA_CACHE_1: {
2045             if (devinfo->gen >= 7) {
2046                format(file, " (");
2047 
2048                unsigned msg_ctrl = brw_dp_desc_msg_control(devinfo, imm_desc);
2049 
2050                err |= control(file, "DP DC1 message type",
2051                               dp_dc1_msg_type_hsw,
2052                               brw_dp_desc_msg_type(devinfo, imm_desc), &space);
2053 
2054                format(file, ", Surface = %u, ",
2055                       brw_dp_desc_binding_table_index(devinfo, imm_desc));
2056 
2057                switch (brw_inst_dp_msg_type(devinfo, inst)) {
2058                case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP:
2059                case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP:
2060                case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP:
2061                   format(file, "SIMD%d,", (msg_ctrl & (1 << 4)) ? 8 : 16);
2062                   /* fallthrough */
2063                case HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2:
2064                case HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2:
2065                case HSW_DATAPORT_DC_PORT1_ATOMIC_COUNTER_OP_SIMD4X2:
2066                case GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP:
2067                   control(file, "atomic op", aop, msg_ctrl & 0xf, &space);
2068                   break;
2069                case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ:
2070                case HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE:
2071                case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ:
2072                case HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE:
2073                case GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE:
2074                case GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ: {
2075                   static const char *simd_modes[] = { "4x2", "16", "8" };
2076                   format(file, "SIMD%s, Mask = 0x%x",
2077                          simd_modes[msg_ctrl >> 4], msg_ctrl & 0xf);
2078                   break;
2079                }
2080                case GEN9_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_FLOAT_OP:
2081                case GEN9_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_FLOAT_OP:
2082                   format(file, "SIMD%d,", (msg_ctrl & (1 << 4)) ? 8 : 16);
2083                   control(file, "atomic float op", aop_float, msg_ctrl & 0xf,
2084                           &space);
2085                   break;
2086                default:
2087                   format(file, "0x%x", msg_ctrl);
2088                }
2089                format(file, ")");
2090                break;
2091             }
2092          }
2093          /* FALLTHROUGH */
2094 
2095          case GEN7_SFID_PIXEL_INTERPOLATOR:
2096             if (devinfo->gen >= 7) {
2097                format(file, " (%s, %s, 0x%02"PRIx64")",
2098                       brw_inst_pi_nopersp(devinfo, inst) ? "linear" : "persp",
2099                       pixel_interpolator_msg_types[brw_inst_pi_message_type(devinfo, inst)],
2100                       brw_inst_pi_message_data(devinfo, inst));
2101                break;
2102             }
2103             /* FALLTHROUGH */
2104 
2105          default:
2106             format(file, "unsupported shared function ID %d", sfid);
2107             break;
2108          }
2109 
2110          if (space)
2111             string(file, " ");
2112       }
2113       if (has_imm_desc)
2114          format(file, "mlen %u", brw_message_desc_mlen(devinfo, imm_desc));
2115       if (has_imm_ex_desc) {
2116          format(file, " ex_mlen %u",
2117                 brw_message_ex_desc_ex_mlen(devinfo, imm_ex_desc));
2118       }
2119       if (has_imm_desc)
2120          format(file, " rlen %u", brw_message_desc_rlen(devinfo, imm_desc));
2121    }
2122    pad(file, 64);
2123    if (opcode != BRW_OPCODE_NOP && opcode != BRW_OPCODE_NENOP) {
2124       string(file, "{");
2125       space = 1;
2126       err |= control(file, "access mode", access_mode,
2127                      brw_inst_access_mode(devinfo, inst), &space);
2128       if (devinfo->gen >= 6) {
2129          err |= control(file, "write enable control", wectrl,
2130                         brw_inst_mask_control(devinfo, inst), &space);
2131       } else {
2132          err |= control(file, "mask control", mask_ctrl,
2133                         brw_inst_mask_control(devinfo, inst), &space);
2134       }
2135 
2136       if (devinfo->gen < 12) {
2137          err |= control(file, "dependency control", dep_ctrl,
2138                         ((brw_inst_no_dd_check(devinfo, inst) << 1) |
2139                          brw_inst_no_dd_clear(devinfo, inst)), &space);
2140       }
2141 
2142       if (devinfo->gen >= 6)
2143          err |= qtr_ctrl(file, devinfo, inst);
2144       else {
2145          if (brw_inst_qtr_control(devinfo, inst) == BRW_COMPRESSION_COMPRESSED &&
2146              desc && desc->ndst > 0 &&
2147              brw_inst_dst_reg_file(devinfo, inst) == BRW_MESSAGE_REGISTER_FILE &&
2148              brw_inst_dst_da_reg_nr(devinfo, inst) & BRW_MRF_COMPR4) {
2149             format(file, " compr4");
2150          } else {
2151             err |= control(file, "compression control", compr_ctrl,
2152                            brw_inst_qtr_control(devinfo, inst), &space);
2153          }
2154       }
2155 
2156       if (devinfo->gen >= 12)
2157          err |= swsb(file, devinfo, inst);
2158 
2159       err |= control(file, "compaction", cmpt_ctrl, is_compacted, &space);
2160       err |= control(file, "thread control", thread_ctrl,
2161                      (devinfo->gen >= 12 ? brw_inst_atomic_control(devinfo, inst) :
2162                                            brw_inst_thread_control(devinfo, inst)),
2163                      &space);
2164       if (has_branch_ctrl(devinfo, opcode)) {
2165          err |= control(file, "branch ctrl", branch_ctrl,
2166                         brw_inst_branch_control(devinfo, inst), &space);
2167       } else if (devinfo->gen >= 6) {
2168          err |= control(file, "acc write control", accwr,
2169                         brw_inst_acc_wr_control(devinfo, inst), &space);
2170       }
2171       if (is_send(opcode))
2172          err |= control(file, "end of thread", end_of_thread,
2173                         brw_inst_eot(devinfo, inst), &space);
2174       if (space)
2175          string(file, " ");
2176       string(file, "}");
2177    }
2178    string(file, ";");
2179    newline(file);
2180    return err;
2181 }
2182