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