summaryrefslogtreecommitdiff
path: root/src/broadcom/compiler/vir_dump.c
blob: 56960e6d7ab6f51e0cf6584b9abe77a94d221699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
 * Copyright © 2016-2017 Broadcom
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include "broadcom/common/v3d_device_info.h"
#include "v3d_compiler.h"

/* Prints a human-readable description of the uniform reference. */
void
vir_dump_uniform(enum quniform_contents contents,
                 uint32_t data)
{
        static const char *quniform_names[] = {
                [QUNIFORM_VIEWPORT_X_SCALE] = "vp_x_scale",
                [QUNIFORM_VIEWPORT_Y_SCALE] = "vp_y_scale",
                [QUNIFORM_VIEWPORT_Z_OFFSET] = "vp_z_offset",
                [QUNIFORM_VIEWPORT_Z_SCALE] = "vp_z_scale",
        };

        switch (contents) {
        case QUNIFORM_CONSTANT:
                fprintf(stderr, "0x%08x / %f", data, uif(data));
                break;

        case QUNIFORM_UNIFORM:
                fprintf(stderr, "push[%d]", data);
                break;

        case QUNIFORM_TEXTURE_CONFIG_P1:
                fprintf(stderr, "tex[%d].p1", data);
                break;

        case QUNIFORM_TMU_CONFIG_P0:
                fprintf(stderr, "tex[%d].p0 | 0x%x",
                        v3d_tmu_config_data_get_unit(data),
                        v3d_tmu_config_data_get_value(data));
                break;

        case QUNIFORM_TMU_CONFIG_P1:
                fprintf(stderr, "tex[%d].p1 | 0x%x",
                        v3d_tmu_config_data_get_unit(data),
                        v3d_tmu_config_data_get_value(data));
                break;

        case QUNIFORM_TEXTURE_WIDTH:
                fprintf(stderr, "tex[%d].width", data);
                break;
        case QUNIFORM_TEXTURE_HEIGHT:
                fprintf(stderr, "tex[%d].height", data);
                break;
        case QUNIFORM_TEXTURE_DEPTH:
                fprintf(stderr, "tex[%d].depth", data);
                break;
        case QUNIFORM_TEXTURE_ARRAY_SIZE:
                fprintf(stderr, "tex[%d].array_size", data);
                break;
        case QUNIFORM_TEXTURE_LEVELS:
                fprintf(stderr, "tex[%d].levels", data);
                break;

        case QUNIFORM_UBO_ADDR:
                fprintf(stderr, "ubo[%d]", data);
                break;

        default:
                if (quniform_contents_is_texture_p0(contents)) {
                        fprintf(stderr, "tex[%d].p0: 0x%08x",
                                contents - QUNIFORM_TEXTURE_CONFIG_P0_0,
                                data);
                } else if (contents < ARRAY_SIZE(quniform_names)) {
                        fprintf(stderr, "%s",
                                quniform_names[contents]);
                } else {
                        fprintf(stderr, "%d / 0x%08x", contents, data);
                }
        }
}

static void
vir_print_reg(struct v3d_compile *c, const struct qinst *inst,
              struct qreg reg)
{
        static const char *files[] = {
                [QFILE_TEMP] = "t",
                [QFILE_UNIF] = "u",
                [QFILE_TLB] = "tlb",
                [QFILE_TLBU] = "tlbu",
        };

        switch (reg.file) {

        case QFILE_NULL:
                fprintf(stderr, "null");
                break;

        case QFILE_LOAD_IMM:
                fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
                break;

        case QFILE_REG:
                fprintf(stderr, "rf%d", reg.index);
                break;

        case QFILE_MAGIC:
                fprintf(stderr, "%s", v3d_qpu_magic_waddr_name(reg.index));
                break;

        case QFILE_SMALL_IMM: {
                uint32_t unpacked;
                bool ok = v3d_qpu_small_imm_unpack(c->devinfo,
                                                   inst->qpu.raddr_b,
                                                   &unpacked);
                assert(ok); (void) ok;

                if ((int)inst->qpu.raddr_b >= -16 &&
                    (int)inst->qpu.raddr_b <= 15)
                        fprintf(stderr, "%d", unpacked);
                else
                        fprintf(stderr, "%f", uif(unpacked));
                break;
        }

        case QFILE_VPM:
                fprintf(stderr, "vpm%d.%d",
                        reg.index / 4, reg.index % 4);
                break;

        case QFILE_TLB:
        case QFILE_TLBU:
                fprintf(stderr, "%s", files[reg.file]);
                break;

        case QFILE_UNIF:
                fprintf(stderr, "%s%d", files[reg.file], reg.index);
                fprintf(stderr, " (");
                vir_dump_uniform(c->uniform_contents[reg.index],
                                 c->uniform_data[reg.index]);
                fprintf(stderr, ")");
                break;

        default:
                fprintf(stderr, "%s%d", files[reg.file], reg.index);
                break;
        }
}

static void
vir_dump_sig_addr(const struct v3d_device_info *devinfo,
                  const struct v3d_qpu_instr *instr)
{
        if (devinfo->ver < 41)
                return;

        if (!instr->sig_magic)
                fprintf(stderr, ".rf%d", instr->sig_addr);
        else {
                const char *name = v3d_qpu_magic_waddr_name(instr->sig_addr);
                if (name)
                        fprintf(stderr, ".%s", name);
                else
                        fprintf(stderr, ".UNKNOWN%d", instr->sig_addr);
        }
}

static void
vir_dump_sig(struct v3d_compile *c, struct qinst *inst)
{
        struct v3d_qpu_sig *sig = &inst->qpu.sig;

        if (sig->thrsw)
                fprintf(stderr, "; thrsw");
        if (sig->ldvary) {
                fprintf(stderr, "; ldvary");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->ldvpm)
                fprintf(stderr, "; ldvpm");
        if (sig->ldtmu) {
                fprintf(stderr, "; ldtmu");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->ldtlb) {
                fprintf(stderr, "; ldtlb");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->ldtlbu) {
                fprintf(stderr, "; ldtlbu");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->ldunif)
                fprintf(stderr, "; ldunif");
        if (sig->ldunifrf) {
                fprintf(stderr, "; ldunifrf");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->ldunifa)
                fprintf(stderr, "; ldunifa");
        if (sig->ldunifarf) {
                fprintf(stderr, "; ldunifarf");
                vir_dump_sig_addr(c->devinfo, &inst->qpu);
        }
        if (sig->wrtmuc)
                fprintf(stderr, "; wrtmuc");
}

static void
vir_dump_alu(struct v3d_compile *c, struct qinst *inst)
{
        struct v3d_qpu_instr *instr = &inst->qpu;
        int nsrc = vir_get_non_sideband_nsrc(inst);
        int sideband_nsrc = vir_get_nsrc(inst);
        enum v3d_qpu_input_unpack unpack[2];

        if (inst->qpu.alu.add.op != V3D_QPU_A_NOP) {
                fprintf(stderr, "%s", v3d_qpu_add_op_name(instr->alu.add.op));
                fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.ac));
                fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.apf));
                fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.auf));
                fprintf(stderr, " ");

                vir_print_reg(c, inst, inst->dst);
                fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.add.output_pack));

                unpack[0] = instr->alu.add.a_unpack;
                unpack[1] = instr->alu.add.b_unpack;
        } else {
                fprintf(stderr, "%s", v3d_qpu_mul_op_name(instr->alu.mul.op));
                fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.mc));
                fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.mpf));
                fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.muf));
                fprintf(stderr, " ");

                vir_print_reg(c, inst, inst->dst);
                fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.mul.output_pack));

                unpack[0] = instr->alu.mul.a_unpack;
                unpack[1] = instr->alu.mul.b_unpack;
        }

        for (int i = 0; i < sideband_nsrc; i++) {
                fprintf(stderr, ", ");
                vir_print_reg(c, inst, inst->src[i]);
                if (i < nsrc)
                        fprintf(stderr, "%s", v3d_qpu_unpack_name(unpack[i]));
        }

        vir_dump_sig(c, inst);
}

void
vir_dump_inst(struct v3d_compile *c, struct qinst *inst)
{
        struct v3d_qpu_instr *instr = &inst->qpu;

        switch (inst->qpu.type) {
        case V3D_QPU_INSTR_TYPE_ALU:
                vir_dump_alu(c, inst);
                break;
        case V3D_QPU_INSTR_TYPE_BRANCH:
                fprintf(stderr, "b");
                if (instr->branch.ub)
                        fprintf(stderr, "u");

                fprintf(stderr, "%s",
                        v3d_qpu_branch_cond_name(instr->branch.cond));
                fprintf(stderr, "%s", v3d_qpu_msfign_name(instr->branch.msfign));

                switch (instr->branch.bdi) {
                case V3D_QPU_BRANCH_DEST_ABS:
                        fprintf(stderr, "  zero_addr+0x%08x", instr->branch.offset);
                        break;

                case V3D_QPU_BRANCH_DEST_REL:
                        fprintf(stderr, "  %d", instr->branch.offset);
                        break;

                case V3D_QPU_BRANCH_DEST_LINK_REG:
                        fprintf(stderr, "  lri");
                        break;

                case V3D_QPU_BRANCH_DEST_REGFILE:
                        fprintf(stderr, "  rf%d", instr->branch.raddr_a);
                        break;
                }

                if (instr->branch.ub) {
                        switch (instr->branch.bdu) {
                        case V3D_QPU_BRANCH_DEST_ABS:
                                fprintf(stderr, ", a:unif");
                                break;

                        case V3D_QPU_BRANCH_DEST_REL:
                                fprintf(stderr, ", r:unif");
                                break;

                        case V3D_QPU_BRANCH_DEST_LINK_REG:
                                fprintf(stderr, ", lri");
                                break;

                        case V3D_QPU_BRANCH_DEST_REGFILE:
                                fprintf(stderr, ", rf%d", instr->branch.raddr_a);
                                break;
                        }
                }

                if (vir_has_implicit_uniform(inst)) {
                        fprintf(stderr, " ");
                        vir_print_reg(c, inst, inst->src[vir_get_implicit_uniform_src(inst)]);
                }

                break;
        }
}

void
vir_dump(struct v3d_compile *c)
{
        int ip = 0;

        vir_for_each_block(block, c) {
                fprintf(stderr, "BLOCK %d:\n", block->index);
                vir_for_each_inst(inst, block) {
                        if (c->live_intervals_valid) {
                                bool first = true;

                                for (int i = 0; i < c->num_temps; i++) {
                                        if (c->temp_start[i] != ip)
                                                continue;

                                        if (first) {
                                                first = false;
                                        } else {
                                                fprintf(stderr, ", ");
                                        }
                                        fprintf(stderr, "S%4d", i);
                                }

                                if (first)
                                        fprintf(stderr, "      ");
                                else
                                        fprintf(stderr, " ");
                        }

                        if (c->live_intervals_valid) {
                                bool first = true;

                                for (int i = 0; i < c->num_temps; i++) {
                                        if (c->temp_end[i] != ip)
                                                continue;

                                        if (first) {
                                                first = false;
                                        } else {
                                                fprintf(stderr, ", ");
                                        }
                                        fprintf(stderr, "E%4d", i);
                                }

                                if (first)
                                        fprintf(stderr, "      ");
                                else
                                        fprintf(stderr, " ");
                        }

                        vir_dump_inst(c, inst);
                        fprintf(stderr, "\n");
                        ip++;
                }
                if (block->successors[1]) {
                        fprintf(stderr, "-> BLOCK %d, %d\n",
                                block->successors[0]->index,
                                block->successors[1]->index);
                } else if (block->successors[0]) {
                        fprintf(stderr, "-> BLOCK %d\n",
                                block->successors[0]->index);
                }
        }
}