xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/r600/r600_isa.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2012 Vadim Girlin <[email protected]>
3  * Authors:
4  *      Vadim Girlin
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #ifndef R600_ISA_H_
9 #define R600_ISA_H_
10 
11 #include "amd_family.h"
12 #include "util/u_debug.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /* ALU flags */
19 enum alu_op_flags
20 {
21 	AF_NONE = 0,
22 	AF_V		= (1<<0),    /* allowed in vector slots */
23 
24 	/* allowed in scalar(trans) slot (slots xyz on cayman, may be replicated
25 	 * to w) */
26 	AF_S		= (1<<1),
27 
28 	AF_4SLOT	= (1<<2),            /* uses four vector slots (e.g. DOT4) */
29 	AF_4V		= (AF_V | AF_4SLOT),
30 	AF_VS		= (AF_V | AF_S),     /* allowed in any slot */
31 
32 	AF_2SLOT = (1 << 3),
33 	AF_2V    = AF_V | AF_2SLOT, /* XY or ZW */
34 
35 	AF_KILL		= (1<<4),
36 	AF_PRED		= (1<<5),
37 	AF_SET		= (1<<6),
38 
39 	/* e.g. MUL_PREV instructions, allowed in x/y, depends on z/w */
40 	AF_PREV_INTERLEAVE	= (1<<7),
41 
42 	AF_MOVA		= (1<<8),    /* all MOVA instructions */
43 
44 	AF_IEEE		= (1<<10),
45 
46 	AF_DST_TYPE_MASK = (3<<11),
47 	AF_FLOAT_DST	= 0,
48 	AF_INT_DST		= (1<<11),
49 	AF_UINT_DST		= (3<<11),
50 
51 	/* DP instructions, 2-slot pairs */
52 	AF_64		= (1<<13),
53 	/* 24 bit instructions */
54 	AF_24		= (1<<14),
55 	/* DX10 variants */
56 	AF_DX10		= (1<<15),
57 
58 	/* result is replicated to all channels (only if AF_4V is also set -
59 	 * for special handling of MULLO_INT on CM) */
60 	AF_REPL		= (1<<16),
61 
62 	/* interpolation instructions */
63 	AF_INTERP	= (1<<17),
64 
65 	/* LDS instructions */
66 	AF_LDS		= (1<<20),
67 
68 	/* e.g. DOT - depends on the next slot in the same group (x<=y/y<=z/z<=w) */
69 	AF_PREV_NEXT	= (1<<21),
70 
71 	/* int<->flt conversions */
72 	AF_CVT = (1<<22),
73 
74 	/* commutative operation on src0 and src1 ( a op b = b op a),
75 	 * includes MULADDs (considering the MUL part on src0 and src1 only) */
76 	AF_M_COMM = (1 << 23),
77 
78 	/* associative operation ((a op b) op c) == (a op (b op c)),
79 	 * includes MULADDs (considering the MUL part on src0 and src1 only) */
80 	AF_M_ASSOC = (1 << 24),
81 
82 	AF_PRED_PUSH = (1 << 25),
83 
84 	AF_ANY_PRED = (AF_PRED | AF_PRED_PUSH),
85 
86 	AF_CMOV = (1 << 26),
87 
88 	// for SETcc, PREDSETcc, ... - type of comparison
89 	AF_CMP_TYPE_MASK = (3 << 27),
90 	AF_FLOAT_CMP = 0,
91 	AF_INT_CMP = (1 << 27),
92 	AF_UINT_CMP = (3 << 27),
93 
94 	/* condition codes - 3 bits */
95 	AF_CC_SHIFT = 29,
96 
97 	AF_CC_MASK	= (7U << AF_CC_SHIFT),
98 	AF_CC_E		= (0U << AF_CC_SHIFT),
99 	AF_CC_GT	= (1U << AF_CC_SHIFT),
100 	AF_CC_GE	= (2U << AF_CC_SHIFT),
101 	AF_CC_NE	= (3U << AF_CC_SHIFT),
102 	AF_CC_LT	= (4U << AF_CC_SHIFT),
103 	AF_CC_LE	= (5U << AF_CC_SHIFT),
104 };
105 
106 /* flags for FETCH instructions (TEX/VTX/GDS) */
107 enum fetch_op_flags
108 {
109 	FF_GDS		= (1<<0),
110 	FF_TEX		= (1<<1),
111 
112 	FF_SETGRAD	= (1<<2),
113 	FF_GETGRAD	= (1<<3),
114 	FF_USEGRAD	= (1<<4),
115 
116 	FF_VTX		= (1<<5),
117 	FF_MEM		= (1<<6),
118 
119 	FF_SET_TEXTURE_OFFSETS = (1<<7),
120 	FF_USE_TEXTURE_OFFSETS = (1<<8),
121 };
122 
123 /* flags for CF instructions */
124 enum cf_op_flags
125 {
126 	CF_CLAUSE	= (1<<0), 	/* execute clause (alu/fetch ...) */
127 	CF_ACK		= (1<<1),	/* acked versions of some instructions */
128 	CF_ALU		= (1<<2),	/* alu clause execution */
129 	CF_ALU_EXT	= (1<<3),	/* ALU_EXTENDED */
130 	CF_EXP		= (1<<4),	/* export (CF_ALLOC_EXPORT_WORD1_SWIZ) */
131 	CF_BRANCH	= (1<<5),   /* branch instructions */
132 	CF_LOOP		= (1<<6),   /* loop instructions */
133 	CF_CALL		= (1<<7),   /* call instructions */
134 	CF_MEM		= (1<<8),	/* export_mem (CF_ALLOC_EXPORT_WORD1_BUF) */
135 	CF_FETCH	= (1<<9),	/* fetch clause */
136 
137 	CF_UNCOND	= (1<<10),	/* COND = ACTIVE required */
138 	CF_EMIT		= (1<<11),
139 	CF_STRM		= (1<<12),	/* MEM_STREAM* */
140 
141 	CF_RAT		= (1<<13),  /* MEM_RAT* */
142 
143 	CF_LOOP_START = (1<<14)
144 };
145 
146 /* ALU instruction info */
147 struct alu_op_info
148 {
149 	/* instruction name */
150 	const char	*name;
151 	/* number of source operands */
152 	int	src_count;
153 	/* opcodes, [0] - for r6xx/r7xx, [1] - for evergreen/cayman
154 	 * (-1) if instruction doesn't exist (more precise info in "slots") */
155 	int opcode[2];
156 	/* slots for r6xx, r7xx, evergreen, cayman
157 	 * (0 if instruction doesn't exist for gfx level) */
158 	int	slots[4];
159 	/* flags (mostly autogenerated from instruction name) */
160 	unsigned int flags;
161 };
162 
163 /* FETCH instruction info */
164 struct fetch_op_info
165 {
166 	const char * name;
167 	/* for every gfx level */
168 	int opcode[4];
169 	int flags;
170 };
171 
172 /* CF instruction info */
173 struct cf_op_info
174 {
175 	const char * name;
176 	/* for every gfx level */
177 	int opcode[4];
178 	int flags;
179 };
180 
181 
182 #define ALU_OP2_ADD                             0
183 #define ALU_OP2_MUL                             1
184 #define ALU_OP2_MUL_IEEE                        2
185 #define ALU_OP2_MAX                             3
186 #define ALU_OP2_MIN                             4
187 #define ALU_OP2_MAX_DX10                        5
188 #define ALU_OP2_MIN_DX10                        6
189 #define ALU_OP2_SETE                            7
190 #define ALU_OP2_SETGT                           8
191 #define ALU_OP2_SETGE                           9
192 #define ALU_OP2_SETNE                          10
193 #define ALU_OP2_SETE_DX10                      11
194 #define ALU_OP2_SETGT_DX10                     12
195 #define ALU_OP2_SETGE_DX10                     13
196 #define ALU_OP2_SETNE_DX10                     14
197 #define ALU_OP1_FRACT                          15
198 #define ALU_OP1_TRUNC                          16
199 #define ALU_OP1_CEIL                           17
200 #define ALU_OP1_RNDNE                          18
201 #define ALU_OP1_FLOOR                          19
202 #define ALU_OP2_ASHR_INT                       20
203 #define ALU_OP2_LSHR_INT                       21
204 #define ALU_OP2_LSHL_INT                       22
205 #define ALU_OP1_MOV                            23
206 #define ALU_OP0_NOP                            24
207 #define ALU_OP2_PRED_SETGT_UINT                25
208 #define ALU_OP2_PRED_SETGE_UINT                26
209 #define ALU_OP2_PRED_SETE                      27
210 #define ALU_OP2_PRED_SETGT                     28
211 #define ALU_OP2_PRED_SETGE                     29
212 #define ALU_OP2_PRED_SETNE                     30
213 #define ALU_OP1_PRED_SET_INV                   31
214 #define ALU_OP2_PRED_SET_POP                   32
215 #define ALU_OP0_PRED_SET_CLR                   33
216 #define ALU_OP1_PRED_SET_RESTORE               34
217 #define ALU_OP2_PRED_SETE_PUSH                 35
218 #define ALU_OP2_PRED_SETGT_PUSH                36
219 #define ALU_OP2_PRED_SETGE_PUSH                37
220 #define ALU_OP2_PRED_SETNE_PUSH                38
221 #define ALU_OP2_KILLE                          39
222 #define ALU_OP2_KILLGT                         40
223 #define ALU_OP2_KILLGE                         41
224 #define ALU_OP2_KILLNE                         42
225 #define ALU_OP2_AND_INT                        43
226 #define ALU_OP2_OR_INT                         44
227 #define ALU_OP2_XOR_INT                        45
228 #define ALU_OP1_NOT_INT                        46
229 #define ALU_OP2_ADD_INT                        47
230 #define ALU_OP2_SUB_INT                        48
231 #define ALU_OP2_MAX_INT                        49
232 #define ALU_OP2_MIN_INT                        50
233 #define ALU_OP2_MAX_UINT                       51
234 #define ALU_OP2_MIN_UINT                       52
235 #define ALU_OP2_SETE_INT                       53
236 #define ALU_OP2_SETGT_INT                      54
237 #define ALU_OP2_SETGE_INT                      55
238 #define ALU_OP2_SETNE_INT                      56
239 #define ALU_OP2_SETGT_UINT                     57
240 #define ALU_OP2_SETGE_UINT                     58
241 #define ALU_OP2_KILLGT_UINT                    59
242 #define ALU_OP2_KILLGE_UINT                    60
243 #define ALU_OP2_PRED_SETE_INT                  61
244 #define ALU_OP2_PRED_SETGT_INT                 62
245 #define ALU_OP2_PRED_SETGE_INT                 63
246 #define ALU_OP2_PRED_SETNE_INT                 64
247 #define ALU_OP2_KILLE_INT                      65
248 #define ALU_OP2_KILLGT_INT                     66
249 #define ALU_OP2_KILLGE_INT                     67
250 #define ALU_OP2_KILLNE_INT                     68
251 #define ALU_OP2_PRED_SETE_PUSH_INT             69
252 #define ALU_OP2_PRED_SETGT_PUSH_INT            70
253 #define ALU_OP2_PRED_SETGE_PUSH_INT            71
254 #define ALU_OP2_PRED_SETNE_PUSH_INT            72
255 #define ALU_OP2_PRED_SETLT_PUSH_INT            73
256 #define ALU_OP2_PRED_SETLE_PUSH_INT            74
257 #define ALU_OP1_FLT_TO_INT                     75
258 #define ALU_OP1_BFREV_INT                      76
259 #define ALU_OP2_ADDC_UINT                      77
260 #define ALU_OP2_SUBB_UINT                      78
261 #define ALU_OP0_GROUP_BARRIER                  79
262 #define ALU_OP0_GROUP_SEQ_BEGIN                80
263 #define ALU_OP0_GROUP_SEQ_END                  81
264 #define ALU_OP2_SET_MODE                       82
265 #define ALU_OP0_SET_CF_IDX0                    83
266 #define ALU_OP0_SET_CF_IDX1                    84
267 #define ALU_OP2_SET_LDS_SIZE                   85
268 #define ALU_OP2_MUL_INT24                      86
269 #define ALU_OP2_MULHI_INT24                    87
270 #define ALU_OP1_FLT_TO_INT_TRUNC               88
271 #define ALU_OP1_EXP_IEEE                       89
272 #define ALU_OP1_LOG_CLAMPED                    90
273 #define ALU_OP1_LOG_IEEE                       91
274 #define ALU_OP1_RECIP_CLAMPED                  92
275 #define ALU_OP1_RECIP_FF                       93
276 #define ALU_OP1_RECIP_IEEE                     94
277 #define ALU_OP1_RECIPSQRT_CLAMPED              95
278 #define ALU_OP1_RECIPSQRT_FF                   96
279 #define ALU_OP1_RECIPSQRT_IEEE                 97
280 #define ALU_OP1_SQRT_IEEE                      98
281 #define ALU_OP1_SIN                            99
282 #define ALU_OP1_COS                           100
283 #define ALU_OP2_MULLO_INT                     101
284 #define ALU_OP2_MULHI_INT                     102
285 #define ALU_OP2_MULLO_UINT                    103
286 #define ALU_OP2_MULHI_UINT                    104
287 #define ALU_OP1_RECIP_INT                     105
288 #define ALU_OP1_RECIP_UINT                    106
289 #define ALU_OP2_RECIP_64                      107
290 #define ALU_OP2_RECIP_CLAMPED_64              108
291 #define ALU_OP2_RECIPSQRT_64                  109
292 #define ALU_OP2_RECIPSQRT_CLAMPED_64          110
293 #define ALU_OP2_SQRT_64                       111
294 #define ALU_OP1_FLT_TO_UINT                   112
295 #define ALU_OP1_INT_TO_FLT                    113
296 #define ALU_OP1_UINT_TO_FLT                   114
297 #define ALU_OP2_BFM_INT                       115
298 #define ALU_OP1_FLT32_TO_FLT16                116
299 #define ALU_OP1_FLT16_TO_FLT32                117
300 #define ALU_OP1_UBYTE0_FLT                    118
301 #define ALU_OP1_UBYTE1_FLT                    119
302 #define ALU_OP1_UBYTE2_FLT                    120
303 #define ALU_OP1_UBYTE3_FLT                    121
304 #define ALU_OP1_BCNT_INT                      122
305 #define ALU_OP1_FFBH_UINT                     123
306 #define ALU_OP1_FFBL_INT                      124
307 #define ALU_OP1_FFBH_INT                      125
308 #define ALU_OP1_FLT_TO_UINT4                  126
309 #define ALU_OP2_DOT_IEEE                      127
310 #define ALU_OP1_FLT_TO_INT_RPI                128
311 #define ALU_OP1_FLT_TO_INT_FLOOR              129
312 #define ALU_OP2_MULHI_UINT24                  130
313 #define ALU_OP1_MBCNT_32HI_INT                131
314 #define ALU_OP1_OFFSET_TO_FLT                 132
315 #define ALU_OP2_MUL_UINT24                    133
316 #define ALU_OP1_BCNT_ACCUM_PREV_INT           134
317 #define ALU_OP1_MBCNT_32LO_ACCUM_PREV_INT     135
318 #define ALU_OP2_SETE_64                       136
319 #define ALU_OP2_SETNE_64                      137
320 #define ALU_OP2_SETGT_64                      138
321 #define ALU_OP2_SETGE_64                      139
322 #define ALU_OP2_MIN_64                        140
323 #define ALU_OP2_MAX_64                        141
324 #define ALU_OP2_DOT4                          142
325 #define ALU_OP2_DOT4_IEEE                     143
326 #define ALU_OP2_CUBE                          144
327 #define ALU_OP1_MAX4                          145
328 #define ALU_OP1_FREXP_64                      146
329 #define ALU_OP2_LDEXP_64                      147
330 #define ALU_OP1_FRACT_64                      148
331 #define ALU_OP2_PRED_SETGT_64                 149
332 #define ALU_OP2_PRED_SETE_64                  150
333 #define ALU_OP2_PRED_SETGE_64                 151
334 #define ALU_OP2_MUL_64                        152
335 #define ALU_OP2_ADD_64                        153
336 #define ALU_OP1_MOVA_INT                      154
337 #define ALU_OP1_FLT64_TO_FLT32                155
338 #define ALU_OP1_FLT32_TO_FLT64                156
339 #define ALU_OP2_SAD_ACCUM_PREV_UINT           157
340 #define ALU_OP2_DOT                           158
341 #define ALU_OP1_MUL_PREV                      159
342 #define ALU_OP1_MUL_IEEE_PREV                 160
343 #define ALU_OP1_ADD_PREV                      161
344 #define ALU_OP2_MULADD_PREV                   162
345 #define ALU_OP2_MULADD_IEEE_PREV              163
346 #define ALU_OP2_INTERP_XY                     164
347 #define ALU_OP2_INTERP_ZW                     165
348 #define ALU_OP2_INTERP_X                      166
349 #define ALU_OP2_INTERP_Z                      167
350 #define ALU_OP1_STORE_FLAGS                   168
351 #define ALU_OP1_LOAD_STORE_FLAGS              169
352 #define ALU_OP2_LDS_1A                        170
353 #define ALU_OP2_LDS_1A1D                      171
354 #define ALU_OP2_LDS_2A                        172
355 #define ALU_OP1_INTERP_LOAD_P0                173
356 #define ALU_OP1_INTERP_LOAD_P10               174
357 #define ALU_OP1_INTERP_LOAD_P20               175
358 #define ALU_OP3_BFE_UINT                      176
359 #define ALU_OP3_BFE_INT                       177
360 #define ALU_OP3_BFI_INT                       178
361 #define ALU_OP3_FMA                           179
362 #define ALU_OP3_MULADD_INT24                  180
363 #define ALU_OP3_CNDNE_64                      181
364 #define ALU_OP3_FMA_64                        182
365 #define ALU_OP3_LERP_UINT                     183
366 #define ALU_OP3_BIT_ALIGN_INT                 184
367 #define ALU_OP3_BYTE_ALIGN_INT                185
368 #define ALU_OP3_SAD_ACCUM_UINT                186
369 #define ALU_OP3_SAD_ACCUM_HI_UINT             187
370 #define ALU_OP3_MULADD_UINT24                 188
371 #define ALU_OP3_LDS_IDX_OP                    189
372 #define ALU_OP3_MULADD                        190
373 #define ALU_OP3_MULADD_M2                     191
374 #define ALU_OP3_MULADD_M4                     192
375 #define ALU_OP3_MULADD_D2                     193
376 #define ALU_OP3_MULADD_IEEE                   194
377 #define ALU_OP3_CNDE                          195
378 #define ALU_OP3_CNDGT                         196
379 #define ALU_OP3_CNDGE                         197
380 #define ALU_OP3_CNDE_INT                      198
381 #define ALU_OP3_CNDGT_INT                     199
382 #define ALU_OP3_CNDGE_INT                     200
383 #define ALU_OP3_MUL_LIT                       201
384 #define ALU_OP1_MOVA                          202
385 #define ALU_OP1_MOVA_FLOOR                    203
386 #define ALU_OP1_MOVA_GPR_INT                  204
387 #define ALU_OP3_MULADD_64                     205
388 #define ALU_OP3_MULADD_64_M2                  206
389 #define ALU_OP3_MULADD_64_M4                  207
390 #define ALU_OP3_MULADD_64_D2                  208
391 #define ALU_OP3_MUL_LIT_M2                    209
392 #define ALU_OP3_MUL_LIT_M4                    210
393 #define ALU_OP3_MUL_LIT_D2                    211
394 #define ALU_OP3_MULADD_IEEE_M2                212
395 #define ALU_OP3_MULADD_IEEE_M4                213
396 #define ALU_OP3_MULADD_IEEE_D2                214
397 
398 #define LDS_OP2_LDS_ADD                       215
399 #define LDS_OP2_LDS_SUB                       216
400 #define LDS_OP2_LDS_RSUB                      217
401 #define LDS_OP2_LDS_INC                       218
402 #define LDS_OP2_LDS_DEC                       219
403 #define LDS_OP2_LDS_MIN_INT                   220
404 #define LDS_OP2_LDS_MAX_INT                   221
405 #define LDS_OP2_LDS_MIN_UINT                  222
406 #define LDS_OP2_LDS_MAX_UINT                  223
407 #define LDS_OP2_LDS_AND                       224
408 #define LDS_OP2_LDS_OR                        225
409 #define LDS_OP2_LDS_XOR                       226
410 #define LDS_OP3_LDS_MSKOR                     227
411 #define LDS_OP2_LDS_WRITE                     228
412 #define LDS_OP3_LDS_WRITE_REL                 229
413 #define LDS_OP3_LDS_WRITE2                    230
414 #define LDS_OP3_LDS_CMP_STORE                 231
415 #define LDS_OP3_LDS_CMP_STORE_SPF             232
416 #define LDS_OP2_LDS_BYTE_WRITE                233
417 #define LDS_OP2_LDS_SHORT_WRITE               234
418 #define LDS_OP2_LDS_ADD_RET                   235
419 #define LDS_OP2_LDS_SUB_RET                   236
420 #define LDS_OP2_LDS_RSUB_RET                  237
421 #define LDS_OP2_LDS_INC_RET                   238
422 #define LDS_OP2_LDS_DEC_RET                   239
423 #define LDS_OP2_LDS_MIN_INT_RET               240
424 #define LDS_OP2_LDS_MAX_INT_RET               241
425 #define LDS_OP2_LDS_MIN_UINT_RET              242
426 #define LDS_OP2_LDS_MAX_UINT_RET              243
427 #define LDS_OP2_LDS_AND_RET                   244
428 #define LDS_OP2_LDS_OR_RET                    245
429 #define LDS_OP2_LDS_XOR_RET                   246
430 #define LDS_OP3_LDS_MSKOR_RET                 247
431 #define LDS_OP2_LDS_XCHG_RET                  248
432 #define LDS_OP3_LDS_XCHG_REL_RET              249
433 #define LDS_OP3_LDS_XCHG2_RET                 250
434 #define LDS_OP3_LDS_CMP_XCHG_RET              251
435 #define LDS_OP3_LDS_CMP_XCHG_SPF_RET          252
436 #define LDS_OP1_LDS_READ_RET                  253
437 #define LDS_OP1_LDS_READ_REL_RET              254
438 #define LDS_OP2_LDS_READ2_RET                 255
439 #define LDS_OP3_LDS_READWRITE_RET             256
440 #define LDS_OP1_LDS_BYTE_READ_RET             257
441 #define LDS_OP1_LDS_UBYTE_READ_RET            258
442 #define LDS_OP1_LDS_SHORT_READ_RET            259
443 #define LDS_OP1_LDS_USHORT_READ_RET           260
444 
445 #define FETCH_OP_VFETCH                           0
446 #define FETCH_OP_SEMFETCH                         1
447 #define FETCH_OP_READ_SCRATCH                     2
448 #define FETCH_OP_READ_REDUCT                      3
449 #define FETCH_OP_READ_MEM                         4
450 #define FETCH_OP_DS_LOCAL_WRITE                   5
451 #define FETCH_OP_DS_LOCAL_READ                    6
452 #define FETCH_OP_GDS_ADD                          7
453 #define FETCH_OP_GDS_SUB                          8
454 #define FETCH_OP_GDS_RSUB                         9
455 #define FETCH_OP_GDS_INC                         10
456 #define FETCH_OP_GDS_DEC                         11
457 #define FETCH_OP_GDS_MIN_INT                     12
458 #define FETCH_OP_GDS_MAX_INT                     13
459 #define FETCH_OP_GDS_MIN_UINT                    14
460 #define FETCH_OP_GDS_MAX_UINT                    15
461 #define FETCH_OP_GDS_AND                         16
462 #define FETCH_OP_GDS_OR                          17
463 #define FETCH_OP_GDS_XOR                         18
464 #define FETCH_OP_GDS_MSKOR                       19
465 #define FETCH_OP_GDS_WRITE                       20
466 #define FETCH_OP_GDS_WRITE_REL                   21
467 #define FETCH_OP_GDS_WRITE2                      22
468 #define FETCH_OP_GDS_CMP_STORE                   23
469 #define FETCH_OP_GDS_CMP_STORE_SPF               24
470 #define FETCH_OP_GDS_BYTE_WRITE                  25
471 #define FETCH_OP_GDS_SHORT_WRITE                 26
472 #define FETCH_OP_GDS_ADD_RET                     27
473 #define FETCH_OP_GDS_SUB_RET                     28
474 #define FETCH_OP_GDS_RSUB_RET                    29
475 #define FETCH_OP_GDS_INC_RET                     30
476 #define FETCH_OP_GDS_DEC_RET                     31
477 #define FETCH_OP_GDS_MIN_INT_RET                 32
478 #define FETCH_OP_GDS_MAX_INT_RET                 33
479 #define FETCH_OP_GDS_MIN_UINT_RET                34
480 #define FETCH_OP_GDS_MAX_UINT_RET                35
481 #define FETCH_OP_GDS_AND_RET                     36
482 #define FETCH_OP_GDS_OR_RET                      37
483 #define FETCH_OP_GDS_XOR_RET                     38
484 #define FETCH_OP_GDS_MSKOR_RET                   39
485 #define FETCH_OP_GDS_XCHG_RET                    40
486 #define FETCH_OP_GDS_XCHG_REL_RET                41
487 #define FETCH_OP_GDS_XCHG2_RET                   42
488 #define FETCH_OP_GDS_CMP_XCHG_RET                43
489 #define FETCH_OP_GDS_CMP_XCHG_SPF_RET            44
490 #define FETCH_OP_GDS_READ_RET                    45
491 #define FETCH_OP_GDS_READ_REL_RET                46
492 #define FETCH_OP_GDS_READ2_RET                   47
493 #define FETCH_OP_GDS_READWRITE_RET               48
494 #define FETCH_OP_GDS_BYTE_READ_RET               49
495 #define FETCH_OP_GDS_UBYTE_READ_RET              50
496 #define FETCH_OP_GDS_SHORT_READ_RET              51
497 #define FETCH_OP_GDS_USHORT_READ_RET             52
498 #define FETCH_OP_GDS_ATOMIC_ORDERED_ALLOC        53
499 #define FETCH_OP_TF_WRITE                        54
500 #define FETCH_OP_DS_GLOBAL_WRITE                 55
501 #define FETCH_OP_DS_GLOBAL_READ                  56
502 #define FETCH_OP_LD                              57
503 #define FETCH_OP_LDFPTR                          58
504 #define FETCH_OP_GET_TEXTURE_RESINFO             59
505 #define FETCH_OP_GET_NUMBER_OF_SAMPLES           60
506 #define FETCH_OP_GET_LOD                         61
507 #define FETCH_OP_GET_GRADIENTS_H                 62
508 #define FETCH_OP_GET_GRADIENTS_V                 63
509 #define FETCH_OP_GET_GRADIENTS_H_FINE            64
510 #define FETCH_OP_GET_GRADIENTS_V_FINE            65
511 #define FETCH_OP_GET_LERP                        66
512 #define FETCH_OP_SET_TEXTURE_OFFSETS             67
513 #define FETCH_OP_KEEP_GRADIENTS                  68
514 #define FETCH_OP_SET_GRADIENTS_H                 69
515 #define FETCH_OP_SET_GRADIENTS_V                 70
516 #define FETCH_OP_SET_GRADIENTS_H_COARSE          71
517 #define FETCH_OP_SET_GRADIENTS_V_COARSE          72
518 #define FETCH_OP_SET_GRADIENTS_H_PACKED_FINE     73
519 #define FETCH_OP_SET_GRADIENTS_V_PACKED_FINE     74
520 #define FETCH_OP_SET_GRADIENTS_H_PACKED_COARSE   75
521 #define FETCH_OP_SET_GRADIENTS_V_PACKED_COARSE   76
522 #define FETCH_OP_PASS                            77
523 #define FETCH_OP_PASS1                           78
524 #define FETCH_OP_PASS2                           79
525 #define FETCH_OP_PASS3                           80
526 #define FETCH_OP_SET_CUBEMAP_INDEX               81
527 #define FETCH_OP_GET_BUFFER_RESINFO              82
528 #define FETCH_OP_FETCH4                          83
529 #define FETCH_OP_SAMPLE                          84
530 #define FETCH_OP_SAMPLE_L                        85
531 #define FETCH_OP_SAMPLE_LB                       86
532 #define FETCH_OP_SAMPLE_LZ                       87
533 #define FETCH_OP_SAMPLE_G                        88
534 #define FETCH_OP_SAMPLE_G_L                      89
535 #define FETCH_OP_GATHER4                         90
536 #define FETCH_OP_SAMPLE_G_LB                     91
537 #define FETCH_OP_SAMPLE_G_LZ                     92
538 #define FETCH_OP_GATHER4_O                       93
539 #define FETCH_OP_SAMPLE_C                        94
540 #define FETCH_OP_SAMPLE_C_L                      95
541 #define FETCH_OP_SAMPLE_C_LB                     96
542 #define FETCH_OP_SAMPLE_C_LZ                     97
543 #define FETCH_OP_SAMPLE_C_G                      98
544 #define FETCH_OP_SAMPLE_C_G_L                    99
545 #define FETCH_OP_GATHER4_C                      100
546 #define FETCH_OP_SAMPLE_C_G_LB                  101
547 #define FETCH_OP_SAMPLE_C_G_LZ                  102
548 #define FETCH_OP_GATHER4_C_O                    103
549 
550 #define CF_OP_NOP                           0
551 #define CF_OP_TEX                           1
552 #define CF_OP_VTX                           2
553 #define CF_OP_VTX_TC                        3
554 #define CF_OP_GDS                           4
555 #define CF_OP_LOOP_START                    5
556 #define CF_OP_LOOP_END                      6
557 #define CF_OP_LOOP_START_DX10               7
558 #define CF_OP_LOOP_START_NO_AL              8
559 #define CF_OP_LOOP_CONTINUE                 9
560 #define CF_OP_LOOP_BREAK                   10
561 #define CF_OP_JUMP                         11
562 #define CF_OP_PUSH                         12
563 #define CF_OP_PUSH_ELSE                    13
564 #define CF_OP_ELSE                         14
565 #define CF_OP_POP                          15
566 #define CF_OP_POP_JUMP                     16
567 #define CF_OP_POP_PUSH                     17
568 #define CF_OP_POP_PUSH_ELSE                18
569 #define CF_OP_CALL                         19
570 #define CF_OP_CALL_FS                      20
571 #define CF_OP_RET                          21
572 #define CF_OP_EMIT_VERTEX                  22
573 #define CF_OP_EMIT_CUT_VERTEX              23
574 #define CF_OP_CUT_VERTEX                   24
575 #define CF_OP_KILL                         25
576 #define CF_OP_END_PROGRAM                  26
577 #define CF_OP_WAIT_ACK                     27
578 #define CF_OP_TEX_ACK                      28
579 #define CF_OP_VTX_ACK                      29
580 #define CF_OP_VTX_TC_ACK                   30
581 #define CF_OP_JUMPTABLE                    31
582 #define CF_OP_WAVE_SYNC                    32
583 #define CF_OP_HALT                         33
584 #define CF_OP_CF_END                       34
585 #define CF_OP_LDS_DEALLOC                  35
586 #define CF_OP_PUSH_WQM                     36
587 #define CF_OP_POP_WQM                      37
588 #define CF_OP_ELSE_WQM                     38
589 #define CF_OP_JUMP_ANY                     39
590 #define CF_OP_REACTIVATE                   40
591 #define CF_OP_REACTIVATE_WQM               41
592 #define CF_OP_INTERRUPT                    42
593 #define CF_OP_INTERRUPT_AND_SLEEP          43
594 #define CF_OP_SET_PRIORITY                 44
595 #define CF_OP_MEM_STREAM0_BUF0             45
596 #define CF_OP_MEM_STREAM0_BUF1             46
597 #define CF_OP_MEM_STREAM0_BUF2             47
598 #define CF_OP_MEM_STREAM0_BUF3             48
599 #define CF_OP_MEM_STREAM1_BUF0             49
600 #define CF_OP_MEM_STREAM1_BUF1             50
601 #define CF_OP_MEM_STREAM1_BUF2             51
602 #define CF_OP_MEM_STREAM1_BUF3             52
603 #define CF_OP_MEM_STREAM2_BUF0             53
604 #define CF_OP_MEM_STREAM2_BUF1             54
605 #define CF_OP_MEM_STREAM2_BUF2             55
606 #define CF_OP_MEM_STREAM2_BUF3             56
607 #define CF_OP_MEM_STREAM3_BUF0             57
608 #define CF_OP_MEM_STREAM3_BUF1             58
609 #define CF_OP_MEM_STREAM3_BUF2             59
610 #define CF_OP_MEM_STREAM3_BUF3             60
611 #define CF_OP_MEM_STREAM0                  61
612 #define CF_OP_MEM_STREAM1                  62
613 #define CF_OP_MEM_STREAM2                  63
614 #define CF_OP_MEM_STREAM3                  64
615 #define CF_OP_MEM_SCRATCH                  65
616 #define CF_OP_MEM_REDUCT                   66
617 #define CF_OP_MEM_RING                     67
618 #define CF_OP_EXPORT                       68
619 #define CF_OP_EXPORT_DONE                  69
620 #define CF_OP_MEM_EXPORT                   70
621 #define CF_OP_MEM_RAT                      71
622 #define CF_OP_MEM_RAT_NOCACHE              72
623 #define CF_OP_MEM_RING1                    73
624 #define CF_OP_MEM_RING2                    74
625 #define CF_OP_MEM_RING3                    75
626 #define CF_OP_MEM_MEM_COMBINED             76
627 #define CF_OP_MEM_RAT_COMBINED_NOCACHE     77
628 #define CF_OP_MEM_RAT_COMBINED             78
629 #define CF_OP_EXPORT_DONE_END              79
630 #define CF_OP_ALU                          80
631 #define CF_OP_ALU_PUSH_BEFORE              81
632 #define CF_OP_ALU_POP_AFTER                82
633 #define CF_OP_ALU_POP2_AFTER               83
634 #define CF_OP_ALU_EXT                      84
635 #define CF_OP_ALU_CONTINUE                 85
636 #define CF_OP_ALU_BREAK                    86
637 #define CF_OP_ALU_VALID_PIXEL_MODE         87
638 #define CF_OP_ALU_ELSE_AFTER               88
639 
640 /* CF_NATIVE means that r600_bytecode_cf contains pre-encoded native data */
641 #define CF_NATIVE                          89
642 
643 enum r600_chip_class {
644 	ISA_CC_R600,
645 	ISA_CC_R700,
646 	ISA_CC_EVERGREEN,
647 	ISA_CC_CAYMAN
648 };
649 
650 struct r600_isa {
651 	enum r600_chip_class hw_class;
652 
653 	/* these arrays provide reverse mapping - opcode => table_index,
654 	 * typically we don't need such lookup, unless we are decoding the native
655 	 * bytecode (e.g. when reading the bytestream from llvm backend) */
656 	unsigned *alu_op2_map;
657 	unsigned *alu_op3_map;
658 	unsigned *fetch_map;
659 	unsigned *cf_map;
660 };
661 
662 struct r600_context;
663 
664 int r600_isa_init(enum amd_gfx_level gfx_level, struct r600_isa *isa);
665 int r600_isa_destroy(struct r600_isa *isa);
666 
667 extern const struct alu_op_info r600_alu_op_table[];
668 
669 unsigned
670 r600_alu_op_table_size(void);
671 
672 const struct alu_op_info *
673 r600_isa_alu(unsigned op);
674 
675 const struct fetch_op_info *
676 r600_isa_fetch(unsigned op);
677 
678 const struct cf_op_info *
679 r600_isa_cf(unsigned op);
680 
681 static inline unsigned
r600_isa_alu_opcode(enum r600_chip_class gfx_level,unsigned op)682 r600_isa_alu_opcode(enum r600_chip_class gfx_level, unsigned op) {
683 	int opc =  r600_isa_alu(op)->opcode[gfx_level >> 1];
684 	assert(opc != -1);
685 	return opc;
686 }
687 
688 static inline unsigned
r600_isa_alu_slots(enum r600_chip_class gfx_level,unsigned op)689 r600_isa_alu_slots(enum r600_chip_class gfx_level, unsigned op) {
690 	unsigned slots = r600_isa_alu(op)->slots[gfx_level];
691 	assert(slots != 0);
692 	return slots;
693 }
694 
695 static inline unsigned
r600_isa_fetch_opcode(enum r600_chip_class gfx_level,unsigned op)696 r600_isa_fetch_opcode(enum r600_chip_class gfx_level, unsigned op) {
697 	int opc = r600_isa_fetch(op)->opcode[gfx_level];
698 	assert(opc != -1);
699 	return opc;
700 }
701 
702 static inline unsigned
r600_isa_cf_opcode(enum r600_chip_class gfx_level,unsigned op)703 r600_isa_cf_opcode(enum r600_chip_class gfx_level, unsigned op) {
704 	int opc = r600_isa_cf(op)->opcode[gfx_level];
705 	assert(opc != -1);
706 	return opc;
707 }
708 
709 static inline unsigned
r600_isa_alu_by_opcode(struct r600_isa * isa,unsigned opcode,unsigned is_op3)710 r600_isa_alu_by_opcode(struct r600_isa* isa, unsigned opcode, unsigned is_op3) {
711 	unsigned op;
712 	if (is_op3) {
713 		assert(isa->alu_op3_map);
714 		op = isa->alu_op3_map[opcode];
715 	} else {
716 		assert(isa->alu_op2_map);
717 		op = isa->alu_op2_map[opcode];
718 	}
719 	assert(op);
720 	return op - 1;
721 }
722 
723 static inline unsigned
r600_isa_fetch_by_opcode(struct r600_isa * isa,unsigned opcode)724 r600_isa_fetch_by_opcode(struct r600_isa* isa, unsigned opcode) {
725 	unsigned op;
726 	assert(isa->fetch_map);
727 	op = isa->fetch_map[opcode];
728 	assert(op);
729 	return op - 1;
730 }
731 
732 static inline unsigned
r600_isa_cf_by_opcode(struct r600_isa * isa,unsigned opcode,unsigned is_alu)733 r600_isa_cf_by_opcode(struct r600_isa* isa, unsigned opcode, unsigned is_alu) {
734 	unsigned op;
735 	assert(isa->cf_map);
736 	/* using offset for CF_ALU_xxx opcodes because they overlap with other
737 	 * CF opcodes (they use different encoding in hw) */
738 	op = isa->cf_map[is_alu ? opcode + 0x80 : opcode];
739 	assert(op);
740 	return op - 1;
741 }
742 
743 #ifdef __cplusplus
744 } /* extern "C" */
745 #endif
746 
747 #endif /* R600_ISA_H_ */
748