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