2 * Copyright © 2016-2017 Broadcom
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:
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
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
24 #include "broadcom/common/v3d_device_info.h"
25 #include "v3d_compiler.h"
27 /* Prints a human-readable description of the uniform reference. */
29 vir_dump_uniform(enum quniform_contents contents
,
32 static const char *quniform_names
[] = {
33 [QUNIFORM_ALPHA_REF
] = "alpha_ref",
34 [QUNIFORM_VIEWPORT_X_SCALE
] = "vp_x_scale",
35 [QUNIFORM_VIEWPORT_Y_SCALE
] = "vp_y_scale",
36 [QUNIFORM_VIEWPORT_Z_OFFSET
] = "vp_z_offset",
37 [QUNIFORM_VIEWPORT_Z_SCALE
] = "vp_z_scale",
38 [QUNIFORM_SHARED_OFFSET
] = "shared_offset",
42 case QUNIFORM_CONSTANT
:
43 fprintf(stderr
, "0x%08x / %f", data
, uif(data
));
46 case QUNIFORM_UNIFORM
:
47 fprintf(stderr
, "push[%d]", data
);
50 case QUNIFORM_TEXTURE_CONFIG_P1
:
51 fprintf(stderr
, "tex[%d].p1", data
);
54 case QUNIFORM_TMU_CONFIG_P0
:
55 fprintf(stderr
, "tex[%d].p0 | 0x%x",
56 v3d_unit_data_get_unit(data
),
57 v3d_unit_data_get_offset(data
));
60 case QUNIFORM_TMU_CONFIG_P1
:
61 fprintf(stderr
, "tex[%d].p1 | 0x%x",
62 v3d_unit_data_get_unit(data
),
63 v3d_unit_data_get_offset(data
));
66 case QUNIFORM_IMAGE_TMU_CONFIG_P0
:
67 fprintf(stderr
, "img[%d].p0 | 0x%x",
68 v3d_unit_data_get_unit(data
),
69 v3d_unit_data_get_offset(data
));
72 case QUNIFORM_TEXTURE_WIDTH
:
73 fprintf(stderr
, "tex[%d].width", data
);
75 case QUNIFORM_TEXTURE_HEIGHT
:
76 fprintf(stderr
, "tex[%d].height", data
);
78 case QUNIFORM_TEXTURE_DEPTH
:
79 fprintf(stderr
, "tex[%d].depth", data
);
81 case QUNIFORM_TEXTURE_ARRAY_SIZE
:
82 fprintf(stderr
, "tex[%d].array_size", data
);
84 case QUNIFORM_TEXTURE_LEVELS
:
85 fprintf(stderr
, "tex[%d].levels", data
);
88 case QUNIFORM_IMAGE_WIDTH
:
89 fprintf(stderr
, "img[%d].width", data
);
91 case QUNIFORM_IMAGE_HEIGHT
:
92 fprintf(stderr
, "img[%d].height", data
);
94 case QUNIFORM_IMAGE_DEPTH
:
95 fprintf(stderr
, "img[%d].depth", data
);
97 case QUNIFORM_IMAGE_ARRAY_SIZE
:
98 fprintf(stderr
, "img[%d].array_size", data
);
101 case QUNIFORM_UBO_ADDR
:
102 fprintf(stderr
, "ubo[%d]", data
);
105 case QUNIFORM_SSBO_OFFSET
:
106 fprintf(stderr
, "ssbo[%d]", data
);
109 case QUNIFORM_GET_BUFFER_SIZE
:
110 fprintf(stderr
, "ssbo_size[%d]", data
);
113 case QUNIFORM_NUM_WORK_GROUPS
:
114 fprintf(stderr
, "num_wg.%c", data
< 3 ? "xyz"[data
] : '?');
118 if (quniform_contents_is_texture_p0(contents
)) {
119 fprintf(stderr
, "tex[%d].p0: 0x%08x",
120 contents
- QUNIFORM_TEXTURE_CONFIG_P0_0
,
122 } else if (contents
< ARRAY_SIZE(quniform_names
) &&
123 quniform_names
[contents
]) {
124 fprintf(stderr
, "%s",
125 quniform_names
[contents
]);
127 fprintf(stderr
, "%d / 0x%08x", contents
, data
);
133 vir_print_reg(struct v3d_compile
*c
, const struct qinst
*inst
,
139 fprintf(stderr
, "null");
143 fprintf(stderr
, "0x%08x (%f)", reg
.index
, uif(reg
.index
));
147 fprintf(stderr
, "rf%d", reg
.index
);
151 fprintf(stderr
, "%s", v3d_qpu_magic_waddr_name(reg
.index
));
154 case QFILE_SMALL_IMM
: {
156 bool ok
= v3d_qpu_small_imm_unpack(c
->devinfo
,
159 assert(ok
); (void) ok
;
161 if ((int)inst
->qpu
.raddr_b
>= -16 &&
162 (int)inst
->qpu
.raddr_b
<= 15)
163 fprintf(stderr
, "%d", unpacked
);
165 fprintf(stderr
, "%f", uif(unpacked
));
170 fprintf(stderr
, "vpm%d.%d",
171 reg
.index
/ 4, reg
.index
% 4);
175 fprintf(stderr
, "t%d", reg
.index
);
181 vir_dump_sig_addr(const struct v3d_device_info
*devinfo
,
182 const struct v3d_qpu_instr
*instr
)
184 if (devinfo
->ver
< 41)
187 if (!instr
->sig_magic
)
188 fprintf(stderr
, ".rf%d", instr
->sig_addr
);
190 const char *name
= v3d_qpu_magic_waddr_name(instr
->sig_addr
);
192 fprintf(stderr
, ".%s", name
);
194 fprintf(stderr
, ".UNKNOWN%d", instr
->sig_addr
);
199 vir_dump_sig(struct v3d_compile
*c
, struct qinst
*inst
)
201 struct v3d_qpu_sig
*sig
= &inst
->qpu
.sig
;
204 fprintf(stderr
, "; thrsw");
206 fprintf(stderr
, "; ldvary");
207 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
210 fprintf(stderr
, "; ldvpm");
212 fprintf(stderr
, "; ldtmu");
213 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
216 fprintf(stderr
, "; ldtlb");
217 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
220 fprintf(stderr
, "; ldtlbu");
221 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
224 fprintf(stderr
, "; ldunif");
226 fprintf(stderr
, "; ldunifrf");
227 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
230 fprintf(stderr
, "; ldunifa");
231 if (sig
->ldunifarf
) {
232 fprintf(stderr
, "; ldunifarf");
233 vir_dump_sig_addr(c
->devinfo
, &inst
->qpu
);
236 fprintf(stderr
, "; wrtmuc");
240 vir_dump_alu(struct v3d_compile
*c
, struct qinst
*inst
)
242 struct v3d_qpu_instr
*instr
= &inst
->qpu
;
243 int nsrc
= vir_get_nsrc(inst
);
244 enum v3d_qpu_input_unpack unpack
[2];
246 if (inst
->qpu
.alu
.add
.op
!= V3D_QPU_A_NOP
) {
247 fprintf(stderr
, "%s", v3d_qpu_add_op_name(instr
->alu
.add
.op
));
248 fprintf(stderr
, "%s", v3d_qpu_cond_name(instr
->flags
.ac
));
249 fprintf(stderr
, "%s", v3d_qpu_pf_name(instr
->flags
.apf
));
250 fprintf(stderr
, "%s", v3d_qpu_uf_name(instr
->flags
.auf
));
251 fprintf(stderr
, " ");
253 vir_print_reg(c
, inst
, inst
->dst
);
254 fprintf(stderr
, "%s", v3d_qpu_pack_name(instr
->alu
.add
.output_pack
));
256 unpack
[0] = instr
->alu
.add
.a_unpack
;
257 unpack
[1] = instr
->alu
.add
.b_unpack
;
259 fprintf(stderr
, "%s", v3d_qpu_mul_op_name(instr
->alu
.mul
.op
));
260 fprintf(stderr
, "%s", v3d_qpu_cond_name(instr
->flags
.mc
));
261 fprintf(stderr
, "%s", v3d_qpu_pf_name(instr
->flags
.mpf
));
262 fprintf(stderr
, "%s", v3d_qpu_uf_name(instr
->flags
.muf
));
263 fprintf(stderr
, " ");
265 vir_print_reg(c
, inst
, inst
->dst
);
266 fprintf(stderr
, "%s", v3d_qpu_pack_name(instr
->alu
.mul
.output_pack
));
268 unpack
[0] = instr
->alu
.mul
.a_unpack
;
269 unpack
[1] = instr
->alu
.mul
.b_unpack
;
272 for (int i
= 0; i
< nsrc
; i
++) {
273 fprintf(stderr
, ", ");
274 vir_print_reg(c
, inst
, inst
->src
[i
]);
275 fprintf(stderr
, "%s", v3d_qpu_unpack_name(unpack
[i
]));
278 vir_dump_sig(c
, inst
);
282 vir_dump_inst(struct v3d_compile
*c
, struct qinst
*inst
)
284 struct v3d_qpu_instr
*instr
= &inst
->qpu
;
286 switch (inst
->qpu
.type
) {
287 case V3D_QPU_INSTR_TYPE_ALU
:
288 vir_dump_alu(c
, inst
);
290 case V3D_QPU_INSTR_TYPE_BRANCH
:
291 fprintf(stderr
, "b");
292 if (instr
->branch
.ub
)
293 fprintf(stderr
, "u");
295 fprintf(stderr
, "%s",
296 v3d_qpu_branch_cond_name(instr
->branch
.cond
));
297 fprintf(stderr
, "%s", v3d_qpu_msfign_name(instr
->branch
.msfign
));
299 switch (instr
->branch
.bdi
) {
300 case V3D_QPU_BRANCH_DEST_ABS
:
301 fprintf(stderr
, " zero_addr+0x%08x", instr
->branch
.offset
);
304 case V3D_QPU_BRANCH_DEST_REL
:
305 fprintf(stderr
, " %d", instr
->branch
.offset
);
308 case V3D_QPU_BRANCH_DEST_LINK_REG
:
309 fprintf(stderr
, " lri");
312 case V3D_QPU_BRANCH_DEST_REGFILE
:
313 fprintf(stderr
, " rf%d", instr
->branch
.raddr_a
);
317 if (instr
->branch
.ub
) {
318 switch (instr
->branch
.bdu
) {
319 case V3D_QPU_BRANCH_DEST_ABS
:
320 fprintf(stderr
, ", a:unif");
323 case V3D_QPU_BRANCH_DEST_REL
:
324 fprintf(stderr
, ", r:unif");
327 case V3D_QPU_BRANCH_DEST_LINK_REG
:
328 fprintf(stderr
, ", lri");
331 case V3D_QPU_BRANCH_DEST_REGFILE
:
332 fprintf(stderr
, ", rf%d", instr
->branch
.raddr_a
);
339 if (vir_has_uniform(inst
)) {
340 fprintf(stderr
, " (");
341 vir_dump_uniform(c
->uniform_contents
[inst
->uniform
],
342 c
->uniform_data
[inst
->uniform
]);
343 fprintf(stderr
, ")");
348 vir_dump(struct v3d_compile
*c
)
353 vir_for_each_block(block
, c
) {
354 fprintf(stderr
, "BLOCK %d:\n", block
->index
);
355 vir_for_each_inst(inst
, block
) {
356 if (c
->live_intervals_valid
) {
357 for (int i
= 0; i
< c
->num_temps
; i
++) {
358 if (c
->temp_start
[i
] == ip
)
362 fprintf(stderr
, "P%4d ", pressure
);
366 for (int i
= 0; i
< c
->num_temps
; i
++) {
367 if (c
->temp_start
[i
] != ip
)
373 fprintf(stderr
, ", ");
375 if (BITSET_TEST(c
->spillable
, i
))
376 fprintf(stderr
, "S%4d", i
);
378 fprintf(stderr
, "U%4d", i
);
382 fprintf(stderr
, " ");
384 fprintf(stderr
, " ");
387 if (c
->live_intervals_valid
) {
390 for (int i
= 0; i
< c
->num_temps
; i
++) {
391 if (c
->temp_end
[i
] != ip
)
397 fprintf(stderr
, ", ");
399 fprintf(stderr
, "E%4d", i
);
404 fprintf(stderr
, " ");
406 fprintf(stderr
, " ");
409 vir_dump_inst(c
, inst
);
410 fprintf(stderr
, "\n");
413 if (block
->successors
[1]) {
414 fprintf(stderr
, "-> BLOCK %d, %d\n",
415 block
->successors
[0]->index
,
416 block
->successors
[1]->index
);
417 } else if (block
->successors
[0]) {
418 fprintf(stderr
, "-> BLOCK %d\n",
419 block
->successors
[0]->index
);