2 * Copyright © 2014 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
27 * Validates the QPU instruction sequence after register allocation and
34 #include "v3d_compiler.h"
35 #include "qpu/qpu_disasm.h"
37 struct v3d_qpu_validate_state
{
38 struct v3d_compile
*c
;
39 const struct v3d_qpu_instr
*last
;
45 fail_instr(struct v3d_qpu_validate_state
*state
, const char *msg
)
47 struct v3d_compile
*c
= state
->c
;
49 fprintf(stderr
, "v3d_qpu_validate at ip %d: %s:\n", state
->ip
, msg
);
52 vir_for_each_inst_inorder(inst
, c
) {
53 v3d_qpu_dump(c
->devinfo
, &inst
->qpu
);
55 if (dump_ip
++ == state
->ip
)
56 fprintf(stderr
, " *** ERROR ***");
58 fprintf(stderr
, "\n");
61 fprintf(stderr
, "\n");
66 qpu_magic_waddr_matches(const struct v3d_qpu_instr
*inst
,
67 bool (*predicate
)(enum v3d_qpu_waddr waddr
))
69 if (inst
->type
== V3D_QPU_INSTR_TYPE_ALU
)
72 if (inst
->alu
.add
.op
!= V3D_QPU_A_NOP
&&
73 inst
->alu
.add
.magic_write
&&
74 predicate(inst
->alu
.add
.waddr
))
77 if (inst
->alu
.mul
.op
!= V3D_QPU_M_NOP
&&
78 inst
->alu
.mul
.magic_write
&&
79 predicate(inst
->alu
.mul
.waddr
))
86 qpu_validate_inst(struct v3d_qpu_validate_state
*state
, struct qinst
*qinst
)
88 const struct v3d_device_info
*devinfo
= state
->c
->devinfo
;
89 const struct v3d_qpu_instr
*inst
= &qinst
->qpu
;
91 if (inst
->type
!= V3D_QPU_INSTR_TYPE_ALU
)
94 /* LDVARY writes r5 two instructions later and LDUNIF writes
95 * r5 one instruction later, which is illegal to have
98 if (state
->last
&& state
->last
->sig
.ldvary
&&
99 (inst
->sig
.ldunif
|| inst
->sig
.ldunifa
)) {
100 fail_instr(state
, "LDUNIF after a LDVARY");
109 if (inst
->alu
.add
.op
!= V3D_QPU_A_NOP
) {
110 if (inst
->alu
.add
.magic_write
) {
111 if (v3d_qpu_magic_waddr_is_tmu(inst
->alu
.add
.waddr
))
113 if (v3d_qpu_magic_waddr_is_sfu(inst
->alu
.add
.waddr
))
115 if (v3d_qpu_magic_waddr_is_vpm(inst
->alu
.add
.waddr
))
117 if (v3d_qpu_magic_waddr_is_tlb(inst
->alu
.add
.waddr
))
119 if (v3d_qpu_magic_waddr_is_tsy(inst
->alu
.add
.waddr
))
124 if (inst
->alu
.mul
.op
!= V3D_QPU_M_NOP
) {
125 if (inst
->alu
.mul
.magic_write
) {
126 if (v3d_qpu_magic_waddr_is_tmu(inst
->alu
.mul
.waddr
))
128 if (v3d_qpu_magic_waddr_is_sfu(inst
->alu
.mul
.waddr
))
130 if (v3d_qpu_magic_waddr_is_vpm(inst
->alu
.mul
.waddr
))
132 if (v3d_qpu_magic_waddr_is_tlb(inst
->alu
.mul
.waddr
))
134 if (v3d_qpu_magic_waddr_is_tsy(inst
->alu
.mul
.waddr
))
139 (void)qpu_magic_waddr_matches
; /* XXX */
141 /* SFU r4 results come back two instructions later. No doing
142 * r4 read/writes or other SFU lookups until it's done.
144 if (state
->ip
- state
->last_sfu_write
< 2) {
145 if (v3d_qpu_uses_mux(inst
, V3D_QPU_MUX_R4
))
146 fail_instr(state
, "R4 read too soon after SFU");
148 if (v3d_qpu_writes_r4(devinfo
, inst
))
149 fail_instr(state
, "R4 write too soon after SFU");
152 fail_instr(state
, "SFU write too soon after SFU");
155 /* XXX: The docs say VPM can happen with the others, but the simulator
166 inst
->sig
.ldtlbu
> 1) {
168 "Only one of [TMU, SFU, TSY, TLB read, VPM] allowed");
172 state
->last_sfu_write
= state
->ip
;
176 qpu_validate_block(struct v3d_qpu_validate_state
*state
, struct qblock
*block
)
178 vir_for_each_inst(qinst
, block
) {
179 qpu_validate_inst(state
, qinst
);
181 state
->last
= &qinst
->qpu
;
187 * Checks for the instruction restrictions from page 37 ("Summary of
188 * Instruction Restrictions").
191 qpu_validate(struct v3d_compile
*c
)
193 /* We don't want to do validation in release builds, but we want to
194 * keep compiling the validation code to make sure it doesn't get
201 struct v3d_qpu_validate_state state
= {
203 .last_sfu_write
= -10,
207 vir_for_each_block(block
, c
) {
208 qpu_validate_block(&state
, block
);