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