nv50: insert MOVs also for PHI sources from dominating block
[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 "(undefined)",
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 "BAD_OP"
99 };
100
101 static const char *nv_cond_names[] =
102 {
103 "never", "lt" , "eq" , "le" , "gt" , "ne" , "ge" , "",
104 "never", "ltu", "equ", "leu", "gtu", "neu", "geu", ""
105 };
106
107 static const char *nv_modifier_strings[] =
108 {
109 "",
110 "neg",
111 "abs",
112 "neg abs",
113 "not",
114 "not neg"
115 "not abs",
116 "not neg abs",
117 "sat",
118 "BAD_MOD"
119 };
120
121 const char *
122 nv_opcode_name(uint opcode)
123 {
124 return nv_opcode_names[MIN2(opcode, ARRAY_SIZE(nv_opcode_names) - 1)];
125 }
126
127 static INLINE const char *
128 nv_type_name(ubyte type)
129 {
130 switch (type) {
131 case NV_TYPE_U16: return "u16";
132 case NV_TYPE_S16: return "s16";
133 case NV_TYPE_F32: return "f32";
134 case NV_TYPE_U32: return "u32";
135 case NV_TYPE_S32: return "s32";
136 case NV_TYPE_P32: return "p32";
137 case NV_TYPE_F64: return "f64";
138 default:
139 return "BAD_TYPE";
140 }
141 }
142
143 static INLINE const char *
144 nv_cond_name(ubyte cc)
145 {
146 return nv_cond_names[MIN2(cc, 15)];
147 }
148
149 static INLINE const char *
150 nv_modifier_string(ubyte mod)
151 {
152 return nv_modifier_strings[MIN2(mod, 9)];
153 }
154
155 static INLINE int
156 nv_value_id(struct nv_value *value)
157 {
158 if (value->join->reg.id >= 0)
159 return value->join->reg.id;
160 return value->n;
161 }
162
163 static INLINE boolean
164 nv_value_allocated(struct nv_value *value)
165 {
166 return (value->reg.id >= 0) ? TRUE : FALSE;
167 }
168
169 static INLINE void
170 nv_print_address(const char c, int buf, struct nv_value *a, int offset)
171 {
172 if (buf >= 0)
173 PRINT(" %s%c%i[", cyan, c, buf);
174 else
175 PRINT(" %s%c[", cyan, c);
176 if (a)
177 PRINT("%s$a%i%s+", mgta, nv_value_id(a), cyan);
178 PRINT("%s0x%x%s]", orng, offset, cyan);
179 }
180
181 static INLINE void
182 nv_print_cond(struct nv_instruction *nvi)
183 {
184 char pfx = nv_value_allocated(nvi->flags_src->value->join) ? '$' : '%';
185
186 PRINT("%s%s %s%cc%i ",
187 gree, nv_cond_name(nvi->cc),
188 mgta, pfx, nv_value_id(nvi->flags_src->value));
189 }
190
191 static INLINE void
192 nv_print_value(struct nv_value *value, struct nv_value *ind, ubyte type)
193 {
194 char reg_pfx = '$';
195
196 if (type == NV_TYPE_ANY)
197 type = value->reg.type;
198
199 if (value->reg.file != NV_FILE_FLAGS)
200 PRINT(" %s%s", gree, nv_type_name(type));
201
202 if (!nv_value_allocated(value->join))
203 reg_pfx = '%';
204
205 switch (value->reg.file) {
206 case NV_FILE_GPR:
207 PRINT(" %s%cr%i", blue, reg_pfx, nv_value_id(value));
208 break;
209 case NV_FILE_OUT:
210 PRINT(" %s%co%i", mgta, reg_pfx, nv_value_id(value));
211 break;
212 case NV_FILE_ADDR:
213 PRINT(" %s%ca%i", mgta, reg_pfx, nv_value_id(value));
214 break;
215 case NV_FILE_FLAGS:
216 PRINT(" %s%cc%i", mgta, reg_pfx, nv_value_id(value));
217 break;
218 case NV_FILE_MEM_S:
219 nv_print_address('s', -1, ind, 4 * nv_value_id(value));
220 break;
221 case NV_FILE_MEM_P:
222 nv_print_address('p', -1, ind, 4 * nv_value_id(value));
223 break;
224 case NV_FILE_MEM_V:
225 nv_print_address('v', -1, ind, 4 * nv_value_id(value));
226 break;
227 case NV_FILE_IMM:
228 switch (type) {
229 case NV_TYPE_U16:
230 case NV_TYPE_S16:
231 PRINT(" %s0x%04x", orng, value->reg.imm.u32);
232 break;
233 case NV_TYPE_F32:
234 PRINT(" %s%f", orng, value->reg.imm.f32);
235 break;
236 case NV_TYPE_F64:
237 PRINT(" %s%f", orng, value->reg.imm.f64);
238 break;
239 case NV_TYPE_U32:
240 case NV_TYPE_S32:
241 case NV_TYPE_P32:
242 PRINT(" %s0x%08x", orng, value->reg.imm.u32);
243 break;
244 }
245 break;
246 default:
247 if (value->reg.file >= NV_FILE_MEM_G(0) &&
248 value->reg.file <= NV_FILE_MEM_G(15))
249 nv_print_address('g', value->reg.file - NV_FILE_MEM_G(0), ind,
250 nv_value_id(value) * 4);
251 else
252 if (value->reg.file >= NV_FILE_MEM_C(0) &&
253 value->reg.file <= NV_FILE_MEM_C(15))
254 nv_print_address('c', value->reg.file - NV_FILE_MEM_C(0), ind,
255 nv_value_id(value) * 4);
256 else
257 NOUVEAU_ERR(" BAD_FILE[%i]", nv_value_id(value));
258 break;
259 }
260 }
261
262 static INLINE void
263 nv_print_ref(struct nv_ref *ref, struct nv_value *ind)
264 {
265 nv_print_value(ref->value, ind, ref->typecast);
266 }
267
268 void
269 nv_print_instruction(struct nv_instruction *i)
270 {
271 int j;
272
273 PRINT("%i: ", i->serial);
274
275 if (i->flags_src)
276 nv_print_cond(i);
277
278 PRINT("%s", gree);
279 if (i->opcode == NV_OP_SET)
280 PRINT("set %s", nv_cond_name(i->set_cond));
281 else
282 if (i->saturate)
283 PRINT("sat %s", nv_opcode_name(i->opcode));
284 else
285 PRINT("%s", nv_opcode_name(i->opcode));
286
287 if (i->flags_def)
288 nv_print_value(i->flags_def, NULL, NV_TYPE_ANY);
289
290 /* Only STORE & STA can write to MEM, and they do not def
291 * anything, so the address is thus part of the source.
292 */
293 if (i->def[0])
294 nv_print_value(i->def[0], NULL, NV_TYPE_ANY);
295 else
296 if (i->target)
297 PRINT(" %s(BB:%i)", orng, i->target->id);
298 else
299 PRINT(" #");
300
301 for (j = 0; j < 4; ++j) {
302 if (!i->src[j])
303 continue;
304
305 if (i->src[j]->mod)
306 PRINT(" %s%s", gree, nv_modifier_string(i->src[j]->mod));
307
308 nv_print_ref(i->src[j],
309 (j == nv50_indirect_opnd(i)) ?
310 i->src[4]->value : NULL);
311 }
312 PRINT(" %s%c\n", norm, i->is_long ? 'l' : 's');
313 }