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_qpu_instr
*inst
= &qinst
->qpu
;
90 if (inst
->type
!= V3D_QPU_INSTR_TYPE_ALU
)
93 /* LDVARY writes r5 two instructions later and LDUNIF writes
94 * r5 one instruction later, which is illegal to have
97 if (state
->last
&& state
->last
->sig
.ldvary
&& inst
->sig
.ldunif
) {
98 fail_instr(state
, "LDUNIF after a LDVARY");
107 if (inst
->alu
.add
.op
!= V3D_QPU_A_NOP
) {
108 if (inst
->alu
.add
.magic_write
) {
109 if (v3d_qpu_magic_waddr_is_tmu(inst
->alu
.add
.waddr
))
111 if (v3d_qpu_magic_waddr_is_sfu(inst
->alu
.add
.waddr
))
113 if (v3d_qpu_magic_waddr_is_vpm(inst
->alu
.add
.waddr
))
115 if (v3d_qpu_magic_waddr_is_tlb(inst
->alu
.add
.waddr
))
117 if (v3d_qpu_magic_waddr_is_tsy(inst
->alu
.add
.waddr
))
122 if (inst
->alu
.mul
.op
!= V3D_QPU_M_NOP
) {
123 if (inst
->alu
.mul
.magic_write
) {
124 if (v3d_qpu_magic_waddr_is_tmu(inst
->alu
.mul
.waddr
))
126 if (v3d_qpu_magic_waddr_is_sfu(inst
->alu
.mul
.waddr
))
128 if (v3d_qpu_magic_waddr_is_vpm(inst
->alu
.mul
.waddr
))
130 if (v3d_qpu_magic_waddr_is_tlb(inst
->alu
.mul
.waddr
))
132 if (v3d_qpu_magic_waddr_is_tsy(inst
->alu
.mul
.waddr
))
137 (void)qpu_magic_waddr_matches
; /* XXX */
139 /* SFU r4 results come back two instructions later. No doing
140 * r4 read/writes or other SFU lookups until it's done.
142 if (state
->ip
- state
->last_sfu_write
< 2) {
143 if (v3d_qpu_uses_mux(inst
, V3D_QPU_MUX_R4
))
144 fail_instr(state
, "R4 read too soon after SFU");
146 if (v3d_qpu_writes_r4(inst
))
147 fail_instr(state
, "R4 write too soon after SFU");
150 fail_instr(state
, "SFU write too soon after SFU");
153 /* XXX: The docs say VPM can happen with the others, but the simulator
164 inst
->sig
.ldtlbu
> 1) {
166 "Only one of [TMU, SFU, TSY, TLB read, VPM] allowed");
170 state
->last_sfu_write
= state
->ip
;
174 qpu_validate_block(struct v3d_qpu_validate_state
*state
, struct qblock
*block
)
176 vir_for_each_inst(qinst
, block
) {
177 qpu_validate_inst(state
, qinst
);
179 state
->last
= &qinst
->qpu
;
185 * Checks for the instruction restrictions from page 37 ("Summary of
186 * Instruction Restrictions").
189 qpu_validate(struct v3d_compile
*c
)
191 /* We don't want to do validation in release builds, but we want to
192 * keep compiling the validation code to make sure it doesn't get
199 struct v3d_qpu_validate_state state
= {
201 .last_sfu_write
= -10,
205 vir_for_each_block(block
, c
) {
206 qpu_validate_block(&state
, block
);