• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 %code requires {
25 #include "ir3/ir3_assembler.h"
26 #include "ir3/ir3_shader.h"
27 
28 struct ir3 * ir3_parse(struct ir3_shader_variant *v,
29 		struct ir3_kernel_info *k, FILE *f);
30 }
31 
32 %{
33 #define YYDEBUG 0
34 
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <math.h>
39 
40 #include "util/half_float.h"
41 #include "util/u_math.h"
42 
43 #include "ir3/ir3.h"
44 #include "ir3/ir3_shader.h"
45 #include "ir3/instr-a3xx.h"
46 
47 #include "ir3_parser.h"
48 
49 #define swap(a, b) \
50 	do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
51 
52 /* ir3 treats the abs/neg flags as separate flags for float vs integer,
53  * but in the instruction encoding they are the same thing.  Tracking
54  * them separately is only for the benefit of ir3 opt passes, and not
55  * required here, so just use the float versions:
56  */
57 #define IR3_REG_ABS     IR3_REG_FABS
58 #define IR3_REG_NEGATE  IR3_REG_FNEG
59 
60 static struct ir3_kernel_info    *info;
61 static struct ir3_shader_variant *variant;
62 /* NOTE the assembler doesn't really use the ir3_block construction
63  * like the compiler does.  Everything is treated as one large block.
64  * Which might happen to contain flow control.  But since we don't
65  * use any of the ir3 backend passes (sched, RA, etc) this doesn't
66  * really matter.
67  */
68 static struct ir3_block          *block;   /* current shader block */
69 static struct ir3_instruction    *instr;   /* current instruction */
70 static unsigned ip; /* current instruction pointer */
71 static struct hash_table *labels;
72 
73 void *ir3_parser_dead_ctx;
74 
75 static struct {
76 	unsigned flags;
77 	unsigned repeat;
78 	unsigned nop;
79 } iflags;
80 
81 static struct {
82 	unsigned flags;
83 	unsigned wrmask;
84 } rflags;
85 
86 static struct {
87         uint32_t reg_address_hi;
88         uint32_t reg_address_lo;
89         uint32_t reg_tmp;
90 
91         uint32_t regs_to_dump[128];
92         uint32_t regs_count;
93 } meta_print_data;
94 
95 int ir3_yyget_lineno(void);
96 
new_label(const char * name)97 static void new_label(const char *name)
98 {
99 	ralloc_steal(labels, (void *) name);
100 	_mesa_hash_table_insert(labels, name, (void *)(uintptr_t)ip);
101 }
102 
new_instr(opc_t opc)103 static struct ir3_instruction * new_instr(opc_t opc)
104 {
105 	instr = ir3_instr_create(block, opc, 4, 6);
106 	instr->flags = iflags.flags;
107 	instr->repeat = iflags.repeat;
108 	instr->nop = iflags.nop;
109 	instr->line = ir3_yyget_lineno();
110 	iflags.flags = iflags.repeat = iflags.nop = 0;
111 	ip++;
112 	return instr;
113 }
114 
new_shader(void)115 static void new_shader(void)
116 {
117 	variant->ir = ir3_create(variant->compiler, variant);
118 	block = ir3_block_create(variant->ir);
119 	list_addtail(&block->node, &variant->ir->block_list);
120 	ip = 0;
121 	labels = _mesa_hash_table_create(variant, _mesa_hash_string, _mesa_key_string_equal);
122 	ir3_parser_dead_ctx = ralloc_context(NULL);
123 }
124 
parse_type(const char ** type)125 static type_t parse_type(const char **type)
126 {
127 	if (!strncmp("f16", *type, 3)) {
128 		*type += 3;
129 		return TYPE_F16;
130 	} else if (!strncmp("f32", *type, 3)) {
131 		*type += 3;
132 		return TYPE_F32;
133 	} else if (!strncmp("u16", *type, 3)) {
134 		*type += 3;
135 		return TYPE_U16;
136 	} else if (!strncmp("u32", *type, 3)) {
137 		*type += 3;
138 		return TYPE_U32;
139 	} else if (!strncmp("s16", *type, 3)) {
140 		*type += 3;
141 		return TYPE_S16;
142 	} else if (!strncmp("s32", *type, 3)) {
143 		*type += 3;
144 		return TYPE_S32;
145 	} else if (!strncmp("u8", *type, 2)) {
146 		*type += 2;
147 		return TYPE_U8;
148 	} else if (!strncmp("s8", *type, 2)) {
149 		*type += 2;
150 		return TYPE_S8;
151 	} else {
152 		assert(0);  /* shouldn't get here */
153 		return ~0;
154 	}
155 }
156 
parse_type_type(struct ir3_instruction * instr,const char * type_type)157 static struct ir3_instruction * parse_type_type(struct ir3_instruction *instr,
158 		const char *type_type)
159 {
160 	instr->cat1.src_type = parse_type(&type_type);
161 	instr->cat1.dst_type = parse_type(&type_type);
162 	return instr;
163 }
164 
new_src(int num,unsigned flags)165 static struct ir3_register * new_src(int num, unsigned flags)
166 {
167 	struct ir3_register *reg;
168 	flags |= rflags.flags;
169 	if (num & 0x1)
170 		flags |= IR3_REG_HALF;
171 	reg = ir3_src_create(instr, num>>1, flags);
172 	reg->wrmask = MAX2(1, rflags.wrmask);
173 	rflags.flags = rflags.wrmask = 0;
174 	return reg;
175 }
176 
new_dst(int num,unsigned flags)177 static struct ir3_register * new_dst(int num, unsigned flags)
178 {
179 	struct ir3_register *reg;
180 	flags |= rflags.flags;
181 	if (num & 0x1)
182 		flags |= IR3_REG_HALF;
183 	reg = ir3_dst_create(instr, num>>1, flags);
184 	reg->wrmask = MAX2(1, rflags.wrmask);
185 	rflags.flags = rflags.wrmask = 0;
186 	return reg;
187 }
188 
dummy_dst(void)189 static struct ir3_register * dummy_dst(void)
190 {
191 	return new_dst(0, 0);
192 }
193 
fixup_cat5_s2en(void)194 static void fixup_cat5_s2en(void)
195 {
196 	assert(opc_cat(instr->opc) == 5);
197 	if (!(instr->flags & IR3_INSTR_S2EN))
198 		return;
199 	/* For various reasons (ie. mainly to make the .s2en src easier to
200 	 * find, given that various different cat5 tex instructions can have
201 	 * different # of src registers), in ir3 the samp/tex src register
202 	 * is first, rather than last.  So we have to detect this case and
203 	 * fix things up.
204 	 */
205 	struct ir3_register *s2en_src = instr->srcs[instr->srcs_count - 1];
206 
207 	if (instr->flags & IR3_INSTR_B)
208 		assert(!(s2en_src->flags & IR3_REG_HALF));
209 	else
210 		assert(s2en_src->flags & IR3_REG_HALF);
211 
212 	for (int i = 0; i < instr->srcs_count - 1; i++) {
213 		instr->srcs[i+1] = instr->srcs[i];
214 	}
215 	instr->srcs[0] = s2en_src;
216 }
217 
add_const(unsigned reg,unsigned c0,unsigned c1,unsigned c2,unsigned c3)218 static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsigned c3)
219 {
220 	struct ir3_const_state *const_state = ir3_const_state(variant);
221 	assert((reg & 0x7) == 0);
222 	int idx = reg >> (1 + 2); /* low bit is half vs full, next two bits are swiz */
223 	if (idx * 4 + 4 > const_state->immediates_size) {
224 		const_state->immediates = rerzalloc(const_state,
225 				const_state->immediates,
226 				__typeof__(const_state->immediates[0]),
227 				const_state->immediates_size,
228 				idx * 4 + 4);
229 		for (unsigned i = const_state->immediates_size; i < idx * 4; i++)
230 			const_state->immediates[i] = 0xd0d0d0d0;
231 		const_state->immediates_size = const_state->immediates_count = idx * 4 + 4;
232 	}
233 	const_state->immediates[idx * 4 + 0] = c0;
234 	const_state->immediates[idx * 4 + 1] = c1;
235 	const_state->immediates[idx * 4 + 2] = c2;
236 	const_state->immediates[idx * 4 + 3] = c3;
237 }
238 
add_sysval(unsigned reg,unsigned compmask,gl_system_value sysval)239 static void add_sysval(unsigned reg, unsigned compmask, gl_system_value sysval)
240 {
241 	unsigned n = variant->inputs_count++;
242 	variant->inputs[n].regid = reg;
243 	variant->inputs[n].sysval = true;
244 	variant->inputs[n].slot = sysval;
245 	variant->inputs[n].compmask = compmask;
246 	variant->total_in++;
247 }
248 
resolve_labels(void)249 static bool resolve_labels(void)
250 {
251 	int instr_ip = 0;
252 	foreach_instr (instr, &block->instr_list) {
253 		if (opc_cat(instr->opc) == 0 && instr->cat0.target_label) {
254 			struct hash_entry *entry = _mesa_hash_table_search(labels, instr->cat0.target_label);
255 			if (!entry) {
256 				fprintf(stderr, "unknown label %s\n", instr->cat0.target_label);
257 				return false;
258 			}
259 			int target_ip = (uintptr_t)entry->data;
260 			instr->cat0.immed = target_ip - instr_ip;
261 		}
262 		instr_ip++;
263 	}
264 	return true;
265 }
266 
267 #ifdef YYDEBUG
268 int yydebug;
269 #endif
270 
271 extern int yylex(void);
272 void ir3_yyset_lineno(int _line_number);
273 void ir3_yyset_input(FILE *f);
274 
275 int yyparse(void);
276 
yyerror(const char * error)277 static void yyerror(const char *error)
278 {
279 	fprintf(stderr, "error at line %d: %s\n", ir3_yyget_lineno(), error);
280 }
281 
ir3_parse(struct ir3_shader_variant * v,struct ir3_kernel_info * k,FILE * f)282 struct ir3 * ir3_parse(struct ir3_shader_variant *v,
283 		struct ir3_kernel_info *k, FILE *f)
284 {
285 	ir3_yyset_lineno(1);
286 	ir3_yyset_input(f);
287 #ifdef YYDEBUG
288 	yydebug = 1;
289 #endif
290 	info = k;
291 	variant = v;
292 	if (yyparse() || !resolve_labels()) {
293 		ir3_destroy(variant->ir);
294 		variant->ir = NULL;
295 	}
296 	ralloc_free(labels);
297 	ralloc_free(ir3_parser_dead_ctx);
298 	return variant->ir;
299 }
300 %}
301 
302 %union {
303 	int tok;
304 	int num;
305 	uint32_t unum;
306 	uint64_t u64;
307 	double flt;
308 	const char *str;
309 	struct ir3_register *reg;
310 	struct {
311 		int start;
312 		int num;
313 	} range;
314 	type_t type;
315 }
316 
317 %{
318 #if YYDEBUG
print_token(FILE * file,int type,YYSTYPE value)319 static void print_token(FILE *file, int type, YYSTYPE value)
320 {
321 	fprintf(file, "\ntype: %d\n", type);
322 }
323 
324 #define YYPRINT(file, type, value) print_token(file, type, value)
325 #endif
326 %}
327 
328 %token <num> T_INT
329 %token <unum> T_HEX
330 %token <flt> T_FLOAT
331 %token <str> T_IDENTIFIER
332 %token <num> T_REGISTER
333 %token <num> T_CONSTANT
334 
335 /* @ headers (@const/@sampler/@uniform/@varying) */
336 %token <tok> T_A_LOCALSIZE
337 %token <tok> T_A_CONST
338 %token <tok> T_A_BUF
339 %token <tok> T_A_INVOCATIONID
340 %token <tok> T_A_WGID
341 %token <tok> T_A_NUMWG
342 %token <tok> T_A_BRANCHSTACK
343 %token <tok> T_A_IN
344 %token <tok> T_A_OUT
345 %token <tok> T_A_TEX
346 %token <tok> T_A_PVTMEM
347 %token <tok> T_A_EARLYPREAMBLE
348 /* todo, re-add @sampler/@uniform/@varying if needed someday */
349 
350 /* src register flags */
351 %token <tok> T_ABSNEG
352 %token <tok> T_NEG
353 %token <tok> T_ABS
354 %token <tok> T_R
355 %token <tok> T_LAST
356 
357 %token <tok> T_HR
358 %token <tok> T_HC
359 
360 /* dst register flags */
361 %token <tok> T_EVEN
362 %token <tok> T_POS_INFINITY
363 %token <tok> T_NEG_INFINITY
364 %token <tok> T_EI
365 %token <num> T_WRMASK
366 
367 /* Float LUT values accepted as immed: */
368 %token <num> T_FLUT_0_0
369 %token <num> T_FLUT_0_5
370 %token <num> T_FLUT_1_0
371 %token <num> T_FLUT_2_0
372 %token <num> T_FLUT_E
373 %token <num> T_FLUT_PI
374 %token <num> T_FLUT_INV_PI
375 %token <num> T_FLUT_INV_LOG2_E
376 %token <num> T_FLUT_LOG2_E
377 %token <num> T_FLUT_INV_LOG2_10
378 %token <num> T_FLUT_LOG2_10
379 %token <num> T_FLUT_4_0
380 
381 /* instruction flags */
382 %token <tok> T_SY
383 %token <tok> T_SS
384 %token <tok> T_JP
385 %token <tok> T_EQ_FLAG
386 %token <tok> T_SAT
387 %token <num> T_RPT
388 %token <tok> T_UL
389 %token <tok> T_NOP
390 
391 /* category 0: */
392 %token <tok> T_OP_NOP
393 %token <tok> T_OP_BR
394 %token <tok> T_OP_BRAO
395 %token <tok> T_OP_BRAA
396 %token <tok> T_OP_BRAC
397 %token <tok> T_OP_BANY
398 %token <tok> T_OP_BALL
399 %token <tok> T_OP_BRAX
400 %token <tok> T_OP_JUMP
401 %token <tok> T_OP_CALL
402 %token <tok> T_OP_RET
403 %token <tok> T_OP_KILL
404 %token <tok> T_OP_END
405 %token <tok> T_OP_EMIT
406 %token <tok> T_OP_CUT
407 %token <tok> T_OP_CHMASK
408 %token <tok> T_OP_CHSH
409 %token <tok> T_OP_FLOW_REV
410 %token <tok> T_OP_BKT
411 %token <tok> T_OP_STKS
412 %token <tok> T_OP_STKR
413 %token <tok> T_OP_XSET
414 %token <tok> T_OP_XCLR
415 %token <tok> T_OP_GETLAST
416 %token <tok> T_OP_GETONE
417 %token <tok> T_OP_DBG
418 %token <tok> T_OP_SHPS
419 %token <tok> T_OP_SHPE
420 %token <tok> T_OP_PREDT
421 %token <tok> T_OP_PREDF
422 %token <tok> T_OP_PREDE
423 
424 /* category 1: */
425 %token <tok> T_OP_MOVMSK
426 %token <tok> T_OP_MOVA1
427 %token <tok> T_OP_MOVA
428 %token <tok> T_OP_MOV
429 %token <tok> T_OP_COV
430 %token <tok> T_OP_SWZ
431 %token <tok> T_OP_GAT
432 %token <tok> T_OP_SCT
433 
434 /* category 2: */
435 %token <tok> T_OP_ADD_F
436 %token <tok> T_OP_MIN_F
437 %token <tok> T_OP_MAX_F
438 %token <tok> T_OP_MUL_F
439 %token <tok> T_OP_SIGN_F
440 %token <tok> T_OP_CMPS_F
441 %token <tok> T_OP_ABSNEG_F
442 %token <tok> T_OP_CMPV_F
443 %token <tok> T_OP_FLOOR_F
444 %token <tok> T_OP_CEIL_F
445 %token <tok> T_OP_RNDNE_F
446 %token <tok> T_OP_RNDAZ_F
447 %token <tok> T_OP_TRUNC_F
448 %token <tok> T_OP_ADD_U
449 %token <tok> T_OP_ADD_S
450 %token <tok> T_OP_SUB_U
451 %token <tok> T_OP_SUB_S
452 %token <tok> T_OP_CMPS_U
453 %token <tok> T_OP_CMPS_S
454 %token <tok> T_OP_MIN_U
455 %token <tok> T_OP_MIN_S
456 %token <tok> T_OP_MAX_U
457 %token <tok> T_OP_MAX_S
458 %token <tok> T_OP_ABSNEG_S
459 %token <tok> T_OP_AND_B
460 %token <tok> T_OP_OR_B
461 %token <tok> T_OP_NOT_B
462 %token <tok> T_OP_XOR_B
463 %token <tok> T_OP_CMPV_U
464 %token <tok> T_OP_CMPV_S
465 %token <tok> T_OP_MUL_U24
466 %token <tok> T_OP_MUL_S24
467 %token <tok> T_OP_MULL_U
468 %token <tok> T_OP_BFREV_B
469 %token <tok> T_OP_CLZ_S
470 %token <tok> T_OP_CLZ_B
471 %token <tok> T_OP_SHL_B
472 %token <tok> T_OP_SHR_B
473 %token <tok> T_OP_ASHR_B
474 %token <tok> T_OP_BARY_F
475 %token <tok> T_OP_FLAT_B
476 %token <tok> T_OP_MGEN_B
477 %token <tok> T_OP_GETBIT_B
478 %token <tok> T_OP_SETRM
479 %token <tok> T_OP_CBITS_B
480 %token <tok> T_OP_SHB
481 %token <tok> T_OP_MSAD
482 
483 /* category 3: */
484 %token <tok> T_OP_MAD_U16
485 %token <tok> T_OP_MADSH_U16
486 %token <tok> T_OP_MAD_S16
487 %token <tok> T_OP_MADSH_M16
488 %token <tok> T_OP_MAD_U24
489 %token <tok> T_OP_MAD_S24
490 %token <tok> T_OP_MAD_F16
491 %token <tok> T_OP_MAD_F32
492 %token <tok> T_OP_SEL_B16
493 %token <tok> T_OP_SEL_B32
494 %token <tok> T_OP_SEL_S16
495 %token <tok> T_OP_SEL_S32
496 %token <tok> T_OP_SEL_F16
497 %token <tok> T_OP_SEL_F32
498 %token <tok> T_OP_SAD_S16
499 %token <tok> T_OP_SAD_S32
500 %token <tok> T_OP_SHRM
501 %token <tok> T_OP_SHLM
502 %token <tok> T_OP_SHRG
503 %token <tok> T_OP_SHLG
504 %token <tok> T_OP_ANDG
505 %token <tok> T_OP_DP2ACC
506 %token <tok> T_OP_DP4ACC
507 %token <tok> T_OP_WMM
508 %token <tok> T_OP_WMM_ACCU
509 
510 /* category 4: */
511 %token <tok> T_OP_RCP
512 %token <tok> T_OP_RSQ
513 %token <tok> T_OP_LOG2
514 %token <tok> T_OP_EXP2
515 %token <tok> T_OP_SIN
516 %token <tok> T_OP_COS
517 %token <tok> T_OP_SQRT
518 %token <tok> T_OP_HRSQ
519 %token <tok> T_OP_HLOG2
520 %token <tok> T_OP_HEXP2
521 
522 /* category 5: */
523 %token <tok> T_OP_ISAM
524 %token <tok> T_OP_ISAML
525 %token <tok> T_OP_ISAMM
526 %token <tok> T_OP_SAM
527 %token <tok> T_OP_SAMB
528 %token <tok> T_OP_SAML
529 %token <tok> T_OP_SAMGQ
530 %token <tok> T_OP_GETLOD
531 %token <tok> T_OP_CONV
532 %token <tok> T_OP_CONVM
533 %token <tok> T_OP_GETSIZE
534 %token <tok> T_OP_GETBUF
535 %token <tok> T_OP_GETPOS
536 %token <tok> T_OP_GETINFO
537 %token <tok> T_OP_DSX
538 %token <tok> T_OP_DSY
539 %token <tok> T_OP_GATHER4R
540 %token <tok> T_OP_GATHER4G
541 %token <tok> T_OP_GATHER4B
542 %token <tok> T_OP_GATHER4A
543 %token <tok> T_OP_SAMGP0
544 %token <tok> T_OP_SAMGP1
545 %token <tok> T_OP_SAMGP2
546 %token <tok> T_OP_SAMGP3
547 %token <tok> T_OP_DSXPP_1
548 %token <tok> T_OP_DSYPP_1
549 %token <tok> T_OP_RGETPOS
550 %token <tok> T_OP_RGETINFO
551 %token <tok> T_OP_BRCST_A
552 %token <tok> T_OP_QSHUFFLE_BRCST
553 %token <tok> T_OP_QSHUFFLE_H
554 %token <tok> T_OP_QSHUFFLE_V
555 %token <tok> T_OP_QSHUFFLE_DIAG
556 %token <tok> T_OP_TCINV
557 
558 /* category 6: */
559 %token <tok> T_OP_LDG
560 %token <tok> T_OP_LDG_A
561 %token <tok> T_OP_LDG_K
562 %token <tok> T_OP_LDL
563 %token <tok> T_OP_LDP
564 %token <tok> T_OP_STG
565 %token <tok> T_OP_STG_A
566 %token <tok> T_OP_STL
567 %token <tok> T_OP_STP
568 %token <tok> T_OP_LDIB
569 %token <tok> T_OP_G2L
570 %token <tok> T_OP_L2G
571 %token <tok> T_OP_PREFETCH
572 %token <tok> T_OP_LDLW
573 %token <tok> T_OP_STLW
574 %token <tok> T_OP_RESFMT
575 %token <tok> T_OP_RESINFO
576 %token <tok> T_OP_ATOMIC_ADD
577 %token <tok> T_OP_ATOMIC_SUB
578 %token <tok> T_OP_ATOMIC_XCHG
579 %token <tok> T_OP_ATOMIC_INC
580 %token <tok> T_OP_ATOMIC_DEC
581 %token <tok> T_OP_ATOMIC_CMPXCHG
582 %token <tok> T_OP_ATOMIC_MIN
583 %token <tok> T_OP_ATOMIC_MAX
584 %token <tok> T_OP_ATOMIC_AND
585 %token <tok> T_OP_ATOMIC_OR
586 %token <tok> T_OP_ATOMIC_XOR
587 %token <tok> T_OP_RESINFO_B
588 %token <tok> T_OP_LDIB_B
589 %token <tok> T_OP_STIB_B
590 %token <tok> T_OP_ATOMIC_B_ADD
591 %token <tok> T_OP_ATOMIC_B_SUB
592 %token <tok> T_OP_ATOMIC_B_XCHG
593 %token <tok> T_OP_ATOMIC_B_INC
594 %token <tok> T_OP_ATOMIC_B_DEC
595 %token <tok> T_OP_ATOMIC_B_CMPXCHG
596 %token <tok> T_OP_ATOMIC_B_MIN
597 %token <tok> T_OP_ATOMIC_B_MAX
598 %token <tok> T_OP_ATOMIC_B_AND
599 %token <tok> T_OP_ATOMIC_B_OR
600 %token <tok> T_OP_ATOMIC_B_XOR
601 %token <tok> T_OP_ATOMIC_S_ADD
602 %token <tok> T_OP_ATOMIC_S_SUB
603 %token <tok> T_OP_ATOMIC_S_XCHG
604 %token <tok> T_OP_ATOMIC_S_INC
605 %token <tok> T_OP_ATOMIC_S_DEC
606 %token <tok> T_OP_ATOMIC_S_CMPXCHG
607 %token <tok> T_OP_ATOMIC_S_MIN
608 %token <tok> T_OP_ATOMIC_S_MAX
609 %token <tok> T_OP_ATOMIC_S_AND
610 %token <tok> T_OP_ATOMIC_S_OR
611 %token <tok> T_OP_ATOMIC_S_XOR
612 %token <tok> T_OP_ATOMIC_G_ADD
613 %token <tok> T_OP_ATOMIC_G_SUB
614 %token <tok> T_OP_ATOMIC_G_XCHG
615 %token <tok> T_OP_ATOMIC_G_INC
616 %token <tok> T_OP_ATOMIC_G_DEC
617 %token <tok> T_OP_ATOMIC_G_CMPXCHG
618 %token <tok> T_OP_ATOMIC_G_MIN
619 %token <tok> T_OP_ATOMIC_G_MAX
620 %token <tok> T_OP_ATOMIC_G_AND
621 %token <tok> T_OP_ATOMIC_G_OR
622 %token <tok> T_OP_ATOMIC_G_XOR
623 %token <tok> T_OP_LDGB
624 %token <tok> T_OP_STGB
625 %token <tok> T_OP_STIB
626 %token <tok> T_OP_LDC
627 %token <tok> T_OP_LDLV
628 %token <tok> T_OP_GETSPID
629 %token <tok> T_OP_GETWID
630 %token <tok> T_OP_GETFIBERID
631 %token <tok> T_OP_STC
632 %token <tok> T_OP_STSC
633 
634 /* category 7: */
635 %token <tok> T_OP_BAR
636 %token <tok> T_OP_FENCE
637 %token <tok> T_OP_SLEEP
638 %token <tok> T_OP_ICINV
639 %token <tok> T_OP_DCCLN
640 %token <tok> T_OP_DCINV
641 %token <tok> T_OP_DCFLU
642 %token <tok> T_OP_CCINV
643 %token <tok> T_OP_LOCK
644 %token <tok> T_OP_UNLOCK
645 %token <tok> T_OP_ALIAS
646 
647 %token <u64> T_RAW
648 
649 %token <tok> T_OP_PRINT
650 
651 /* type qualifiers: */
652 %token <tok> T_TYPE_F16
653 %token <tok> T_TYPE_F32
654 %token <tok> T_TYPE_U16
655 %token <tok> T_TYPE_U32
656 %token <tok> T_TYPE_S16
657 %token <tok> T_TYPE_S32
658 %token <tok> T_TYPE_U8
659 %token <tok> T_TYPE_S8
660 
661 %token <tok> T_UNTYPED
662 %token <tok> T_TYPED
663 
664 %token <tok> T_MIXED
665 %token <tok> T_UNSIGNED
666 %token <tok> T_LOW
667 %token <tok> T_HIGH
668 
669 %token <tok> T_1D
670 %token <tok> T_2D
671 %token <tok> T_3D
672 %token <tok> T_4D
673 
674 /* condition qualifiers: */
675 %token <tok> T_LT
676 %token <tok> T_LE
677 %token <tok> T_GT
678 %token <tok> T_GE
679 %token <tok> T_EQ
680 %token <tok> T_NE
681 
682 %token <tok> T_S2EN
683 %token <tok> T_SAMP
684 %token <tok> T_TEX
685 %token <tok> T_BASE
686 %token <tok> T_OFFSET
687 %token <tok> T_UNIFORM
688 %token <tok> T_NONUNIFORM
689 %token <tok> T_IMM
690 
691 %token <tok> T_NAN
692 %token <tok> T_INF
693 %token <num> T_A0
694 %token <num> T_A1
695 %token <num> T_P0
696 %token <num> T_W
697 %token <str> T_CAT1_TYPE_TYPE
698 %token <str> T_INSTR_TYPE
699 
700 %token <tok> T_MOD_TEX
701 %token <tok> T_MOD_MEM
702 %token <tok> T_MOD_RT
703 
704 %type <num> integer offset
705 %type <num> flut_immed
706 %type <flt> float
707 %type <reg> src dst const
708 %type <tok> cat1_opc
709 %type <tok> cat2_opc_1src cat2_opc_2src_cnd cat2_opc_2src
710 %type <tok> cat3_opc
711 %type <tok> cat4_opc
712 %type <tok> cat5_opc cat5_samp cat5_tex cat5_type
713 %type <type> type
714 %type <unum> const_val
715 
716 %error-verbose
717 
718 %start shader
719 
720 %%
721 
722 shader:            { new_shader(); } headers instrs
723 
724 headers:
725 |                  header headers
726 
727 header:            localsize_header
728 |                  const_header
729 |                  buf_header
730 |                  invocationid_header
731 |                  wgid_header
732 |                  numwg_header
733 |                  branchstack_header
734 |                  in_header
735 |                  out_header
736 |                  tex_header
737 |                  pvtmem_header
738 |                  earlypreamble_header
739 
740 const_val:         T_FLOAT   { $$ = fui($1); }
741 |                  T_INT     { $$ = $1;      }
742 |                  '-' T_INT { $$ = -$2;     }
743 |                  T_HEX     { $$ = $1;      }
744 
745 localsize_header:  T_A_LOCALSIZE const_val ',' const_val ',' const_val {
746                        variant->local_size[0] = $2;
747                        variant->local_size[1] = $4;
748                        variant->local_size[2] = $6;
749 }
750 
751 const_header:      T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' const_val ',' const_val {
752                        add_const($3, $5, $7, $9, $11);
753 }
754 
755 buf_header_addr_reg:
756                    '(' T_CONSTANT ')' {
757                        assert(($2 & 0x1) == 0);  /* half-reg not allowed */
758                        unsigned reg = $2 >> 1;
759 
760                        info->buf_addr_regs[info->num_bufs - 1] = reg;
761                        /* reserve space in immediates for the actual value to be plugged in later: */
762                        add_const($2, 0, 0, 0, 0);
763 }
764 |
765 
766 buf_header:        T_A_BUF const_val {
767                        int idx = info->num_bufs++;
768                        assert(idx < MAX_BUFS);
769                        info->buf_sizes[idx] = $2;
770 } buf_header_addr_reg
771 
772 invocationid_header: T_A_INVOCATIONID '(' T_REGISTER ')' {
773                        assert(($3 & 0x1) == 0);  /* half-reg not allowed */
774                        unsigned reg = $3 >> 1;
775                        add_sysval(reg, 0x7, SYSTEM_VALUE_LOCAL_INVOCATION_ID);
776 }
777 
778 wgid_header:       T_A_WGID '(' T_REGISTER ')' {
779                        assert(($3 & 0x1) == 0);  /* half-reg not allowed */
780                        unsigned reg = $3 >> 1;
781                        assert(variant->compiler->gen >= 5);
782                        assert(reg >= regid(48, 0)); /* must be a high reg */
783                        add_sysval(reg, 0x7, SYSTEM_VALUE_WORKGROUP_ID);
784 }
785 |                  T_A_WGID '(' T_CONSTANT ')' {
786                        assert(($3 & 0x1) == 0);  /* half-reg not allowed */
787                        unsigned reg = $3 >> 1;
788                        assert(variant->compiler->gen < 5);
789                        info->wgid = reg;
790 }
791 
792 numwg_header:      T_A_NUMWG '(' T_CONSTANT ')' {
793                        assert(($3 & 0x1) == 0);  /* half-reg not allowed */
794                        unsigned reg = $3 >> 1;
795                        info->numwg = reg;
796                        /* reserve space in immediates for the actual value to be plugged in later: */
797                        if (variant->compiler->gen >= 5)
798                           add_const($3, 0, 0, 0, 0);
799 }
800 
801 branchstack_header: T_A_BRANCHSTACK const_val { variant->branchstack = $2; }
802 
803 pvtmem_header: T_A_PVTMEM const_val { variant->pvtmem_size = $2; }
804 
805 earlypreamble_header: T_A_EARLYPREAMBLE { info->early_preamble = 1; }
806 
807 /* Stubs for now */
808 in_header:         T_A_IN '(' T_REGISTER ')' T_IDENTIFIER '(' T_IDENTIFIER '=' integer ')' { }
809 
810 out_header:        T_A_OUT '(' T_REGISTER ')' T_IDENTIFIER '(' T_IDENTIFIER '=' integer ')' { }
811 
812 tex_header:        T_A_TEX '(' T_REGISTER ')'
813                        T_IDENTIFIER '=' integer ',' /* src */
814                        T_IDENTIFIER '=' integer ',' /* samp */
815                        T_IDENTIFIER '=' integer ',' /* tex */
816                        T_IDENTIFIER '=' integer ',' /* wrmask */
817                        T_IDENTIFIER '=' integer     /* cmd */ { }
818 
819 iflag:             T_SY   { iflags.flags |= IR3_INSTR_SY; }
820 |                  T_SS   { iflags.flags |= IR3_INSTR_SS; }
821 |                  T_JP   { iflags.flags |= IR3_INSTR_JP; }
822 |                  T_EQ_FLAG { iflags.flags |= IR3_INSTR_EQ; }
823 |                  T_SAT  { iflags.flags |= IR3_INSTR_SAT; }
824 |                  T_RPT  { iflags.repeat = $1; }
825 |                  T_UL   { iflags.flags |= IR3_INSTR_UL; }
826 |                  T_NOP  { iflags.nop = $1; }
827 
828 iflags:
829 |                  iflag iflags
830 
831 instrs:            instrs instr
832 |                  instr
833 
834 instr:             iflags cat0_instr
835 |                  iflags cat1_instr
836 |                  iflags cat2_instr
837 |                  iflags cat3_instr
838 |                  iflags cat4_instr
839 |                  iflags cat5_instr { fixup_cat5_s2en(); }
840 |                  iflags cat6_instr
841 |                  iflags cat7_instr
842 |                  raw_instr
843 |                  meta_print
844 |                  label
845 
846 label:             T_IDENTIFIER ':' { new_label($1); }
847 
848 cat0_src1:         '!' T_P0        { instr->cat0.inv1 = true; instr->cat0.comp1 = $2 >> 1; }
849 |                  T_P0            { instr->cat0.comp1 = $1 >> 1; }
850 
851 cat0_src2:         '!' T_P0        { instr->cat0.inv2 = true; instr->cat0.comp2 = $2 >> 1; }
852 |                  T_P0            { instr->cat0.comp2 = $1 >> 1; }
853 
854 cat0_immed:        '#' integer     { instr->cat0.immed = $2; }
855 |                  '#' T_IDENTIFIER { ralloc_steal(instr, (void *)$2); instr->cat0.target_label = $2; }
856 
857 cat0_instr:        T_OP_NOP        { new_instr(OPC_NOP); }
858 |                  T_OP_BR         { new_instr(OPC_B)->cat0.brtype = BRANCH_PLAIN; } cat0_src1 ',' cat0_immed
859 |                  T_OP_BRAO       { new_instr(OPC_B)->cat0.brtype = BRANCH_OR;    } cat0_src1 ',' cat0_src2 ',' cat0_immed
860 |                  T_OP_BRAA       { new_instr(OPC_B)->cat0.brtype = BRANCH_AND;    } cat0_src1 ',' cat0_src2 ',' cat0_immed
861 |                  T_OP_BRAC '.' integer { new_instr(OPC_B)->cat0.brtype = BRANCH_CONST; instr->cat0.idx = $3; } cat0_immed
862 |                  T_OP_BANY       { new_instr(OPC_B)->cat0.brtype = BRANCH_ANY; } cat0_src1 ',' cat0_immed
863 |                  T_OP_BALL       { new_instr(OPC_B)->cat0.brtype = BRANCH_ALL; } cat0_src1 ',' cat0_immed
864 |                  T_OP_BRAX       { new_instr(OPC_B)->cat0.brtype = BRANCH_X; } cat0_immed
865 |                  T_OP_JUMP       { new_instr(OPC_JUMP); }  cat0_immed
866 |                  T_OP_CALL       { new_instr(OPC_CALL); }  cat0_immed
867 |                  T_OP_RET        { new_instr(OPC_RET); }
868 |                  T_OP_KILL       { new_instr(OPC_KILL); }  cat0_src1
869 |                  T_OP_END        { new_instr(OPC_END); }
870 |                  T_OP_EMIT       { new_instr(OPC_EMIT); }
871 |                  T_OP_CUT        { new_instr(OPC_CUT); }
872 |                  T_OP_CHMASK     { new_instr(OPC_CHMASK); }
873 |                  T_OP_CHSH       { new_instr(OPC_CHSH); }
874 |                  T_OP_FLOW_REV   { new_instr(OPC_FLOW_REV); }
875 |                  T_OP_BKT        { new_instr(OPC_BKT); }      cat0_immed
876 |                  T_OP_STKS       { new_instr(OPC_STKS); }
877 |                  T_OP_STKR       { new_instr(OPC_STKR); }
878 |                  T_OP_XSET       { new_instr(OPC_XSET); }
879 |                  T_OP_XCLR       { new_instr(OPC_XCLR); }
880 |                  T_OP_GETONE     { new_instr(OPC_GETONE); }   cat0_immed
881 |                  T_OP_DBG        { new_instr(OPC_DBG); }
882 |                  T_OP_SHPS       { new_instr(OPC_SHPS); }     cat0_immed
883 |                  T_OP_SHPE       { new_instr(OPC_SHPE); }
884 |                  T_OP_PREDT      { new_instr(OPC_PREDT); }    cat0_src1
885 |                  T_OP_PREDF      { new_instr(OPC_PREDF); }    cat0_src1
886 |                  T_OP_PREDE      { new_instr(OPC_PREDE); }
887 |                  T_OP_GETLAST '.' T_W { new_instr(OPC_GETLAST); }   cat0_immed
888 
889 cat1_opc:          T_OP_MOV '.' T_CAT1_TYPE_TYPE {
890                        parse_type_type(new_instr(OPC_MOV), $3);
891 }
892 |                  T_OP_COV '.' T_CAT1_TYPE_TYPE {
893                        parse_type_type(new_instr(OPC_MOV), $3);
894 }
895 
896 cat1_src:          src_reg_or_const_or_rel
897 |                  immediate_cat1
898 
899 cat1_movmsk:       T_OP_MOVMSK '.' T_W {
900                        new_instr(OPC_MOVMSK);
901                        instr->cat1.src_type = TYPE_U32;
902                        instr->cat1.dst_type = TYPE_U32;
903                    } dst_reg {
904                        if (($3 % 32) != 0)
905                           yyerror("w# must be multiple of 32");
906                        if ($3 < 32)
907                           yyerror("w# must be at least 32");
908 
909                        int num = $3 / 32;
910 
911                        instr->repeat = num - 1;
912                        instr->dsts[0]->wrmask = (1 << num) - 1;
913                    }
914 
915 cat1_mova1:        T_OP_MOVA1 T_A1 ',' {
916                        new_instr(OPC_MOV);
917                        instr->cat1.src_type = TYPE_U16;
918                        instr->cat1.dst_type = TYPE_U16;
919                        new_dst((61 << 3) + 2, IR3_REG_HALF);
920                    } cat1_src
921 
922 cat1_mova:         T_OP_MOVA T_A0 ',' {
923                        new_instr(OPC_MOV);
924                        instr->cat1.src_type = TYPE_S16;
925                        instr->cat1.dst_type = TYPE_S16;
926                        new_dst((61 << 3), IR3_REG_HALF);
927                    } cat1_src
928 
929 cat1_swz:          T_OP_SWZ '.' T_CAT1_TYPE_TYPE { parse_type_type(new_instr(OPC_SWZ), $3); } dst_reg ',' dst_reg ',' src_reg ',' src_reg
930 
931 cat1_gat:          T_OP_GAT '.' T_CAT1_TYPE_TYPE { parse_type_type(new_instr(OPC_GAT), $3); } dst_reg ',' src_reg ',' src_reg ',' src_reg ',' src_reg
932 
933 cat1_sct:          T_OP_SCT '.' T_CAT1_TYPE_TYPE { parse_type_type(new_instr(OPC_SCT), $3); } dst_reg ',' dst_reg ',' dst_reg ',' dst_reg ',' src_reg
934 
935                    /* NOTE: cat1 can also *write* to relative gpr */
936 cat1_instr:        cat1_movmsk
937 |                  cat1_mova1
938 |                  cat1_mova
939 |                  cat1_swz
940 |                  cat1_gat
941 |                  cat1_sct
942 |                  cat1_opc dst_reg ',' cat1_src
943 |                  cat1_opc relative_gpr_dst ',' cat1_src
944 
945 cat2_opc_1src:     T_OP_ABSNEG_F  { new_instr(OPC_ABSNEG_F); }
946 |                  T_OP_ABSNEG_S  { new_instr(OPC_ABSNEG_S); }
947 |                  T_OP_CLZ_B     { new_instr(OPC_CLZ_B); }
948 |                  T_OP_CLZ_S     { new_instr(OPC_CLZ_S); }
949 |                  T_OP_SIGN_F    { new_instr(OPC_SIGN_F); }
950 |                  T_OP_FLOOR_F   { new_instr(OPC_FLOOR_F); }
951 |                  T_OP_CEIL_F    { new_instr(OPC_CEIL_F); }
952 |                  T_OP_RNDNE_F   { new_instr(OPC_RNDNE_F); }
953 |                  T_OP_RNDAZ_F   { new_instr(OPC_RNDAZ_F); }
954 |                  T_OP_TRUNC_F   { new_instr(OPC_TRUNC_F); }
955 |                  T_OP_NOT_B     { new_instr(OPC_NOT_B); }
956 |                  T_OP_BFREV_B   { new_instr(OPC_BFREV_B); }
957 |                  T_OP_SETRM     { new_instr(OPC_SETRM); }
958 |                  T_OP_CBITS_B   { new_instr(OPC_CBITS_B); }
959 
960 cat2_opc_2src_cnd: T_OP_CMPS_F    { new_instr(OPC_CMPS_F); }
961 |                  T_OP_CMPS_U    { new_instr(OPC_CMPS_U); }
962 |                  T_OP_CMPS_S    { new_instr(OPC_CMPS_S); }
963 |                  T_OP_CMPV_F    { new_instr(OPC_CMPV_F); }
964 |                  T_OP_CMPV_U    { new_instr(OPC_CMPV_U); }
965 |                  T_OP_CMPV_S    { new_instr(OPC_CMPV_S); }
966 
967 cat2_opc_2src:     T_OP_ADD_F     { new_instr(OPC_ADD_F); }
968 |                  T_OP_MIN_F     { new_instr(OPC_MIN_F); }
969 |                  T_OP_MAX_F     { new_instr(OPC_MAX_F); }
970 |                  T_OP_MUL_F     { new_instr(OPC_MUL_F); }
971 |                  T_OP_ADD_U     { new_instr(OPC_ADD_U); }
972 |                  T_OP_ADD_S     { new_instr(OPC_ADD_S); }
973 |                  T_OP_SUB_U     { new_instr(OPC_SUB_U); }
974 |                  T_OP_SUB_S     { new_instr(OPC_SUB_S); }
975 |                  T_OP_MIN_U     { new_instr(OPC_MIN_U); }
976 |                  T_OP_MIN_S     { new_instr(OPC_MIN_S); }
977 |                  T_OP_MAX_U     { new_instr(OPC_MAX_U); }
978 |                  T_OP_MAX_S     { new_instr(OPC_MAX_S); }
979 |                  T_OP_AND_B     { new_instr(OPC_AND_B); }
980 |                  T_OP_OR_B      { new_instr(OPC_OR_B); }
981 |                  T_OP_XOR_B     { new_instr(OPC_XOR_B); }
982 |                  T_OP_MUL_U24   { new_instr(OPC_MUL_U24); }
983 |                  T_OP_MUL_S24   { new_instr(OPC_MUL_S24); }
984 |                  T_OP_MULL_U    { new_instr(OPC_MULL_U); }
985 |                  T_OP_SHL_B     { new_instr(OPC_SHL_B); }
986 |                  T_OP_SHR_B     { new_instr(OPC_SHR_B); }
987 |                  T_OP_ASHR_B    { new_instr(OPC_ASHR_B); }
988 |                  T_OP_BARY_F    { new_instr(OPC_BARY_F); }
989 |                  T_OP_FLAT_B    { new_instr(OPC_FLAT_B); }
990 |                  T_OP_MGEN_B    { new_instr(OPC_MGEN_B); }
991 |                  T_OP_GETBIT_B  { new_instr(OPC_GETBIT_B); }
992 |                  T_OP_SHB       { new_instr(OPC_SHB); }
993 |                  T_OP_MSAD      { new_instr(OPC_MSAD); }
994 
995 cond:              T_LT           { instr->cat2.condition = IR3_COND_LT; }
996 |                  T_LE           { instr->cat2.condition = IR3_COND_LE; }
997 |                  T_GT           { instr->cat2.condition = IR3_COND_GT; }
998 |                  T_GE           { instr->cat2.condition = IR3_COND_GE; }
999 |                  T_EQ           { instr->cat2.condition = IR3_COND_EQ; }
1000 |                  T_NE           { instr->cat2.condition = IR3_COND_NE; }
1001 
1002 cat2_instr:        cat2_opc_1src dst_reg ',' src_reg_or_const_or_rel_or_imm
1003 |                  cat2_opc_2src_cnd '.' cond dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
1004 |                  cat2_opc_2src dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
1005 
1006 cat3_dp_signedness:'.' T_MIXED   { instr->cat3.signedness = IR3_SRC_MIXED; }
1007 |                  '.' T_UNSIGNED{ instr->cat3.signedness = IR3_SRC_UNSIGNED; }
1008 
1009 cat3_dp_pack:      '.' T_LOW     { instr->cat3.packed = IR3_SRC_PACKED_LOW; }
1010 |                  '.' T_HIGH    { instr->cat3.packed = IR3_SRC_PACKED_HIGH; }
1011 
1012 cat3_opc:          T_OP_MAD_U16   { new_instr(OPC_MAD_U16); }
1013 |                  T_OP_MADSH_U16 { new_instr(OPC_MADSH_U16); }
1014 |                  T_OP_MAD_S16   { new_instr(OPC_MAD_S16); }
1015 |                  T_OP_MADSH_M16 { new_instr(OPC_MADSH_M16); }
1016 |                  T_OP_MAD_U24   { new_instr(OPC_MAD_U24); }
1017 |                  T_OP_MAD_S24   { new_instr(OPC_MAD_S24); }
1018 |                  T_OP_MAD_F16   { new_instr(OPC_MAD_F16); }
1019 |                  T_OP_MAD_F32   { new_instr(OPC_MAD_F32); }
1020 |                  T_OP_SEL_B16   { new_instr(OPC_SEL_B16); }
1021 |                  T_OP_SEL_B32   { new_instr(OPC_SEL_B32); }
1022 |                  T_OP_SEL_S16   { new_instr(OPC_SEL_S16); }
1023 |                  T_OP_SEL_S32   { new_instr(OPC_SEL_S32); }
1024 |                  T_OP_SEL_F16   { new_instr(OPC_SEL_F16); }
1025 |                  T_OP_SEL_F32   { new_instr(OPC_SEL_F32); }
1026 |                  T_OP_SAD_S16   { new_instr(OPC_SAD_S16); }
1027 |                  T_OP_SAD_S32   { new_instr(OPC_SAD_S32); }
1028 
1029 cat3_imm_reg_opc:  T_OP_SHRM      { new_instr(OPC_SHRM); }
1030 |                  T_OP_SHLM      { new_instr(OPC_SHLM); }
1031 |                  T_OP_SHRG      { new_instr(OPC_SHRG); }
1032 |                  T_OP_SHLG      { new_instr(OPC_SHLG); }
1033 |                  T_OP_ANDG      { new_instr(OPC_ANDG); }
1034 
1035 cat3_wmm:          T_OP_WMM       { new_instr(OPC_WMM); }
1036 |                  T_OP_WMM_ACCU  { new_instr(OPC_WMM_ACCU); }
1037 
1038 cat3_dp:           T_OP_DP2ACC    { new_instr(OPC_DP2ACC); }
1039 |                  T_OP_DP4ACC    { new_instr(OPC_DP4ACC); }
1040 
1041 cat3_instr:        cat3_opc dst_reg ',' src_reg_or_const_or_rel ',' src_reg_or_const ',' src_reg_or_const_or_rel
1042 |                  cat3_imm_reg_opc dst_reg ',' src_reg_or_rel_or_imm ',' src_reg_or_const ',' src_reg_or_rel_or_imm
1043 |                  cat3_wmm         dst_reg ',' src_reg_gpr ',' src_reg ',' immediate
1044 |                  cat3_dp cat3_dp_signedness cat3_dp_pack dst_reg ',' src_reg_or_rel_or_imm ',' src_reg_or_const ',' src_reg_or_rel_or_imm
1045 
1046 cat4_opc:          T_OP_RCP       { new_instr(OPC_RCP); }
1047 |                  T_OP_RSQ       { new_instr(OPC_RSQ); }
1048 |                  T_OP_LOG2      { new_instr(OPC_LOG2); }
1049 |                  T_OP_EXP2      { new_instr(OPC_EXP2); }
1050 |                  T_OP_SIN       { new_instr(OPC_SIN); }
1051 |                  T_OP_COS       { new_instr(OPC_COS); }
1052 |                  T_OP_SQRT      { new_instr(OPC_SQRT); }
1053 |                  T_OP_HRSQ      { new_instr(OPC_HRSQ); }
1054 |                  T_OP_HLOG2     { new_instr(OPC_HLOG2); }
1055 |                  T_OP_HEXP2     { new_instr(OPC_HEXP2); }
1056 
1057 cat4_instr:        cat4_opc dst_reg ',' src_reg_or_const_or_rel_or_imm
1058 
1059 cat5_opc_dsxypp:   T_OP_DSXPP_1   { new_instr(OPC_DSXPP_1)->cat5.type = TYPE_F32; }
1060 |                  T_OP_DSYPP_1   { new_instr(OPC_DSYPP_1)->cat5.type = TYPE_F32; }
1061 
1062 cat5_opc:          T_OP_ISAM      { new_instr(OPC_ISAM); }
1063 |                  T_OP_ISAML     { new_instr(OPC_ISAML); }
1064 |                  T_OP_ISAMM     { new_instr(OPC_ISAMM); }
1065 |                  T_OP_SAM       { new_instr(OPC_SAM); }
1066 |                  T_OP_SAMB      { new_instr(OPC_SAMB); }
1067 |                  T_OP_SAML      { new_instr(OPC_SAML); }
1068 |                  T_OP_SAMGQ     { new_instr(OPC_SAMGQ); }
1069 |                  T_OP_GETLOD    { new_instr(OPC_GETLOD); }
1070 |                  T_OP_CONV      { new_instr(OPC_CONV); }
1071 |                  T_OP_CONVM     { new_instr(OPC_CONVM); }
1072 |                  T_OP_GETSIZE   { new_instr(OPC_GETSIZE); }
1073 |                  T_OP_GETBUF    { new_instr(OPC_GETBUF); }
1074 |                  T_OP_GETPOS    { new_instr(OPC_GETPOS); }
1075 |                  T_OP_GETINFO   { new_instr(OPC_GETINFO); }
1076 |                  T_OP_DSX       { new_instr(OPC_DSX); }
1077 |                  T_OP_DSY       { new_instr(OPC_DSY); }
1078 |                  T_OP_GATHER4R  { new_instr(OPC_GATHER4R); }
1079 |                  T_OP_GATHER4G  { new_instr(OPC_GATHER4G); }
1080 |                  T_OP_GATHER4B  { new_instr(OPC_GATHER4B); }
1081 |                  T_OP_GATHER4A  { new_instr(OPC_GATHER4A); }
1082 |                  T_OP_SAMGP0    { new_instr(OPC_SAMGP0); }
1083 |                  T_OP_SAMGP1    { new_instr(OPC_SAMGP1); }
1084 |                  T_OP_SAMGP2    { new_instr(OPC_SAMGP2); }
1085 |                  T_OP_SAMGP3    { new_instr(OPC_SAMGP3); }
1086 |                  T_OP_RGETPOS   { new_instr(OPC_RGETPOS); }
1087 |                  T_OP_RGETINFO  { new_instr(OPC_RGETINFO); }
1088 |                  T_OP_BRCST_A   { new_instr(OPC_BRCST_ACTIVE); }
1089 |                  T_OP_QSHUFFLE_BRCST { new_instr(OPC_QUAD_SHUFFLE_BRCST); }
1090 |                  T_OP_QSHUFFLE_H     { new_instr(OPC_QUAD_SHUFFLE_HORIZ); }
1091 |                  T_OP_QSHUFFLE_V     { new_instr(OPC_QUAD_SHUFFLE_VERT); }
1092 |                  T_OP_QSHUFFLE_DIAG  { new_instr(OPC_QUAD_SHUFFLE_DIAG); }
1093 
1094 cat5_flag:         '.' T_3D       { instr->flags |= IR3_INSTR_3D; }
1095 |                  '.' 'a'        { instr->flags |= IR3_INSTR_A; }
1096 |                  '.' 'o'        { instr->flags |= IR3_INSTR_O; }
1097 |                  '.' 'p'        { instr->flags |= IR3_INSTR_P; }
1098 |                  '.' 's'        { instr->flags |= IR3_INSTR_S; }
1099 |                  '.' T_S2EN     { instr->flags |= IR3_INSTR_S2EN; }
1100 |                  '.' T_UNIFORM  { }
1101 |                  '.' T_NONUNIFORM  { instr->flags |= IR3_INSTR_NONUNIF; }
1102 |                  '.' T_BASE     { instr->flags |= IR3_INSTR_B; instr->cat5.tex_base = $2; }
1103 |                  '.' T_W        { instr->cat5.cluster_size = $2; }
1104 cat5_flags:
1105 |                  cat5_flag cat5_flags
1106 
1107 cat5_samp:         T_SAMP         { instr->cat5.samp = $1; }
1108 cat5_tex:          T_TEX          { instr->cat5.tex = $1; }
1109 cat5_type:         '(' type ')'   { instr->cat5.type = $2; }
1110 cat5_a1:           src_reg        { instr->flags |= IR3_INSTR_A1EN; }
1111 
1112 cat5_instr:        cat5_opc_dsxypp cat5_flags dst_reg ',' src_reg
1113 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' src_reg
1114 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp ',' cat5_tex
1115 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp ',' cat5_a1
1116 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_tex ',' cat5_a1
1117 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp
1118 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_tex
1119 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg
1120 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp ',' cat5_tex
1121 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp ',' cat5_a1
1122 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_tex ',' cat5_a1
1123 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp
1124 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_tex
1125 |                  cat5_opc cat5_flags cat5_type dst_reg ',' src_reg
1126 |                  cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp ',' cat5_tex
1127 |                  cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp
1128 |                  cat5_opc cat5_flags cat5_type dst_reg ',' cat5_tex
1129 |                  cat5_opc cat5_flags cat5_type dst_reg
1130 |                  T_OP_TCINV { new_instr(OPC_TCINV); }
1131 
1132 cat6_typed:        '.' T_UNTYPED  { instr->cat6.typed = 0; }
1133 |                  '.' T_TYPED    { instr->cat6.typed = 1; }
1134 
1135 cat6_dim:          '.' T_1D  { instr->cat6.d = 1; }
1136 |                  '.' T_2D  { instr->cat6.d = 2; }
1137 |                  '.' T_3D  { instr->cat6.d = 3; }
1138 |                  '.' T_4D  { instr->cat6.d = 4; }
1139 
1140 cat6_type:         '.' type  { instr->cat6.type = $2; }
1141 cat6_imm_offset:   offset    { new_src(0, IR3_REG_IMMED)->iim_val = $1; }
1142 cat6_offset:       cat6_imm_offset
1143 |                  '+' src
1144 cat6_dst_offset:   offset    { instr->cat6.dst_offset = $1; }
1145 |                  '+' src
1146 
1147 cat6_immed:        integer   { instr->cat6.iim_val = $1; }
1148 
1149 cat6_a6xx_global_address_pt3:
1150                    '<' '<' integer offset '<' '<' integer {
1151                         assert($7 == 2);
1152                         new_src(0, IR3_REG_IMMED)->uim_val = $3 - 2;
1153                         new_src(0, IR3_REG_IMMED)->uim_val = $4;
1154                    }
1155 |                  '+' cat6_reg_or_immed {
1156                         // Dummy src to smooth the difference between a6xx and a7xx
1157                         new_src(0, IR3_REG_IMMED)->uim_val = 0;
1158                    }
1159 
1160 cat6_a6xx_global_address_pt2:
1161                    '(' src offset ')' '<' '<' integer {
1162                         assert($7 == 2);
1163                         new_src(0, IR3_REG_IMMED)->uim_val = 0;
1164                         new_src(0, IR3_REG_IMMED)->uim_val = $3;
1165                    }
1166 
1167 |                  src cat6_a6xx_global_address_pt3
1168 
1169 cat6_a6xx_global_address:
1170                    src_reg_or_const '+' cat6_a6xx_global_address_pt2
1171 
1172 cat6_load:         T_OP_LDG   { new_instr(OPC_LDG); }   cat6_type dst_reg ',' 'g' '[' src cat6_offset ']' ',' immediate
1173 |                  T_OP_LDG_A { new_instr(OPC_LDG_A); } cat6_type dst_reg ',' 'g' '[' cat6_a6xx_global_address ']' ',' immediate
1174 |                  T_OP_LDG_K { new_instr(OPC_LDG_K); } cat6_type 'c' '[' const_dst ']' ',' 'g' '[' src cat6_offset ']' ',' immediate
1175 |                  T_OP_LDP   { new_instr(OPC_LDP); }   cat6_type dst_reg ',' 'p' '[' src cat6_offset ']' ',' immediate
1176 |                  T_OP_LDL   { new_instr(OPC_LDL); }   cat6_type dst_reg ',' 'l' '[' src cat6_offset ']' ',' immediate
1177 |                  T_OP_LDLW  { new_instr(OPC_LDLW); }  cat6_type dst_reg ',' 'l' '[' src cat6_offset ']' ',' immediate
1178 |                  T_OP_LDLV  { new_instr(OPC_LDLV); }  cat6_type dst_reg ',' 'l' '[' integer ']' {
1179                        new_src(0, IR3_REG_IMMED)->iim_val = $8;
1180                    } ',' immediate
1181 
1182 cat6_store:        T_OP_STG   { new_instr(OPC_STG); dummy_dst(); }   cat6_type 'g' '[' src cat6_imm_offset ']' ',' src ',' immediate
1183 |                  T_OP_STG_A { new_instr(OPC_STG_A); dummy_dst(); } cat6_type 'g' '[' cat6_a6xx_global_address ']' ',' src ',' immediate
1184 |                  T_OP_STP  { new_instr(OPC_STP); dummy_dst(); }  cat6_type 'p' '[' src cat6_dst_offset ']' ',' src ',' immediate
1185 |                  T_OP_STL  { new_instr(OPC_STL); dummy_dst(); }  cat6_type 'l' '[' src cat6_dst_offset ']' ',' src ',' immediate
1186 |                  T_OP_STLW { new_instr(OPC_STLW); dummy_dst(); } cat6_type 'l' '[' src cat6_dst_offset ']' ',' src ',' immediate
1187 
1188 cat6_loadib:       T_OP_LDIB { new_instr(OPC_LDIB); } cat6_typed cat6_dim cat6_type '.' cat6_immed dst_reg ',' 'g' '[' immediate ']' ',' src ',' src
1189 cat6_storeib:      T_OP_STIB { new_instr(OPC_STIB); dummy_dst(); } cat6_typed cat6_dim cat6_type '.' cat6_immed'g' '[' immediate ']' ',' src ',' src ',' src
1190 
1191 cat6_prefetch:     T_OP_PREFETCH { new_instr(OPC_PREFETCH); new_dst(0,0); /* dummy dst */ } 'g' '[' src cat6_offset ']' ',' cat6_immed
1192 
1193 cat6_atomic_opc:   T_OP_ATOMIC_ADD     { new_instr(OPC_ATOMIC_ADD); }
1194 |                  T_OP_ATOMIC_SUB     { new_instr(OPC_ATOMIC_SUB); }
1195 |                  T_OP_ATOMIC_XCHG    { new_instr(OPC_ATOMIC_XCHG); }
1196 |                  T_OP_ATOMIC_INC     { new_instr(OPC_ATOMIC_INC); }
1197 |                  T_OP_ATOMIC_DEC     { new_instr(OPC_ATOMIC_DEC); }
1198 |                  T_OP_ATOMIC_CMPXCHG { new_instr(OPC_ATOMIC_CMPXCHG); }
1199 |                  T_OP_ATOMIC_MIN     { new_instr(OPC_ATOMIC_MIN); }
1200 |                  T_OP_ATOMIC_MAX     { new_instr(OPC_ATOMIC_MAX); }
1201 |                  T_OP_ATOMIC_AND     { new_instr(OPC_ATOMIC_AND); }
1202 |                  T_OP_ATOMIC_OR      { new_instr(OPC_ATOMIC_OR); }
1203 |                  T_OP_ATOMIC_XOR     { new_instr(OPC_ATOMIC_XOR); }
1204 
1205 cat6_a3xx_atomic_opc:   T_OP_ATOMIC_S_ADD     { new_instr(OPC_ATOMIC_S_ADD); }
1206 |                       T_OP_ATOMIC_S_SUB     { new_instr(OPC_ATOMIC_S_SUB); }
1207 |                       T_OP_ATOMIC_S_XCHG    { new_instr(OPC_ATOMIC_S_XCHG); }
1208 |                       T_OP_ATOMIC_S_INC     { new_instr(OPC_ATOMIC_S_INC); }
1209 |                       T_OP_ATOMIC_S_DEC     { new_instr(OPC_ATOMIC_S_DEC); }
1210 |                       T_OP_ATOMIC_S_CMPXCHG { new_instr(OPC_ATOMIC_S_CMPXCHG); }
1211 |                       T_OP_ATOMIC_S_MIN     { new_instr(OPC_ATOMIC_S_MIN); }
1212 |                       T_OP_ATOMIC_S_MAX     { new_instr(OPC_ATOMIC_S_MAX); }
1213 |                       T_OP_ATOMIC_S_AND     { new_instr(OPC_ATOMIC_S_AND); }
1214 |                       T_OP_ATOMIC_S_OR      { new_instr(OPC_ATOMIC_S_OR); }
1215 |                       T_OP_ATOMIC_S_XOR     { new_instr(OPC_ATOMIC_S_XOR); }
1216 
1217 cat6_a6xx_atomic_opc:   T_OP_ATOMIC_G_ADD     { new_instr(OPC_ATOMIC_G_ADD); }
1218 |                       T_OP_ATOMIC_G_SUB     { new_instr(OPC_ATOMIC_G_SUB); }
1219 |                       T_OP_ATOMIC_G_XCHG    { new_instr(OPC_ATOMIC_G_XCHG); }
1220 |                       T_OP_ATOMIC_G_INC     { new_instr(OPC_ATOMIC_G_INC); }
1221 |                       T_OP_ATOMIC_G_DEC     { new_instr(OPC_ATOMIC_G_DEC); }
1222 |                       T_OP_ATOMIC_G_CMPXCHG { new_instr(OPC_ATOMIC_G_CMPXCHG); }
1223 |                       T_OP_ATOMIC_G_MIN     { new_instr(OPC_ATOMIC_G_MIN); }
1224 |                       T_OP_ATOMIC_G_MAX     { new_instr(OPC_ATOMIC_G_MAX); }
1225 |                       T_OP_ATOMIC_G_AND     { new_instr(OPC_ATOMIC_G_AND); }
1226 |                       T_OP_ATOMIC_G_OR      { new_instr(OPC_ATOMIC_G_OR); }
1227 |                       T_OP_ATOMIC_G_XOR     { new_instr(OPC_ATOMIC_G_XOR); }
1228 
1229 cat6_a3xx_atomic_s: cat6_a3xx_atomic_opc cat6_typed cat6_dim cat6_type '.' cat6_immed '.' 'g' dst_reg ',' 'g' '[' cat6_reg_or_immed ']' ',' src ',' src ',' src
1230 
1231 cat6_a6xx_atomic_g: cat6_a6xx_atomic_opc cat6_typed cat6_dim cat6_type '.' cat6_immed '.' 'g' dst_reg ',' src ',' src
1232 
1233 cat6_atomic_l:     cat6_atomic_opc cat6_typed cat6_dim cat6_type '.' cat6_immed '.' 'l' dst_reg ',' 'l' '[' cat6_reg_or_immed ']' ',' src
1234 
1235 cat6_atomic:       cat6_atomic_l
1236 |                  cat6_a3xx_atomic_s
1237 |                  cat6_a6xx_atomic_g
1238 
1239 cat6_ibo_opc_1src: T_OP_RESINFO   { new_instr(OPC_RESINFO); }
1240 
1241 cat6_ibo_opc_ldgb: T_OP_LDGB      { new_instr(OPC_LDGB); }
1242 cat6_ibo_opc_stgb: T_OP_STGB      { new_instr(OPC_STGB); }
1243 
1244 cat6_ibo:          cat6_ibo_opc_1src cat6_type cat6_dim dst_reg ',' 'g' '[' cat6_reg_or_immed ']'
1245 |                  cat6_ibo_opc_ldgb cat6_typed cat6_dim cat6_type '.' cat6_immed dst_reg ',' 'g' '[' cat6_reg_or_immed ']' ',' src ',' src
1246 |                  cat6_ibo_opc_stgb cat6_typed cat6_dim cat6_type '.' cat6_immed { dummy_dst(); } 'g' '[' cat6_reg_or_immed ']' ',' src ',' cat6_reg_or_immed ',' src
1247 
1248 cat6_id_opc:
1249                    T_OP_GETSPID { new_instr(OPC_GETSPID); }
1250 |                  T_OP_GETWID  { new_instr(OPC_GETWID); }
1251 |                  T_OP_GETFIBERID { new_instr(OPC_GETFIBERID); }
1252 
1253 cat6_id:           cat6_id_opc cat6_type dst_reg
1254 
1255 cat6_bindless_base:
1256 |                  '.' T_BASE { instr->flags |= IR3_INSTR_B; instr->cat6.base = $2; }
1257 
1258 cat6_bindless_mode: T_IMM cat6_bindless_base
1259 |                  T_UNIFORM cat6_bindless_base
1260 |                  T_NONUNIFORM cat6_bindless_base { instr->flags |= IR3_INSTR_NONUNIF; }
1261 
1262 cat6_reg_or_immed: src
1263 |                  integer { new_src(0, IR3_REG_IMMED)->iim_val = $1; }
1264 
1265 cat6_bindless_ibo_opc_1src: T_OP_RESINFO_B       { new_instr(OPC_RESINFO); }
1266 
1267 cat6_bindless_ibo_opc_2src: T_OP_ATOMIC_B_ADD        { new_instr(OPC_ATOMIC_B_ADD); dummy_dst(); }
1268 |                  T_OP_ATOMIC_B_SUB        { new_instr(OPC_ATOMIC_B_SUB); dummy_dst(); }
1269 |                  T_OP_ATOMIC_B_XCHG       { new_instr(OPC_ATOMIC_B_XCHG); dummy_dst(); }
1270 |                  T_OP_ATOMIC_B_INC        { new_instr(OPC_ATOMIC_B_INC); dummy_dst(); }
1271 |                  T_OP_ATOMIC_B_DEC        { new_instr(OPC_ATOMIC_B_DEC); dummy_dst(); }
1272 |                  T_OP_ATOMIC_B_CMPXCHG    { new_instr(OPC_ATOMIC_B_CMPXCHG); dummy_dst(); }
1273 |                  T_OP_ATOMIC_B_MIN        { new_instr(OPC_ATOMIC_B_MIN); dummy_dst(); }
1274 |                  T_OP_ATOMIC_B_MAX        { new_instr(OPC_ATOMIC_B_MAX); dummy_dst(); }
1275 |                  T_OP_ATOMIC_B_AND        { new_instr(OPC_ATOMIC_B_AND); dummy_dst(); }
1276 |                  T_OP_ATOMIC_B_OR         { new_instr(OPC_ATOMIC_B_OR); dummy_dst(); }
1277 |                  T_OP_ATOMIC_B_XOR        { new_instr(OPC_ATOMIC_B_XOR); dummy_dst(); }
1278 |                  T_OP_STIB_B              { new_instr(OPC_STIB); dummy_dst(); }
1279 
1280 cat6_bindless_ibo_opc_2src_dst: T_OP_LDIB_B              { new_instr(OPC_LDIB); }
1281 
1282 cat6_bindless_ibo: cat6_bindless_ibo_opc_1src cat6_typed cat6_dim cat6_type '.' cat6_immed '.' cat6_bindless_mode dst_reg ',' cat6_reg_or_immed
1283 |                  cat6_bindless_ibo_opc_2src cat6_typed cat6_dim cat6_type '.' cat6_immed '.' cat6_bindless_mode src_reg ',' cat6_reg_or_immed ',' cat6_reg_or_immed { swap(instr->srcs[0], instr->srcs[2]); }
1284 |                  cat6_bindless_ibo_opc_2src_dst cat6_typed cat6_dim cat6_type '.' cat6_immed '.' cat6_bindless_mode dst_reg ',' cat6_reg_or_immed ',' cat6_reg_or_immed { swap(instr->srcs[0], instr->srcs[1]); }
1285 
1286 cat6_bindless_ldc_opc: T_OP_LDC  { new_instr(OPC_LDC); }
1287 
1288 /* This is separated from the opcode to avoid lookahead/shift-reduce conflicts */
1289 cat6_bindless_ldc_middle:
1290                         T_OFFSET '.' cat6_immed '.' cat6_bindless_mode dst_reg { instr->cat6.d = $1; }
1291 |                       cat6_immed '.' 'k' '.' cat6_bindless_mode 'c' '[' T_A1 ']' { instr->opc = OPC_LDC_K; }
1292 
1293 cat6_bindless_ldc: cat6_bindless_ldc_opc '.' cat6_bindless_ldc_middle ',' cat6_reg_or_immed ',' cat6_reg_or_immed {
1294                       instr->cat6.type = TYPE_U32;
1295                       /* TODO cleanup ir3 src order: */
1296                       swap(instr->srcs[0], instr->srcs[1]);
1297                    }
1298 
1299 const_dst:        integer { new_src(0, IR3_REG_IMMED)->iim_val = $1; }
1300 |                 T_A1 { new_src(0, IR3_REG_IMMED)->iim_val = 0; instr->flags |= IR3_INSTR_A1EN; }
1301 |                 T_A1 '+' integer { new_src(0, IR3_REG_IMMED)->iim_val = $3; instr->flags |= IR3_INSTR_A1EN; }
1302 
1303 cat6_stc:
1304               T_OP_STC  { new_instr(OPC_STC); }  cat6_type 'c' '[' const_dst ']' ',' src_reg ',' cat6_immed
1305 |             T_OP_STSC { new_instr(OPC_STSC); } cat6_type 'c' '[' const_dst ']' ',' immediate ',' cat6_immed
1306 
1307 cat6_todo:         T_OP_G2L                 { new_instr(OPC_G2L); }
1308 |                  T_OP_L2G                 { new_instr(OPC_L2G); }
1309 |                  T_OP_RESFMT              { new_instr(OPC_RESFMT); }
1310 
1311 cat6_instr:        cat6_load
1312 |                  cat6_loadib
1313 |                  cat6_store
1314 |                  cat6_storeib
1315 |                  cat6_prefetch
1316 |                  cat6_atomic
1317 |                  cat6_ibo
1318 |                  cat6_id
1319 |                  cat6_bindless_ldc
1320 |                  cat6_bindless_ibo
1321 |                  cat6_stc
1322 |                  cat6_todo
1323 
1324 cat7_scope:        '.' 'w'  { instr->cat7.w = true; }
1325 |                  '.' 'r'  { instr->cat7.r = true; }
1326 |                  '.' 'l'  { instr->cat7.l = true; }
1327 |                  '.' 'g'  { instr->cat7.g = true; }
1328 
1329 cat7_scopes:
1330 |                  cat7_scope cat7_scopes
1331 
1332 cat7_barrier:      T_OP_BAR                { new_instr(OPC_BAR); } cat7_scopes
1333 |                  T_OP_FENCE              { new_instr(OPC_FENCE); } cat7_scopes
1334 
1335 cat7_data_cache:   T_OP_DCCLN              { new_instr(OPC_DCCLN); }
1336 |                  T_OP_DCINV              { new_instr(OPC_DCINV); }
1337 |                  T_OP_DCFLU              { new_instr(OPC_DCFLU); }
1338 
1339 cat7_alias_src:    src_reg_or_const
1340 |                  immediate_cat1
1341 
1342 cat7_alias_scope: T_MOD_TEX	{ instr->cat7.alias_scope = ALIAS_TEX; }
1343 |                 T_MOD_MEM	{ instr->cat7.alias_scope = ALIAS_MEM; }
1344 |                 T_MOD_RT	{ instr->cat7.alias_scope = ALIAS_RT; }
1345 
1346 cat7_instr:        cat7_barrier
1347 |                  cat7_data_cache
1348 |                  T_OP_SLEEP              { new_instr(OPC_SLEEP); }
1349 |                  T_OP_CCINV              { new_instr(OPC_CCINV); }
1350 |                  T_OP_ICINV              { new_instr(OPC_ICINV); }
1351 |                  T_OP_LOCK               { new_instr(OPC_LOCK); }
1352 |                  T_OP_UNLOCK             { new_instr(OPC_UNLOCK); }
1353 |                  T_OP_ALIAS {
1354                        /* TODO: handle T_INSTR_TYPE */
1355                        new_instr(OPC_ALIAS);
1356                    } '.' cat7_alias_scope '.' T_INSTR_TYPE '.' integer dst_reg ',' cat7_alias_src {
1357                        new_src(0, IR3_REG_IMMED)->uim_val = $8;
1358                    }
1359 
1360 raw_instr: T_RAW   {new_instr(OPC_META_RAW)->raw.value = $1;}
1361 
1362 meta_print_regs:	meta_print_reg
1363 |					meta_print_reg meta_print_regs
1364 
1365 meta_print_reg: ',' T_REGISTER {
1366 	meta_print_data.regs_to_dump[meta_print_data.regs_count++] = $2;
1367 }
1368 
1369 meta_print_start: T_OP_PRINT T_REGISTER {
1370 	meta_print_data.reg_address_lo = $2;
1371 	meta_print_data.reg_address_hi = $2 + 2;
1372 	meta_print_data.reg_tmp = $2 + 4;
1373 	meta_print_data.regs_count = 0;
1374 }
1375 
1376 meta_print: meta_print_start meta_print_regs {
1377 	/* low */
1378 	new_instr(OPC_MOV);
1379 	instr->cat1.src_type = TYPE_U32;
1380 	instr->cat1.dst_type = TYPE_U32;
1381 	new_dst(meta_print_data.reg_address_lo, 0);
1382 	new_src(0, IR3_REG_IMMED)->uim_val = info->shader_print_buffer_iova & 0xffffffff;
1383 
1384 	/* high */
1385 	new_instr(OPC_MOV);
1386 	instr->cat1.src_type = TYPE_U32;
1387 	instr->cat1.dst_type = TYPE_U32;
1388 	new_dst(meta_print_data.reg_address_hi, 0);
1389 	new_src(0, IR3_REG_IMMED)->uim_val = info->shader_print_buffer_iova >> 32;
1390 
1391 	/* offset */
1392 	new_instr(OPC_MOV);
1393 	instr->cat1.src_type = TYPE_U32;
1394 	instr->cat1.dst_type = TYPE_U32;
1395 	new_dst(meta_print_data.reg_tmp, 0);
1396 	new_src(0, IR3_REG_IMMED)->uim_val = 4 * meta_print_data.regs_count;
1397 
1398 	new_instr(OPC_NOP);
1399 	instr->repeat = 5;
1400 
1401 	/* Increment and get current offset into print buffer */
1402 	new_instr(OPC_ATOMIC_G_ADD);
1403 	instr->cat6.d = 1;
1404 	instr->cat6.typed = 0;
1405 	instr->cat6.type = TYPE_U32;
1406 	instr->cat6.iim_val = 1;
1407 
1408 	new_dst(meta_print_data.reg_address_lo, 0);
1409 	new_src(meta_print_data.reg_address_lo, 0);
1410 	new_src(meta_print_data.reg_tmp, 0);
1411 
1412 	/* Store all regs */
1413 	for (uint32_t i = 0; i < meta_print_data.regs_count; i++) {
1414 		new_instr(OPC_STG);
1415 		dummy_dst();
1416 		instr->cat6.type = TYPE_U32;
1417 		instr->flags = IR3_INSTR_SY;
1418 		new_src(meta_print_data.reg_address_lo, 0);
1419 		new_src(0, IR3_REG_IMMED)->iim_val = 0;
1420 		new_src(meta_print_data.regs_to_dump[i], IR3_REG_R);
1421 		new_src(0, IR3_REG_IMMED)->iim_val = 1;
1422 
1423 		new_instr(OPC_ADD_U);
1424 		instr->flags = IR3_INSTR_SS;
1425 		new_dst(meta_print_data.reg_address_lo, 0);
1426 		new_src(meta_print_data.reg_address_lo, 0);
1427 		new_src(0, IR3_REG_IMMED)->uim_val = 4;
1428 
1429 		new_instr(OPC_NOP);
1430 		instr->repeat = 5;
1431 	}
1432 }
1433 
1434 src:               T_REGISTER     { $$ = new_src($1, 0); }
1435 |                  T_A0           { $$ = new_src((61 << 3), IR3_REG_HALF); }
1436 |                  T_A1           { $$ = new_src((61 << 3) + 1, IR3_REG_HALF); }
1437 |                  T_P0           { $$ = new_src((62 << 3) + $1, 0); }
1438 
1439 dst:               T_REGISTER     { $$ = new_dst($1, 0); }
1440 |                  T_A0           { $$ = new_dst((61 << 3), IR3_REG_HALF); }
1441 |                  T_A1           { $$ = new_dst((61 << 3) + 1, IR3_REG_HALF); }
1442 |                  T_P0           { $$ = new_dst((62 << 3) + $1, 0); }
1443 
1444 const:             T_CONSTANT     { $$ = new_src($1, IR3_REG_CONST); }
1445 
1446 dst_reg_flag:      T_EVEN         { instr->cat1.round = ROUND_EVEN; }
1447 |                  T_POS_INFINITY { instr->cat1.round = ROUND_POS_INF; }
1448 |                  T_NEG_INFINITY { instr->cat1.round = ROUND_NEG_INF; }
1449 |                  T_EI           { rflags.flags |= IR3_REG_EI; }
1450 |                  T_WRMASK       { rflags.wrmask = $1; }
1451 
1452 dst_reg_flags:     dst_reg_flag
1453 |                  dst_reg_flag dst_reg_flags
1454 
1455                    /* note: destination registers are always incremented in repeat */
1456 dst_reg:           dst                 { $1->flags |= IR3_REG_R; }
1457 |                  dst_reg_flags dst   { $2->flags |= IR3_REG_R; }
1458 
1459 src_reg_flag:      T_ABSNEG       { rflags.flags |= IR3_REG_ABS|IR3_REG_NEGATE; }
1460 |                  T_NEG          { rflags.flags |= IR3_REG_NEGATE; }
1461 |                  T_ABS          { rflags.flags |= IR3_REG_ABS; }
1462 |                  T_R            { rflags.flags |= IR3_REG_R; }
1463 |                  T_LAST         { rflags.flags |= IR3_REG_LAST_USE; }
1464 
1465 src_reg_flags:     src_reg_flag
1466 |                  src_reg_flag src_reg_flags
1467 
1468 src_reg:           src
1469 |                  src_reg_flags src
1470 
1471 src_reg_gpr:       src_reg
1472 |                  relative_gpr_src
1473 
1474 src_const:         const
1475 |                  src_reg_flags const
1476 
1477 src_reg_or_const:  src_reg
1478 |                  src_const
1479 
1480 src_reg_or_const_or_rel: src_reg_or_const
1481 |                  relative
1482 |                  src_reg_flags relative
1483 
1484 src_reg_or_const_or_rel_or_imm: src_reg_or_const_or_rel
1485 |                  src_reg_flags immediate
1486 |                  immediate
1487 
1488 src_reg_or_rel_or_imm: src_reg
1489 |                  relative
1490 |                  immediate
1491 
1492 offset:            { $$ = 0; }
1493 |                  '+' integer { $$ = $2; }
1494 |                  '-' integer { $$ = -$2; }
1495 
1496 relative_gpr_src:  'r' '<' T_A0 offset '>'  { new_src(0, IR3_REG_RELATIV)->array.offset = $4; }
1497 |                  T_HR '<' T_A0 offset '>'  { new_src(0, IR3_REG_RELATIV | IR3_REG_HALF)->array.offset = $4; }
1498 
1499 relative_gpr_dst:  'r' '<' T_A0 offset '>'  { new_dst(0, IR3_REG_RELATIV)->array.offset = $4; }
1500 |                  T_HR '<' T_A0 offset '>'  { new_dst(0, IR3_REG_RELATIV | IR3_REG_HALF)->array.offset = $4; }
1501 
1502 relative_const:    'c' '<' T_A0 offset '>'  { new_src(0, IR3_REG_RELATIV | IR3_REG_CONST)->array.offset = $4; }
1503 |                  T_HC '<' T_A0 offset '>'  { new_src(0, IR3_REG_RELATIV | IR3_REG_CONST | IR3_REG_HALF)->array.offset = $4; }
1504 
1505 relative:          relative_gpr_src
1506 |                  relative_const
1507 
1508 /* cat1 immediates differ slighly in the floating point case from the cat2
1509  * case which can only encode certain predefined values (ie. and index into
1510  * the FLUT table)
1511  */
1512 immediate_cat1:    integer             { new_src(0, IR3_REG_IMMED)->iim_val = type_size(instr->cat1.src_type) < 32 ? $1 & 0xffff : $1; }
1513 |                  '(' integer ')'     { new_src(0, IR3_REG_IMMED)->fim_val = $2; }
1514 |                  '(' float ')'       { new_src(0, IR3_REG_IMMED)->fim_val = $2; }
1515 |                  'h' '(' integer ')' { new_src(0, IR3_REG_IMMED | IR3_REG_HALF)->iim_val = $3 & 0xffff; }
1516 |                  'h' '(' float ')'   { new_src(0, IR3_REG_IMMED | IR3_REG_HALF)->uim_val = _mesa_float_to_half($3); }
1517 |                  '(' T_NAN ')'       { new_src(0, IR3_REG_IMMED)->fim_val = NAN; }
1518 |                  '(' T_INF ')'       { new_src(0, IR3_REG_IMMED)->fim_val = INFINITY; }
1519 
1520 immediate:         integer             { new_src(0, IR3_REG_IMMED)->iim_val = $1; }
1521 |                  '(' integer ')'     { new_src(0, IR3_REG_IMMED)->fim_val = $2; }
1522 |                  flut_immed          { new_src(0, IR3_REG_IMMED)->uim_val = $1; }
1523 |                  'h' '(' integer ')' { new_src(0, IR3_REG_IMMED | IR3_REG_HALF)->iim_val = $3; }
1524 |                  'h' flut_immed      { new_src(0, IR3_REG_IMMED | IR3_REG_HALF)->uim_val = $2; }
1525 
1526 /* Float LUT values accepted as immed: */
1527 flut_immed:        T_FLUT_0_0
1528 |                  T_FLUT_0_5
1529 |                  T_FLUT_1_0
1530 |                  T_FLUT_2_0
1531 |                  T_FLUT_E
1532 |                  T_FLUT_PI
1533 |                  T_FLUT_INV_PI
1534 |                  T_FLUT_INV_LOG2_E
1535 |                  T_FLUT_LOG2_E
1536 |                  T_FLUT_INV_LOG2_10
1537 |                  T_FLUT_LOG2_10
1538 |                  T_FLUT_4_0
1539 
1540 integer:           T_INT       { $$ = $1; }
1541 |                  '-' T_INT   { $$ = -$2; }
1542 |                  T_HEX       { $$ = $1; }
1543 |                  '-' T_HEX   { $$ = -$2; }
1544 
1545 float:             T_FLOAT     { $$ = $1; }
1546 |                  '-' T_FLOAT { $$ = -$2; }
1547 
1548 type:              T_TYPE_F16  { $$ = TYPE_F16; }
1549 |                  T_TYPE_F32  { $$ = TYPE_F32; }
1550 |                  T_TYPE_U16  { $$ = TYPE_U16; }
1551 |                  T_TYPE_U32  { $$ = TYPE_U32; }
1552 |                  T_TYPE_S16  { $$ = TYPE_S16; }
1553 |                  T_TYPE_S32  { $$ = TYPE_S32; }
1554 |                  T_TYPE_U8   { $$ = TYPE_U8;  }
1555 |                  T_TYPE_S8   { $$ = TYPE_S8;  }
1556