Debian Codegraph @

src/freedreno/ir3/instr-a3xx.h

raw symbols SCIP
1 /*
2 * Copyright © 2013 Rob Clark <[email protected]>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef INSTR_A3XX_H_
7 #define INSTR_A3XX_H_
8
9 #define PACKED __attribute__((__packed__))
10
11 #include <assert.h>
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <stdio.h>
15
16 /* clang-format off */
17 void ir3_assert_handler(const char *expr, const char *file, int line,
18 const char *func) __attribute__((weak)) __attribute__((__noreturn__));
19 /* clang-format on */
20
21 /* A wrapper for assert() that allows overriding handling of a failed
22 * assert. This is needed for tools like crashdec which can want to
23 * attempt to disassemble memory that might not actually be valid
24 * instructions.
25 */
26 #define ir3_assert(expr) \
27 do { \
28 if (!(expr)) { \
29 if (ir3_assert_handler) { \
30 ir3_assert_handler(#expr, __FILE__, __LINE__, __func__); \
31 } \
32 assert(expr); \
33 } \
34 } while (0)
35 /* size of largest OPC field of all the instruction categories: */
36 #define NOPC_BITS 7
37
38 #define _OPC(cat, opc) (((cat) << NOPC_BITS) | opc)
39
40 /* clang-format off */
41 typedef enum {
42 /* category 0: */
43 OPC_NOP = _OPC(0, 0),
44 OPC_JUMP = _OPC(0, 2),
45 OPC_CALL = _OPC(0, 3),
46 OPC_RET = _OPC(0, 4),
47 OPC_KILL = _OPC(0, 5),
48 OPC_END = _OPC(0, 6),
49 OPC_EMIT = _OPC(0, 7),
50 OPC_CUT = _OPC(0, 8),
51 OPC_CHMASK = _OPC(0, 9),
52 OPC_CHSH = _OPC(0, 10),
53 OPC_FLOW_REV = _OPC(0, 11),
54
55 OPC_BKT = _OPC(0, 16),
56 OPC_STKS = _OPC(0, 17),
57 OPC_STKR = _OPC(0, 18),
58 OPC_XSET = _OPC(0, 19),
59 OPC_XCLR = _OPC(0, 20),
60 OPC_GETONE = _OPC(0, 21),
61 OPC_DBG = _OPC(0, 22),
62 OPC_SHPS = _OPC(0, 23), /* shader prologue start */
63 OPC_SHPE = _OPC(0, 24), /* shader prologue end */
64 OPC_GETLAST = _OPC(0, 25),
65
66 OPC_PREDT = _OPC(0, 29), /* predicated true */
67 OPC_PREDF = _OPC(0, 30), /* predicated false */
68 OPC_PREDE = _OPC(0, 31), /* predicated end */
69
70 /* Logical opcodes for different branch instruction variations: */
71 OPC_BR = _OPC(0, 40),
72 OPC_BRAO = _OPC(0, 41),
73 OPC_BRAA = _OPC(0, 42),
74 OPC_BRAC = _OPC(0, 43),
75 OPC_BANY = _OPC(0, 44),
76 OPC_BALL = _OPC(0, 45),
77 OPC_BRAX = _OPC(0, 46),
78
79 /* Logical opcode to distinguish kill and demote */
80 OPC_DEMOTE = _OPC(0, 47),
81
82 /* category 1: */
83 OPC_MOV = _OPC(1, 0),
84 OPC_MOVP = _OPC(1, 1),
85 OPC_MOVS = _OPC(1, 2),
86 /* swz, gat, sct */
87 OPC_MOVMSK = _OPC(1, 3),
88
89 /* Virtual opcodes for instructions differentiated via a "sub-opcode" that
90 * replaces the repeat field:
91 */
92 OPC_SWZ = _OPC(1, 4),
93 OPC_GAT = _OPC(1, 5),
94 OPC_SCT = _OPC(1, 6),
95
96 /* Logical opcodes for different variants of mov: */
97 OPC_MOV_IMMED = _OPC(1, 40),
98 OPC_MOV_CONST = _OPC(1, 41),
99 OPC_MOV_GPR = _OPC(1, 42),
100 OPC_MOV_RELGPR = _OPC(1, 43),
101 OPC_MOV_RELCONST = _OPC(1, 44),
102 OPC_MOVS_IMMED = _OPC(1, 45),
103 OPC_MOVS_A0 = _OPC(1, 46),
104 OPC_MOVA_R_IMMED = _OPC(1, 47),
105 OPC_MOVA_R_GPR = _OPC(1, 48),
106
107 /* Macros that expand to an if statement + move */
108 OPC_BALLOT_MACRO = _OPC(1, 50),
109 OPC_ANY_MACRO = _OPC(1, 51),
110 OPC_ALL_MACRO = _OPC(1, 52),
111 OPC_ELECT_MACRO = _OPC(1, 53),
112 OPC_READ_COND_MACRO = _OPC(1, 54),
113 OPC_READ_FIRST_MACRO = _OPC(1, 55),
114 OPC_SHPS_MACRO = _OPC(1, 56),
115 OPC_READ_GETLAST_MACRO = _OPC(1, 57),
116
117 /* Macros that expand to a loop */
118 OPC_SCAN_MACRO = _OPC(1, 58),
119 OPC_SCAN_CLUSTERS_MACRO = _OPC(1, 60),
120
121 /* category 2: */
122 OPC_ADD_F = _OPC(2, 0),
123 OPC_MIN_F = _OPC(2, 1),
124 OPC_MAX_F = _OPC(2, 2),
125 OPC_MUL_F = _OPC(2, 3),
126 OPC_SIGN_F = _OPC(2, 4),
127 OPC_CMPS_F = _OPC(2, 5),
128 OPC_ABSNEG_F = _OPC(2, 6),
129 OPC_CMPV_F = _OPC(2, 7),
130 /* 8 - invalid */
131 OPC_FLOOR_F = _OPC(2, 9),
132 OPC_CEIL_F = _OPC(2, 10),
133 OPC_RNDNE_F = _OPC(2, 11),
134 OPC_RNDAZ_F = _OPC(2, 12),
135 OPC_TRUNC_F = _OPC(2, 13),
136 /* 14-15 - invalid */
137 OPC_ADD_U = _OPC(2, 16),
138 OPC_ADD_S = _OPC(2, 17),
139 OPC_SUB_U = _OPC(2, 18),
140 OPC_SUB_S = _OPC(2, 19),
141 OPC_CMPS_U = _OPC(2, 20),
142 OPC_CMPS_S = _OPC(2, 21),
143 OPC_MIN_U = _OPC(2, 22),
144 OPC_MIN_S = _OPC(2, 23),
145 OPC_MAX_U = _OPC(2, 24),
146 OPC_MAX_S = _OPC(2, 25),
147 OPC_ABSNEG_S = _OPC(2, 26),
148 /* 27 - invalid */
149 OPC_AND_B = _OPC(2, 28),
150 OPC_OR_B = _OPC(2, 29),
151 OPC_NOT_B = _OPC(2, 30),
152 OPC_XOR_B = _OPC(2, 31),
153 /* 32 - invalid */
154 OPC_CMPV_U = _OPC(2, 33),
155 OPC_CMPV_S = _OPC(2, 34),
156 OPC_MUL_F_MUL2 = _OPC(2, 35),
157 OPC_ADD_F_MUL2 = _OPC(2, 36),
158 OPC_MUL_F_DIV2 = _OPC(2, 37),
159 OPC_ADD_F_DIV2 = _OPC(2, 38),
160 /* 35-47 - invalid */
161 OPC_MUL_U24 = _OPC(2, 48), /* 24b mul into 32b result */
162 OPC_MUL_S24 = _OPC(2, 49), /* 24b mul into 32b result with sign extension */
163 OPC_MULL_U = _OPC(2, 50),
164 OPC_BFREV_B = _OPC(2, 51),
165 OPC_CLZ_S = _OPC(2, 52),
166 OPC_CLZ_B = _OPC(2, 53),
167 OPC_SHL_B = _OPC(2, 54),
168 OPC_SHR_B = _OPC(2, 55),
169 OPC_ASHR_B = _OPC(2, 56),
170 OPC_BARY_F = _OPC(2, 57),
171 OPC_MGEN_B = _OPC(2, 58),
172 OPC_GETBIT_B = _OPC(2, 59),
173 OPC_SETRM = _OPC(2, 60),
174 OPC_CBITS_B = _OPC(2, 61),
175 OPC_SHB = _OPC(2, 62),
176 OPC_MSAD = _OPC(2, 63),
177 OPC_FLAT_B = _OPC(2, 64),
178
179 /* category 3: */
180 OPC_MAD_U16 = _OPC(3, 0),
181 OPC_MADSH_U16 = _OPC(3, 1),
182 OPC_MAD_S16 = _OPC(3, 2),
183 OPC_MADSH_M16 = _OPC(3, 3), /* should this be .s16? */
184 OPC_MAD_U24 = _OPC(3, 4),
185 OPC_MAD_S24 = _OPC(3, 5),
186 OPC_MAD_F16 = _OPC(3, 6),
187 OPC_MAD_F32 = _OPC(3, 7),
188 OPC_SEL_B16 = _OPC(3, 8),
189 OPC_SEL_B32 = _OPC(3, 9),
190 OPC_SEL_S16 = _OPC(3, 10),
191 OPC_SEL_S32 = _OPC(3, 11),
192 OPC_SEL_F16 = _OPC(3, 12),
193 OPC_SEL_F32 = _OPC(3, 13),
194 OPC_SAD_S16 = _OPC(3, 14),
195 OPC_SAD_S32 = _OPC(3, 15),
196 OPC_SHRM = _OPC(3, 16),
197 OPC_SHLM = _OPC(3, 17),
198 OPC_SHRG = _OPC(3, 18),
199 OPC_SHLG = _OPC(3, 19),
200 OPC_ANDG = _OPC(3, 20),
201 OPC_DP2ACC = _OPC(3, 21),
202 OPC_DP4ACC = _OPC(3, 22),
203 OPC_WMM = _OPC(3, 23),
204 OPC_WMM_ACCU = _OPC(3, 24),
205 OPC_MAD_F16_MUL2 = _OPC(3, 25),
206 OPC_MAD_F32_MUL2 = _OPC(3, 26),
207 OPC_MAD_F16_DIV2 = _OPC(3, 27),
208 OPC_MAD_F32_DIV2 = _OPC(3, 28),
209
210 /* category 4: */
211 OPC_RCP = _OPC(4, 0),
212 OPC_RSQ = _OPC(4, 1),
213 OPC_LOG2 = _OPC(4, 2),
214 OPC_EXP2 = _OPC(4, 3),
215 OPC_SIN = _OPC(4, 4),
216 OPC_COS = _OPC(4, 5),
217 OPC_SQRT = _OPC(4, 6),
218 /* NOTE that these are 8+opc from their highp equivs, so it's possible
219 * that the high order bit in the opc field has been repurposed for
220 * half-precision use? But note that other ops (rcp/lsin/cos/sqrt)
221 * still use the same opc as highp
222 */
223 OPC_HRSQ = _OPC(4, 9),
224 OPC_HLOG2 = _OPC(4, 10),
225 OPC_HEXP2 = _OPC(4, 11),
226
227 /* category 5: */
228 OPC_ISAM = _OPC(5, 0),
229 OPC_ISAML = _OPC(5, 1),
230 OPC_ISAMM = _OPC(5, 2),
231 OPC_SAM = _OPC(5, 3),
232 OPC_SAMB = _OPC(5, 4),
233 OPC_SAML = _OPC(5, 5),
234 OPC_SAMGQ = _OPC(5, 6),
235 OPC_GETLOD = _OPC(5, 7),
236 OPC_CONV = _OPC(5, 8),
237 OPC_CONVM = _OPC(5, 9),
238 OPC_GETSIZE = _OPC(5, 10),
239 OPC_GETBUF = _OPC(5, 11),
240 OPC_GETPOS = _OPC(5, 12),
241 OPC_GETINFO = _OPC(5, 13),
242 OPC_DSX = _OPC(5, 14),
243 OPC_DSY = _OPC(5, 15),
244 OPC_GATHER4R = _OPC(5, 16),
245 OPC_GATHER4G = _OPC(5, 17),
246 OPC_GATHER4B = _OPC(5, 18),
247 OPC_GATHER4A = _OPC(5, 19),
248 OPC_SAMGP0 = _OPC(5, 20),
249 OPC_SAMGP1 = _OPC(5, 21),
250 OPC_SAMGP2 = _OPC(5, 22),
251 OPC_SAMGP3 = _OPC(5, 23),
252 OPC_DSXPP_1 = _OPC(5, 24),
253 OPC_DSYPP_1 = _OPC(5, 25),
254 OPC_RGETPOS = _OPC(5, 26),
255 OPC_RGETINFO = _OPC(5, 27),
256 OPC_BRCST_ACTIVE = _OPC(5, 28),
257 OPC_QUAD_SHUFFLE_BRCST = _OPC(5, 29),
258 OPC_QUAD_SHUFFLE_HORIZ = _OPC(5, 30),
259 OPC_QUAD_SHUFFLE_VERT = _OPC(5, 31),
260 OPC_QUAD_SHUFFLE_DIAG = _OPC(5, 32),
261 OPC_TCINV = _OPC(5, 33),
262 OPC_IMG_BINDLESS_HOF = _OPC(5, 34),
263 OPC_IMG_BINDLESS_PCMN = _OPC(5, 35),
264 OPC_IMG_BINDLESS = _OPC(5, 36),
265 /* cat5 meta instructions, placed above the cat5 opc field's size */
266 OPC_DSXPP_MACRO = _OPC(5, 37),
267 OPC_DSYPP_MACRO = _OPC(5, 38),
268
269 /* category 6: */
270 OPC_LDG = _OPC(6, 0), /* load-global */
271 OPC_LDL = _OPC(6, 1),
272 OPC_LDP = _OPC(6, 2),
273 OPC_STG = _OPC(6, 3), /* store-global */
274 OPC_STL = _OPC(6, 4),
275 OPC_STP = _OPC(6, 5),
276 OPC_LDIB = _OPC(6, 6),
277 OPC_G2L = _OPC(6, 7),
278 OPC_L2G = _OPC(6, 8),
279 OPC_PREFETCH = _OPC(6, 9),
280 OPC_LDLW = _OPC(6, 10),
281 OPC_STLW = _OPC(6, 11),
282 OPC_RESFMT = _OPC(6, 14),
283 OPC_RESINFO = _OPC(6, 15),
284 OPC_ATOMIC_ADD = _OPC(6, 16),
285 OPC_ATOMIC_SUB = _OPC(6, 17),
286 OPC_ATOMIC_XCHG = _OPC(6, 18),
287 OPC_ATOMIC_INC = _OPC(6, 19),
288 OPC_ATOMIC_DEC = _OPC(6, 20),
289 OPC_ATOMIC_CMPXCHG = _OPC(6, 21),
290 OPC_ATOMIC_MIN = _OPC(6, 22),
291 OPC_ATOMIC_MAX = _OPC(6, 23),
292 OPC_ATOMIC_AND = _OPC(6, 24),
293 OPC_ATOMIC_OR = _OPC(6, 25),
294 OPC_ATOMIC_XOR = _OPC(6, 26),
295 OPC_LDGB = _OPC(6, 27),
296 OPC_STGB = _OPC(6, 28),
297 OPC_STIB = _OPC(6, 29),
298 OPC_LDC = _OPC(6, 30),
299 OPC_LDLV = _OPC(6, 31),
300 OPC_PIPR = _OPC(6, 32), /* ??? */
301 OPC_PIPC = _OPC(6, 33), /* ??? */
302 OPC_EMIT2 = _OPC(6, 34), /* ??? */
303 OPC_ENDLS = _OPC(6, 35), /* ??? */
304 OPC_GETSPID = _OPC(6, 36), /* SP ID */
305 OPC_GETWID = _OPC(6, 37), /* wavefront ID */
306 OPC_GETFIBERID = _OPC(6, 38), /* fiber ID */
307 OPC_SHFL = _OPC(6, 39),
308
309 /* Logical opcodes for things that differ in a6xx+ */
310 OPC_STC = _OPC(6, 40),
311 OPC_RESINFO_B = _OPC(6, 41),
312 OPC_LDIB_B = _OPC(6, 42),
313 OPC_STIB_B = _OPC(6, 43),
314
315 /* Logical opcodes for different atomic instruction variations: */
316 OPC_ATOMIC_B_ADD = _OPC(6, 44),
317 OPC_ATOMIC_B_SUB = _OPC(6, 45),
318 OPC_ATOMIC_B_XCHG = _OPC(6, 46),
319 OPC_ATOMIC_B_INC = _OPC(6, 47),
320 OPC_ATOMIC_B_DEC = _OPC(6, 48),
321 OPC_ATOMIC_B_CMPXCHG = _OPC(6, 49),
322 OPC_ATOMIC_B_MIN = _OPC(6, 50),
323 OPC_ATOMIC_B_MAX = _OPC(6, 51),
324 OPC_ATOMIC_B_AND = _OPC(6, 52),
325 OPC_ATOMIC_B_OR = _OPC(6, 53),
326 OPC_ATOMIC_B_XOR = _OPC(6, 54),
327
328 OPC_ATOMIC_S_ADD = _OPC(6, 55),
329 OPC_ATOMIC_S_SUB = _OPC(6, 56),
330 OPC_ATOMIC_S_XCHG = _OPC(6, 57),
331 OPC_ATOMIC_S_INC = _OPC(6, 58),
332 OPC_ATOMIC_S_DEC = _OPC(6, 59),
333 OPC_ATOMIC_S_CMPXCHG = _OPC(6, 60),
334 OPC_ATOMIC_S_MIN = _OPC(6, 61),
335 OPC_ATOMIC_S_MAX = _OPC(6, 62),
336 OPC_ATOMIC_S_AND = _OPC(6, 63),
337 OPC_ATOMIC_S_OR = _OPC(6, 64),
338 OPC_ATOMIC_S_XOR = _OPC(6, 65),
339
340 OPC_ATOMIC_G_ADD = _OPC(6, 66),
341 OPC_ATOMIC_G_SUB = _OPC(6, 67),
342 OPC_ATOMIC_G_XCHG = _OPC(6, 68),
343 OPC_ATOMIC_G_INC = _OPC(6, 69),
344 OPC_ATOMIC_G_DEC = _OPC(6, 70),
345 OPC_ATOMIC_G_CMPXCHG = _OPC(6, 71),
346 OPC_ATOMIC_G_MIN = _OPC(6, 72),
347 OPC_ATOMIC_G_MAX = _OPC(6, 73),
348 OPC_ATOMIC_G_AND = _OPC(6, 74),
349 OPC_ATOMIC_G_OR = _OPC(6, 75),
350 OPC_ATOMIC_G_XOR = _OPC(6, 76),
351
352 OPC_LDG_A = _OPC(6, 77),
353 OPC_STG_A = _OPC(6, 78),
354
355 OPC_SPILL_MACRO = _OPC(6, 79),
356 OPC_RELOAD_MACRO = _OPC(6, 80),
357
358 OPC_LDC_K = _OPC(6, 81),
359 OPC_STSC = _OPC(6, 82),
360 OPC_LDG_K = _OPC(6, 83),
361
362 /* Macros that expand to an stsc at the start of the preamble.
363 * It loads into const file and should not be optimized in any way.
364 */
365 OPC_PUSH_CONSTS_LOAD_MACRO = _OPC(6, 84),
366
367 OPC_RAY_INTERSECTION = _OPC(6, 90),
368 OPC_RESBASE = _OPC(6, 91),
369
370 /* category 7: */
371 OPC_BAR = _OPC(7, 0),
372 OPC_FENCE = _OPC(7, 1),
373 OPC_SLEEP = _OPC(7, 2),
374 OPC_ICINV = _OPC(7, 3),
375 OPC_DCCLN = _OPC(7, 4),
376 OPC_DCINV = _OPC(7, 5),
377 OPC_DCFLU = _OPC(7, 6),
378
379 OPC_LOCK = _OPC(7, 7),
380 OPC_UNLOCK = _OPC(7, 8),
381
382 OPC_ALIAS = _OPC(7, 9),
383
384 OPC_CCINV = _OPC(7, 10),
385
386 /* meta instructions (category 8): */
387 #define OPC_META 8
388 /* placeholder instr to mark shader inputs: */
389 OPC_META_INPUT = _OPC(OPC_META, 0),
390 /* The "collect" and "split" instructions are used for keeping
391 * track of instructions that write to multiple dst registers
392 * (split) like texture sample instructions, or read multiple
393 * consecutive scalar registers (collect) (bary.f, texture samp)
394 *
395 * A "split" extracts a scalar component from a vecN, and a
396 * "collect" gathers multiple scalar components into a vecN
397 */
398 OPC_META_SPLIT = _OPC(OPC_META, 2),
399 OPC_META_COLLECT = _OPC(OPC_META, 3),
400
401 /* placeholder for texture fetches that run before FS invocation
402 * starts:
403 */
404 OPC_META_TEX_PREFETCH = _OPC(OPC_META, 4),
405
406 /* Parallel copies have multiple destinations, and copy each destination
407 * to its corresponding source. This happens "in parallel," meaning that
408 * it happens as-if every source is read first and then every destination
409 * is stored. These are produced in RA when register shuffling is
410 * required, and then lowered away immediately afterwards.
411 */
412 OPC_META_PARALLEL_COPY = _OPC(OPC_META, 5),
413 OPC_META_PHI = _OPC(OPC_META, 6),
414 /*
415 * A manually encoded opcode
416 */
417 OPC_META_RAW = _OPC(OPC_META, 7),
418 } opc_t;
419 /* clang-format on */
420
421 #define opc_cat(opc) ((int)((opc) >> NOPC_BITS))
422 #define opc_op(opc) ((unsigned)((opc) & ((1 << NOPC_BITS) - 1)))
423
424 const char *disasm_a3xx_instr_name(opc_t opc);
425
426 typedef enum {
427 TYPE_F16 = 0,
428 TYPE_F32 = 1,
429 TYPE_U16 = 2,
430 TYPE_U32 = 3,
431 TYPE_S16 = 4,
432 TYPE_S32 = 5,
433 TYPE_ATOMIC_U64 = 6, /* Only valid for a7xx atomics */
434 TYPE_U8 = 6,
435 TYPE_U8_32 = 7,
436 } type_t;
437
438 static inline uint32_t
439 type_size(type_t type)
440 {
441 switch (type) {
442 case TYPE_F32:
443 case TYPE_U32:
444 case TYPE_U8_32:
445 case TYPE_S32:
446 return 32;
447 case TYPE_F16:
448 case TYPE_U16:
449 case TYPE_S16:
450 return 16;
451 case TYPE_U8:
452 return 8;
453 default:
454 ir3_assert(0); /* invalid type */
455 return 0;
456 }
457 }
458
459 static inline type_t
460 type_uint_size(unsigned bit_size)
461 {
462 switch (bit_size) {
463 case 8: return TYPE_U8;
464 case 1: /* 1b bools are treated as normal half-regs */
465 case 16: return TYPE_U16;
466 case 32: return TYPE_U32;
467 case 64:
468 return TYPE_U32;
469 default:
470 ir3_assert(0); /* invalid size */
471 return (type_t)0;
472 }
473 }
474
475 static inline type_t
476 type_float_size(unsigned bit_size)
477 {
478 switch (bit_size) {
479 case 16: return TYPE_F16;
480 case 32: return TYPE_F32;
481 default:
482 ir3_assert(0); /* invalid size */
483 return (type_t)0;
484 }
485 }
486
487 static inline int
488 type_float(type_t type)
489 {
490 return (type == TYPE_F32) || (type == TYPE_F16);
491 }
492
493 static inline int
494 type_uint(type_t type)
495 {
496 return (type == TYPE_U32) || (type == TYPE_U16) || (type == TYPE_U8) || (type == TYPE_U8_32);
497 }
498
499 static inline int
500 type_sint(type_t type)
501 {
502 return (type == TYPE_S32) || (type == TYPE_S16);
503 }
504
505 typedef enum {
506 ROUND_ZERO = 0,
507 ROUND_EVEN = 1,
508 ROUND_POS_INF = 2,
509 ROUND_NEG_INF = 3,
510 } round_t;
511
512 /* comp:
513 * 0 - x
514 * 1 - y
515 * 2 - z
516 * 3 - w
517 */
518 static inline uint32_t
519 regid(int num, int comp)
520 {
521 return (num << 2) | (comp & 0x3);
522 }
523
524 #define INVALID_REG regid(63, 0)
525 #define VALIDREG(r) ((r) != INVALID_REG)
526 #define CONDREG(r, val) COND(VALIDREG(r), (val))
527
528 /* special registers: */
529 #define REG_A0 61 /* address register */
530 #define REG_P0 62 /* predicate register */
531 #define REG_P0_X regid(REG_P0, 0) /* p0.x */
532
533 #define INVALID_CONST_REG UINT16_MAX
534
535 /* With is_bindless_s2en = 1, this determines whether bindless is enabled and
536 * if so, how to get the (base, index) pair for both sampler and texture.
537 * There is a single base embedded in the instruction, which is always used
538 * for the texture.
539 */
540 typedef enum {
541 /* Use traditional GL binding model, get texture and sampler index from src3
542 * which is presumed to be uniform on a4xx+ (a3xx doesn't have the other
543 * modes, but does handle non-uniform indexing).
544 */
545 CAT5_UNIFORM = 0,
546
547 /* The sampler base comes from the low 3 bits of a1.x, and the sampler
548 * and texture index come from src3 which is presumed to be uniform.
549 */
550 CAT5_BINDLESS_A1_UNIFORM = 1,
551
552 /* The texture and sampler share the same base, and the sampler and
553 * texture index come from src3 which is *not* presumed to be uniform.
554 */
555 CAT5_BINDLESS_NONUNIFORM = 2,
556
557 /* The sampler base comes from the low 3 bits of a1.x, and the sampler
558 * and texture index come from src3 which is *not* presumed to be
559 * uniform.
560 */
561 CAT5_BINDLESS_A1_NONUNIFORM = 3,
562
563 /* Use traditional GL binding model, get texture and sampler index
564 * from src3 which is *not* presumed to be uniform.
565 */
566 CAT5_NONUNIFORM = 4,
567
568 /* The texture and sampler share the same base, and the sampler and
569 * texture index come from src3 which is presumed to be uniform.
570 */
571 CAT5_BINDLESS_UNIFORM = 5,
572
573 /* The texture and sampler share the same base, get sampler index from low
574 * 4 bits of src3 and texture index from high 4 bits.
575 */
576 CAT5_BINDLESS_IMM = 6,
577
578 /* The sampler base comes from the low 3 bits of a1.x, and the texture
579 * index comes from the next 8 bits of a1.x. The sampler index is an
580 * immediate in src3.
581 */
582 CAT5_BINDLESS_A1_IMM = 7,
583 } cat5_desc_mode_t;
584
585 /* Similar to cat5_desc_mode_t, describes how the descriptor is loaded.
586 */
587 typedef enum {
588 /* Use old GL binding model with an immediate index. */
589 CAT6_IMM = 0,
590
591 CAT6_UNIFORM = 1,
592
593 CAT6_NONUNIFORM = 2,
594
595 /* Use the bindless model, with an immediate index.
596 */
597 CAT6_BINDLESS_IMM = 4,
598
599 /* Use the bindless model, with a uniform register index.
600 */
601 CAT6_BINDLESS_UNIFORM = 5,
602
603 /* Use the bindless model, with a register index that isn't guaranteed
604 * to be uniform. This presumably checks if the indices are equal and
605 * splits up the load/store, because it works the way you would
606 * expect.
607 */
608 CAT6_BINDLESS_NONUNIFORM = 6,
609 } cat6_desc_mode_t;
610
611 static inline bool
612 is_sat_compatible(opc_t opc)
613 {
614 /* On a6xx saturation doesn't work on cat4 */
615 if (opc_cat(opc) != 2 && opc_cat(opc) != 3)
616 return false;
617
618 switch (opc) {
619 /* On a3xx and a6xx saturation doesn't work on bary.f/flat.b */
620 case OPC_BARY_F:
621 case OPC_FLAT_B:
622 /* On a6xx saturation doesn't work on sel.* */
623 case OPC_SEL_B16:
624 case OPC_SEL_B32:
625 case OPC_SEL_S16:
626 case OPC_SEL_S32:
627 case OPC_SEL_F16:
628 case OPC_SEL_F32:
629 return false;
630 default:
631 return true;
632 }
633 }
634
635 static inline bool
636 is_mad(opc_t opc)
637 {
638 switch (opc) {
639 case OPC_MAD_U16:
640 case OPC_MAD_S16:
641 case OPC_MAD_U24:
642 case OPC_MAD_S24:
643 case OPC_MAD_F16:
644 case OPC_MAD_F32:
645 return true;
646 default:
647 return false;
648 }
649 }
650
651 static inline bool
652 is_madsh(opc_t opc)
653 {
654 switch (opc) {
655 case OPC_MADSH_U16:
656 case OPC_MADSH_M16:
657 return true;
658 default:
659 return false;
660 }
661 }
662
663 static inline bool
664 is_sad(opc_t opc)
665 {
666 switch (opc) {
667 case OPC_SAD_S16:
668 case OPC_SAD_S32:
669 return true;
670 default:
671 return false;
672 }
673 }
674
675 static inline bool
676 is_local_atomic(opc_t opc)
677 {
678 switch (opc) {
679 case OPC_ATOMIC_ADD:
680 case OPC_ATOMIC_SUB:
681 case OPC_ATOMIC_XCHG:
682 case OPC_ATOMIC_INC:
683 case OPC_ATOMIC_DEC:
684 case OPC_ATOMIC_CMPXCHG:
685 case OPC_ATOMIC_MIN:
686 case OPC_ATOMIC_MAX:
687 case OPC_ATOMIC_AND:
688 case OPC_ATOMIC_OR:
689 case OPC_ATOMIC_XOR:
690 return true;
691 default:
692 return false;
693 }
694 }
695
696 static inline bool
697 is_global_a3xx_atomic(opc_t opc)
698 {
699 switch (opc) {
700 case OPC_ATOMIC_S_ADD:
701 case OPC_ATOMIC_S_SUB:
702 case OPC_ATOMIC_S_XCHG:
703 case OPC_ATOMIC_S_INC:
704 case OPC_ATOMIC_S_DEC:
705 case OPC_ATOMIC_S_CMPXCHG:
706 case OPC_ATOMIC_S_MIN:
707 case OPC_ATOMIC_S_MAX:
708 case OPC_ATOMIC_S_AND:
709 case OPC_ATOMIC_S_OR:
710 case OPC_ATOMIC_S_XOR:
711 return true;
712 default:
713 return false;
714 }
715 }
716
717 static inline bool
718 is_global_a6xx_atomic(opc_t opc)
719 {
720 switch (opc) {
721 case OPC_ATOMIC_G_ADD:
722 case OPC_ATOMIC_G_SUB:
723 case OPC_ATOMIC_G_XCHG:
724 case OPC_ATOMIC_G_INC:
725 case OPC_ATOMIC_G_DEC:
726 case OPC_ATOMIC_G_CMPXCHG:
727 case OPC_ATOMIC_G_MIN:
728 case OPC_ATOMIC_G_MAX:
729 case OPC_ATOMIC_G_AND:
730 case OPC_ATOMIC_G_OR:
731 case OPC_ATOMIC_G_XOR:
732 return true;
733 default:
734 return false;
735 }
736 }
737
738 static inline bool
739 is_bindless_atomic(opc_t opc)
740 {
741 switch (opc) {
742 case OPC_ATOMIC_B_ADD:
743 case OPC_ATOMIC_B_SUB:
744 case OPC_ATOMIC_B_XCHG:
745 case OPC_ATOMIC_B_INC:
746 case OPC_ATOMIC_B_DEC:
747 case OPC_ATOMIC_B_CMPXCHG:
748 case OPC_ATOMIC_B_MIN:
749 case OPC_ATOMIC_B_MAX:
750 case OPC_ATOMIC_B_AND:
751 case OPC_ATOMIC_B_OR:
752 case OPC_ATOMIC_B_XOR:
753 return true;
754 default:
755 return false;
756 }
757 }
758
759 static inline bool
760 is_atomic(opc_t opc)
761 {
762 return is_local_atomic(opc) || is_global_a3xx_atomic(opc) ||
763 is_global_a6xx_atomic(opc) || is_bindless_atomic(opc);
764 }
765
766 static inline bool
767 is_ssbo(opc_t opc)
768 {
769 switch (opc) {
770 case OPC_RESFMT:
771 case OPC_RESINFO:
772 case OPC_LDGB:
773 case OPC_STGB:
774 case OPC_STIB:
775 return true;
776 default:
777 return false;
778 }
779 }
780
781 static inline bool
782 is_isam(opc_t opc)
783 {
784 switch (opc) {
785 case OPC_ISAM:
786 case OPC_ISAML:
787 case OPC_ISAMM:
788 return true;
789 default:
790 return false;
791 }
792 }
793
794 static inline bool
795 is_cat2_float(opc_t opc)
796 {
797 switch (opc) {
798 case OPC_ADD_F:
799 case OPC_MIN_F:
800 case OPC_MAX_F:
801 case OPC_MUL_F:
802 case OPC_SIGN_F:
803 case OPC_CMPS_F:
804 case OPC_ABSNEG_F:
805 case OPC_CMPV_F:
806 case OPC_FLOOR_F:
807 case OPC_CEIL_F:
808 case OPC_RNDNE_F:
809 case OPC_RNDAZ_F:
810 case OPC_TRUNC_F:
811 return true;
812
813 default:
814 return false;
815 }
816 }
817
818 static inline bool
819 is_cat3_float(opc_t opc)
820 {
821 switch (opc) {
822 case OPC_MAD_F16:
823 case OPC_MAD_F32:
824 case OPC_SEL_F16:
825 case OPC_SEL_F32:
826 return true;
827 default:
828 return false;
829 }
830 }
831
832 static inline bool
833 is_cat3_alt(opc_t opc)
834 {
835 switch (opc) {
836 case OPC_SHLM:
837 case OPC_SHRM:
838 case OPC_SHLG:
839 case OPC_SHRG:
840 case OPC_ANDG:
841 return true;
842 default:
843 return false;
844 }
845 }
846
847 #endif /* INSTR_A3XX_H_ */