2 #include "i915_context.h"
6 static const char *opcodes
[0x20] = {
42 static const int args
[0x20] = {
78 static const char *regname
[0x8] = {
89 static void print_reg_type_nr( GLuint type
, GLuint nr
)
94 case T_DIFFUSE
: fprintf(stderr
, "T_DIFFUSE"); return;
95 case T_SPECULAR
: fprintf(stderr
, "T_SPECULAR"); return;
96 case T_FOG_W
: fprintf(stderr
, "T_FOG_W"); return;
97 default: fprintf(stderr
, "T_TEX%d", nr
); return;
101 fprintf(stderr
, "oC");
107 fprintf(stderr
, "oD");
115 fprintf(stderr
, "%s[%d]", regname
[type
], nr
);
118 #define REG_SWIZZLE_MASK 0x7777
119 #define REG_NEGATE_MASK 0x8888
121 #define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
122 (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
123 (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
124 (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
127 static void print_reg_neg_swizzle( GLuint reg
)
131 if ((reg
& REG_SWIZZLE_MASK
) == REG_SWIZZLE_XYZW
&&
132 (reg
& REG_NEGATE_MASK
) == 0)
135 fprintf(stderr
, ".");
137 for (i
= 3 ; i
>= 0; i
--) {
138 if (reg
& (1<<((i
*4)+3)))
139 fprintf(stderr
, "-");
141 switch ((reg
>>(i
*4)) & 0x7) {
142 case 0: fprintf(stderr
, "x"); break;
143 case 1: fprintf(stderr
, "y"); break;
144 case 2: fprintf(stderr
, "z"); break;
145 case 3: fprintf(stderr
, "w"); break;
146 case 4: fprintf(stderr
, "0"); break;
147 case 5: fprintf(stderr
, "1"); break;
148 default: fprintf(stderr
, "?"); break;
154 static void print_src_reg( GLuint dword
)
156 GLuint nr
= (dword
>> A2_SRC2_NR_SHIFT
) & REG_NR_MASK
;
157 GLuint type
= (dword
>> A2_SRC2_TYPE_SHIFT
) & REG_TYPE_MASK
;
158 print_reg_type_nr( type
, nr
);
159 print_reg_neg_swizzle( dword
);
162 void i915_print_ureg( const char *msg
, GLuint ureg
)
164 fprintf(stderr
, "%s: ", msg
);
165 print_src_reg( ureg
>> 8 );
166 fprintf(stderr
, "\n");
169 static void print_dest_reg( GLuint dword
)
171 GLuint nr
= (dword
>> A0_DEST_NR_SHIFT
) & REG_NR_MASK
;
172 GLuint type
= (dword
>> A0_DEST_TYPE_SHIFT
) & REG_TYPE_MASK
;
173 print_reg_type_nr( type
, nr
);
174 if ((dword
& A0_DEST_CHANNEL_ALL
) == A0_DEST_CHANNEL_ALL
)
176 fprintf(stderr
, ".");
177 if (dword
& A0_DEST_CHANNEL_X
) fprintf(stderr
, "x");
178 if (dword
& A0_DEST_CHANNEL_Y
) fprintf(stderr
, "y");
179 if (dword
& A0_DEST_CHANNEL_Z
) fprintf(stderr
, "z");
180 if (dword
& A0_DEST_CHANNEL_W
) fprintf(stderr
, "w");
184 #define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
185 #define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
186 #define GET_SRC2_REG(r) (r)
189 static void print_arith_op( GLuint opcode
, const GLuint
*program
)
191 if (opcode
!= A0_NOP
) {
192 print_dest_reg(program
[0]);
193 if (program
[0] & A0_DEST_SATURATE
)
194 fprintf(stderr
, " = SATURATE ");
196 fprintf(stderr
, " = ");
199 fprintf(stderr
, "%s ", opcodes
[opcode
]);
201 print_src_reg(GET_SRC0_REG(program
[0], program
[1]));
202 if (args
[opcode
] == 1) {
203 fprintf(stderr
, "\n");
207 fprintf(stderr
, ", ");
208 print_src_reg(GET_SRC1_REG(program
[1], program
[2]));
209 if (args
[opcode
] == 2) {
210 fprintf(stderr
, "\n");
214 fprintf(stderr
, ", ");
215 print_src_reg(GET_SRC2_REG(program
[2]));
216 fprintf(stderr
, "\n");
221 static void print_tex_op( GLuint opcode
, const GLuint
*program
)
223 print_dest_reg(program
[0] | A0_DEST_CHANNEL_ALL
);
224 fprintf(stderr
, " = ");
226 fprintf(stderr
, "%s ", opcodes
[opcode
]);
228 fprintf(stderr
, "S[%d],",
229 program
[0] & T0_SAMPLER_NR_MASK
);
231 print_reg_type_nr( (program
[1]>>T1_ADDRESS_REG_TYPE_SHIFT
) & REG_TYPE_MASK
,
232 (program
[1]>>T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
233 fprintf(stderr
, "\n");
236 static void print_dcl_op( GLuint opcode
, const GLuint
*program
)
238 fprintf(stderr
, "%s ", opcodes
[opcode
]);
239 print_dest_reg(program
[0] | A0_DEST_CHANNEL_ALL
);
240 fprintf(stderr
, "\n");
244 void i915_disassemble_program( const GLuint
*program
, GLuint sz
)
246 GLuint size
= program
[0] & 0x1ff;
249 fprintf(stderr
, "BEGIN\n");
252 fprintf(stderr
, "%s: program size mismatch %d/%d\n", __FUNCTION__
,
258 for (i
= 1 ; i
< sz
; i
+=3, program
+=3) {
259 GLuint opcode
= program
[0] & (0x1f<<24);
261 if (opcode
>= A0_NOP
&& opcode
<= A0_SLT
)
262 print_arith_op(opcode
>> 24, program
);
263 else if (opcode
>= T0_TEXLD
&& opcode
<= T0_TEXKILL
)
264 print_tex_op(opcode
>> 24, program
);
265 else if (opcode
== D0_DCL
)
266 print_dcl_op(opcode
>> 24, program
);
268 fprintf(stderr
, "Unknown opcode 0x%x\n", opcode
);
271 fprintf(stderr
, "END\n\n");