Merge remote-tracking branch 'mesa-public/master' into vulkan
[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
120 qpu_tlbc_ms()
121 {
122 struct qpu_reg r = {
123 QPU_MUX_A,
124 QPU_W_TLB_COLOR_MS,
125 };
126
127 return r;
128 }
129
130 static inline struct qpu_reg qpu_r0(void) { return qpu_rn(0); }
131 static inline struct qpu_reg qpu_r1(void) { return qpu_rn(1); }
132 static inline struct qpu_reg qpu_r2(void) { return qpu_rn(2); }
133 static inline struct qpu_reg qpu_r3(void) { return qpu_rn(3); }
134 static inline struct qpu_reg qpu_r4(void) { return qpu_rn(4); }
135 static inline struct qpu_reg qpu_r5(void) { return qpu_rn(5); }
136
137 uint64_t qpu_NOP(void) ATTRIBUTE_CONST;
138 uint64_t qpu_a_MOV(struct qpu_reg dst, struct qpu_reg src) ATTRIBUTE_CONST;
139 uint64_t qpu_m_MOV(struct qpu_reg dst, struct qpu_reg src) ATTRIBUTE_CONST;
140 uint64_t qpu_a_alu2(enum qpu_op_add op, struct qpu_reg dst,
141 struct qpu_reg src0, struct qpu_reg src1) ATTRIBUTE_CONST;
142 uint64_t qpu_m_alu2(enum qpu_op_mul op, struct qpu_reg dst,
143 struct qpu_reg src0, struct qpu_reg src1) ATTRIBUTE_CONST;
144 uint64_t qpu_merge_inst(uint64_t a, uint64_t b) ATTRIBUTE_CONST;
145 uint64_t qpu_load_imm_ui(struct qpu_reg dst, uint32_t val) ATTRIBUTE_CONST;
146 uint64_t qpu_set_sig(uint64_t inst, uint32_t sig) ATTRIBUTE_CONST;
147 uint64_t qpu_set_cond_add(uint64_t inst, uint32_t cond) ATTRIBUTE_CONST;
148 uint64_t qpu_set_cond_mul(uint64_t inst, uint32_t cond) ATTRIBUTE_CONST;
149 uint32_t qpu_encode_small_immediate(uint32_t i) ATTRIBUTE_CONST;
150
151 bool qpu_waddr_is_tlb(uint32_t waddr) ATTRIBUTE_CONST;
152 bool qpu_inst_is_tlb(uint64_t inst) ATTRIBUTE_CONST;
153 int qpu_num_sf_accesses(uint64_t inst) ATTRIBUTE_CONST;
154 void qpu_serialize_one_inst(struct vc4_compile *c, uint64_t inst);
155
156 static inline uint64_t
157 qpu_load_imm_f(struct qpu_reg dst, float val)
158 {
159 return qpu_load_imm_ui(dst, fui(val));
160 }
161
162 #define A_ALU2(op) \
163 static inline uint64_t \
164 qpu_a_##op(struct qpu_reg dst, struct qpu_reg src0, struct qpu_reg src1) \
165 { \
166 return qpu_a_alu2(QPU_A_##op, dst, src0, src1); \
167 }
168
169 #define M_ALU2(op) \
170 static inline uint64_t \
171 qpu_m_##op(struct qpu_reg dst, struct qpu_reg src0, struct qpu_reg src1) \
172 { \
173 return qpu_m_alu2(QPU_M_##op, dst, src0, src1); \
174 }
175
176 #define A_ALU1(op) \
177 static inline uint64_t \
178 qpu_a_##op(struct qpu_reg dst, struct qpu_reg src0) \
179 { \
180 return qpu_a_alu2(QPU_A_##op, dst, src0, src0); \
181 }
182
183 /*A_ALU2(NOP) */
184 A_ALU2(FADD)
185 A_ALU2(FSUB)
186 A_ALU2(FMIN)
187 A_ALU2(FMAX)
188 A_ALU2(FMINABS)
189 A_ALU2(FMAXABS)
190 A_ALU1(FTOI)
191 A_ALU1(ITOF)
192 A_ALU2(ADD)
193 A_ALU2(SUB)
194 A_ALU2(SHR)
195 A_ALU2(ASR)
196 A_ALU2(ROR)
197 A_ALU2(SHL)
198 A_ALU2(MIN)
199 A_ALU2(MAX)
200 A_ALU2(AND)
201 A_ALU2(OR)
202 A_ALU2(XOR)
203 A_ALU1(NOT)
204 A_ALU1(CLZ)
205 A_ALU2(V8ADDS)
206 A_ALU2(V8SUBS)
207
208 /* M_ALU2(NOP) */
209 M_ALU2(FMUL)
210 M_ALU2(MUL24)
211 M_ALU2(V8MULD)
212 M_ALU2(V8MIN)
213 M_ALU2(V8MAX)
214 M_ALU2(V8ADDS)
215 M_ALU2(V8SUBS)
216
217 void
218 vc4_qpu_disasm(const uint64_t *instructions, int num_instructions);
219
220 void
221 vc4_qpu_disasm_pack_mul(FILE *out, uint32_t pack);
222
223 void
224 vc4_qpu_disasm_pack_a(FILE *out, uint32_t pack);
225
226 void
227 vc4_qpu_disasm_unpack(FILE *out, uint32_t pack);
228
229 void
230 vc4_qpu_validate(uint64_t *insts, uint32_t num_inst);
231
232 #endif /* VC4_QPU_H */