summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nv50/nv50_pc_print.c
blob: 7bdeb1c78d465b5afca4d095eed0ed9de21496cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/*
 * Copyright 2010 Christoph Bumiller
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "nv50_context.h"
#include "nv50_pc.h"

#define NVXX_DEBUG 0

#define PRINT(args...) debug_printf(args)

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#endif

static const char *norm = "\x1b[00m";
static const char *gree = "\x1b[32m";
static const char *blue = "\x1b[34m";
static const char *cyan = "\x1b[36m";
static const char *orng = "\x1b[33m";
static const char *mgta = "\x1b[35m";

static const char *nv_opcode_names[NV_OP_COUNT + 1] = {
   "phi",
   "extract",
   "combine",
   "lda",
   "sta",
   "mov",
   "add",
   "sub",
   "neg",
   "mul",
   "mad",
   "cvt",
   "sat",
   "not",
   "and",
   "or",
   "xor",
   "shl",
   "shr",
   "rcp",
   "undef",
   "rsqrt",
   "lg2",
   "sin",
   "cos",
   "ex2",
   "presin",
   "preex2",
   "min",
   "max",
   "set",
   "sad",
   "kil",
   "bra",
   "call",
   "ret",
   "break",
   "breakaddr",
   "joinat",
   "tex",
   "texbias",
   "texlod",
   "texfetch",
   "texsize",
   "dfdx",
   "dfdy",
   "quadop",
   "linterp",
   "pinterp",
   "abs",
   "ceil",
   "floor",
   "trunc",
   "nop",
   "select",
   "export",
   "join",
   "BAD_OP"
};

static const char *nv_cond_names[] =
{
   "never", "lt" , "eq" , "le" , "gt" , "ne" , "ge" , "",
   "never", "ltu", "equ", "leu", "gtu", "neu", "geu", ""
};

static const char *nv_modifier_strings[] =
{
   "",
   "neg",
   "abs",
   "neg abs",
   "not",
   "not neg"
   "not abs",
   "not neg abs",
   "sat",
   "BAD_MOD"
};

const char *
nv_opcode_name(uint opcode)
{
   return nv_opcode_names[MIN2(opcode, ARRAY_SIZE(nv_opcode_names) - 1)];
}

static INLINE const char *
nv_type_name(ubyte type)
{
   switch (type) {
   case NV_TYPE_U16: return "u16";
   case NV_TYPE_S16: return "s16";
   case NV_TYPE_F32: return "f32";
   case NV_TYPE_U32: return "u32";
   case NV_TYPE_S32: return "s32";
   case NV_TYPE_P32: return "p32";
   case NV_TYPE_F64: return "f64";
   default:
      return "BAD_TYPE";
   }
}

static INLINE const char *
nv_cond_name(ubyte cc)
{
   return nv_cond_names[MIN2(cc, 15)];
}

static INLINE const char *
nv_modifier_string(ubyte mod)
{
   return nv_modifier_strings[MIN2(mod, 9)];
}

static INLINE int
nv_value_id(struct nv_value *value)
{
   if (value->join->reg.id >= 0)
      return value->join->reg.id;
   return value->n;
}

static INLINE boolean
nv_value_allocated(struct nv_value *value)
{
   return (value->reg.id >= 0) ? TRUE : FALSE;
}

static INLINE void
nv_print_address(const char c, int buf, struct nv_value *a, int offset)
{
   if (buf >= 0)
      PRINT(" %s%c%i[", cyan, c, buf);
   else
      PRINT(" %s%c[", cyan, c);
   if (a)
      PRINT("%s$a%i%s+", mgta, nv_value_id(a), cyan);
   PRINT("%s0x%x%s]", orng, offset, cyan);
}

static INLINE void
nv_print_cond(struct nv_instruction *nvi)
{
   char pfx = nv_value_allocated(nvi->flags_src->value->join) ? '$' : '%';

   PRINT("%s%s %s%cc%i ",
         gree, nv_cond_name(nvi->cc),
         mgta, pfx, nv_value_id(nvi->flags_src->value));
}

static INLINE void
nv_print_value(struct nv_value *value, struct nv_value *ind, ubyte type)
{
   char reg_pfx = '$';

   if (type == NV_TYPE_ANY)
      type = value->reg.type;

   if (value->reg.file != NV_FILE_FLAGS)
      PRINT(" %s%s", gree, nv_type_name(type));

   if (!nv_value_allocated(value->join))
      reg_pfx = '%';

   switch (value->reg.file) {
   case NV_FILE_GPR:
      PRINT(" %s%cr%i", blue, reg_pfx, nv_value_id(value));
      break;
   case NV_FILE_OUT:
      PRINT(" %s%co%i", mgta, reg_pfx, nv_value_id(value));
      break;
   case NV_FILE_ADDR:
      PRINT(" %s%ca%i", mgta, reg_pfx, nv_value_id(value));
      break;
   case NV_FILE_FLAGS:
      PRINT(" %s%cc%i", mgta, reg_pfx, nv_value_id(value));
      break;
   case NV_FILE_MEM_S:
      nv_print_address('s', -1, ind, 4 * nv_value_id(value));
      break;
   case NV_FILE_MEM_P:
      nv_print_address('p', -1, ind, 4 * nv_value_id(value));
      break;
   case NV_FILE_MEM_V:
      nv_print_address('v', -1, ind, 4 * nv_value_id(value));
      break;
   case NV_FILE_IMM:
      switch (type) {
      case NV_TYPE_U16:
      case NV_TYPE_S16:
         PRINT(" %s0x%04x", orng, value->reg.imm.u32);
         break;
      case NV_TYPE_F32:
         PRINT(" %s%f", orng, value->reg.imm.f32);
         break;
      case NV_TYPE_F64:
         PRINT(" %s%f", orng, value->reg.imm.f64);
         break;
      case NV_TYPE_U32:
      case NV_TYPE_S32:
      case NV_TYPE_P32:
         PRINT(" %s0x%08x", orng, value->reg.imm.u32);
         break;
      }
      break;
   default:
      if (value->reg.file >= NV_FILE_MEM_G(0) &&
          value->reg.file <= NV_FILE_MEM_G(15))
         nv_print_address('g', value->reg.file - NV_FILE_MEM_G(0), ind,
                          nv_value_id(value) * 4);
      else
      if (value->reg.file >= NV_FILE_MEM_C(0) &&
          value->reg.file <= NV_FILE_MEM_C(15))
         nv_print_address('c', value->reg.file - NV_FILE_MEM_C(0), ind,
                          nv_value_id(value) * 4);
      else
         NOUVEAU_ERR(" BAD_FILE[%i]", nv_value_id(value));
      break;
   }
}

static INLINE void
nv_print_ref(struct nv_ref *ref, struct nv_value *ind)
{
   nv_print_value(ref->value, ind, ref->typecast);
}

void
nv_print_instruction(struct nv_instruction *i)
{
   int j;

   PRINT("%i: ", i->serial);

   if (i->flags_src)
      nv_print_cond(i);

   PRINT("%s", gree);
   if (i->opcode == NV_OP_SET)
      PRINT("set %s", nv_cond_name(i->set_cond));
   else
   if (i->saturate)
      PRINT("sat %s", nv_opcode_name(i->opcode));
   else
      PRINT("%s", nv_opcode_name(i->opcode));

   if (i->flags_def)
      nv_print_value(i->flags_def, NULL, NV_TYPE_ANY);

   /* Only STORE & STA can write to MEM, and they do not def
    * anything, so the address is thus part of the source.
    */
   if (i->def[0])
      nv_print_value(i->def[0], NULL, NV_TYPE_ANY);
   else
   if (i->target)
      PRINT(" %s(BB:%i)", orng, i->target->id);
   else
      PRINT(" #");

   for (j = 0; j < 4; ++j) {
      if (!i->src[j])
         continue;

      if (i->src[j]->mod)
         PRINT(" %s%s", gree, nv_modifier_string(i->src[j]->mod));

      nv_print_ref(i->src[j],
                   (j == nv50_indirect_opnd(i)) ?
                   i->src[4]->value : NULL);
   }
   PRINT(" %s%c\n", norm, i->is_long ? 'l' : 's');
}