2 * Copyright (c) 2013 Rob Clark <robclark@freedesktop.org>
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:
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
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
26 struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f);
37 #include "util/u_math.h"
40 #include "ir3/ir3_shader.h"
41 #include "ir3/instr-a3xx.h"
43 #include "ir3_parser.h"
46 /* ir3 treats the abs/neg flags as separate flags for float vs integer,
47 * but in the instruction encoding they are the same thing. Tracking
48 * them separately is only for the benefit of ir3 opt passes, and not
49 * required here, so just use the float versions:
51 #define IR3_REG_ABS IR3_REG_FABS
52 #define IR3_REG_NEGATE IR3_REG_FNEG
54 static struct ir3_kernel *kernel;
55 static struct ir3_shader_variant *variant;
56 /* NOTE the assembler doesn't really use the ir3_block construction
57 * like the compiler does. Everything is treated as one large block.
58 * Which might happen to contain flow control. But since we don't
59 * use any of the ir3 backend passes (sched, RA, etc) this doesn't
62 static struct ir3_block *block; /* current shader block */
63 static struct ir3_instruction *instr; /* current instruction */
75 int ir3_yyget_lineno(void);
77 static struct ir3_instruction * new_instr(opc_t opc)
79 instr = ir3_instr_create(block, opc);
80 instr->flags = iflags.flags;
81 instr->repeat = iflags.repeat;
82 instr->line = ir3_yyget_lineno();
83 iflags.flags = iflags.repeat = 0;
87 static void new_shader(void)
89 variant->ir = ir3_create(variant->shader->compiler, variant->shader->type);
90 block = ir3_block_create(variant->ir);
91 list_addtail(&block->node, &variant->ir->block_list);
94 static type_t parse_type(const char **type)
96 if (!strncmp("f16", *type, 3)) {
99 } else if (!strncmp("f32", *type, 3)) {
102 } else if (!strncmp("u16", *type, 3)) {
105 } else if (!strncmp("u32", *type, 3)) {
108 } else if (!strncmp("s16", *type, 3)) {
111 } else if (!strncmp("s32", *type, 3)) {
114 } else if (!strncmp("u8", *type, 2)) {
117 } else if (!strncmp("s8", *type, 2)) {
121 assert(0); /* shouldn't get here */
126 static struct ir3_instruction * parse_type_type(struct ir3_instruction *instr,
127 const char *type_type)
129 instr->cat1.src_type = parse_type(&type_type);
130 instr->cat1.dst_type = parse_type(&type_type);
134 static struct ir3_register * new_reg(int num, unsigned flags)
136 struct ir3_register *reg;
137 flags |= rflags.flags;
139 flags |= IR3_REG_HALF;
140 reg = ir3_reg_create(instr, num>>1, flags);
141 reg->wrmask = MAX2(1, rflags.wrmask);
142 rflags.flags = rflags.wrmask = 0;
146 static struct ir3_register * dummy_dst(void)
148 return new_reg(0, 0);
151 static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsigned c3)
153 struct ir3_const_state *const_state = &variant->shader->const_state;
154 assert((reg & 0x7) == 0);
155 int idx = reg >> (1 + 2); /* low bit is half vs full, next two bits are swiz */
156 if (const_state->immediate_idx == const_state->immediates_size * 4) {
157 const_state->immediates_size += 4;
158 const_state->immediates = realloc (const_state->immediates,
159 const_state->immediates_size * sizeof(const_state->immediates[0]));
161 const_state->immediates[idx].val[0] = c0;
162 const_state->immediates[idx].val[1] = c1;
163 const_state->immediates[idx].val[2] = c2;
164 const_state->immediates[idx].val[3] = c3;
165 const_state->immediates_count = idx + 1;
166 const_state->immediate_idx++;
169 static void add_sysval(unsigned reg, unsigned compmask, gl_system_value sysval)
171 unsigned n = variant->inputs_count++;
172 variant->inputs[n].regid = reg;
173 variant->inputs[n].sysval = true;
174 variant->inputs[n].slot = sysval;
175 variant->inputs[n].compmask = compmask;
176 variant->inputs[n].interpolate = INTERP_MODE_FLAT;
184 extern int yylex(void);
185 extern FILE *ir3_yyin;
189 static void yyerror(const char *error)
191 fprintf(stderr, "error at line %d: %s\n", ir3_yyget_lineno(), error);
194 struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f)
203 ir3_destroy(variant->ir);
216 struct ir3_register *reg;
226 static void print_token(FILE *file, int type, YYSTYPE value)
228 fprintf(file, "\ntype: %d\n", type);
231 #define YYPRINT(file, type, value) print_token(file, type, value)
238 %token <str> T_IDENTIFIER
239 %token <num> T_REGISTER
240 %token <num> T_CONSTANT
242 /* @ headers (@const/@sampler/@uniform/@varying) */
243 %token <tok> T_A_LOCALSIZE
244 %token <tok> T_A_CONST
246 %token <tok> T_A_INVOCATIONID
247 %token <tok> T_A_WGID
248 %token <tok> T_A_NUMWG
249 /* todo, re-add @sampler/@uniform/@varying if needed someday */
251 /* src register flags */
252 %token <tok> T_ABSNEG
257 /* dst register flags */
259 %token <tok> T_POS_INFINITY
261 %token <num> T_WRMASK
263 /* instruction flags */
271 %token <tok> T_OP_NOP
273 %token <tok> T_OP_JUMP
274 %token <tok> T_OP_CALL
275 %token <tok> T_OP_RET
276 %token <tok> T_OP_KILL
277 %token <tok> T_OP_END
278 %token <tok> T_OP_EMIT
279 %token <tok> T_OP_CUT
280 %token <tok> T_OP_CHMASK
281 %token <tok> T_OP_CHSH
282 %token <tok> T_OP_FLOW_REV
285 %token <tok> T_OP_MOVA
286 %token <tok> T_OP_MOV
287 %token <tok> T_OP_COV
290 %token <tok> T_OP_ADD_F
291 %token <tok> T_OP_MIN_F
292 %token <tok> T_OP_MAX_F
293 %token <tok> T_OP_MUL_F
294 %token <tok> T_OP_SIGN_F
295 %token <tok> T_OP_CMPS_F
296 %token <tok> T_OP_ABSNEG_F
297 %token <tok> T_OP_CMPV_F
298 %token <tok> T_OP_FLOOR_F
299 %token <tok> T_OP_CEIL_F
300 %token <tok> T_OP_RNDNE_F
301 %token <tok> T_OP_RNDAZ_F
302 %token <tok> T_OP_TRUNC_F
303 %token <tok> T_OP_ADD_U
304 %token <tok> T_OP_ADD_S
305 %token <tok> T_OP_SUB_U
306 %token <tok> T_OP_SUB_S
307 %token <tok> T_OP_CMPS_U
308 %token <tok> T_OP_CMPS_S
309 %token <tok> T_OP_MIN_U
310 %token <tok> T_OP_MIN_S
311 %token <tok> T_OP_MAX_U
312 %token <tok> T_OP_MAX_S
313 %token <tok> T_OP_ABSNEG_S
314 %token <tok> T_OP_AND_B
315 %token <tok> T_OP_OR_B
316 %token <tok> T_OP_NOT_B
317 %token <tok> T_OP_XOR_B
318 %token <tok> T_OP_CMPV_U
319 %token <tok> T_OP_CMPV_S
320 %token <tok> T_OP_MUL_U24
321 %token <tok> T_OP_MUL_S24
322 %token <tok> T_OP_MULL_U
323 %token <tok> T_OP_BFREV_B
324 %token <tok> T_OP_CLZ_S
325 %token <tok> T_OP_CLZ_B
326 %token <tok> T_OP_SHL_B
327 %token <tok> T_OP_SHR_B
328 %token <tok> T_OP_ASHR_B
329 %token <tok> T_OP_BARY_F
330 %token <tok> T_OP_MGEN_B
331 %token <tok> T_OP_GETBIT_B
332 %token <tok> T_OP_SETRM
333 %token <tok> T_OP_CBITS_B
334 %token <tok> T_OP_SHB
335 %token <tok> T_OP_MSAD
338 %token <tok> T_OP_MAD_U16
339 %token <tok> T_OP_MADSH_U16
340 %token <tok> T_OP_MAD_S16
341 %token <tok> T_OP_MADSH_M16
342 %token <tok> T_OP_MAD_U24
343 %token <tok> T_OP_MAD_S24
344 %token <tok> T_OP_MAD_F16
345 %token <tok> T_OP_MAD_F32
346 %token <tok> T_OP_SEL_B16
347 %token <tok> T_OP_SEL_B32
348 %token <tok> T_OP_SEL_S16
349 %token <tok> T_OP_SEL_S32
350 %token <tok> T_OP_SEL_F16
351 %token <tok> T_OP_SEL_F32
352 %token <tok> T_OP_SAD_S16
353 %token <tok> T_OP_SAD_S32
356 %token <tok> T_OP_RCP
357 %token <tok> T_OP_RSQ
358 %token <tok> T_OP_LOG2
359 %token <tok> T_OP_EXP2
360 %token <tok> T_OP_SIN
361 %token <tok> T_OP_COS
362 %token <tok> T_OP_SQRT
365 %token <tok> T_OP_ISAM
366 %token <tok> T_OP_ISAML
367 %token <tok> T_OP_ISAMM
368 %token <tok> T_OP_SAM
369 %token <tok> T_OP_SAMB
370 %token <tok> T_OP_SAML
371 %token <tok> T_OP_SAMGQ
372 %token <tok> T_OP_GETLOD
373 %token <tok> T_OP_CONV
374 %token <tok> T_OP_CONVM
375 %token <tok> T_OP_GETSIZE
376 %token <tok> T_OP_GETBUF
377 %token <tok> T_OP_GETPOS
378 %token <tok> T_OP_GETINFO
379 %token <tok> T_OP_DSX
380 %token <tok> T_OP_DSY
381 %token <tok> T_OP_GATHER4R
382 %token <tok> T_OP_GATHER4G
383 %token <tok> T_OP_GATHER4B
384 %token <tok> T_OP_GATHER4A
385 %token <tok> T_OP_SAMGP0
386 %token <tok> T_OP_SAMGP1
387 %token <tok> T_OP_SAMGP2
388 %token <tok> T_OP_SAMGP3
389 %token <tok> T_OP_DSXPP_1
390 %token <tok> T_OP_DSYPP_1
391 %token <tok> T_OP_RGETPOS
392 %token <tok> T_OP_RGETINFO
395 %token <tok> T_OP_LDG
396 %token <tok> T_OP_LDL
397 %token <tok> T_OP_LDP
398 %token <tok> T_OP_STG
399 %token <tok> T_OP_STL
400 %token <tok> T_OP_STP
401 %token <tok> T_OP_LDIB
402 %token <tok> T_OP_G2L
403 %token <tok> T_OP_L2G
404 %token <tok> T_OP_PREFETCH
405 %token <tok> T_OP_LDLW
406 %token <tok> T_OP_STLW
407 %token <tok> T_OP_RESFMT
408 %token <tok> T_OP_RESINF
409 %token <tok> T_OP_ATOMIC_ADD
410 %token <tok> T_OP_ATOMIC_SUB
411 %token <tok> T_OP_ATOMIC_XCHG
412 %token <tok> T_OP_ATOMIC_INC
413 %token <tok> T_OP_ATOMIC_DEC
414 %token <tok> T_OP_ATOMIC_CMPXCHG
415 %token <tok> T_OP_ATOMIC_MIN
416 %token <tok> T_OP_ATOMIC_MAX
417 %token <tok> T_OP_ATOMIC_AND
418 %token <tok> T_OP_ATOMIC_OR
419 %token <tok> T_OP_ATOMIC_XOR
420 %token <tok> T_OP_LDGB
421 %token <tok> T_OP_STGB
422 %token <tok> T_OP_STIB
423 %token <tok> T_OP_LDC
424 %token <tok> T_OP_LDLV
426 /* type qualifiers: */
427 %token <tok> T_TYPE_F16
428 %token <tok> T_TYPE_F32
429 %token <tok> T_TYPE_U16
430 %token <tok> T_TYPE_U32
431 %token <tok> T_TYPE_S16
432 %token <tok> T_TYPE_S32
433 %token <tok> T_TYPE_U8
434 %token <tok> T_TYPE_S8
436 %token <tok> T_UNTYPED
444 /* condition qualifiers: */
460 %token <str> T_CAT1_TYPE_TYPE
462 %type <num> integer offset
464 %type <reg> reg const
466 %type <tok> cat2_opc_1src cat2_opc_2src_cnd cat2_opc_2src
469 %type <tok> cat5_opc cat5_samp cat5_tex cat5_type
471 %type <unum> const_val
479 shader: { new_shader(); } headers instrs
484 header: localsize_header
487 | invocationid_header
491 const_val: T_FLOAT { $$ = fui($1); }
493 | '-' T_INT { $$ = -$2; }
496 localsize_header: T_A_LOCALSIZE const_val ',' const_val ',' const_val {
497 struct kernel *k = &kernel->base;
498 k->local_size[0] = $2;
499 k->local_size[1] = $4;
500 k->local_size[2] = $6;
503 const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' const_val ',' const_val {
504 add_const($3, $5, $7, $9, $11);
507 buf_header: T_A_BUF const_val {
508 struct kernel *k = &kernel->base;
509 int idx = k->num_bufs++;
510 assert(idx < MAX_BUFS);
511 k->buf_sizes[idx] = $2;
514 invocationid_header: T_A_INVOCATIONID '(' T_REGISTER ')' {
515 assert(($3 & 0x1) == 0); /* half-reg not allowed */
516 unsigned reg = $3 >> 1;
517 add_sysval(reg, 0x7, SYSTEM_VALUE_LOCAL_INVOCATION_ID);
520 wgid_header: T_A_WGID '(' T_REGISTER ')' {
521 assert(($3 & 0x1) == 0); /* half-reg not allowed */
522 unsigned reg = $3 >> 1;
523 assert(reg >= regid(48, 0)); /* must be a high reg */
524 add_sysval(reg, 0x7, SYSTEM_VALUE_WORK_GROUP_ID);
527 numwg_header: T_A_NUMWG '(' T_CONSTANT ')' {
528 assert(($3 & 0x1) == 0); /* half-reg not allowed */
529 unsigned reg = $3 >> 1;
531 /* reserve space in immediates for the actual value to be plugged in later: */
532 add_const($3, 0, 0, 0, 0);
535 iflag: T_SY { iflags.flags |= IR3_INSTR_SY; }
536 | T_SS { iflags.flags |= IR3_INSTR_SS; }
537 | T_JP { iflags.flags |= IR3_INSTR_JP; }
538 | T_RPT { iflags.repeat = $1; }
539 | T_UL { iflags.flags |= IR3_INSTR_UL; }
547 instr: iflags cat0_instr
555 cat0_src: '!' T_P0 { instr->cat0.inv = true; instr->cat0.comp = $2 >> 1; }
556 | T_P0 { instr->cat0.comp = $1 >> 1; }
558 cat0_immed: '#' integer { instr->cat0.immed = $2; }
560 cat0_instr: T_OP_NOP { new_instr(OPC_NOP); }
561 | T_OP_BR { new_instr(OPC_BR); } cat0_src ',' cat0_immed
562 | T_OP_JUMP { new_instr(OPC_JUMP); } cat0_immed
563 | T_OP_CALL { new_instr(OPC_CALL); } cat0_immed
564 | T_OP_RET { new_instr(OPC_RET); }
565 | T_OP_KILL { new_instr(OPC_KILL); } cat0_src
566 | T_OP_END { new_instr(OPC_END); }
567 | T_OP_EMIT { new_instr(OPC_EMIT); }
568 | T_OP_CUT { new_instr(OPC_CUT); }
569 | T_OP_CHMASK { new_instr(OPC_CHMASK); }
570 | T_OP_CHSH { new_instr(OPC_CHSH); }
571 | T_OP_FLOW_REV { new_instr(OPC_FLOW_REV); }
573 cat1_opc: T_OP_MOVA {
575 instr->cat1.src_type = TYPE_S16;
576 instr->cat1.dst_type = TYPE_S16;
578 | T_OP_MOV '.' T_CAT1_TYPE_TYPE {
579 parse_type_type(new_instr(OPC_MOV), $3);
581 | T_OP_COV '.' T_CAT1_TYPE_TYPE {
582 parse_type_type(new_instr(OPC_MOV), $3);
585 cat1_instr: cat1_opc dst_reg ',' src_reg_or_const_or_rel_or_imm
587 cat2_opc_1src: T_OP_ABSNEG_F { new_instr(OPC_ABSNEG_F); }
588 | T_OP_ABSNEG_S { new_instr(OPC_ABSNEG_S); }
589 | T_OP_CLZ_B { new_instr(OPC_CLZ_B); }
590 | T_OP_CLZ_S { new_instr(OPC_CLZ_S); }
591 | T_OP_SIGN_F { new_instr(OPC_SIGN_F); }
592 | T_OP_FLOOR_F { new_instr(OPC_FLOOR_F); }
593 | T_OP_CEIL_F { new_instr(OPC_CEIL_F); }
594 | T_OP_RNDNE_F { new_instr(OPC_RNDNE_F); }
595 | T_OP_RNDAZ_F { new_instr(OPC_RNDAZ_F); }
596 | T_OP_TRUNC_F { new_instr(OPC_TRUNC_F); }
597 | T_OP_NOT_B { new_instr(OPC_NOT_B); }
598 | T_OP_BFREV_B { new_instr(OPC_BFREV_B); }
599 | T_OP_SETRM { new_instr(OPC_SETRM); }
600 | T_OP_CBITS_B { new_instr(OPC_CBITS_B); }
602 cat2_opc_2src_cnd: T_OP_CMPS_F { new_instr(OPC_CMPS_F); }
603 | T_OP_CMPS_U { new_instr(OPC_CMPS_U); }
604 | T_OP_CMPS_S { new_instr(OPC_CMPS_S); }
605 | T_OP_CMPV_F { new_instr(OPC_CMPV_F); }
606 | T_OP_CMPV_U { new_instr(OPC_CMPV_U); }
607 | T_OP_CMPV_S { new_instr(OPC_CMPV_S); }
609 cat2_opc_2src: T_OP_ADD_F { new_instr(OPC_ADD_F); }
610 | T_OP_MIN_F { new_instr(OPC_MIN_F); }
611 | T_OP_MAX_F { new_instr(OPC_MAX_F); }
612 | T_OP_MUL_F { new_instr(OPC_MUL_F); }
613 | T_OP_ADD_U { new_instr(OPC_ADD_U); }
614 | T_OP_ADD_S { new_instr(OPC_ADD_S); }
615 | T_OP_SUB_U { new_instr(OPC_SUB_U); }
616 | T_OP_SUB_S { new_instr(OPC_SUB_S); }
617 | T_OP_MIN_U { new_instr(OPC_MIN_U); }
618 | T_OP_MIN_S { new_instr(OPC_MIN_S); }
619 | T_OP_MAX_U { new_instr(OPC_MAX_U); }
620 | T_OP_MAX_S { new_instr(OPC_MAX_S); }
621 | T_OP_AND_B { new_instr(OPC_AND_B); }
622 | T_OP_OR_B { new_instr(OPC_OR_B); }
623 | T_OP_XOR_B { new_instr(OPC_XOR_B); }
624 | T_OP_MUL_U24 { new_instr(OPC_MUL_U24); }
625 | T_OP_MUL_S24 { new_instr(OPC_MUL_S24); }
626 | T_OP_MULL_U { new_instr(OPC_MULL_U); }
627 | T_OP_SHL_B { new_instr(OPC_SHL_B); }
628 | T_OP_SHR_B { new_instr(OPC_SHR_B); }
629 | T_OP_ASHR_B { new_instr(OPC_ASHR_B); }
630 | T_OP_BARY_F { new_instr(OPC_BARY_F); }
631 | T_OP_MGEN_B { new_instr(OPC_MGEN_B); }
632 | T_OP_GETBIT_B { new_instr(OPC_GETBIT_B); }
633 | T_OP_SHB { new_instr(OPC_SHB); }
634 | T_OP_MSAD { new_instr(OPC_MSAD); }
636 cond: T_LT { instr->cat2.condition = IR3_COND_LT; }
637 | T_LE { instr->cat2.condition = IR3_COND_LE; }
638 | T_GT { instr->cat2.condition = IR3_COND_GT; }
639 | T_GE { instr->cat2.condition = IR3_COND_GE; }
640 | T_EQ { instr->cat2.condition = IR3_COND_EQ; }
641 | T_NE { instr->cat2.condition = IR3_COND_NE; }
643 cat2_instr: cat2_opc_1src dst_reg ',' src_reg_or_const_or_rel_or_imm
644 | cat2_opc_2src_cnd '.' cond dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
645 | cat2_opc_2src dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
647 cat3_opc: T_OP_MAD_U16 { new_instr(OPC_MAD_U16); }
648 | T_OP_MADSH_U16 { new_instr(OPC_MADSH_U16); }
649 | T_OP_MAD_S16 { new_instr(OPC_MAD_S16); }
650 | T_OP_MADSH_M16 { new_instr(OPC_MADSH_M16); }
651 | T_OP_MAD_U24 { new_instr(OPC_MAD_U24); }
652 | T_OP_MAD_S24 { new_instr(OPC_MAD_S24); }
653 | T_OP_MAD_F16 { new_instr(OPC_MAD_F16); }
654 | T_OP_MAD_F32 { new_instr(OPC_MAD_F32); }
655 | T_OP_SEL_B16 { new_instr(OPC_SEL_B16); }
656 | T_OP_SEL_B32 { new_instr(OPC_SEL_B32); }
657 | T_OP_SEL_S16 { new_instr(OPC_SEL_S16); }
658 | T_OP_SEL_S32 { new_instr(OPC_SEL_S32); }
659 | T_OP_SEL_F16 { new_instr(OPC_SEL_F16); }
660 | T_OP_SEL_F32 { new_instr(OPC_SEL_F32); }
661 | T_OP_SAD_S16 { new_instr(OPC_SAD_S16); }
662 | T_OP_SAD_S32 { new_instr(OPC_SAD_S32); }
664 cat3_instr: cat3_opc dst_reg ',' src_reg_or_const_or_rel ',' src_reg_or_const ',' src_reg_or_const_or_rel
666 cat4_opc: T_OP_RCP { new_instr(OPC_RCP); }
667 | T_OP_RSQ { new_instr(OPC_RSQ); }
668 | T_OP_LOG2 { new_instr(OPC_LOG2); }
669 | T_OP_EXP2 { new_instr(OPC_EXP2); }
670 | T_OP_SIN { new_instr(OPC_SIN); }
671 | T_OP_COS { new_instr(OPC_COS); }
672 | T_OP_SQRT { new_instr(OPC_SQRT); }
674 cat4_instr: cat4_opc dst_reg ',' src_reg_or_const_or_rel_or_imm
676 cat5_opc_dsxypp: T_OP_DSXPP_1 { new_instr(OPC_DSXPP_1); }
677 | T_OP_DSYPP_1 { new_instr(OPC_DSYPP_1); }
679 cat5_opc: T_OP_ISAM { new_instr(OPC_ISAM); }
680 | T_OP_ISAML { new_instr(OPC_ISAML); }
681 | T_OP_ISAMM { new_instr(OPC_ISAMM); }
682 | T_OP_SAM { new_instr(OPC_SAM); }
683 | T_OP_SAMB { new_instr(OPC_SAMB); }
684 | T_OP_SAML { new_instr(OPC_SAML); }
685 | T_OP_SAMGQ { new_instr(OPC_SAMGQ); }
686 | T_OP_GETLOD { new_instr(OPC_GETLOD); }
687 | T_OP_CONV { new_instr(OPC_CONV); }
688 | T_OP_CONVM { new_instr(OPC_CONVM); }
689 | T_OP_GETSIZE { new_instr(OPC_GETSIZE); }
690 | T_OP_GETBUF { new_instr(OPC_GETBUF); }
691 | T_OP_GETPOS { new_instr(OPC_GETPOS); }
692 | T_OP_GETINFO { new_instr(OPC_GETINFO); }
693 | T_OP_DSX { new_instr(OPC_DSX); }
694 | T_OP_DSY { new_instr(OPC_DSY); }
695 | T_OP_GATHER4R { new_instr(OPC_GATHER4R); }
696 | T_OP_GATHER4G { new_instr(OPC_GATHER4G); }
697 | T_OP_GATHER4B { new_instr(OPC_GATHER4B); }
698 | T_OP_GATHER4A { new_instr(OPC_GATHER4A); }
699 | T_OP_SAMGP0 { new_instr(OPC_SAMGP0); }
700 | T_OP_SAMGP1 { new_instr(OPC_SAMGP1); }
701 | T_OP_SAMGP2 { new_instr(OPC_SAMGP2); }
702 | T_OP_SAMGP3 { new_instr(OPC_SAMGP3); }
703 | T_OP_RGETPOS { new_instr(OPC_RGETPOS); }
704 | T_OP_RGETINFO { new_instr(OPC_RGETINFO); }
706 cat5_flag: '.' T_3D { instr->flags |= IR3_INSTR_3D; }
707 | '.' 'a' { instr->flags |= IR3_INSTR_A; }
708 | '.' 'o' { instr->flags |= IR3_INSTR_O; }
709 | '.' 'p' { instr->flags |= IR3_INSTR_P; }
710 | '.' 's' { instr->flags |= IR3_INSTR_S; }
711 | '.' T_S2EN { instr->flags |= IR3_INSTR_S2EN; }
713 | cat5_flag cat5_flags
715 cat5_samp: T_SAMP { instr->cat5.samp = $1; }
716 cat5_tex: T_TEX { instr->cat5.tex = $1; }
717 cat5_type: '(' type ')' { instr->cat5.type = $2; }
719 cat5_instr: cat5_opc_dsxypp cat5_flags dst_reg ',' src_reg
720 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp ',' cat5_tex
721 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp
722 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_tex
723 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg
724 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp ',' cat5_tex
725 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp
726 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_tex
727 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg
728 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp ',' cat5_tex
729 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp
730 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_tex
731 | cat5_opc cat5_flags cat5_type dst_reg
733 cat6_typed: '.' T_UNTYPED { instr->cat6.typed = 0; }
734 | '.' T_TYPED { instr->cat6.typed = 1; }
736 cat6_dim: '.' T_1D { instr->cat6.d = 1; }
737 | '.' T_2D { instr->cat6.d = 2; }
738 | '.' T_3D { instr->cat6.d = 3; }
739 | '.' T_4D { instr->cat6.d = 4; }
741 cat6_type: '.' type { instr->cat6.type = $2; }
742 cat6_offset: offset { instr->cat6.src_offset = $1; }
743 cat6_immed: integer { instr->cat6.iim_val = $1; }
745 cat6_load: T_OP_LDG { new_instr(OPC_LDG); } cat6_type dst_reg ',' 'g' '[' reg cat6_offset ']' ',' cat6_immed
746 | T_OP_LDP { new_instr(OPC_LDP); } cat6_type dst_reg ',' 'p' '[' reg cat6_offset ']' ',' cat6_immed
747 | T_OP_LDL { new_instr(OPC_LDL); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
748 | T_OP_LDLW { new_instr(OPC_LDLW); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
749 | T_OP_LDLV { new_instr(OPC_LDLV); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
751 // TODO some of the cat6 instructions have different syntax for a6xx..
752 //| T_OP_LDIB { new_instr(OPC_LDIB); } cat6_type dst_reg cat6_offset ',' reg ',' cat6_immed
754 cat6_store: T_OP_STG { new_instr(OPC_STG); } cat6_type 'g' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
755 | T_OP_STP { new_instr(OPC_STP); } cat6_type 'p' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
756 | T_OP_STL { new_instr(OPC_STL); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
757 | T_OP_STLW { new_instr(OPC_STLW); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
759 cat6_storeib: T_OP_STIB { new_instr(OPC_STIB); dummy_dst(); } cat6_typed cat6_dim cat6_type '.' cat6_immed'g' '[' immediate ']' '+' reg ',' reg
761 cat6_prefetch: T_OP_PREFETCH { new_instr(OPC_PREFETCH); new_reg(0,0); /* dummy dst */ } 'g' '[' reg cat6_offset ']' ',' cat6_immed
763 cat6_atomic_l_g: '.' 'g' { instr->flags |= IR3_INSTR_G; }
766 cat6_atomic: T_OP_ATOMIC_ADD { new_instr(OPC_ATOMIC_ADD); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
767 | T_OP_ATOMIC_SUB { new_instr(OPC_ATOMIC_SUB); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
768 | T_OP_ATOMIC_XCHG { new_instr(OPC_ATOMIC_XCHG); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
769 | T_OP_ATOMIC_INC { new_instr(OPC_ATOMIC_INC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
770 | T_OP_ATOMIC_DEC { new_instr(OPC_ATOMIC_DEC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
771 | T_OP_ATOMIC_CMPXCHG { new_instr(OPC_ATOMIC_CMPXCHG); }cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
772 | T_OP_ATOMIC_MIN { new_instr(OPC_ATOMIC_MIN); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
773 | T_OP_ATOMIC_MAX { new_instr(OPC_ATOMIC_MAX); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
774 | T_OP_ATOMIC_AND { new_instr(OPC_ATOMIC_AND); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
775 | T_OP_ATOMIC_OR { new_instr(OPC_ATOMIC_OR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
776 | T_OP_ATOMIC_XOR { new_instr(OPC_ATOMIC_XOR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
778 cat6_todo: T_OP_G2L { new_instr(OPC_G2L); }
779 | T_OP_L2G { new_instr(OPC_L2G); }
780 | T_OP_RESFMT { new_instr(OPC_RESFMT); }
781 | T_OP_RESINF { new_instr(OPC_RESINFO); }
782 | T_OP_LDGB { new_instr(OPC_LDGB); }
783 | T_OP_STGB { new_instr(OPC_STGB); }
784 | T_OP_LDC { new_instr(OPC_LDC); }
786 cat6_instr: cat6_load
793 reg: T_REGISTER { $$ = new_reg($1, 0); }
794 | T_A0 { $$ = new_reg((61 << 3) + $1, IR3_REG_HALF); }
795 | T_P0 { $$ = new_reg((62 << 3) + $1, 0); }
797 const: T_CONSTANT { $$ = new_reg($1, IR3_REG_CONST); }
799 dst_reg_flag: T_EVEN { rflags.flags |= IR3_REG_EVEN; }
800 | T_POS_INFINITY { rflags.flags |= IR3_REG_POS_INF; }
801 | T_EI { rflags.flags |= IR3_REG_EI; }
802 | T_WRMASK { rflags.wrmask = $1; }
804 dst_reg_flags: dst_reg_flag
805 | dst_reg_flag dst_reg_flags
807 /* note: destination registers are always incremented in repeat */
808 dst_reg: reg { $1->flags |= IR3_REG_R; }
809 | dst_reg_flags reg { $2->flags |= IR3_REG_R; }
811 src_reg_flag: T_ABSNEG { rflags.flags |= IR3_REG_ABS|IR3_REG_NEGATE; }
812 | T_NEG { rflags.flags |= IR3_REG_NEGATE; }
813 | T_ABS { rflags.flags |= IR3_REG_ABS; }
814 | T_R { rflags.flags |= IR3_REG_R; }
816 src_reg_flags: src_reg_flag
817 | src_reg_flag src_reg_flags
823 | src_reg_flags const
825 src_reg_or_const: src_reg
828 src_reg_or_const_or_rel: src_reg_or_const
831 src_reg_or_const_or_rel_or_imm: src_reg_or_const_or_rel
832 | src_reg_flags immediate
836 | '+' integer { $$ = $2; }
837 | '-' integer { $$ = -$2; }
839 relative: 'r' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV)->array.offset = $4; }
840 | 'c' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV | IR3_REG_CONST)->array.offset = $4; }
842 immediate: integer { new_reg(0, IR3_REG_IMMED)->iim_val = $1; }
843 | '(' integer ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; }
844 | '(' float ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; }
845 | '(' T_NAN ')' { new_reg(0, IR3_REG_IMMED)->fim_val = NAN; }
846 | '(' T_INF ')' { new_reg(0, IR3_REG_IMMED)->fim_val = INFINITY; }
848 integer: T_INT { $$ = $1; }
849 | '-' T_INT { $$ = -$2; }
851 | '-' T_HEX { $$ = -$2; }
853 float: T_FLOAT { $$ = $1; }
854 | '-' T_FLOAT { $$ = -$2; }
856 type: T_TYPE_F16 { $$ = TYPE_F16; }
857 | T_TYPE_F32 { $$ = TYPE_F32; }
858 | T_TYPE_U16 { $$ = TYPE_U16; }
859 | T_TYPE_U32 { $$ = TYPE_U32; }
860 | T_TYPE_S16 { $$ = TYPE_S16; }
861 | T_TYPE_S32 { $$ = TYPE_S32; }
862 | T_TYPE_U8 { $$ = TYPE_U8; }
863 | T_TYPE_S8 { $$ = TYPE_S8; }