f12222e7a5cb8f5af39c047eec551c4c7719cb50
[mesa.git] / src / freedreno / computerator / ir3_parser.y
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
26 #define MAX_BUFS 4
27
28 struct ir3_kernel_info {
29 uint32_t local_size[3];
30 uint32_t num_bufs;
31 uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */
32
33 /* driver-param uniforms: */
34 unsigned numwg;
35 };
36
37 struct ir3 * ir3_parse(struct ir3_shader_variant *v,
38 struct ir3_kernel_info *k, FILE *f);
39 }
40
41 %{
42 #define YYDEBUG 0
43
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <math.h>
48
49 #include "util/u_math.h"
50
51 #include "ir3/ir3.h"
52 #include "ir3/ir3_shader.h"
53 #include "ir3/instr-a3xx.h"
54
55 #include "ir3_parser.h"
56
57 /* ir3 treats the abs/neg flags as separate flags for float vs integer,
58 * but in the instruction encoding they are the same thing. Tracking
59 * them separately is only for the benefit of ir3 opt passes, and not
60 * required here, so just use the float versions:
61 */
62 #define IR3_REG_ABS IR3_REG_FABS
63 #define IR3_REG_NEGATE IR3_REG_FNEG
64
65 static struct ir3_kernel_info *info;
66 static struct ir3_shader_variant *variant;
67 /* NOTE the assembler doesn't really use the ir3_block construction
68 * like the compiler does. Everything is treated as one large block.
69 * Which might happen to contain flow control. But since we don't
70 * use any of the ir3 backend passes (sched, RA, etc) this doesn't
71 * really matter.
72 */
73 static struct ir3_block *block; /* current shader block */
74 static struct ir3_instruction *instr; /* current instruction */
75
76 static struct {
77 unsigned flags;
78 unsigned repeat;
79 unsigned nop;
80 } iflags;
81
82 static struct {
83 unsigned flags;
84 unsigned wrmask;
85 } rflags;
86
87 int ir3_yyget_lineno(void);
88
89 static struct ir3_instruction * new_instr(opc_t opc)
90 {
91 instr = ir3_instr_create(block, opc);
92 instr->flags = iflags.flags;
93 instr->repeat = iflags.repeat;
94 instr->nop = iflags.nop;
95 instr->line = ir3_yyget_lineno();
96 iflags.flags = iflags.repeat = iflags.nop = 0;
97 return instr;
98 }
99
100 static void new_shader(void)
101 {
102 variant->ir = ir3_create(variant->shader->compiler, variant->shader->type);
103 block = ir3_block_create(variant->ir);
104 list_addtail(&block->node, &variant->ir->block_list);
105 }
106
107 static type_t parse_type(const char **type)
108 {
109 if (!strncmp("f16", *type, 3)) {
110 *type += 3;
111 return TYPE_F16;
112 } else if (!strncmp("f32", *type, 3)) {
113 *type += 3;
114 return TYPE_F32;
115 } else if (!strncmp("u16", *type, 3)) {
116 *type += 3;
117 return TYPE_U16;
118 } else if (!strncmp("u32", *type, 3)) {
119 *type += 3;
120 return TYPE_U32;
121 } else if (!strncmp("s16", *type, 3)) {
122 *type += 3;
123 return TYPE_S16;
124 } else if (!strncmp("s32", *type, 3)) {
125 *type += 3;
126 return TYPE_S32;
127 } else if (!strncmp("u8", *type, 2)) {
128 *type += 2;
129 return TYPE_U8;
130 } else if (!strncmp("s8", *type, 2)) {
131 *type += 2;
132 return TYPE_S8;
133 } else {
134 assert(0); /* shouldn't get here */
135 return ~0;
136 }
137 }
138
139 static struct ir3_instruction * parse_type_type(struct ir3_instruction *instr,
140 const char *type_type)
141 {
142 instr->cat1.src_type = parse_type(&type_type);
143 instr->cat1.dst_type = parse_type(&type_type);
144 return instr;
145 }
146
147 static struct ir3_register * new_reg(int num, unsigned flags)
148 {
149 struct ir3_register *reg;
150 flags |= rflags.flags;
151 if (num & 0x1)
152 flags |= IR3_REG_HALF;
153 reg = ir3_reg_create(instr, num>>1, flags);
154 reg->wrmask = MAX2(1, rflags.wrmask);
155 rflags.flags = rflags.wrmask = 0;
156 return reg;
157 }
158
159 static struct ir3_register * dummy_dst(void)
160 {
161 return new_reg(0, 0);
162 }
163
164 static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsigned c3)
165 {
166 struct ir3_const_state *const_state = &variant->shader->const_state;
167 assert((reg & 0x7) == 0);
168 int idx = reg >> (1 + 2); /* low bit is half vs full, next two bits are swiz */
169 if (const_state->immediate_idx == const_state->immediates_size * 4) {
170 const_state->immediates_size += 4;
171 const_state->immediates = realloc (const_state->immediates,
172 const_state->immediates_size * sizeof(const_state->immediates[0]));
173 }
174 const_state->immediates[idx].val[0] = c0;
175 const_state->immediates[idx].val[1] = c1;
176 const_state->immediates[idx].val[2] = c2;
177 const_state->immediates[idx].val[3] = c3;
178 const_state->immediates_count = idx + 1;
179 const_state->immediate_idx++;
180 }
181
182 static void add_sysval(unsigned reg, unsigned compmask, gl_system_value sysval)
183 {
184 unsigned n = variant->inputs_count++;
185 variant->inputs[n].regid = reg;
186 variant->inputs[n].sysval = true;
187 variant->inputs[n].slot = sysval;
188 variant->inputs[n].compmask = compmask;
189 variant->inputs[n].interpolate = INTERP_MODE_FLAT;
190 variant->total_in++;
191 }
192
193 #ifdef YYDEBUG
194 int yydebug;
195 #endif
196
197 extern int yylex(void);
198 extern FILE *ir3_yyin;
199
200 int yyparse(void);
201
202 static void yyerror(const char *error)
203 {
204 fprintf(stderr, "error at line %d: %s\n", ir3_yyget_lineno(), error);
205 }
206
207 struct ir3 * ir3_parse(struct ir3_shader_variant *v,
208 struct ir3_kernel_info *k, FILE *f)
209 {
210 ir3_yyin = f;
211 #ifdef YYDEBUG
212 yydebug = 1;
213 #endif
214 info = k;
215 variant = v;
216 if (yyparse()) {
217 ir3_destroy(variant->ir);
218 variant->ir = NULL;
219 }
220 return variant->ir;
221 }
222 %}
223
224 %union {
225 int tok;
226 int num;
227 uint32_t unum;
228 double flt;
229 const char *str;
230 struct ir3_register *reg;
231 struct {
232 int start;
233 int num;
234 } range;
235 type_t type;
236 }
237
238 %{
239 #if YYDEBUG
240 static void print_token(FILE *file, int type, YYSTYPE value)
241 {
242 fprintf(file, "\ntype: %d\n", type);
243 }
244
245 #define YYPRINT(file, type, value) print_token(file, type, value)
246 #endif
247 %}
248
249 %token <num> T_INT
250 %token <unum> T_HEX
251 %token <flt> T_FLOAT
252 %token <str> T_IDENTIFIER
253 %token <num> T_REGISTER
254 %token <num> T_CONSTANT
255
256 /* @ headers (@const/@sampler/@uniform/@varying) */
257 %token <tok> T_A_LOCALSIZE
258 %token <tok> T_A_CONST
259 %token <tok> T_A_BUF
260 %token <tok> T_A_INVOCATIONID
261 %token <tok> T_A_WGID
262 %token <tok> T_A_NUMWG
263 /* todo, re-add @sampler/@uniform/@varying if needed someday */
264
265 /* src register flags */
266 %token <tok> T_ABSNEG
267 %token <tok> T_NEG
268 %token <tok> T_ABS
269 %token <tok> T_R
270
271 /* dst register flags */
272 %token <tok> T_EVEN
273 %token <tok> T_POS_INFINITY
274 %token <tok> T_EI
275 %token <num> T_WRMASK
276
277 /* instruction flags */
278 %token <tok> T_SY
279 %token <tok> T_SS
280 %token <tok> T_JP
281 %token <num> T_RPT
282 %token <tok> T_UL
283 %token <tok> T_NOP
284
285 /* category 0: */
286 %token <tok> T_OP_NOP
287 %token <tok> T_OP_BR
288 %token <tok> T_OP_JUMP
289 %token <tok> T_OP_CALL
290 %token <tok> T_OP_RET
291 %token <tok> T_OP_KILL
292 %token <tok> T_OP_END
293 %token <tok> T_OP_EMIT
294 %token <tok> T_OP_CUT
295 %token <tok> T_OP_CHMASK
296 %token <tok> T_OP_CHSH
297 %token <tok> T_OP_FLOW_REV
298
299 /* category 1: */
300 %token <tok> T_OP_MOVA
301 %token <tok> T_OP_MOV
302 %token <tok> T_OP_COV
303
304 /* category 2: */
305 %token <tok> T_OP_ADD_F
306 %token <tok> T_OP_MIN_F
307 %token <tok> T_OP_MAX_F
308 %token <tok> T_OP_MUL_F
309 %token <tok> T_OP_SIGN_F
310 %token <tok> T_OP_CMPS_F
311 %token <tok> T_OP_ABSNEG_F
312 %token <tok> T_OP_CMPV_F
313 %token <tok> T_OP_FLOOR_F
314 %token <tok> T_OP_CEIL_F
315 %token <tok> T_OP_RNDNE_F
316 %token <tok> T_OP_RNDAZ_F
317 %token <tok> T_OP_TRUNC_F
318 %token <tok> T_OP_ADD_U
319 %token <tok> T_OP_ADD_S
320 %token <tok> T_OP_SUB_U
321 %token <tok> T_OP_SUB_S
322 %token <tok> T_OP_CMPS_U
323 %token <tok> T_OP_CMPS_S
324 %token <tok> T_OP_MIN_U
325 %token <tok> T_OP_MIN_S
326 %token <tok> T_OP_MAX_U
327 %token <tok> T_OP_MAX_S
328 %token <tok> T_OP_ABSNEG_S
329 %token <tok> T_OP_AND_B
330 %token <tok> T_OP_OR_B
331 %token <tok> T_OP_NOT_B
332 %token <tok> T_OP_XOR_B
333 %token <tok> T_OP_CMPV_U
334 %token <tok> T_OP_CMPV_S
335 %token <tok> T_OP_MUL_U24
336 %token <tok> T_OP_MUL_S24
337 %token <tok> T_OP_MULL_U
338 %token <tok> T_OP_BFREV_B
339 %token <tok> T_OP_CLZ_S
340 %token <tok> T_OP_CLZ_B
341 %token <tok> T_OP_SHL_B
342 %token <tok> T_OP_SHR_B
343 %token <tok> T_OP_ASHR_B
344 %token <tok> T_OP_BARY_F
345 %token <tok> T_OP_MGEN_B
346 %token <tok> T_OP_GETBIT_B
347 %token <tok> T_OP_SETRM
348 %token <tok> T_OP_CBITS_B
349 %token <tok> T_OP_SHB
350 %token <tok> T_OP_MSAD
351
352 /* category 3: */
353 %token <tok> T_OP_MAD_U16
354 %token <tok> T_OP_MADSH_U16
355 %token <tok> T_OP_MAD_S16
356 %token <tok> T_OP_MADSH_M16
357 %token <tok> T_OP_MAD_U24
358 %token <tok> T_OP_MAD_S24
359 %token <tok> T_OP_MAD_F16
360 %token <tok> T_OP_MAD_F32
361 %token <tok> T_OP_SEL_B16
362 %token <tok> T_OP_SEL_B32
363 %token <tok> T_OP_SEL_S16
364 %token <tok> T_OP_SEL_S32
365 %token <tok> T_OP_SEL_F16
366 %token <tok> T_OP_SEL_F32
367 %token <tok> T_OP_SAD_S16
368 %token <tok> T_OP_SAD_S32
369
370 /* category 4: */
371 %token <tok> T_OP_RCP
372 %token <tok> T_OP_RSQ
373 %token <tok> T_OP_LOG2
374 %token <tok> T_OP_EXP2
375 %token <tok> T_OP_SIN
376 %token <tok> T_OP_COS
377 %token <tok> T_OP_SQRT
378 %token <tok> T_OP_HRSQ
379 %token <tok> T_OP_HLOG2
380 %token <tok> T_OP_HEXP2
381
382 /* category 5: */
383 %token <tok> T_OP_ISAM
384 %token <tok> T_OP_ISAML
385 %token <tok> T_OP_ISAMM
386 %token <tok> T_OP_SAM
387 %token <tok> T_OP_SAMB
388 %token <tok> T_OP_SAML
389 %token <tok> T_OP_SAMGQ
390 %token <tok> T_OP_GETLOD
391 %token <tok> T_OP_CONV
392 %token <tok> T_OP_CONVM
393 %token <tok> T_OP_GETSIZE
394 %token <tok> T_OP_GETBUF
395 %token <tok> T_OP_GETPOS
396 %token <tok> T_OP_GETINFO
397 %token <tok> T_OP_DSX
398 %token <tok> T_OP_DSY
399 %token <tok> T_OP_GATHER4R
400 %token <tok> T_OP_GATHER4G
401 %token <tok> T_OP_GATHER4B
402 %token <tok> T_OP_GATHER4A
403 %token <tok> T_OP_SAMGP0
404 %token <tok> T_OP_SAMGP1
405 %token <tok> T_OP_SAMGP2
406 %token <tok> T_OP_SAMGP3
407 %token <tok> T_OP_DSXPP_1
408 %token <tok> T_OP_DSYPP_1
409 %token <tok> T_OP_RGETPOS
410 %token <tok> T_OP_RGETINFO
411
412 /* category 6: */
413 %token <tok> T_OP_LDG
414 %token <tok> T_OP_LDL
415 %token <tok> T_OP_LDP
416 %token <tok> T_OP_STG
417 %token <tok> T_OP_STL
418 %token <tok> T_OP_STP
419 %token <tok> T_OP_LDIB
420 %token <tok> T_OP_G2L
421 %token <tok> T_OP_L2G
422 %token <tok> T_OP_PREFETCH
423 %token <tok> T_OP_LDLW
424 %token <tok> T_OP_STLW
425 %token <tok> T_OP_RESFMT
426 %token <tok> T_OP_RESINF
427 %token <tok> T_OP_ATOMIC_ADD
428 %token <tok> T_OP_ATOMIC_SUB
429 %token <tok> T_OP_ATOMIC_XCHG
430 %token <tok> T_OP_ATOMIC_INC
431 %token <tok> T_OP_ATOMIC_DEC
432 %token <tok> T_OP_ATOMIC_CMPXCHG
433 %token <tok> T_OP_ATOMIC_MIN
434 %token <tok> T_OP_ATOMIC_MAX
435 %token <tok> T_OP_ATOMIC_AND
436 %token <tok> T_OP_ATOMIC_OR
437 %token <tok> T_OP_ATOMIC_XOR
438 %token <tok> T_OP_LDGB
439 %token <tok> T_OP_STGB
440 %token <tok> T_OP_STIB
441 %token <tok> T_OP_LDC
442 %token <tok> T_OP_LDLV
443
444 /* type qualifiers: */
445 %token <tok> T_TYPE_F16
446 %token <tok> T_TYPE_F32
447 %token <tok> T_TYPE_U16
448 %token <tok> T_TYPE_U32
449 %token <tok> T_TYPE_S16
450 %token <tok> T_TYPE_S32
451 %token <tok> T_TYPE_U8
452 %token <tok> T_TYPE_S8
453
454 %token <tok> T_UNTYPED
455 %token <tok> T_TYPED
456
457 %token <tok> T_1D
458 %token <tok> T_2D
459 %token <tok> T_3D
460 %token <tok> T_4D
461
462 /* condition qualifiers: */
463 %token <tok> T_LT
464 %token <tok> T_LE
465 %token <tok> T_GT
466 %token <tok> T_GE
467 %token <tok> T_EQ
468 %token <tok> T_NE
469
470 %token <tok> T_S2EN
471 %token <tok> T_SAMP
472 %token <tok> T_TEX
473 %token <tok> T_BASE
474
475 %token <tok> T_NAN
476 %token <tok> T_INF
477 %token <num> T_A0
478 %token <num> T_P0
479 %token <str> T_CAT1_TYPE_TYPE
480
481 %type <num> integer offset
482 %type <flt> float
483 %type <reg> reg const
484 %type <tok> cat1_opc
485 %type <tok> cat2_opc_1src cat2_opc_2src_cnd cat2_opc_2src
486 %type <tok> cat3_opc
487 %type <tok> cat4_opc
488 %type <tok> cat5_opc cat5_samp cat5_tex cat5_type
489 %type <type> type
490 %type <unum> const_val
491
492 %error-verbose
493
494 %start shader
495
496 %%
497
498 shader: { new_shader(); } headers instrs
499
500 headers:
501 | header headers
502
503 header: localsize_header
504 | const_header
505 | buf_header
506 | invocationid_header
507 | wgid_header
508 | numwg_header
509
510 const_val: T_FLOAT { $$ = fui($1); }
511 | T_INT { $$ = $1; }
512 | '-' T_INT { $$ = -$2; }
513 | T_HEX { $$ = $1; }
514
515 localsize_header: T_A_LOCALSIZE const_val ',' const_val ',' const_val {
516 info->local_size[0] = $2;
517 info->local_size[1] = $4;
518 info->local_size[2] = $6;
519 }
520
521 const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' const_val ',' const_val {
522 add_const($3, $5, $7, $9, $11);
523 }
524
525 buf_header: T_A_BUF const_val {
526 int idx = info->num_bufs++;
527 assert(idx < MAX_BUFS);
528 info->buf_sizes[idx] = $2;
529 }
530
531 invocationid_header: T_A_INVOCATIONID '(' T_REGISTER ')' {
532 assert(($3 & 0x1) == 0); /* half-reg not allowed */
533 unsigned reg = $3 >> 1;
534 add_sysval(reg, 0x7, SYSTEM_VALUE_LOCAL_INVOCATION_ID);
535 }
536
537 wgid_header: T_A_WGID '(' T_REGISTER ')' {
538 assert(($3 & 0x1) == 0); /* half-reg not allowed */
539 unsigned reg = $3 >> 1;
540 assert(reg >= regid(48, 0)); /* must be a high reg */
541 add_sysval(reg, 0x7, SYSTEM_VALUE_WORK_GROUP_ID);
542 }
543
544 numwg_header: T_A_NUMWG '(' T_CONSTANT ')' {
545 assert(($3 & 0x1) == 0); /* half-reg not allowed */
546 unsigned reg = $3 >> 1;
547 info->numwg = reg;
548 /* reserve space in immediates for the actual value to be plugged in later: */
549 add_const($3, 0, 0, 0, 0);
550 }
551
552 iflag: T_SY { iflags.flags |= IR3_INSTR_SY; }
553 | T_SS { iflags.flags |= IR3_INSTR_SS; }
554 | T_JP { iflags.flags |= IR3_INSTR_JP; }
555 | T_RPT { iflags.repeat = $1; }
556 | T_UL { iflags.flags |= IR3_INSTR_UL; }
557 | T_NOP { iflags.nop = $1; }
558
559 iflags:
560 | iflag iflags
561
562 instrs: instr instrs
563 | instr
564
565 instr: iflags cat0_instr
566 | iflags cat1_instr
567 | iflags cat2_instr
568 | iflags cat3_instr
569 | iflags cat4_instr
570 | iflags cat5_instr
571 | iflags cat6_instr
572
573 cat0_src: '!' T_P0 { instr->cat0.inv = true; instr->cat0.comp = $2 >> 1; }
574 | T_P0 { instr->cat0.comp = $1 >> 1; }
575
576 cat0_immed: '#' integer { instr->cat0.immed = $2; }
577
578 cat0_instr: T_OP_NOP { new_instr(OPC_NOP); }
579 | T_OP_BR { new_instr(OPC_BR); } cat0_src ',' cat0_immed
580 | T_OP_JUMP { new_instr(OPC_JUMP); } cat0_immed
581 | T_OP_CALL { new_instr(OPC_CALL); } cat0_immed
582 | T_OP_RET { new_instr(OPC_RET); }
583 | T_OP_KILL { new_instr(OPC_KILL); } cat0_src
584 | T_OP_END { new_instr(OPC_END); }
585 | T_OP_EMIT { new_instr(OPC_EMIT); }
586 | T_OP_CUT { new_instr(OPC_CUT); }
587 | T_OP_CHMASK { new_instr(OPC_CHMASK); }
588 | T_OP_CHSH { new_instr(OPC_CHSH); }
589 | T_OP_FLOW_REV { new_instr(OPC_FLOW_REV); }
590
591 cat1_opc: T_OP_MOVA {
592 new_instr(OPC_MOV);
593 instr->cat1.src_type = TYPE_S16;
594 instr->cat1.dst_type = TYPE_S16;
595 }
596 | T_OP_MOV '.' T_CAT1_TYPE_TYPE {
597 parse_type_type(new_instr(OPC_MOV), $3);
598 }
599 | T_OP_COV '.' T_CAT1_TYPE_TYPE {
600 parse_type_type(new_instr(OPC_MOV), $3);
601 }
602
603 cat1_instr: cat1_opc dst_reg ',' src_reg_or_const_or_rel_or_imm
604
605 cat2_opc_1src: T_OP_ABSNEG_F { new_instr(OPC_ABSNEG_F); }
606 | T_OP_ABSNEG_S { new_instr(OPC_ABSNEG_S); }
607 | T_OP_CLZ_B { new_instr(OPC_CLZ_B); }
608 | T_OP_CLZ_S { new_instr(OPC_CLZ_S); }
609 | T_OP_SIGN_F { new_instr(OPC_SIGN_F); }
610 | T_OP_FLOOR_F { new_instr(OPC_FLOOR_F); }
611 | T_OP_CEIL_F { new_instr(OPC_CEIL_F); }
612 | T_OP_RNDNE_F { new_instr(OPC_RNDNE_F); }
613 | T_OP_RNDAZ_F { new_instr(OPC_RNDAZ_F); }
614 | T_OP_TRUNC_F { new_instr(OPC_TRUNC_F); }
615 | T_OP_NOT_B { new_instr(OPC_NOT_B); }
616 | T_OP_BFREV_B { new_instr(OPC_BFREV_B); }
617 | T_OP_SETRM { new_instr(OPC_SETRM); }
618 | T_OP_CBITS_B { new_instr(OPC_CBITS_B); }
619
620 cat2_opc_2src_cnd: T_OP_CMPS_F { new_instr(OPC_CMPS_F); }
621 | T_OP_CMPS_U { new_instr(OPC_CMPS_U); }
622 | T_OP_CMPS_S { new_instr(OPC_CMPS_S); }
623 | T_OP_CMPV_F { new_instr(OPC_CMPV_F); }
624 | T_OP_CMPV_U { new_instr(OPC_CMPV_U); }
625 | T_OP_CMPV_S { new_instr(OPC_CMPV_S); }
626
627 cat2_opc_2src: T_OP_ADD_F { new_instr(OPC_ADD_F); }
628 | T_OP_MIN_F { new_instr(OPC_MIN_F); }
629 | T_OP_MAX_F { new_instr(OPC_MAX_F); }
630 | T_OP_MUL_F { new_instr(OPC_MUL_F); }
631 | T_OP_ADD_U { new_instr(OPC_ADD_U); }
632 | T_OP_ADD_S { new_instr(OPC_ADD_S); }
633 | T_OP_SUB_U { new_instr(OPC_SUB_U); }
634 | T_OP_SUB_S { new_instr(OPC_SUB_S); }
635 | T_OP_MIN_U { new_instr(OPC_MIN_U); }
636 | T_OP_MIN_S { new_instr(OPC_MIN_S); }
637 | T_OP_MAX_U { new_instr(OPC_MAX_U); }
638 | T_OP_MAX_S { new_instr(OPC_MAX_S); }
639 | T_OP_AND_B { new_instr(OPC_AND_B); }
640 | T_OP_OR_B { new_instr(OPC_OR_B); }
641 | T_OP_XOR_B { new_instr(OPC_XOR_B); }
642 | T_OP_MUL_U24 { new_instr(OPC_MUL_U24); }
643 | T_OP_MUL_S24 { new_instr(OPC_MUL_S24); }
644 | T_OP_MULL_U { new_instr(OPC_MULL_U); }
645 | T_OP_SHL_B { new_instr(OPC_SHL_B); }
646 | T_OP_SHR_B { new_instr(OPC_SHR_B); }
647 | T_OP_ASHR_B { new_instr(OPC_ASHR_B); }
648 | T_OP_BARY_F { new_instr(OPC_BARY_F); }
649 | T_OP_MGEN_B { new_instr(OPC_MGEN_B); }
650 | T_OP_GETBIT_B { new_instr(OPC_GETBIT_B); }
651 | T_OP_SHB { new_instr(OPC_SHB); }
652 | T_OP_MSAD { new_instr(OPC_MSAD); }
653
654 cond: T_LT { instr->cat2.condition = IR3_COND_LT; }
655 | T_LE { instr->cat2.condition = IR3_COND_LE; }
656 | T_GT { instr->cat2.condition = IR3_COND_GT; }
657 | T_GE { instr->cat2.condition = IR3_COND_GE; }
658 | T_EQ { instr->cat2.condition = IR3_COND_EQ; }
659 | T_NE { instr->cat2.condition = IR3_COND_NE; }
660
661 cat2_instr: cat2_opc_1src dst_reg ',' src_reg_or_const_or_rel_or_imm
662 | cat2_opc_2src_cnd '.' cond dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
663 | cat2_opc_2src dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm
664
665 cat3_opc: T_OP_MAD_U16 { new_instr(OPC_MAD_U16); }
666 | T_OP_MADSH_U16 { new_instr(OPC_MADSH_U16); }
667 | T_OP_MAD_S16 { new_instr(OPC_MAD_S16); }
668 | T_OP_MADSH_M16 { new_instr(OPC_MADSH_M16); }
669 | T_OP_MAD_U24 { new_instr(OPC_MAD_U24); }
670 | T_OP_MAD_S24 { new_instr(OPC_MAD_S24); }
671 | T_OP_MAD_F16 { new_instr(OPC_MAD_F16); }
672 | T_OP_MAD_F32 { new_instr(OPC_MAD_F32); }
673 | T_OP_SEL_B16 { new_instr(OPC_SEL_B16); }
674 | T_OP_SEL_B32 { new_instr(OPC_SEL_B32); }
675 | T_OP_SEL_S16 { new_instr(OPC_SEL_S16); }
676 | T_OP_SEL_S32 { new_instr(OPC_SEL_S32); }
677 | T_OP_SEL_F16 { new_instr(OPC_SEL_F16); }
678 | T_OP_SEL_F32 { new_instr(OPC_SEL_F32); }
679 | T_OP_SAD_S16 { new_instr(OPC_SAD_S16); }
680 | T_OP_SAD_S32 { new_instr(OPC_SAD_S32); }
681
682 cat3_instr: cat3_opc dst_reg ',' src_reg_or_const_or_rel ',' src_reg_or_const ',' src_reg_or_const_or_rel
683
684 cat4_opc: T_OP_RCP { new_instr(OPC_RCP); }
685 | T_OP_RSQ { new_instr(OPC_RSQ); }
686 | T_OP_LOG2 { new_instr(OPC_LOG2); }
687 | T_OP_EXP2 { new_instr(OPC_EXP2); }
688 | T_OP_SIN { new_instr(OPC_SIN); }
689 | T_OP_COS { new_instr(OPC_COS); }
690 | T_OP_SQRT { new_instr(OPC_SQRT); }
691 | T_OP_HRSQ { new_instr(OPC_HRSQ); }
692 | T_OP_HLOG2 { new_instr(OPC_HLOG2); }
693 | T_OP_HEXP2 { new_instr(OPC_HEXP2); }
694
695 cat4_instr: cat4_opc dst_reg ',' src_reg_or_const_or_rel_or_imm
696
697 cat5_opc_dsxypp: T_OP_DSXPP_1 { new_instr(OPC_DSXPP_1); }
698 | T_OP_DSYPP_1 { new_instr(OPC_DSYPP_1); }
699
700 cat5_opc: T_OP_ISAM { new_instr(OPC_ISAM); }
701 | T_OP_ISAML { new_instr(OPC_ISAML); }
702 | T_OP_ISAMM { new_instr(OPC_ISAMM); }
703 | T_OP_SAM { new_instr(OPC_SAM); }
704 | T_OP_SAMB { new_instr(OPC_SAMB); }
705 | T_OP_SAML { new_instr(OPC_SAML); }
706 | T_OP_SAMGQ { new_instr(OPC_SAMGQ); }
707 | T_OP_GETLOD { new_instr(OPC_GETLOD); }
708 | T_OP_CONV { new_instr(OPC_CONV); }
709 | T_OP_CONVM { new_instr(OPC_CONVM); }
710 | T_OP_GETSIZE { new_instr(OPC_GETSIZE); }
711 | T_OP_GETBUF { new_instr(OPC_GETBUF); }
712 | T_OP_GETPOS { new_instr(OPC_GETPOS); }
713 | T_OP_GETINFO { new_instr(OPC_GETINFO); }
714 | T_OP_DSX { new_instr(OPC_DSX); }
715 | T_OP_DSY { new_instr(OPC_DSY); }
716 | T_OP_GATHER4R { new_instr(OPC_GATHER4R); }
717 | T_OP_GATHER4G { new_instr(OPC_GATHER4G); }
718 | T_OP_GATHER4B { new_instr(OPC_GATHER4B); }
719 | T_OP_GATHER4A { new_instr(OPC_GATHER4A); }
720 | T_OP_SAMGP0 { new_instr(OPC_SAMGP0); }
721 | T_OP_SAMGP1 { new_instr(OPC_SAMGP1); }
722 | T_OP_SAMGP2 { new_instr(OPC_SAMGP2); }
723 | T_OP_SAMGP3 { new_instr(OPC_SAMGP3); }
724 | T_OP_RGETPOS { new_instr(OPC_RGETPOS); }
725 | T_OP_RGETINFO { new_instr(OPC_RGETINFO); }
726
727 cat5_flag: '.' T_3D { instr->flags |= IR3_INSTR_3D; }
728 | '.' 'a' { instr->flags |= IR3_INSTR_A; }
729 | '.' 'o' { instr->flags |= IR3_INSTR_O; }
730 | '.' 'p' { instr->flags |= IR3_INSTR_P; }
731 | '.' 's' { instr->flags |= IR3_INSTR_S; }
732 | '.' T_S2EN { instr->flags |= IR3_INSTR_S2EN; }
733 | '.' T_BASE { instr->flags |= IR3_INSTR_B; instr->cat5.tex_base = $2; }
734 cat5_flags:
735 | cat5_flag cat5_flags
736
737 cat5_samp: T_SAMP { instr->cat5.samp = $1; }
738 cat5_tex: T_TEX { if (instr->flags & IR3_INSTR_B) instr->cat5.samp |= ($1 << 4); else instr->cat5.tex = $1; }
739 cat5_type: '(' type ')' { instr->cat5.type = $2; }
740
741 cat5_instr: cat5_opc_dsxypp cat5_flags dst_reg ',' src_reg
742 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp ',' cat5_tex
743 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp
744 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_tex
745 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg
746 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp ',' cat5_tex
747 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp
748 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_tex
749 | cat5_opc cat5_flags cat5_type dst_reg ',' src_reg
750 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp ',' cat5_tex
751 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp
752 | cat5_opc cat5_flags cat5_type dst_reg ',' cat5_tex
753 | cat5_opc cat5_flags cat5_type dst_reg
754
755 cat6_typed: '.' T_UNTYPED { instr->cat6.typed = 0; }
756 | '.' T_TYPED { instr->cat6.typed = 1; }
757
758 cat6_dim: '.' T_1D { instr->cat6.d = 1; }
759 | '.' T_2D { instr->cat6.d = 2; }
760 | '.' T_3D { instr->cat6.d = 3; }
761 | '.' T_4D { instr->cat6.d = 4; }
762
763 cat6_type: '.' type { instr->cat6.type = $2; }
764 cat6_offset: offset { instr->cat6.src_offset = $1; }
765 cat6_immed: integer { instr->cat6.iim_val = $1; }
766
767 cat6_load: T_OP_LDG { new_instr(OPC_LDG); } cat6_type dst_reg ',' 'g' '[' reg cat6_offset ']' ',' cat6_immed
768 | T_OP_LDP { new_instr(OPC_LDP); } cat6_type dst_reg ',' 'p' '[' reg cat6_offset ']' ',' cat6_immed
769 | T_OP_LDL { new_instr(OPC_LDL); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
770 | T_OP_LDLW { new_instr(OPC_LDLW); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
771 | T_OP_LDLV { new_instr(OPC_LDLV); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
772
773 // TODO some of the cat6 instructions have different syntax for a6xx..
774 //| T_OP_LDIB { new_instr(OPC_LDIB); } cat6_type dst_reg cat6_offset ',' reg ',' cat6_immed
775
776 cat6_store: T_OP_STG { new_instr(OPC_STG); } cat6_type 'g' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
777 | T_OP_STP { new_instr(OPC_STP); } cat6_type 'p' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
778 | T_OP_STL { new_instr(OPC_STL); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
779 | T_OP_STLW { new_instr(OPC_STLW); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed
780
781 cat6_storeib: T_OP_STIB { new_instr(OPC_STIB); dummy_dst(); } cat6_typed cat6_dim cat6_type '.' cat6_immed'g' '[' immediate ']' '+' reg ',' reg
782
783 cat6_prefetch: T_OP_PREFETCH { new_instr(OPC_PREFETCH); new_reg(0,0); /* dummy dst */ } 'g' '[' reg cat6_offset ']' ',' cat6_immed
784
785 cat6_atomic_l_g: '.' 'g' { instr->flags |= IR3_INSTR_G; }
786 | '.' 'l' { }
787
788 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
789 | T_OP_ATOMIC_SUB { new_instr(OPC_ATOMIC_SUB); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
790 | T_OP_ATOMIC_XCHG { new_instr(OPC_ATOMIC_XCHG); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
791 | T_OP_ATOMIC_INC { new_instr(OPC_ATOMIC_INC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
792 | T_OP_ATOMIC_DEC { new_instr(OPC_ATOMIC_DEC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
793 | T_OP_ATOMIC_CMPXCHG { new_instr(OPC_ATOMIC_CMPXCHG); }cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
794 | T_OP_ATOMIC_MIN { new_instr(OPC_ATOMIC_MIN); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
795 | T_OP_ATOMIC_MAX { new_instr(OPC_ATOMIC_MAX); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
796 | T_OP_ATOMIC_AND { new_instr(OPC_ATOMIC_AND); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
797 | T_OP_ATOMIC_OR { new_instr(OPC_ATOMIC_OR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
798 | T_OP_ATOMIC_XOR { new_instr(OPC_ATOMIC_XOR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed
799
800 cat6_todo: T_OP_G2L { new_instr(OPC_G2L); }
801 | T_OP_L2G { new_instr(OPC_L2G); }
802 | T_OP_RESFMT { new_instr(OPC_RESFMT); }
803 | T_OP_RESINF { new_instr(OPC_RESINFO); }
804 | T_OP_LDGB { new_instr(OPC_LDGB); }
805 | T_OP_STGB { new_instr(OPC_STGB); }
806 | T_OP_LDC { new_instr(OPC_LDC); }
807
808 cat6_instr: cat6_load
809 | cat6_store
810 | cat6_storeib
811 | cat6_prefetch
812 | cat6_atomic
813 | cat6_todo
814
815 reg: T_REGISTER { $$ = new_reg($1, 0); }
816 | T_A0 { $$ = new_reg((61 << 3) + $1, IR3_REG_HALF); }
817 | T_P0 { $$ = new_reg((62 << 3) + $1, 0); }
818
819 const: T_CONSTANT { $$ = new_reg($1, IR3_REG_CONST); }
820
821 dst_reg_flag: T_EVEN { rflags.flags |= IR3_REG_EVEN; }
822 | T_POS_INFINITY { rflags.flags |= IR3_REG_POS_INF; }
823 | T_EI { rflags.flags |= IR3_REG_EI; }
824 | T_WRMASK { rflags.wrmask = $1; }
825
826 dst_reg_flags: dst_reg_flag
827 | dst_reg_flag dst_reg_flags
828
829 /* note: destination registers are always incremented in repeat */
830 dst_reg: reg { $1->flags |= IR3_REG_R; }
831 | dst_reg_flags reg { $2->flags |= IR3_REG_R; }
832
833 src_reg_flag: T_ABSNEG { rflags.flags |= IR3_REG_ABS|IR3_REG_NEGATE; }
834 | T_NEG { rflags.flags |= IR3_REG_NEGATE; }
835 | T_ABS { rflags.flags |= IR3_REG_ABS; }
836 | T_R { rflags.flags |= IR3_REG_R; }
837
838 src_reg_flags: src_reg_flag
839 | src_reg_flag src_reg_flags
840
841 src_reg: reg
842 | src_reg_flags reg
843
844 src_const: const
845 | src_reg_flags const
846
847 src_reg_or_const: src_reg
848 | src_const
849
850 src_reg_or_const_or_rel: src_reg_or_const
851 | relative
852
853 src_reg_or_const_or_rel_or_imm: src_reg_or_const_or_rel
854 | src_reg_flags immediate
855 | immediate
856
857 offset: { $$ = 0; }
858 | '+' integer { $$ = $2; }
859 | '-' integer { $$ = -$2; }
860
861 relative: 'r' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV)->array.offset = $4; }
862 | 'c' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV | IR3_REG_CONST)->array.offset = $4; }
863
864 immediate: integer { new_reg(0, IR3_REG_IMMED)->iim_val = $1; }
865 | '(' integer ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; }
866 | '(' float ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; }
867 | '(' T_NAN ')' { new_reg(0, IR3_REG_IMMED)->fim_val = NAN; }
868 | '(' T_INF ')' { new_reg(0, IR3_REG_IMMED)->fim_val = INFINITY; }
869
870 integer: T_INT { $$ = $1; }
871 | '-' T_INT { $$ = -$2; }
872 | T_HEX { $$ = $1; }
873 | '-' T_HEX { $$ = -$2; }
874
875 float: T_FLOAT { $$ = $1; }
876 | '-' T_FLOAT { $$ = -$2; }
877
878 type: T_TYPE_F16 { $$ = TYPE_F16; }
879 | T_TYPE_F32 { $$ = TYPE_F32; }
880 | T_TYPE_U16 { $$ = TYPE_U16; }
881 | T_TYPE_U32 { $$ = TYPE_U32; }
882 | T_TYPE_S16 { $$ = TYPE_S16; }
883 | T_TYPE_S32 { $$ = TYPE_S32; }
884 | T_TYPE_U8 { $$ = TYPE_U8; }
885 | T_TYPE_S8 { $$ = TYPE_S8; }