028e2b36c4b4c367d4dd850996d00173d8d1d329
[mesa.git] / src / broadcom / compiler / vir_dump.c
1 /*
2 * Copyright © 2016-2017 Broadcom
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "broadcom/common/v3d_device_info.h"
25 #include "v3d_compiler.h"
26
27 /* Prints a human-readable description of the uniform reference. */
28 void
29 vir_dump_uniform(enum quniform_contents contents,
30 uint32_t data)
31 {
32 static const char *quniform_names[] = {
33 [QUNIFORM_VIEWPORT_X_SCALE] = "vp_x_scale",
34 [QUNIFORM_VIEWPORT_Y_SCALE] = "vp_y_scale",
35 [QUNIFORM_VIEWPORT_Z_OFFSET] = "vp_z_offset",
36 [QUNIFORM_VIEWPORT_Z_SCALE] = "vp_z_scale",
37 };
38
39 switch (contents) {
40 case QUNIFORM_CONSTANT:
41 fprintf(stderr, "0x%08x / %f", data, uif(data));
42 break;
43
44 case QUNIFORM_UNIFORM:
45 fprintf(stderr, "push[%d]", data);
46 break;
47
48 case QUNIFORM_TEXTURE_CONFIG_P1:
49 fprintf(stderr, "tex[%d].p1", data);
50 break;
51
52 case QUNIFORM_TMU_CONFIG_P0:
53 fprintf(stderr, "tex[%d].p0 | 0x%x",
54 v3d_tmu_config_data_get_unit(data),
55 v3d_tmu_config_data_get_value(data));
56 break;
57
58 case QUNIFORM_TMU_CONFIG_P1:
59 fprintf(stderr, "tex[%d].p1 | 0x%x",
60 v3d_tmu_config_data_get_unit(data),
61 v3d_tmu_config_data_get_value(data));
62 break;
63
64 case QUNIFORM_IMAGE_TMU_CONFIG_P0:
65 fprintf(stderr, "img[%d].p0 | 0x%x",
66 v3d_tmu_config_data_get_unit(data),
67 v3d_tmu_config_data_get_value(data));
68 break;
69
70 case QUNIFORM_TEXTURE_WIDTH:
71 fprintf(stderr, "tex[%d].width", data);
72 break;
73 case QUNIFORM_TEXTURE_HEIGHT:
74 fprintf(stderr, "tex[%d].height", data);
75 break;
76 case QUNIFORM_TEXTURE_DEPTH:
77 fprintf(stderr, "tex[%d].depth", data);
78 break;
79 case QUNIFORM_TEXTURE_ARRAY_SIZE:
80 fprintf(stderr, "tex[%d].array_size", data);
81 break;
82 case QUNIFORM_TEXTURE_LEVELS:
83 fprintf(stderr, "tex[%d].levels", data);
84 break;
85
86 case QUNIFORM_IMAGE_WIDTH:
87 fprintf(stderr, "img[%d].width", data);
88 break;
89 case QUNIFORM_IMAGE_HEIGHT:
90 fprintf(stderr, "img[%d].height", data);
91 break;
92 case QUNIFORM_IMAGE_DEPTH:
93 fprintf(stderr, "img[%d].depth", data);
94 break;
95 case QUNIFORM_IMAGE_ARRAY_SIZE:
96 fprintf(stderr, "img[%d].array_size", data);
97 break;
98
99 case QUNIFORM_UBO_ADDR:
100 fprintf(stderr, "ubo[%d]", data);
101 break;
102
103 case QUNIFORM_SSBO_OFFSET:
104 fprintf(stderr, "ssbo[%d]", data);
105 break;
106
107 case QUNIFORM_GET_BUFFER_SIZE:
108 fprintf(stderr, "ssbo_size[%d]", data);
109 break;
110
111 default:
112 if (quniform_contents_is_texture_p0(contents)) {
113 fprintf(stderr, "tex[%d].p0: 0x%08x",
114 contents - QUNIFORM_TEXTURE_CONFIG_P0_0,
115 data);
116 } else if (contents < ARRAY_SIZE(quniform_names)) {
117 fprintf(stderr, "%s",
118 quniform_names[contents]);
119 } else {
120 fprintf(stderr, "%d / 0x%08x", contents, data);
121 }
122 }
123 }
124
125 static void
126 vir_print_reg(struct v3d_compile *c, const struct qinst *inst,
127 struct qreg reg)
128 {
129 static const char *files[] = {
130 [QFILE_TEMP] = "t",
131 [QFILE_UNIF] = "u",
132 [QFILE_TLB] = "tlb",
133 [QFILE_TLBU] = "tlbu",
134 };
135
136 switch (reg.file) {
137
138 case QFILE_NULL:
139 fprintf(stderr, "null");
140 break;
141
142 case QFILE_LOAD_IMM:
143 fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
144 break;
145
146 case QFILE_REG:
147 fprintf(stderr, "rf%d", reg.index);
148 break;
149
150 case QFILE_MAGIC:
151 fprintf(stderr, "%s", v3d_qpu_magic_waddr_name(reg.index));
152 break;
153
154 case QFILE_SMALL_IMM: {
155 uint32_t unpacked;
156 bool ok = v3d_qpu_small_imm_unpack(c->devinfo,
157 inst->qpu.raddr_b,
158 &unpacked);
159 assert(ok); (void) ok;
160
161 if ((int)inst->qpu.raddr_b >= -16 &&
162 (int)inst->qpu.raddr_b <= 15)
163 fprintf(stderr, "%d", unpacked);
164 else
165 fprintf(stderr, "%f", uif(unpacked));
166 break;
167 }
168
169 case QFILE_VPM:
170 fprintf(stderr, "vpm%d.%d",
171 reg.index / 4, reg.index % 4);
172 break;
173
174 case QFILE_TLB:
175 case QFILE_TLBU:
176 fprintf(stderr, "%s", files[reg.file]);
177 break;
178
179 case QFILE_UNIF:
180 fprintf(stderr, "%s%d", files[reg.file], reg.index);
181 fprintf(stderr, " (");
182 vir_dump_uniform(c->uniform_contents[reg.index],
183 c->uniform_data[reg.index]);
184 fprintf(stderr, ")");
185 break;
186
187 default:
188 fprintf(stderr, "%s%d", files[reg.file], reg.index);
189 break;
190 }
191 }
192
193 static void
194 vir_dump_sig_addr(const struct v3d_device_info *devinfo,
195 const struct v3d_qpu_instr *instr)
196 {
197 if (devinfo->ver < 41)
198 return;
199
200 if (!instr->sig_magic)
201 fprintf(stderr, ".rf%d", instr->sig_addr);
202 else {
203 const char *name = v3d_qpu_magic_waddr_name(instr->sig_addr);
204 if (name)
205 fprintf(stderr, ".%s", name);
206 else
207 fprintf(stderr, ".UNKNOWN%d", instr->sig_addr);
208 }
209 }
210
211 static void
212 vir_dump_sig(struct v3d_compile *c, struct qinst *inst)
213 {
214 struct v3d_qpu_sig *sig = &inst->qpu.sig;
215
216 if (sig->thrsw)
217 fprintf(stderr, "; thrsw");
218 if (sig->ldvary) {
219 fprintf(stderr, "; ldvary");
220 vir_dump_sig_addr(c->devinfo, &inst->qpu);
221 }
222 if (sig->ldvpm)
223 fprintf(stderr, "; ldvpm");
224 if (sig->ldtmu) {
225 fprintf(stderr, "; ldtmu");
226 vir_dump_sig_addr(c->devinfo, &inst->qpu);
227 }
228 if (sig->ldtlb) {
229 fprintf(stderr, "; ldtlb");
230 vir_dump_sig_addr(c->devinfo, &inst->qpu);
231 }
232 if (sig->ldtlbu) {
233 fprintf(stderr, "; ldtlbu");
234 vir_dump_sig_addr(c->devinfo, &inst->qpu);
235 }
236 if (sig->ldunif)
237 fprintf(stderr, "; ldunif");
238 if (sig->ldunifrf) {
239 fprintf(stderr, "; ldunifrf");
240 vir_dump_sig_addr(c->devinfo, &inst->qpu);
241 }
242 if (sig->ldunifa)
243 fprintf(stderr, "; ldunifa");
244 if (sig->ldunifarf) {
245 fprintf(stderr, "; ldunifarf");
246 vir_dump_sig_addr(c->devinfo, &inst->qpu);
247 }
248 if (sig->wrtmuc)
249 fprintf(stderr, "; wrtmuc");
250 }
251
252 static void
253 vir_dump_alu(struct v3d_compile *c, struct qinst *inst)
254 {
255 struct v3d_qpu_instr *instr = &inst->qpu;
256 int nsrc = vir_get_non_sideband_nsrc(inst);
257 int sideband_nsrc = vir_get_nsrc(inst);
258 enum v3d_qpu_input_unpack unpack[2];
259
260 if (inst->qpu.alu.add.op != V3D_QPU_A_NOP) {
261 fprintf(stderr, "%s", v3d_qpu_add_op_name(instr->alu.add.op));
262 fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.ac));
263 fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.apf));
264 fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.auf));
265 fprintf(stderr, " ");
266
267 vir_print_reg(c, inst, inst->dst);
268 fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.add.output_pack));
269
270 unpack[0] = instr->alu.add.a_unpack;
271 unpack[1] = instr->alu.add.b_unpack;
272 } else {
273 fprintf(stderr, "%s", v3d_qpu_mul_op_name(instr->alu.mul.op));
274 fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.mc));
275 fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.mpf));
276 fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.muf));
277 fprintf(stderr, " ");
278
279 vir_print_reg(c, inst, inst->dst);
280 fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.mul.output_pack));
281
282 unpack[0] = instr->alu.mul.a_unpack;
283 unpack[1] = instr->alu.mul.b_unpack;
284 }
285
286 for (int i = 0; i < sideband_nsrc; i++) {
287 fprintf(stderr, ", ");
288 vir_print_reg(c, inst, inst->src[i]);
289 if (i < nsrc)
290 fprintf(stderr, "%s", v3d_qpu_unpack_name(unpack[i]));
291 }
292
293 vir_dump_sig(c, inst);
294 }
295
296 void
297 vir_dump_inst(struct v3d_compile *c, struct qinst *inst)
298 {
299 struct v3d_qpu_instr *instr = &inst->qpu;
300
301 switch (inst->qpu.type) {
302 case V3D_QPU_INSTR_TYPE_ALU:
303 vir_dump_alu(c, inst);
304 break;
305 case V3D_QPU_INSTR_TYPE_BRANCH:
306 fprintf(stderr, "b");
307 if (instr->branch.ub)
308 fprintf(stderr, "u");
309
310 fprintf(stderr, "%s",
311 v3d_qpu_branch_cond_name(instr->branch.cond));
312 fprintf(stderr, "%s", v3d_qpu_msfign_name(instr->branch.msfign));
313
314 switch (instr->branch.bdi) {
315 case V3D_QPU_BRANCH_DEST_ABS:
316 fprintf(stderr, " zero_addr+0x%08x", instr->branch.offset);
317 break;
318
319 case V3D_QPU_BRANCH_DEST_REL:
320 fprintf(stderr, " %d", instr->branch.offset);
321 break;
322
323 case V3D_QPU_BRANCH_DEST_LINK_REG:
324 fprintf(stderr, " lri");
325 break;
326
327 case V3D_QPU_BRANCH_DEST_REGFILE:
328 fprintf(stderr, " rf%d", instr->branch.raddr_a);
329 break;
330 }
331
332 if (instr->branch.ub) {
333 switch (instr->branch.bdu) {
334 case V3D_QPU_BRANCH_DEST_ABS:
335 fprintf(stderr, ", a:unif");
336 break;
337
338 case V3D_QPU_BRANCH_DEST_REL:
339 fprintf(stderr, ", r:unif");
340 break;
341
342 case V3D_QPU_BRANCH_DEST_LINK_REG:
343 fprintf(stderr, ", lri");
344 break;
345
346 case V3D_QPU_BRANCH_DEST_REGFILE:
347 fprintf(stderr, ", rf%d", instr->branch.raddr_a);
348 break;
349 }
350 }
351
352 if (vir_has_implicit_uniform(inst)) {
353 fprintf(stderr, " ");
354 vir_print_reg(c, inst, inst->src[vir_get_implicit_uniform_src(inst)]);
355 }
356
357 break;
358 }
359 }
360
361 void
362 vir_dump(struct v3d_compile *c)
363 {
364 int ip = 0;
365
366 vir_for_each_block(block, c) {
367 fprintf(stderr, "BLOCK %d:\n", block->index);
368 vir_for_each_inst(inst, block) {
369 if (c->live_intervals_valid) {
370 bool first = true;
371
372 for (int i = 0; i < c->num_temps; i++) {
373 if (c->temp_start[i] != ip)
374 continue;
375
376 if (first) {
377 first = false;
378 } else {
379 fprintf(stderr, ", ");
380 }
381 fprintf(stderr, "S%4d", i);
382 }
383
384 if (first)
385 fprintf(stderr, " ");
386 else
387 fprintf(stderr, " ");
388 }
389
390 if (c->live_intervals_valid) {
391 bool first = true;
392
393 for (int i = 0; i < c->num_temps; i++) {
394 if (c->temp_end[i] != ip)
395 continue;
396
397 if (first) {
398 first = false;
399 } else {
400 fprintf(stderr, ", ");
401 }
402 fprintf(stderr, "E%4d", i);
403 }
404
405 if (first)
406 fprintf(stderr, " ");
407 else
408 fprintf(stderr, " ");
409 }
410
411 vir_dump_inst(c, inst);
412 fprintf(stderr, "\n");
413 ip++;
414 }
415 if (block->successors[1]) {
416 fprintf(stderr, "-> BLOCK %d, %d\n",
417 block->successors[0]->index,
418 block->successors[1]->index);
419 } else if (block->successors[0]) {
420 fprintf(stderr, "-> BLOCK %d\n",
421 block->successors[0]->index);
422 }
423 }
424 }