nv50: check dst compatibility in CSE
[mesa.git] / src / gallium / drivers / nv50 / nv50_pc_print.c
1 /*
2 * Copyright 2010 Christoph Bumiller
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 shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "nv50_context.h"
24 #include "nv50_pc.h"
25
26 #define NVXX_DEBUG 0
27
28 #define PRINT(args...) debug_printf(args)
29
30 #ifndef ARRAY_SIZE
31 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
32 #endif
33
34 static const char *norm = "\x1b[00m";
35 static const char *gree = "\x1b[32m";
36 static const char *blue = "\x1b[34m";
37 static const char *cyan = "\x1b[36m";
38 static const char *orng = "\x1b[33m";
39 static const char *mgta = "\x1b[35m";
40
41 static const char *nv_opcode_names[NV_OP_COUNT + 1] = {
42 "phi",
43 "extract",
44 "combine",
45 "lda",
46 "sta",
47 "mov",
48 "add",
49 "sub",
50 "neg",
51 "mul",
52 "mad",
53 "cvt",
54 "sat",
55 "not",
56 "and",
57 "or",
58 "xor",
59 "shl",
60 "shr",
61 "rcp",
62 "undef",
63 "rsqrt",
64 "lg2",
65 "sin",
66 "cos",
67 "ex2",
68 "presin",
69 "preex2",
70 "min",
71 "max",
72 "set",
73 "sad",
74 "kil",
75 "bra",
76 "call",
77 "ret",
78 "break",
79 "breakaddr",
80 "joinat",
81 "tex",
82 "texbias",
83 "texlod",
84 "texfetch",
85 "texsize",
86 "dfdx",
87 "dfdy",
88 "quadop",
89 "linterp",
90 "pinterp",
91 "abs",
92 "ceil",
93 "floor",
94 "trunc",
95 "nop",
96 "select",
97 "export",
98 "join",
99 "BAD_OP"
100 };
101
102 static const char *nv_cond_names[] =
103 {
104 "never", "lt" , "eq" , "le" , "gt" , "ne" , "ge" , "",
105 "never", "ltu", "equ", "leu", "gtu", "neu", "geu", ""
106 };
107
108 static const char *nv_modifier_strings[] =
109 {
110 "",
111 "neg",
112 "abs",
113 "neg abs",
114 "not",
115 "not neg"
116 "not abs",
117 "not neg abs",
118 "sat",
119 "BAD_MOD"
120 };
121
122 const char *
123 nv_opcode_name(uint opcode)
124 {
125 return nv_opcode_names[MIN2(opcode, ARRAY_SIZE(nv_opcode_names) - 1)];
126 }
127
128 static INLINE const char *
129 nv_type_name(ubyte type)
130 {
131 switch (type) {
132 case NV_TYPE_U16: return "u16";
133 case NV_TYPE_S16: return "s16";
134 case NV_TYPE_F32: return "f32";
135 case NV_TYPE_U32: return "u32";
136 case NV_TYPE_S32: return "s32";
137 case NV_TYPE_P32: return "p32";
138 case NV_TYPE_F64: return "f64";
139 default:
140 return "BAD_TYPE";
141 }
142 }
143
144 static INLINE const char *
145 nv_cond_name(ubyte cc)
146 {
147 return nv_cond_names[MIN2(cc, 15)];
148 }
149
150 static INLINE const char *
151 nv_modifier_string(ubyte mod)
152 {
153 return nv_modifier_strings[MIN2(mod, 9)];
154 }
155
156 static INLINE int
157 nv_value_id(struct nv_value *value)
158 {
159 if (value->join->reg.id >= 0)
160 return value->join->reg.id;
161 return value->n;
162 }
163
164 static INLINE boolean
165 nv_value_allocated(struct nv_value *value)
166 {
167 return (value->reg.id >= 0) ? TRUE : FALSE;
168 }
169
170 static INLINE void
171 nv_print_address(const char c, int buf, struct nv_value *a, int offset)
172 {
173 if (buf >= 0)
174 PRINT(" %s%c%i[", cyan, c, buf);
175 else
176 PRINT(" %s%c[", cyan, c);
177 if (a)
178 PRINT("%s$a%i%s+", mgta, nv_value_id(a), cyan);
179 PRINT("%s0x%x%s]", orng, offset, cyan);
180 }
181
182 static INLINE void
183 nv_print_cond(struct nv_instruction *nvi)
184 {
185 char pfx = nv_value_allocated(nvi->flags_src->value->join) ? '$' : '%';
186
187 PRINT("%s%s %s%cc%i ",
188 gree, nv_cond_name(nvi->cc),
189 mgta, pfx, nv_value_id(nvi->flags_src->value));
190 }
191
192 static INLINE void
193 nv_print_value(struct nv_value *value, struct nv_value *ind, ubyte type)
194 {
195 char reg_pfx = '$';
196
197 if (type == NV_TYPE_ANY)
198 type = value->reg.type;
199
200 if (value->reg.file != NV_FILE_FLAGS)
201 PRINT(" %s%s", gree, nv_type_name(type));
202
203 if (!nv_value_allocated(value->join))
204 reg_pfx = '%';
205
206 switch (value->reg.file) {
207 case NV_FILE_GPR:
208 PRINT(" %s%cr%i", blue, reg_pfx, nv_value_id(value));
209 break;
210 case NV_FILE_OUT:
211 PRINT(" %s%co%i", mgta, reg_pfx, nv_value_id(value));
212 break;
213 case NV_FILE_ADDR:
214 PRINT(" %s%ca%i", mgta, reg_pfx, nv_value_id(value));
215 break;
216 case NV_FILE_FLAGS:
217 PRINT(" %s%cc%i", mgta, reg_pfx, nv_value_id(value));
218 break;
219 case NV_FILE_MEM_S:
220 nv_print_address('s', -1, ind, 4 * nv_value_id(value));
221 break;
222 case NV_FILE_MEM_P:
223 nv_print_address('p', -1, ind, 4 * nv_value_id(value));
224 break;
225 case NV_FILE_MEM_V:
226 nv_print_address('v', -1, ind, 4 * nv_value_id(value));
227 break;
228 case NV_FILE_IMM:
229 switch (type) {
230 case NV_TYPE_U16:
231 case NV_TYPE_S16:
232 PRINT(" %s0x%04x", orng, value->reg.imm.u32);
233 break;
234 case NV_TYPE_F32:
235 PRINT(" %s%f", orng, value->reg.imm.f32);
236 break;
237 case NV_TYPE_F64:
238 PRINT(" %s%f", orng, value->reg.imm.f64);
239 break;
240 case NV_TYPE_U32:
241 case NV_TYPE_S32:
242 case NV_TYPE_P32:
243 PRINT(" %s0x%08x", orng, value->reg.imm.u32);
244 break;
245 }
246 break;
247 default:
248 if (value->reg.file >= NV_FILE_MEM_G(0) &&
249 value->reg.file <= NV_FILE_MEM_G(15))
250 nv_print_address('g', value->reg.file - NV_FILE_MEM_G(0), ind,
251 nv_value_id(value) * 4);
252 else
253 if (value->reg.file >= NV_FILE_MEM_C(0) &&
254 value->reg.file <= NV_FILE_MEM_C(15))
255 nv_print_address('c', value->reg.file - NV_FILE_MEM_C(0), ind,
256 nv_value_id(value) * 4);
257 else
258 NOUVEAU_ERR(" BAD_FILE[%i]", nv_value_id(value));
259 break;
260 }
261 }
262
263 static INLINE void
264 nv_print_ref(struct nv_ref *ref, struct nv_value *ind)
265 {
266 nv_print_value(ref->value, ind, ref->typecast);
267 }
268
269 void
270 nv_print_instruction(struct nv_instruction *i)
271 {
272 int j;
273
274 PRINT("%i: ", i->serial);
275
276 if (i->flags_src)
277 nv_print_cond(i);
278
279 PRINT("%s", gree);
280 if (i->opcode == NV_OP_SET)
281 PRINT("set %s", nv_cond_name(i->set_cond));
282 else
283 if (i->saturate)
284 PRINT("sat %s", nv_opcode_name(i->opcode));
285 else
286 PRINT("%s", nv_opcode_name(i->opcode));
287
288 if (i->flags_def)
289 nv_print_value(i->flags_def, NULL, NV_TYPE_ANY);
290
291 /* Only STORE & STA can write to MEM, and they do not def
292 * anything, so the address is thus part of the source.
293 */
294 if (i->def[0])
295 nv_print_value(i->def[0], NULL, NV_TYPE_ANY);
296 else
297 if (i->target)
298 PRINT(" %s(BB:%i)", orng, i->target->id);
299 else
300 PRINT(" #");
301
302 for (j = 0; j < 4; ++j) {
303 if (!i->src[j])
304 continue;
305
306 if (i->src[j]->mod)
307 PRINT(" %s%s", gree, nv_modifier_string(i->src[j]->mod));
308
309 nv_print_ref(i->src[j],
310 (j == nv50_indirect_opnd(i)) ?
311 i->src[4]->value : NULL);
312 }
313 PRINT(" %s%c\n", norm, i->is_long ? 'l' : 's');
314 }