From 3bb340cf4f21e12407720b7f46d2c4486a1ff2a5 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 21 Feb 2020 14:31:39 -0800 Subject: [PATCH] freedreno/computerator: import parser/lexer from fdre-a3xx Import the rusty old parser from freedreno.git Signed-off-by: Rob Clark Part-of: --- src/freedreno/computerator/ir3_lexer.l | 308 ++++++++++ src/freedreno/computerator/ir3_parser.y | 777 ++++++++++++++++++++++++ 2 files changed, 1085 insertions(+) create mode 100644 src/freedreno/computerator/ir3_lexer.l create mode 100644 src/freedreno/computerator/ir3_parser.y diff --git a/src/freedreno/computerator/ir3_lexer.l b/src/freedreno/computerator/ir3_lexer.l new file mode 100644 index 00000000000..84c025f6a0a --- /dev/null +++ b/src/freedreno/computerator/ir3_lexer.l @@ -0,0 +1,308 @@ +/* + * Copyright (c) 2013 Rob Clark + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +%{ +#include +#include "instr-a3xx.h" +#include "parser.h" +#include "util.h" + +#define TOKEN(t) (asm_yylval.tok = t) +extern YYSTYPE asm_yylval; + +static int parse_wrmask(const char *src) +{ + int i, num = 0; + for (i = 0; i < 4; i++) { + if ("xyzw"[i] == src[1]) { + num |= (1 << i); + src++; + } + } + return num; +} + +static int parse_reg(const char *str) +{ + int num = 0; + if (str[0] == 'h') { + str++; + num++; + } + str++; + num += strtol(str, &str, 10) << 3; + switch (str[1]) { + case 'x': num += 0; break; + case 'y': num += 2; break; + case 'z': num += 4; break; + case 'w': num += 6; break; + default: assert(0); break; + } + return num; +} +%} + +%option noyywrap +%option prefix="asm_yy" + +%% +"\n" yylineno++; +[ \t] ; /* ignore whitespace */ +";"[^\n]*"\n" yylineno++; /* ignore comments */ +[0-9]+"."[0-9]+ asm_yylval.flt = strtod(yytext, NULL); return T_FLOAT; +[0-9]* asm_yylval.num = strtoul(yytext, NULL, 0); return T_INT; +"0x"[0-9a-fA-F]* asm_yylval.num = strtoul(yytext, NULL, 0); return T_HEX; +"@attribute" return TOKEN(T_A_ATTRIBUTE); +"@const" return TOKEN(T_A_CONST); +"@sampler" return TOKEN(T_A_SAMPLER); +"@uniform" return TOKEN(T_A_UNIFORM); +"@varying" return TOKEN(T_A_VARYING); +"@buf" return TOKEN(T_A_BUF); +"@out" return TOKEN(T_A_OUT); +"(sy)" return TOKEN(T_SY); +"(ss)" return TOKEN(T_SS); +"(absneg)" return TOKEN(T_ABSNEG); +"(neg)" return TOKEN(T_NEG); +"(abs)" return TOKEN(T_ABS); +"(r)" return TOKEN(T_R); +"(ul)" return TOKEN(T_UL); +"(even)" return TOKEN(T_EVEN); +"(pos_infinity)" return TOKEN(T_POS_INFINITY); +"(ei)" return TOKEN(T_EI); +"(jp)" return TOKEN(T_JP); +"(rpt"[0-7]")" asm_yylval.num = strtol(yytext+4, NULL, 10); return T_RPT; +"("[x]?[y]?[z]?[w]?")" asm_yylval.num = parse_wrmask(yytext); return T_WRMASK; + +[h]?"r"[0-9]+"."[xyzw] asm_yylval.num = parse_reg(yytext); return T_REGISTER; +[h]?"c"[0-9]+"."[xyzw] asm_yylval.num = parse_reg(yytext); return T_CONSTANT; +"a0."[xyzw] asm_yylval.num = parse_reg(yytext); return T_A0; +"p0."[xyzw] asm_yylval.num = parse_reg(yytext); return T_P0; +"s#"[0-9]+ asm_yylval.num = strtol(yytext+2, NULL, 10); return T_SAMP; +"t#"[0-9]+ asm_yylval.num = strtol(yytext+2, NULL, 10); return T_TEX; + + /* category 0: */ +"nop" return TOKEN(T_OP_NOP); +"br" return TOKEN(T_OP_BR); +"jump" return TOKEN(T_OP_JUMP); +"call" return TOKEN(T_OP_CALL); +"ret" return TOKEN(T_OP_RET); +"kill" return TOKEN(T_OP_KILL); +"end" return TOKEN(T_OP_END); +"emit" return TOKEN(T_OP_EMIT); +"cut" return TOKEN(T_OP_CUT); +"chmask" return TOKEN(T_OP_CHMASK); +"chsh" return TOKEN(T_OP_CHSH); +"flow_rev" return TOKEN(T_OP_FLOW_REV); + + /* category 1: */ +"mova" return TOKEN(T_OP_MOVA); +"mov" return TOKEN(T_OP_MOV); +"cov" return TOKEN(T_OP_COV); + +("f16"|"f32"|"u16"|"u32"|"s16"|"s32"|"u8"|"s8"){2} asm_yylval.str = yytext; return T_CAT1_TYPE_TYPE; + + /* category 2: */ +"add.f" return TOKEN(T_OP_ADD_F); +"min.f" return TOKEN(T_OP_MIN_F); +"max.f" return TOKEN(T_OP_MAX_F); +"mul.f" return TOKEN(T_OP_MUL_F); +"sign.f" return TOKEN(T_OP_SIGN_F); +"cmps.f" return TOKEN(T_OP_CMPS_F); +"absneg.f" return TOKEN(T_OP_ABSNEG_F); +"cmpv.f" return TOKEN(T_OP_CMPV_F); +"floor.f" return TOKEN(T_OP_FLOOR_F); +"ceil.f" return TOKEN(T_OP_CEIL_F); +"rndne.f" return TOKEN(T_OP_RNDNE_F); +"rndaz.f" return TOKEN(T_OP_RNDAZ_F); +"trunc.f" return TOKEN(T_OP_TRUNC_F); +"add.u" return TOKEN(T_OP_ADD_U); +"add.s" return TOKEN(T_OP_ADD_S); +"sub.u" return TOKEN(T_OP_SUB_U); +"sub.s" return TOKEN(T_OP_SUB_S); +"cmps.u" return TOKEN(T_OP_CMPS_U); +"cmps.s" return TOKEN(T_OP_CMPS_S); +"min.u" return TOKEN(T_OP_MIN_U); +"min.s" return TOKEN(T_OP_MIN_S); +"max.u" return TOKEN(T_OP_MAX_U); +"max.s" return TOKEN(T_OP_MAX_S); +"absneg.s" return TOKEN(T_OP_ABSNEG_S); +"and.b" return TOKEN(T_OP_AND_B); +"or.b" return TOKEN(T_OP_OR_B); +"not.b" return TOKEN(T_OP_NOT_B); +"xor.b" return TOKEN(T_OP_XOR_B); +"cmpv.u" return TOKEN(T_OP_CMPV_U); +"cmpv.s" return TOKEN(T_OP_CMPV_S); +"mul.u" return TOKEN(T_OP_MUL_U); +"mul.s" return TOKEN(T_OP_MUL_S); +"mull.u" return TOKEN(T_OP_MULL_U); +"bfrev.b" return TOKEN(T_OP_BFREV_B); +"clz.s" return TOKEN(T_OP_CLZ_S); +"clz.b" return TOKEN(T_OP_CLZ_B); +"shl.b" return TOKEN(T_OP_SHL_B); +"shr.b" return TOKEN(T_OP_SHR_B); +"ashr.b" return TOKEN(T_OP_ASHR_B); +"bary.f" return TOKEN(T_OP_BARY_F); +"mgen.b" return TOKEN(T_OP_MGEN_B); +"getbit.b" return TOKEN(T_OP_GETBIT_B); +"setrm" return TOKEN(T_OP_SETRM); +"cbits.b" return TOKEN(T_OP_CBITS_B); +"shb" return TOKEN(T_OP_SHB); +"msad" return TOKEN(T_OP_MSAD); + + /* category 3: */ +"mad.u16" return TOKEN(T_OP_MAD_U16); +"madsh.u16" return TOKEN(T_OP_MADSH_U16); +"mad.s16" return TOKEN(T_OP_MAD_S16); +"madsh.m16" return TOKEN(T_OP_MADSH_M16); +"mad.u24" return TOKEN(T_OP_MAD_U24); +"mad.s24" return TOKEN(T_OP_MAD_S24); +"mad.f16" return TOKEN(T_OP_MAD_F16); +"mad.f32" return TOKEN(T_OP_MAD_F32); +"sel.b16" return TOKEN(T_OP_SEL_B16); +"sel.b32" return TOKEN(T_OP_SEL_B32); +"sel.s16" return TOKEN(T_OP_SEL_S16); +"sel.s32" return TOKEN(T_OP_SEL_S32); +"sel.f16" return TOKEN(T_OP_SEL_F16); +"sel.f32" return TOKEN(T_OP_SEL_F32); +"sad.s16" return TOKEN(T_OP_SAD_S16); +"sad.s32" return TOKEN(T_OP_SAD_S32); + + /* category 4: */ +"rcp" return TOKEN(T_OP_RCP); +"rsq" return TOKEN(T_OP_RSQ); +"log2" return TOKEN(T_OP_LOG2); +"exp2" return TOKEN(T_OP_EXP2); +"sin" return TOKEN(T_OP_SIN); +"cos" return TOKEN(T_OP_COS); +"sqrt" return TOKEN(T_OP_SQRT); + + /* category 5: */ +"isam" return TOKEN(T_OP_ISAM); +"isaml" return TOKEN(T_OP_ISAML); +"isamm" return TOKEN(T_OP_ISAMM); +"sam" return TOKEN(T_OP_SAM); +"samb" return TOKEN(T_OP_SAMB); +"saml" return TOKEN(T_OP_SAML); +"samgq" return TOKEN(T_OP_SAMGQ); +"getlod" return TOKEN(T_OP_GETLOD); +"conv" return TOKEN(T_OP_CONV); +"convm" return TOKEN(T_OP_CONVM); +"getsize" return TOKEN(T_OP_GETSIZE); +"getbuf" return TOKEN(T_OP_GETBUF); +"getpos" return TOKEN(T_OP_GETPOS); +"getinfo" return TOKEN(T_OP_GETINFO); +"dsx" return TOKEN(T_OP_DSX); +"dsy" return TOKEN(T_OP_DSY); +"gather4r" return TOKEN(T_OP_GATHER4R); +"gather4g" return TOKEN(T_OP_GATHER4G); +"gather4b" return TOKEN(T_OP_GATHER4B); +"gather4a" return TOKEN(T_OP_GATHER4A); +"samgp0" return TOKEN(T_OP_SAMGP0); +"samgp1" return TOKEN(T_OP_SAMGP1); +"samgp2" return TOKEN(T_OP_SAMGP2); +"samgp3" return TOKEN(T_OP_SAMGP3); +"dsxpp.1" return TOKEN(T_OP_DSXPP_1); +"dsypp.1" return TOKEN(T_OP_DSYPP_1); +"rgetpos" return TOKEN(T_OP_RGETPOS); +"rgetinfo" return TOKEN(T_OP_RGETINFO); + + /* category 6: */ +"ldg" return TOKEN(T_OP_LDG); +"ldl" return TOKEN(T_OP_LDL); +"ldp" return TOKEN(T_OP_LDP); +"stg" return TOKEN(T_OP_STG); +"stl" return TOKEN(T_OP_STL); +"stp" return TOKEN(T_OP_STP); +"sti" return TOKEN(T_OP_STI); +"g2l" return TOKEN(T_OP_G2L); +"l2g" return TOKEN(T_OP_L2G); +"prefetch" return TOKEN(T_OP_PREFETCH); +"ldlw" return TOKEN(T_OP_LDLW); +"stlw" return TOKEN(T_OP_STLW); +"resfmt" return TOKEN(T_OP_RESFMT); +"resinf" return TOKEN(T_OP_RESINF); +"atomic.add" return TOKEN(T_OP_ATOMIC_ADD); +"atomic.sub" return TOKEN(T_OP_ATOMIC_SUB); +"atomic.xchg" return TOKEN(T_OP_ATOMIC_XCHG); +"atomic.inc" return TOKEN(T_OP_ATOMIC_INC); +"atomic.dec" return TOKEN(T_OP_ATOMIC_DEC); +"atomic.cmpxchg" return TOKEN(T_OP_ATOMIC_CMPXCHG); +"atomic.min" return TOKEN(T_OP_ATOMIC_MIN); +"atomic.max" return TOKEN(T_OP_ATOMIC_MAX); +"atomic.and" return TOKEN(T_OP_ATOMIC_AND); +"atomic.or" return TOKEN(T_OP_ATOMIC_OR); +"atomic.xor" return TOKEN(T_OP_ATOMIC_XOR); +"ldgb.typed.4d" return TOKEN(T_OP_LDGB_TYPED_4D); +"stgb.4d.4" return TOKEN(T_OP_STGB_4D_4); +"stib" return TOKEN(T_OP_STIB); +"ldc.4" return TOKEN(T_OP_LDC_4); +"ldlv" return TOKEN(T_OP_LDLV); + +"f16" return TOKEN(T_TYPE_F16); +"f32" return TOKEN(T_TYPE_F32); +"u16" return TOKEN(T_TYPE_U16); +"u32" return TOKEN(T_TYPE_U32); +"s16" return TOKEN(T_TYPE_S16); +"s32" return TOKEN(T_TYPE_S32); +"u8" return TOKEN(T_TYPE_U8); +"s8" return TOKEN(T_TYPE_S8); + +"lt" return TOKEN(T_LT); +"le" return TOKEN(T_LE); +"gt" return TOKEN(T_GT); +"ge" return TOKEN(T_GE); +"eq" return TOKEN(T_EQ); +"ne" return TOKEN(T_NE); + +"3d" return TOKEN(T_3D); +"a" return 'a'; +"o" return 'o'; +"p" return 'p'; +"s2en" return TOKEN(T_S2EN); +"s" return 's'; + +"=" return '='; +"(" return '('; +")" return ')'; +"[" return '['; +"]" return ']'; +"," return ','; +"." return '.'; +"-" return '-'; +"+" return '+'; +"|" return '|'; +"c" return 'c'; +"r" return 'r'; +"g" return 'g'; +"l" return 'l'; +"<" return '<'; +">" return '>'; +"!" return '!'; +"#" return '#'; + +"nan" return TOKEN(T_NAN); +"inf" return TOKEN(T_INF); + +[a-zA-Z_][a-zA-Z_0-9]* asm_yylval.str = yytext; return T_IDENTIFIER; +. fprintf(stderr, "error at line %d: Unknown token: %s\n", asm_yyget_lineno(), yytext); yyterminate(); +%% diff --git a/src/freedreno/computerator/ir3_parser.y b/src/freedreno/computerator/ir3_parser.y new file mode 100644 index 00000000000..b71a368f664 --- /dev/null +++ b/src/freedreno/computerator/ir3_parser.y @@ -0,0 +1,777 @@ +/* + * Copyright (c) 2013 Rob Clark + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +%{ +#define YYDEBUG 0 + +#include +#include +#include +#include + +#include "ir-a3xx.h" +#include "instr-a3xx.h" + +static struct ir3_shader *shader; /* current shader program */ +static struct ir3_instruction *instr; /* current instruction */ + +static struct { + unsigned flags; + unsigned repeat; +} iflags; + +static struct { + unsigned flags; + unsigned wrmask; +} rflags; + +int asm_yyget_lineno(void); + +static struct ir3_instruction * new_instr(int cat, opc_t opc) +{ + instr = ir3_instr_create(shader, cat, opc); + instr->flags = iflags.flags; + instr->repeat = iflags.repeat; + instr->line = asm_yyget_lineno(); + iflags.flags = iflags.repeat = 0; + return instr; +} + +static type_t parse_type(const char **type) +{ + if (!strncmp("f16", *type, 3)) { + *type += 3; + return TYPE_F16; + } else if (!strncmp("f32", *type, 3)) { + *type += 3; + return TYPE_F32; + } else if (!strncmp("u16", *type, 3)) { + *type += 3; + return TYPE_U16; + } else if (!strncmp("u32", *type, 3)) { + *type += 3; + return TYPE_U32; + } else if (!strncmp("s16", *type, 3)) { + *type += 3; + return TYPE_S16; + } else if (!strncmp("s32", *type, 3)) { + *type += 3; + return TYPE_S32; + } else if (!strncmp("u8", *type, 2)) { + *type += 2; + return TYPE_U8; + } else if (!strncmp("s8", *type, 2)) { + *type += 2; + return TYPE_S8; + } else { + assert(0); /* shouldn't get here */ + return ~0; + } +} + +static struct ir3_instruction * parse_type_type(struct ir3_instruction *instr, + const char *type_type) +{ + instr->cat1.src_type = parse_type(&type_type); + instr->cat1.dst_type = parse_type(&type_type); + return instr; +} + +static struct ir3_register * new_reg(int num, unsigned flags) +{ + struct ir3_register *reg; + flags |= rflags.flags; + if (num & 0x1) + flags |= IR3_REG_HALF; + reg = ir3_reg_create(instr, num>>1, flags); + reg->wrmask = rflags.wrmask; + rflags.flags = rflags.wrmask = 0; + return reg; +} + +#ifdef YYDEBUG +int yydebug; +#endif + +extern int yylex(void); +typedef void *YY_BUFFER_STATE; +extern YY_BUFFER_STATE asm_yy_scan_string(const char *); +extern void asm_yy_delete_buffer(YY_BUFFER_STATE); + +int yyparse(void); + +void yyerror(const char *error) +{ + fprintf(stderr, "error at line %d: %s\n", asm_yyget_lineno(), error); +} + +struct ir3_shader * fd_asm_parse(const char *src) +{ + YY_BUFFER_STATE buffer = asm_yy_scan_string(src); +#ifdef YYDEBUG + yydebug = 1; +#endif + if (yyparse()) { + ir3_shader_destroy(shader); + shader = NULL; + } + asm_yy_delete_buffer(buffer); + return shader; +} +%} + +%union { + int tok; + int num; + uint32_t unum; + double flt; + const char *str; + struct ir3_register *reg; + struct { + int start; + int num; + } range; + type_t type; +} + +%{ +static void print_token(FILE *file, int type, YYSTYPE value) +{ + fprintf(file, "\ntype: %d\n", type); +} + +#define YYPRINT(file, type, value) print_token(file, type, value) +%} + +%token T_INT +%token T_HEX +%token T_FLOAT +%token T_IDENTIFIER +%token T_REGISTER +%token T_CONSTANT + +/* @ headers (@const/@sampler/@uniform/@varying) */ +%token T_A_ATTRIBUTE +%token T_A_CONST +%token T_A_SAMPLER +%token T_A_UNIFORM +%token T_A_VARYING +%token T_A_BUF +%token T_A_OUT + +/* src register flags */ +%token T_ABSNEG +%token T_NEG +%token T_ABS +%token T_R + +/* dst register flags */ +%token T_EVEN +%token T_POS_INFINITY +%token T_EI +%token T_WRMASK + +/* instruction flags */ +%token T_SY +%token T_SS +%token T_JP +%token T_RPT +%token T_UL + +/* category 0: */ +%token T_OP_NOP +%token T_OP_BR +%token T_OP_JUMP +%token T_OP_CALL +%token T_OP_RET +%token T_OP_KILL +%token T_OP_END +%token T_OP_EMIT +%token T_OP_CUT +%token T_OP_CHMASK +%token T_OP_CHSH +%token T_OP_FLOW_REV + +/* category 1: */ +%token T_OP_MOVA +%token T_OP_MOV +%token T_OP_COV + +/* category 2: */ +%token T_OP_ADD_F +%token T_OP_MIN_F +%token T_OP_MAX_F +%token T_OP_MUL_F +%token T_OP_SIGN_F +%token T_OP_CMPS_F +%token T_OP_ABSNEG_F +%token T_OP_CMPV_F +%token T_OP_FLOOR_F +%token T_OP_CEIL_F +%token T_OP_RNDNE_F +%token T_OP_RNDAZ_F +%token T_OP_TRUNC_F +%token T_OP_ADD_U +%token T_OP_ADD_S +%token T_OP_SUB_U +%token T_OP_SUB_S +%token T_OP_CMPS_U +%token T_OP_CMPS_S +%token T_OP_MIN_U +%token T_OP_MIN_S +%token T_OP_MAX_U +%token T_OP_MAX_S +%token T_OP_ABSNEG_S +%token T_OP_AND_B +%token T_OP_OR_B +%token T_OP_NOT_B +%token T_OP_XOR_B +%token T_OP_CMPV_U +%token T_OP_CMPV_S +%token T_OP_MUL_U +%token T_OP_MUL_S +%token T_OP_MULL_U +%token T_OP_BFREV_B +%token T_OP_CLZ_S +%token T_OP_CLZ_B +%token T_OP_SHL_B +%token T_OP_SHR_B +%token T_OP_ASHR_B +%token T_OP_BARY_F +%token T_OP_MGEN_B +%token T_OP_GETBIT_B +%token T_OP_SETRM +%token T_OP_CBITS_B +%token T_OP_SHB +%token T_OP_MSAD + +/* category 3: */ +%token T_OP_MAD_U16 +%token T_OP_MADSH_U16 +%token T_OP_MAD_S16 +%token T_OP_MADSH_M16 +%token T_OP_MAD_U24 +%token T_OP_MAD_S24 +%token T_OP_MAD_F16 +%token T_OP_MAD_F32 +%token T_OP_SEL_B16 +%token T_OP_SEL_B32 +%token T_OP_SEL_S16 +%token T_OP_SEL_S32 +%token T_OP_SEL_F16 +%token T_OP_SEL_F32 +%token T_OP_SAD_S16 +%token T_OP_SAD_S32 + +/* category 4: */ +%token T_OP_RCP +%token T_OP_RSQ +%token T_OP_LOG2 +%token T_OP_EXP2 +%token T_OP_SIN +%token T_OP_COS +%token T_OP_SQRT + +/* category 5: */ +%token T_OP_ISAM +%token T_OP_ISAML +%token T_OP_ISAMM +%token T_OP_SAM +%token T_OP_SAMB +%token T_OP_SAML +%token T_OP_SAMGQ +%token T_OP_GETLOD +%token T_OP_CONV +%token T_OP_CONVM +%token T_OP_GETSIZE +%token T_OP_GETBUF +%token T_OP_GETPOS +%token T_OP_GETINFO +%token T_OP_DSX +%token T_OP_DSY +%token T_OP_GATHER4R +%token T_OP_GATHER4G +%token T_OP_GATHER4B +%token T_OP_GATHER4A +%token T_OP_SAMGP0 +%token T_OP_SAMGP1 +%token T_OP_SAMGP2 +%token T_OP_SAMGP3 +%token T_OP_DSXPP_1 +%token T_OP_DSYPP_1 +%token T_OP_RGETPOS +%token T_OP_RGETINFO + +/* category 6: */ +%token T_OP_LDG +%token T_OP_LDL +%token T_OP_LDP +%token T_OP_STG +%token T_OP_STL +%token T_OP_STP +%token T_OP_STI +%token T_OP_G2L +%token T_OP_L2G +%token T_OP_PREFETCH +%token T_OP_LDLW +%token T_OP_STLW +%token T_OP_RESFMT +%token T_OP_RESINF +%token T_OP_ATOMIC_ADD +%token T_OP_ATOMIC_SUB +%token T_OP_ATOMIC_XCHG +%token T_OP_ATOMIC_INC +%token T_OP_ATOMIC_DEC +%token T_OP_ATOMIC_CMPXCHG +%token T_OP_ATOMIC_MIN +%token T_OP_ATOMIC_MAX +%token T_OP_ATOMIC_AND +%token T_OP_ATOMIC_OR +%token T_OP_ATOMIC_XOR +%token T_OP_LDGB_TYPED_4D +%token T_OP_STGB_4D_4 +%token T_OP_STIB +%token T_OP_LDC_4 +%token T_OP_LDLV + +/* type qualifiers: */ +%token T_TYPE_F16 +%token T_TYPE_F32 +%token T_TYPE_U16 +%token T_TYPE_U32 +%token T_TYPE_S16 +%token T_TYPE_S32 +%token T_TYPE_U8 +%token T_TYPE_S8 + +/* condition qualifiers: */ +%token T_LT +%token T_LE +%token T_GT +%token T_GE +%token T_EQ +%token T_NE + +%token T_3D +%token T_S2EN +%token T_SAMP +%token T_TEX + +%token T_NAN +%token T_INF +%token T_A0 +%token T_P0 +%token T_CAT1_TYPE_TYPE + +%type integer offset +%type float +%type reg const +%type cat1_opc +%type cat2_opc_1src cat2_opc_2src_cnd cat2_opc_2src +%type cat3_opc +%type cat4_opc +%type cat5_opc cat5_samp cat5_tex cat5_type +%type reg_range const_range +%type type +%type const_val + +%error-verbose + +%start shader + +%% + +shader: { shader = ir3_shader_create(); } headers instrs + +headers: +| header headers + +header: attribute_header +| const_header +| sampler_header +| uniform_header +| varying_header +| buf_header +| out_header + +attribute_header: T_A_ATTRIBUTE '(' reg_range ')' T_IDENTIFIER { + ir3_attribute_create(shader, $3.start, $3.num, $5); +} + +const_val: T_FLOAT { $$ = fui($1); printf("%08x\n", $$); } +| T_INT { $$ = $1; printf("%08x\n", $$); } +| '-' T_INT { $$ = -$2; printf("%08x\n", $$); } +| T_HEX { $$ = $1; printf("%08x\n", $$); } + +const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' const_val ',' const_val { + ir3_const_create(shader, $3, $5, $7, $9, $11); +} + +sampler_header: T_A_SAMPLER '(' integer ')' T_IDENTIFIER { + ir3_sampler_create(shader, $3, $5); +} + +uniform_header: T_A_UNIFORM '(' const_range ')' T_IDENTIFIER { + ir3_uniform_create(shader, $3.start, $3.num, $5); +} + +varying_header: T_A_VARYING '(' reg_range ')' T_IDENTIFIER { + ir3_varying_create(shader, $3.start, $3.num, $5); +} + +out_header: T_A_OUT '(' reg_range ')' T_IDENTIFIER { + ir3_out_create(shader, $3.start, $3.num, $5); +} + +buf_header: T_A_BUF '(' T_CONSTANT ')' T_IDENTIFIER { + ir3_buf_create(shader, $3, $5); +} + + /* NOTE: if just single register is specified (rather than a range) assume vec4 */ +reg_range: T_REGISTER { $$.start = $1; $$.num = 4; } +| T_REGISTER '-' T_REGISTER { $$.start = $1; $$.num = 1 + ($3 >> 1) - ($1 >> 1); } + +const_range: T_CONSTANT { $$.start = $1; $$.num = 4; } +| T_CONSTANT '-' T_CONSTANT { $$.start = $1; $$.num = 1 + ($3 >> 1) - ($1 >> 1); } + +iflag: T_SY { iflags.flags |= IR3_INSTR_SY; } +| T_SS { iflags.flags |= IR3_INSTR_SS; } +| T_JP { iflags.flags |= IR3_INSTR_JP; } +| T_RPT { iflags.repeat = $1; } +| T_UL { iflags.flags |= IR3_INSTR_UL; } + +iflags: +| iflag iflags + +instrs: instr instrs +| instr + +instr: iflags cat0_instr +| iflags cat1_instr +| iflags cat2_instr +| iflags cat3_instr +| iflags cat4_instr +| iflags cat5_instr +| iflags cat6_instr + +cat0_src: '!' T_P0 { instr->cat0.inv = true; instr->cat0.comp = $2 >> 1; } +| T_P0 { instr->cat0.comp = $1 >> 1; } + +cat0_immed: '#' integer { instr->cat0.immed = $2; } + +cat0_instr: T_OP_NOP { new_instr(0, OPC_NOP); } +| T_OP_BR { new_instr(0, OPC_BR); } cat0_src ',' cat0_immed +| T_OP_JUMP { new_instr(0, OPC_JUMP); } cat0_immed +| T_OP_CALL { new_instr(0, OPC_CALL); } cat0_immed +| T_OP_RET { new_instr(0, OPC_RET); } +| T_OP_KILL { new_instr(0, OPC_KILL); } cat0_src +| T_OP_END { new_instr(0, OPC_END); } +| T_OP_EMIT { new_instr(0, OPC_EMIT); } +| T_OP_CUT { new_instr(0, OPC_CUT); } +| T_OP_CHMASK { new_instr(0, OPC_CHMASK); } +| T_OP_CHSH { new_instr(0, OPC_CHSH); } +| T_OP_FLOW_REV { new_instr(0, OPC_FLOW_REV); } + +cat1_opc: T_OP_MOVA { + new_instr(1, 0); + instr->cat1.src_type = TYPE_S16; + instr->cat1.dst_type = TYPE_S16; +} +| T_OP_MOV '.' T_CAT1_TYPE_TYPE { + parse_type_type(new_instr(1, 0), $3); +} +| T_OP_COV '.' T_CAT1_TYPE_TYPE { + parse_type_type(new_instr(1, 0), $3); +} + +cat1_instr: cat1_opc dst_reg ',' src_reg_or_const_or_rel_or_imm + +cat2_opc_1src: T_OP_ABSNEG_F { new_instr(2, OPC_ABSNEG_F); } +| T_OP_ABSNEG_S { new_instr(2, OPC_ABSNEG_S); } +| T_OP_CLZ_B { new_instr(2, OPC_CLZ_B); } +| T_OP_CLZ_S { new_instr(2, OPC_CLZ_S); } +| T_OP_SIGN_F { new_instr(2, OPC_SIGN_F); } +| T_OP_FLOOR_F { new_instr(2, OPC_FLOOR_F); } +| T_OP_CEIL_F { new_instr(2, OPC_CEIL_F); } +| T_OP_RNDNE_F { new_instr(2, OPC_RNDNE_F); } +| T_OP_RNDAZ_F { new_instr(2, OPC_RNDAZ_F); } +| T_OP_TRUNC_F { new_instr(2, OPC_TRUNC_F); } +| T_OP_NOT_B { new_instr(2, OPC_NOT_B); } +| T_OP_BFREV_B { new_instr(2, OPC_BFREV_B); } +| T_OP_SETRM { new_instr(2, OPC_SETRM); } +| T_OP_CBITS_B { new_instr(2, OPC_CBITS_B); } + +cat2_opc_2src_cnd: T_OP_CMPS_F { new_instr(2, OPC_CMPS_F); } +| T_OP_CMPS_U { new_instr(2, OPC_CMPS_U); } +| T_OP_CMPS_S { new_instr(2, OPC_CMPS_S); } +| T_OP_CMPV_F { new_instr(2, OPC_CMPV_F); } +| T_OP_CMPV_U { new_instr(2, OPC_CMPV_U); } +| T_OP_CMPV_S { new_instr(2, OPC_CMPV_S); } + +cat2_opc_2src: T_OP_ADD_F { new_instr(2, OPC_ADD_F); } +| T_OP_MIN_F { new_instr(2, OPC_MIN_F); } +| T_OP_MAX_F { new_instr(2, OPC_MAX_F); } +| T_OP_MUL_F { new_instr(2, OPC_MUL_F); } +| T_OP_ADD_U { new_instr(2, OPC_ADD_U); } +| T_OP_ADD_S { new_instr(2, OPC_ADD_S); } +| T_OP_SUB_U { new_instr(2, OPC_SUB_U); } +| T_OP_SUB_S { new_instr(2, OPC_SUB_S); } +| T_OP_MIN_U { new_instr(2, OPC_MIN_U); } +| T_OP_MIN_S { new_instr(2, OPC_MIN_S); } +| T_OP_MAX_U { new_instr(2, OPC_MAX_U); } +| T_OP_MAX_S { new_instr(2, OPC_MAX_S); } +| T_OP_AND_B { new_instr(2, OPC_AND_B); } +| T_OP_OR_B { new_instr(2, OPC_OR_B); } +| T_OP_XOR_B { new_instr(2, OPC_XOR_B); } +| T_OP_MUL_U { new_instr(2, OPC_MUL_U); } +| T_OP_MUL_S { new_instr(2, OPC_MUL_S); } +| T_OP_MULL_U { new_instr(2, OPC_MULL_U); } +| T_OP_SHL_B { new_instr(2, OPC_SHL_B); } +| T_OP_SHR_B { new_instr(2, OPC_SHR_B); } +| T_OP_ASHR_B { new_instr(2, OPC_ASHR_B); } +| T_OP_BARY_F { new_instr(2, OPC_BARY_F); } +| T_OP_MGEN_B { new_instr(2, OPC_MGEN_B); } +| T_OP_GETBIT_B { new_instr(2, OPC_GETBIT_B); } +| T_OP_SHB { new_instr(2, OPC_SHB); } +| T_OP_MSAD { new_instr(2, OPC_MSAD); } + +cond: T_LT { instr->cat2.condition = IR3_COND_LT; } +| T_LE { instr->cat2.condition = IR3_COND_LE; } +| T_GT { instr->cat2.condition = IR3_COND_GT; } +| T_GE { instr->cat2.condition = IR3_COND_GE; } +| T_EQ { instr->cat2.condition = IR3_COND_EQ; } +| T_NE { instr->cat2.condition = IR3_COND_NE; } + +cat2_instr: cat2_opc_1src dst_reg ',' src_reg_or_const_or_rel_or_imm +| cat2_opc_2src_cnd '.' cond dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm +| cat2_opc_2src dst_reg ',' src_reg_or_const_or_rel_or_imm ',' src_reg_or_const_or_rel_or_imm + +cat3_opc: T_OP_MAD_U16 { new_instr(3, OPC_MAD_U16); } +| T_OP_MADSH_U16 { new_instr(3, OPC_MADSH_U16); } +| T_OP_MAD_S16 { new_instr(3, OPC_MAD_S16); } +| T_OP_MADSH_M16 { new_instr(3, OPC_MADSH_M16); } +| T_OP_MAD_U24 { new_instr(3, OPC_MAD_U24); } +| T_OP_MAD_S24 { new_instr(3, OPC_MAD_S24); } +| T_OP_MAD_F16 { new_instr(3, OPC_MAD_F16); } +| T_OP_MAD_F32 { new_instr(3, OPC_MAD_F32); } +| T_OP_SEL_B16 { new_instr(3, OPC_SEL_B16); } +| T_OP_SEL_B32 { new_instr(3, OPC_SEL_B32); } +| T_OP_SEL_S16 { new_instr(3, OPC_SEL_S16); } +| T_OP_SEL_S32 { new_instr(3, OPC_SEL_S32); } +| T_OP_SEL_F16 { new_instr(3, OPC_SEL_F16); } +| T_OP_SEL_F32 { new_instr(3, OPC_SEL_F32); } +| T_OP_SAD_S16 { new_instr(3, OPC_SAD_S16); } +| T_OP_SAD_S32 { new_instr(3, OPC_SAD_S32); } + +cat3_instr: cat3_opc dst_reg ',' src_reg_or_const_or_rel ',' src_reg_or_const ',' src_reg_or_const_or_rel + +cat4_opc: T_OP_RCP { new_instr(4, OPC_RCP); } +| T_OP_RSQ { new_instr(4, OPC_RSQ); } +| T_OP_LOG2 { new_instr(4, OPC_LOG2); } +| T_OP_EXP2 { new_instr(4, OPC_EXP2); } +| T_OP_SIN { new_instr(4, OPC_SIN); } +| T_OP_COS { new_instr(4, OPC_COS); } +| T_OP_SQRT { new_instr(4, OPC_SQRT); } + +cat4_instr: cat4_opc dst_reg ',' src_reg_or_const_or_rel_or_imm + +cat5_opc_dsxypp: T_OP_DSXPP_1 { new_instr(5, OPC_DSXPP_1); } +| T_OP_DSYPP_1 { new_instr(5, OPC_DSYPP_1); } + +cat5_opc: T_OP_ISAM { new_instr(5, OPC_ISAM); } +| T_OP_ISAML { new_instr(5, OPC_ISAML); } +| T_OP_ISAMM { new_instr(5, OPC_ISAMM); } +| T_OP_SAM { new_instr(5, OPC_SAM); } +| T_OP_SAMB { new_instr(5, OPC_SAMB); } +| T_OP_SAML { new_instr(5, OPC_SAML); } +| T_OP_SAMGQ { new_instr(5, OPC_SAMGQ); } +| T_OP_GETLOD { new_instr(5, OPC_GETLOD); } +| T_OP_CONV { new_instr(5, OPC_CONV); } +| T_OP_CONVM { new_instr(5, OPC_CONVM); } +| T_OP_GETSIZE { new_instr(5, OPC_GETSIZE); } +| T_OP_GETBUF { new_instr(5, OPC_GETBUF); } +| T_OP_GETPOS { new_instr(5, OPC_GETPOS); } +| T_OP_GETINFO { new_instr(5, OPC_GETINFO); } +| T_OP_DSX { new_instr(5, OPC_DSX); } +| T_OP_DSY { new_instr(5, OPC_DSY); } +| T_OP_GATHER4R { new_instr(5, OPC_GATHER4R); } +| T_OP_GATHER4G { new_instr(5, OPC_GATHER4G); } +| T_OP_GATHER4B { new_instr(5, OPC_GATHER4B); } +| T_OP_GATHER4A { new_instr(5, OPC_GATHER4A); } +| T_OP_SAMGP0 { new_instr(5, OPC_SAMGP0); } +| T_OP_SAMGP1 { new_instr(5, OPC_SAMGP1); } +| T_OP_SAMGP2 { new_instr(5, OPC_SAMGP2); } +| T_OP_SAMGP3 { new_instr(5, OPC_SAMGP3); } +| T_OP_RGETPOS { new_instr(5, OPC_RGETPOS); } +| T_OP_RGETINFO { new_instr(5, OPC_RGETINFO); } + +cat5_flag: '.' T_3D { instr->flags |= IR3_INSTR_3D; } +| '.' 'a' { instr->flags |= IR3_INSTR_A; } +| '.' 'o' { instr->flags |= IR3_INSTR_O; } +| '.' 'p' { instr->flags |= IR3_INSTR_P; } +| '.' 's' { instr->flags |= IR3_INSTR_S; } +| '.' T_S2EN { instr->flags |= IR3_INSTR_S2EN; } +cat5_flags: +| cat5_flag cat5_flags + +cat5_samp: T_SAMP { instr->cat5.samp = $1; } +cat5_tex: T_TEX { instr->cat5.tex = $1; } +cat5_type: '(' type ')' { instr->cat5.type = $2; } + +cat5_instr: cat5_opc_dsxypp cat5_flags dst_reg ',' src_reg +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_samp +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' src_reg +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_samp +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg ',' src_reg +| cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg ',' cat5_samp +| cat5_opc cat5_flags cat5_type dst_reg ',' cat5_tex +| cat5_opc cat5_flags cat5_type dst_reg + +cat6_type: '.' type { instr->cat6.type = $2; } +cat6_offset: offset { instr->cat6.src_offset = $1; } +cat6_immed: integer { instr->cat6.iim_val = $1; } + +cat6_load: T_OP_LDG { new_instr(6, OPC_LDG); } cat6_type dst_reg ',' 'g' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_LDP { new_instr(6, OPC_LDP); } cat6_type dst_reg ',' 'p' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_LDL { new_instr(6, OPC_LDL); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_LDLW { new_instr(6, OPC_LDLW); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_LDLV { new_instr(6, OPC_LDLV); } cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed + +cat6_store: T_OP_STG { new_instr(6, OPC_STG); } cat6_type 'g' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed +| T_OP_STP { new_instr(6, OPC_STP); } cat6_type 'p' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed +| T_OP_STL { new_instr(6, OPC_STL); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed +| T_OP_STLW { new_instr(6, OPC_STLW); } cat6_type 'l' '[' dst_reg cat6_offset ']' ',' reg ',' cat6_immed + +cat6_storei: T_OP_STI { new_instr(6, OPC_STI); } cat6_type dst_reg cat6_offset ',' reg ',' cat6_immed + +cat6_storeib: T_OP_STIB { new_instr(6, OPC_STIB); } cat6_type 'g' '[' dst_reg ']' ',' reg cat6_offset ',' cat6_immed + +cat6_prefetch: T_OP_PREFETCH { new_instr(6, OPC_PREFETCH); new_reg(0,0); /* dummy dst */ } 'g' '[' reg cat6_offset ']' ',' cat6_immed + +cat6_atomic_l_g: '.' 'g' { instr->flags |= IR3_INSTR_G; } +| '.' 'l' { } + +cat6_atomic: T_OP_ATOMIC_ADD { new_instr(6, OPC_ATOMIC_ADD); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_SUB { new_instr(6, OPC_ATOMIC_SUB); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_XCHG { new_instr(6, OPC_ATOMIC_XCHG); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_INC { new_instr(6, OPC_ATOMIC_INC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_DEC { new_instr(6, OPC_ATOMIC_DEC); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_CMPXCHG { new_instr(6, OPC_ATOMIC_CMPXCHG); }cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_MIN { new_instr(6, OPC_ATOMIC_MIN); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_MAX { new_instr(6, OPC_ATOMIC_MAX); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_AND { new_instr(6, OPC_ATOMIC_AND); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_OR { new_instr(6, OPC_ATOMIC_OR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed +| T_OP_ATOMIC_XOR { new_instr(6, OPC_ATOMIC_XOR); } cat6_atomic_l_g cat6_type dst_reg ',' 'l' '[' reg cat6_offset ']' ',' cat6_immed + +cat6_todo: T_OP_G2L { new_instr(6, OPC_G2L); } +| T_OP_L2G { new_instr(6, OPC_L2G); } +| T_OP_RESFMT { new_instr(6, OPC_RESFMT); } +| T_OP_RESINF { new_instr(6, OPC_RESINFO); } +| T_OP_LDGB_TYPED_4D { new_instr(6, OPC_LDGB_TYPED_4D); } +| T_OP_STGB_4D_4 { new_instr(6, OPC_STGB_4D_4); } +| T_OP_LDC_4 { new_instr(6, OPC_LDC_4); } + +cat6_instr: cat6_load +| cat6_store +| cat6_storei +| cat6_storeib +| cat6_prefetch +| cat6_atomic +| cat6_todo + +reg: T_REGISTER { $$ = new_reg($1, 0); } +| T_A0 { $$ = new_reg((61 << 3) + $1, IR3_REG_HALF); } +| T_P0 { $$ = new_reg((62 << 3) + $1, 0); } + +const: T_CONSTANT { $$ = new_reg($1, IR3_REG_CONST); } + +dst_reg_flag: T_EVEN { rflags.flags |= IR3_REG_EVEN; } +| T_POS_INFINITY { rflags.flags |= IR3_REG_POS_INF; } +| T_EI { rflags.flags |= IR3_REG_EI; } +| T_WRMASK { rflags.wrmask = $1; } + +dst_reg_flags: dst_reg_flag +| dst_reg_flag dst_reg_flags + + /* note: destination registers are always incremented in repeat */ +dst_reg: reg { $1->flags |= IR3_REG_R; } +| dst_reg_flags reg { $2->flags |= IR3_REG_R; } + +src_reg_flag: T_ABSNEG { rflags.flags |= IR3_REG_ABS|IR3_REG_NEGATE; } +| T_NEG { rflags.flags |= IR3_REG_NEGATE; } +| T_ABS { rflags.flags |= IR3_REG_ABS; } +| T_R { rflags.flags |= IR3_REG_R; } + +src_reg_flags: src_reg_flag +| src_reg_flag src_reg_flags + +src_reg: reg +| src_reg_flags reg + +src_const: const +| src_reg_flags const + +src_reg_or_const: src_reg +| src_const + +src_reg_or_const_or_rel: src_reg_or_const +| relative + +src_reg_or_const_or_rel_or_imm: src_reg_or_const_or_rel +| src_reg_flags immediate +| immediate + +offset: { $$ = 0; } +| '+' integer { $$ = $2; } +| '-' integer { $$ = -$2; } + +relative: 'r' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV)->offset = $4; } +| 'c' '<' T_A0 offset '>' { new_reg(0, IR3_REG_RELATIV | IR3_REG_CONST)->offset = $4; } + +immediate: integer { new_reg(0, IR3_REG_IMMED)->iim_val = $1; } +| '(' integer ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; } +| '(' float ')' { new_reg(0, IR3_REG_IMMED)->fim_val = $2; } +| '(' T_NAN ')' { new_reg(0, IR3_REG_IMMED)->fim_val = NAN; } +| '(' T_INF ')' { new_reg(0, IR3_REG_IMMED)->fim_val = INFINITY; } + +integer: T_INT { $$ = $1; } +| '-' T_INT { $$ = -$2; } +| T_HEX { $$ = $1; } +| '-' T_HEX { $$ = -$2; } + +float: T_FLOAT { $$ = $1; } +| '-' T_FLOAT { $$ = -$2; } + +type: T_TYPE_F16 { $$ = TYPE_F16; } +| T_TYPE_F32 { $$ = TYPE_F32; } +| T_TYPE_U16 { $$ = TYPE_U16; } +| T_TYPE_U32 { $$ = TYPE_U32; } +| T_TYPE_S16 { $$ = TYPE_S16; } +| T_TYPE_S32 { $$ = TYPE_S32; } +| T_TYPE_U8 { $$ = TYPE_U8; } +| T_TYPE_S8 { $$ = TYPE_S8; } -- 2.30.2