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