vc4: Reuse QPU dumping for packing bits in QIR.
[mesa.git] / src / gallium / drivers / vc4 / vc4_qpu.h
1 /*
2 * Copyright © 2014 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 #ifndef VC4_QPU_H
25 #define VC4_QPU_H
26
27 #include <stdio.h>
28 #include <stdint.h>
29
30 #include "util/u_math.h"
31
32 #include "vc4_qpu_defines.h"
33
34 struct vc4_compile;
35
36 struct qpu_reg {
37 enum qpu_mux mux;
38 uint8_t addr;
39 };
40
41 static inline struct qpu_reg
42 qpu_rn(int n)
43 {
44 struct qpu_reg r = {
45 QPU_MUX_R0 + n,
46 0,
47 };
48
49 return r;
50 }
51
52 static inline struct qpu_reg
53 qpu_ra(int addr)
54 {
55 struct qpu_reg r = {
56 QPU_MUX_A,
57 addr,
58 };
59
60 return r;
61 }
62
63 static inline struct qpu_reg
64 qpu_rb(int addr)
65 {
66 struct qpu_reg r = {
67 QPU_MUX_B,
68 addr,
69 };
70
71 return r;
72 }
73
74 static inline struct qpu_reg
75 qpu_vary()
76 {
77 struct qpu_reg r = {
78 QPU_MUX_A,
79 QPU_R_VARY,
80 };
81
82 return r;
83 }
84
85 static inline struct qpu_reg
86 qpu_unif()
87 {
88 struct qpu_reg r = {
89 QPU_MUX_A,
90 QPU_R_UNIF,
91 };
92
93 return r;
94 }
95
96 static inline struct qpu_reg
97 qpu_vrsetup()
98 {
99 return qpu_ra(QPU_W_VPMVCD_SETUP);
100 }
101
102 static inline struct qpu_reg
103 qpu_vwsetup()
104 {
105 return qpu_rb(QPU_W_VPMVCD_SETUP);
106 }
107
108 static inline struct qpu_reg
109 qpu_tlbc()
110 {
111 struct qpu_reg r = {
112 QPU_MUX_A,
113 QPU_W_TLB_COLOR_ALL,
114 };
115
116 return r;
117 }
118
119 static inline struct qpu_reg qpu_r0(void) { return qpu_rn(0); }
120 static inline struct qpu_reg qpu_r1(void) { return qpu_rn(1); }
121 static inline struct qpu_reg qpu_r2(void) { return qpu_rn(2); }
122 static inline struct qpu_reg qpu_r3(void) { return qpu_rn(3); }
123 static inline struct qpu_reg qpu_r4(void) { return qpu_rn(4); }
124 static inline struct qpu_reg qpu_r5(void) { return qpu_rn(5); }
125
126 uint64_t qpu_NOP(void) ATTRIBUTE_CONST;
127 uint64_t qpu_a_MOV(struct qpu_reg dst, struct qpu_reg src) ATTRIBUTE_CONST;
128 uint64_t qpu_m_MOV(struct qpu_reg dst, struct qpu_reg src) ATTRIBUTE_CONST;
129 uint64_t qpu_a_alu2(enum qpu_op_add op, struct qpu_reg dst,
130 struct qpu_reg src0, struct qpu_reg src1) ATTRIBUTE_CONST;
131 uint64_t qpu_m_alu2(enum qpu_op_mul op, struct qpu_reg dst,
132 struct qpu_reg src0, struct qpu_reg src1) ATTRIBUTE_CONST;
133 uint64_t qpu_merge_inst(uint64_t a, uint64_t b) ATTRIBUTE_CONST;
134 uint64_t qpu_load_imm_ui(struct qpu_reg dst, uint32_t val) ATTRIBUTE_CONST;
135 uint64_t qpu_set_sig(uint64_t inst, uint32_t sig) ATTRIBUTE_CONST;
136 uint64_t qpu_set_cond_add(uint64_t inst, uint32_t cond) ATTRIBUTE_CONST;
137 uint64_t qpu_set_cond_mul(uint64_t inst, uint32_t cond) ATTRIBUTE_CONST;
138 uint32_t qpu_encode_small_immediate(uint32_t i) ATTRIBUTE_CONST;
139
140 bool qpu_waddr_is_tlb(uint32_t waddr) ATTRIBUTE_CONST;
141 bool qpu_inst_is_tlb(uint64_t inst) ATTRIBUTE_CONST;
142 int qpu_num_sf_accesses(uint64_t inst) ATTRIBUTE_CONST;
143 void qpu_serialize_one_inst(struct vc4_compile *c, uint64_t inst);
144
145 static inline uint64_t
146 qpu_load_imm_f(struct qpu_reg dst, float val)
147 {
148 return qpu_load_imm_ui(dst, fui(val));
149 }
150
151 #define A_ALU2(op) \
152 static inline uint64_t \
153 qpu_a_##op(struct qpu_reg dst, struct qpu_reg src0, struct qpu_reg src1) \
154 { \
155 return qpu_a_alu2(QPU_A_##op, dst, src0, src1); \
156 }
157
158 #define M_ALU2(op) \
159 static inline uint64_t \
160 qpu_m_##op(struct qpu_reg dst, struct qpu_reg src0, struct qpu_reg src1) \
161 { \
162 return qpu_m_alu2(QPU_M_##op, dst, src0, src1); \
163 }
164
165 #define A_ALU1(op) \
166 static inline uint64_t \
167 qpu_a_##op(struct qpu_reg dst, struct qpu_reg src0) \
168 { \
169 return qpu_a_alu2(QPU_A_##op, dst, src0, src0); \
170 }
171
172 /*A_ALU2(NOP) */
173 A_ALU2(FADD)
174 A_ALU2(FSUB)
175 A_ALU2(FMIN)
176 A_ALU2(FMAX)
177 A_ALU2(FMINABS)
178 A_ALU2(FMAXABS)
179 A_ALU1(FTOI)
180 A_ALU1(ITOF)
181 A_ALU2(ADD)
182 A_ALU2(SUB)
183 A_ALU2(SHR)
184 A_ALU2(ASR)
185 A_ALU2(ROR)
186 A_ALU2(SHL)
187 A_ALU2(MIN)
188 A_ALU2(MAX)
189 A_ALU2(AND)
190 A_ALU2(OR)
191 A_ALU2(XOR)
192 A_ALU1(NOT)
193 A_ALU1(CLZ)
194 A_ALU2(V8ADDS)
195 A_ALU2(V8SUBS)
196
197 /* M_ALU2(NOP) */
198 M_ALU2(FMUL)
199 M_ALU2(MUL24)
200 M_ALU2(V8MULD)
201 M_ALU2(V8MIN)
202 M_ALU2(V8MAX)
203 M_ALU2(V8ADDS)
204 M_ALU2(V8SUBS)
205
206 void
207 vc4_qpu_disasm(const uint64_t *instructions, int num_instructions);
208
209 void
210 vc4_qpu_disasm_pack_mul(FILE *out, uint32_t pack);
211
212 void
213 vc4_qpu_disasm_pack_a(FILE *out, uint32_t pack);
214
215 void
216 vc4_qpu_validate(uint64_t *insts, uint32_t num_inst);
217
218 #endif /* VC4_QPU_H */