2 #include "nv50_context.h"
7 #define PRINT(args...) debug_printf(args)
10 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
13 static const char *norm
= "\x1b[00m";
14 static const char *gree
= "\x1b[32m";
15 static const char *blue
= "\x1b[34m";
16 static const char *cyan
= "\x1b[36m";
17 static const char *orng
= "\x1b[33m";
18 static const char *mgta
= "\x1b[35m";
20 static const char *nv_opcode_names
[NV_OP_COUNT
+ 1] = {
80 static const char *nv_cond_names
[] =
82 "never", "lt" , "eq" , "le" , "gt" , "ne" , "ge" , "",
83 "never", "ltu", "equ", "leu", "gtu", "neu", "geu", ""
86 static const char *nv_modifier_strings
[] =
101 nv_opcode_name(uint opcode
)
103 return nv_opcode_names
[MIN2(opcode
, ARRAY_SIZE(nv_opcode_names
) - 1)];
106 static INLINE
const char *
107 nv_type_name(ubyte type
)
110 case NV_TYPE_U16
: return "u16";
111 case NV_TYPE_S16
: return "s16";
112 case NV_TYPE_F32
: return "f32";
113 case NV_TYPE_U32
: return "u32";
114 case NV_TYPE_S32
: return "s32";
115 case NV_TYPE_P32
: return "p32";
116 case NV_TYPE_F64
: return "f64";
122 static INLINE
const char *
123 nv_cond_name(ubyte cc
)
125 return nv_cond_names
[MIN2(cc
, 15)];
128 static INLINE
const char *
129 nv_modifier_string(ubyte mod
)
131 return nv_modifier_strings
[MIN2(mod
, 9)];
135 nv_value_id(struct nv_value
*value
)
137 if (value
->join
->reg
.id
>= 0)
138 return value
->join
->reg
.id
;
142 static INLINE boolean
143 nv_value_allocated(struct nv_value
*value
)
145 return (value
->reg
.id
>= 0) ? TRUE
: FALSE
;
149 nv_print_address(const char c
, int buf
, struct nv_value
*a
, int offset
)
152 PRINT(" %s%c%i[", cyan
, c
, buf
);
154 PRINT(" %s%c[", cyan
, c
);
156 PRINT("%s$a%i%s+", mgta
, nv_value_id(a
), cyan
);
157 PRINT("%s0x%x%s]", orng
, offset
, cyan
);
161 nv_print_cond(struct nv_instruction
*nvi
)
164 gree
, nv_cond_name(nvi
->cc
),
165 mgta
, nv_value_id(nvi
->flags_src
->value
));
169 nv_print_value(struct nv_value
*value
, struct nv_value
*ind
, ubyte type
)
173 if (type
== NV_TYPE_ANY
)
174 type
= value
->reg
.type
;
176 if (value
->reg
.file
!= NV_FILE_FLAGS
)
177 PRINT(" %s%s", gree
, nv_type_name(type
));
179 if (!nv_value_allocated(value
))
182 switch (value
->reg
.file
) {
184 PRINT(" %s%cr%i", blue
, reg_pfx
, nv_value_id(value
));
187 PRINT(" %s%co%i", mgta
, reg_pfx
, nv_value_id(value
));
190 PRINT(" %s%ca%i", mgta
, reg_pfx
, nv_value_id(value
));
193 PRINT(" %s%cc%i", mgta
, reg_pfx
, nv_value_id(value
));
196 nv_print_address('s', -1, ind
, 4 * nv_value_id(value
));
199 nv_print_address('p', -1, ind
, 4 * nv_value_id(value
));
202 nv_print_address('v', -1, ind
, 4 * nv_value_id(value
));
208 PRINT(" %s0x%04x", orng
, value
->reg
.imm
.u32
);
211 PRINT(" %s%f", orng
, value
->reg
.imm
.f32
);
214 PRINT(" %s%f", orng
, value
->reg
.imm
.f64
);
219 PRINT(" %s0x%08x", orng
, value
->reg
.imm
.u32
);
224 if (value
->reg
.file
>= NV_FILE_MEM_G(0) &&
225 value
->reg
.file
<= NV_FILE_MEM_G(15))
226 nv_print_address('g', value
->reg
.file
- NV_FILE_MEM_G(0), ind
,
227 nv_value_id(value
) * 4);
229 if (value
->reg
.file
>= NV_FILE_MEM_C(0) &&
230 value
->reg
.file
<= NV_FILE_MEM_C(15))
231 nv_print_address('c', value
->reg
.file
- NV_FILE_MEM_C(0), ind
,
232 nv_value_id(value
) * 4);
234 NOUVEAU_ERR(" BAD_FILE[%i]", nv_value_id(value
));
240 nv_print_ref(struct nv_ref
*ref
, struct nv_value
*ind
)
242 nv_print_value(ref
->value
, ind
, ref
->typecast
);
246 nv_print_instruction(struct nv_instruction
*i
)
254 if (i
->opcode
== NV_OP_SET
)
255 PRINT("set %s", nv_cond_name(i
->set_cond
));
258 PRINT("sat %s", nv_opcode_name(i
->opcode
));
260 PRINT("%s", nv_opcode_name(i
->opcode
));
263 nv_print_value(i
->flags_def
, NULL
, NV_TYPE_ANY
);
265 /* Only STORE & STA can write to MEM, and they do not def
266 * anything, so the address is thus part of the source.
269 nv_print_value(i
->def
[0], NULL
, NV_TYPE_ANY
);
273 for (j
= 0; j
< 4; ++j
) {
278 PRINT(" %s", nv_modifier_string(i
->src
[j
]->mod
));
280 nv_print_ref(i
->src
[j
],
281 (j
== nv50_indirect_opnd(i
)) ?
282 i
->src
[4]->value
: NULL
);