i915_debug_fp.c revision 40a86b20478024ca7c55400019c536cb5ff631d1
1c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell/**************************************************************************
2c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
3c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * All Rights Reserved.
5c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
6c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
7c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * copy of this software and associated documentation files (the
8c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * "Software"), to deal in the Software without restriction, including
9c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
10c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
11c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to
12c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * the following conditions:
13c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
14c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * The above copyright notice and this permission notice (including the
15c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * next paragraph) shall be included in all copies or substantial portions
16c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * of the Software.
17c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
18c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
26c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell **************************************************************************/
27c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
28c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
29c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#include "i915_reg.h"
30c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#include "i915_debug.h"
3147fc2c4349746997704a7f81dffadd22363e0ff1Keith Whitwell#include "pipe/p_winsys.h"
3240a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell#include "pipe/p_util.h"
3340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell
34c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
35cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
36cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
372eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell#define PRINTF( ... ) (stream)->winsys->printf( (stream)->winsys, __VA_ARGS__ )
38cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
39cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
40cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
41cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
42c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const char *opcodes[0x20] = {
43c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "NOP",
44c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "ADD",
45c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MOV",
46c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MUL",
47c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MAD",
48c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP2ADD",
49c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP3",
50c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP4",
51c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "FRC",
52c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "RCP",
53c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "RSQ",
54c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "EXP",
55c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "LOG",
56c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "CMP",
57c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MIN",
58c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MAX",
59c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "FLR",
60c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MOD",
61c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TRC",
62c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "SGE",
63c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "SLT",
64c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLD",
65c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLDP",
66c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLDB",
67c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXKILL",
68c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DCL",
69c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1a",
70c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1b",
71c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1c",
72c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1d",
73c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1e",
74c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1f",
75c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
76c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
77c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
78c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const int args[0x20] = {
79c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,                           /* 0 nop */
80c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 1 add */
81c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 2 mov */
82c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 3 m ul */
83c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* 4 mad */
84c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* 5 dp2add */
85c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 6 dp3 */
86c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 7 dp4 */
87c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 8 frc */
88c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 9 rcp */
89c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* a rsq */
90c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* b exp */
91c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* c log */
92c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* d cmp */
93c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* e min */
94c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* f max */
95c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 10 flr */
96c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 11 mod */
97c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 12 trc */
98c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 13 sge */
99c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 14 slt */
100c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
101c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
102c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
103c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
104c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
105c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
106c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
107c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
108c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
109c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
110c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
111c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
112c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
113c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
114c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const char *regname[0x8] = {
115c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "R",
116c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "T",
117c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "CONST",
118c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "S",
119c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "OC",
120c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "OD",
121c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "U",
122c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "UNKNOWN",
123c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
124c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
125c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
12640a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_reg_type_nr(struct debug_stream *stream, unsigned type, unsigned nr)
127c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
128c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   switch (type) {
129c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_T:
130c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      switch (nr) {
131c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_DIFFUSE:
1322eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("T_DIFFUSE");
133c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
134c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_SPECULAR:
1352eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("T_SPECULAR");
136c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
137c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_FOG_W:
1382eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("T_FOG_W");
139c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
140c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      default:
1412eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("T_TEX%d", nr);
142c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
143c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
144c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_OC:
145c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (nr == 0) {
1462eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("oC");
147c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
148c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
149c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
150c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_OD:
151c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (nr == 0) {
1522eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("oD");
153c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
154c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
155c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
156c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   default:
157c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
158c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
159c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
1602eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("%s[%d]", regname[type], nr);
161c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
162c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
163c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_SWIZZLE_MASK 0x7777
164c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_NEGATE_MASK 0x8888
165c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
166c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) |	\
167c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) |	\
168c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) |	\
169c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
170c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
171c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
172c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
17340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_reg_neg_swizzle(struct debug_stream *stream, unsigned reg)
174c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
175c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   int i;
176c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
177c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW &&
178c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell       (reg & REG_NEGATE_MASK) == 0)
179c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
180c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
1812eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF(".");
182c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
183c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   for (i = 3; i >= 0; i--) {
184c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (reg & (1 << ((i * 4) + 3)))
1852eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("-");
186c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
187c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      switch ((reg >> (i * 4)) & 0x7) {
188c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 0:
1892eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("x");
190c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
191c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 1:
1922eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("y");
193c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
194c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 2:
1952eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("z");
196c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
197c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 3:
1982eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("w");
199c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
200c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 4:
2012eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("0");
202c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
203c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 5:
2042eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("1");
205c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
206c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      default:
2072eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("?");
208c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
209c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
210c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
211c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
212c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
213c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
214c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
21540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_src_reg(struct debug_stream *stream, unsigned dword)
216c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
21740a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK;
21840a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK;
219cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream, type, nr);
220cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_neg_swizzle(stream, dword);
221c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
222c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
223c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
224c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
22540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_dest_reg(struct debug_stream *stream, unsigned dword)
226c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
22740a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK;
22840a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK;
229cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream, type, nr);
230c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL)
231c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
2322eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF(".");
233c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_X)
2342eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("x");
235c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_Y)
2362eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("y");
237c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_Z)
2382eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("z");
239c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_W)
2402eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("w");
241c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
242c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
243c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
244c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
245c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
246c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC2_REG(r)      (r)
247c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
248c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
249c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
250cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_arith_op(struct debug_stream *stream,
25140a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	       unsigned opcode, const unsigned * program)
252c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
253c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (opcode != A0_NOP) {
254cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell      print_dest_reg(stream, program[0]);
255c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (program[0] & A0_DEST_SATURATE)
2562eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF(" = SATURATE ");
257c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else
2582eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF(" = ");
259c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
260c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2612eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("%s ", opcodes[opcode]);
262c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
263cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC0_REG(program[0], program[1]));
264c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (args[opcode] == 1) {
2652eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("\n");
266c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
267c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
268c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2692eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF(", ");
270cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC1_REG(program[1], program[2]));
271c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (args[opcode] == 2) {
2722eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("\n");
273c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
274c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
275c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2762eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF(", ");
277cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC2_REG(program[2]));
2782eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("\n");
279c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   return;
280c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
281c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
282c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
283c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
284cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_tex_op(struct debug_stream *stream,
28540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	     unsigned opcode, const unsigned * program)
286c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
287cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_dest_reg(stream, program[0] | A0_DEST_CHANNEL_ALL);
2882eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF(" = ");
289c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2902eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("%s ", opcodes[opcode]);
291c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2922eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("S[%d],", program[0] & T0_SAMPLER_NR_MASK);
293c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
294cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream,
295cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell		     (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) &
296c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell                     REG_TYPE_MASK,
297c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell                     (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK);
2982eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("\n");
299c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
300c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
301c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
302cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_dcl_op(struct debug_stream *stream,
30340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	     unsigned opcode, const unsigned * program)
304c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
3052eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("%s ", opcodes[opcode]);
306cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_dest_reg(stream,
307cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell		  program[0] | A0_DEST_CHANNEL_ALL);
3082eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("\n");
309c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
310c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
311c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
312c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellvoid
313cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwelli915_disassemble_program(struct debug_stream *stream,
31440a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell			 const unsigned * program, unsigned sz)
315c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
31640a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned size = program[0] & 0x1ff;
31740a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   int i;
318c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3192eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("\t\tBEGIN\n");
320c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
321c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   assert(size + 2 == sz);
322c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
323c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   program++;
324c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   for (i = 1; i < sz; i += 3, program += 3) {
32540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell      unsigned opcode = program[0] & (0x1f << 24);
326c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3272eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell      PRINTF("\t\t");
328c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
32940a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell      if ((int) opcode >= A0_NOP && opcode <= A0_SLT)
330cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_arith_op(stream, opcode >> 24, program);
331c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else if (opcode >= T0_TEXLD && opcode <= T0_TEXKILL)
332cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_tex_op(stream, opcode >> 24, program);
333c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else if (opcode == D0_DCL)
334cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_dcl_op(stream, opcode >> 24, program);
335c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else
3362eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell         PRINTF("Unknown opcode 0x%x\n", opcode);
337c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
338c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3392eb839ce1dc9a7737925d69d7b628fc839fa752dKeith Whitwell   PRINTF("\t\tEND\n\n");
340c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
341c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
342c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
343