1 %option yylineno 2 %option nounput 3 %{ 4 #include <string.h> 5 #include "i965_asm.h" 6 #undef ALIGN16 7 #include "i965_gram.tab.h" 8 9 /* Locations */ 10 int yycolumn = 1; 11 12 int saved_state = 0; 13 extern char *input_filename; 14 15 #define YY_NO_INPUT 16 #define YY_USER_ACTION \ 17 yylloc.first_line = yylloc.last_line = yylineno; \ 18 yylloc.first_column = yycolumn; \ 19 yylloc.last_column = yycolumn + yyleng - 1; \ 20 yycolumn += yyleng; 21 %} 22 23 %x BLOCK_COMMENT 24 %x FILENAME 25 %x CHANNEL 26 %x REG 27 %x DOTSEL 28 %x LABEL 29 %% 30 31 /* eat up single line comment */ 32 \/\/.*[\r\n] { yycolumn = 1; } 33 34 /* eat up multiline comment */ 35 \/\* { saved_state = YYSTATE; BEGIN(BLOCK_COMMENT); } 36 37 <BLOCK_COMMENT>\*\/ { BEGIN(saved_state); } 38 39 <BLOCK_COMMENT>. { } 40 <BLOCK_COMMENT>[\r\n] { } 41 42 <FILENAME>\"[^\"]+\" { 43 char *name = malloc(yyleng - 1); 44 memmove(name, yytext + 1, yyleng - 2); 45 name[yyleng-1] = '\0'; 46 input_filename = name; 47 } 48 49 /* null register */ 50 null { BEGIN(REG); return NULL_TOKEN; } 51 52 /* Opcodes */ 53 add { yylval.integer = BRW_OPCODE_ADD; return ADD; } 54 addc { yylval.integer = BRW_OPCODE_ADDC; return ADDC; } 55 and { yylval.integer = BRW_OPCODE_AND; return AND; } 56 asr { yylval.integer = BRW_OPCODE_ASR; return ASR; } 57 avg { yylval.integer = BRW_OPCODE_AVG; return AVG; } 58 bfe { yylval.integer = BRW_OPCODE_BFE; return BFE; } 59 bfi1 { yylval.integer = BRW_OPCODE_BFI1; return BFI1; } 60 bfi2 { yylval.integer = BRW_OPCODE_BFI2; return BFI2; } 61 bfrev { yylval.integer = BRW_OPCODE_BFREV; return BFREV; } 62 brc { yylval.integer = BRW_OPCODE_BRC; return BRC; } 63 brd { yylval.integer = BRW_OPCODE_BRD; return BRD; } 64 break { yylval.integer = BRW_OPCODE_BREAK; return BREAK; } 65 call { yylval.integer = BRW_OPCODE_CALL; return CALL; } 66 calla { yylval.integer = BRW_OPCODE_CALLA; return CALLA; } 67 case { yylval.integer = BRW_OPCODE_CASE; return CASE; } 68 cbit { yylval.integer = BRW_OPCODE_CBIT; return CBIT; } 69 cmp { yylval.integer = BRW_OPCODE_CMP; return CMP; } 70 cmpn { yylval.integer = BRW_OPCODE_CMPN; return CMPN; } 71 cont { yylval.integer = BRW_OPCODE_CONTINUE; return CONT; } 72 csel { yylval.integer = BRW_OPCODE_CSEL; return CSEL; } 73 dim { yylval.integer = BRW_OPCODE_DIM; return DIM; } 74 do { yylval.integer = BRW_OPCODE_DO; return DO; } 75 dp2 { yylval.integer = BRW_OPCODE_DP2; return DP2; } 76 dp3 { yylval.integer = BRW_OPCODE_DP3; return DP3; } 77 dp4 { yylval.integer = BRW_OPCODE_DP4; return DP4; } 78 dph { yylval.integer = BRW_OPCODE_DPH; return DPH; } 79 else { yylval.integer = BRW_OPCODE_ELSE; return ELSE; } 80 endif { yylval.integer = BRW_OPCODE_ENDIF; return ENDIF; } 81 f16to32 { yylval.integer = BRW_OPCODE_F16TO32; return F16TO32; } 82 f32to16 { yylval.integer = BRW_OPCODE_F32TO16; return F32TO16; } 83 fbh { yylval.integer = BRW_OPCODE_FBH; return FBH; } 84 fbl { yylval.integer = BRW_OPCODE_FBL; return FBL; } 85 fork { yylval.integer = BRW_OPCODE_FORK; return FORK; } 86 frc { yylval.integer = BRW_OPCODE_FRC; return FRC; } 87 goto { yylval.integer = BRW_OPCODE_GOTO; return GOTO; } 88 halt { yylval.integer = BRW_OPCODE_HALT; return HALT; } 89 if { yylval.integer = BRW_OPCODE_IF; return IF; } 90 iff { yylval.integer = BRW_OPCODE_IFF; return IFF; } 91 illegal { yylval.integer = BRW_OPCODE_ILLEGAL; return ILLEGAL; } 92 jmpi { yylval.integer = BRW_OPCODE_JMPI; return JMPI; } 93 line { yylval.integer = BRW_OPCODE_LINE; return LINE; } 94 lrp { yylval.integer = BRW_OPCODE_LRP; return LRP; } 95 lzd { yylval.integer = BRW_OPCODE_LZD; return LZD; } 96 mac { yylval.integer = BRW_OPCODE_MAC; return MAC; } 97 mach { yylval.integer = BRW_OPCODE_MACH; return MACH; } 98 mad { yylval.integer = BRW_OPCODE_MAD; return MAD; } 99 madm { yylval.integer = BRW_OPCODE_MADM; return MADM; } 100 mov { yylval.integer = BRW_OPCODE_MOV; return MOV; } 101 movi { yylval.integer = BRW_OPCODE_MOVI; return MOVI; } 102 mul { yylval.integer = BRW_OPCODE_MUL; return MUL; } 103 mrest { yylval.integer = BRW_OPCODE_MREST; return MREST; } 104 msave { yylval.integer = BRW_OPCODE_MSAVE; return MSAVE; } 105 nenop { yylval.integer = BRW_OPCODE_NENOP; return NENOP; } 106 nop { yylval.integer = BRW_OPCODE_NOP; return NOP; } 107 not { yylval.integer = BRW_OPCODE_NOT; return NOT; } 108 or { yylval.integer = BRW_OPCODE_OR; return OR; } 109 pln { yylval.integer = BRW_OPCODE_PLN; return PLN; } 110 pop { yylval.integer = BRW_OPCODE_POP; return POP; } 111 push { yylval.integer = BRW_OPCODE_PUSH; return PUSH; } 112 ret { yylval.integer = BRW_OPCODE_RET; return RET; } 113 rndd { yylval.integer = BRW_OPCODE_RNDD; return RNDD; } 114 rnde { yylval.integer = BRW_OPCODE_RNDE; return RNDE; } 115 rndu { yylval.integer = BRW_OPCODE_RNDU; return RNDU; } 116 rndz { yylval.integer = BRW_OPCODE_RNDZ; return RNDZ; } 117 rol { yylval.integer = BRW_OPCODE_ROL; return ROL; } 118 ror { yylval.integer = BRW_OPCODE_ROR; return ROR; } 119 sad2 { yylval.integer = BRW_OPCODE_SAD2; return SAD2; } 120 sada2 { yylval.integer = BRW_OPCODE_SADA2; return SADA2; } 121 sel { yylval.integer = BRW_OPCODE_SEL; return SEL; } 122 send { yylval.integer = BRW_OPCODE_SEND; return SEND; } 123 sendc { yylval.integer = BRW_OPCODE_SENDC; return SENDC; } 124 sends { yylval.integer = BRW_OPCODE_SENDS; return SENDS; } 125 sendsc { yylval.integer = BRW_OPCODE_SENDSC; return SENDSC; } 126 shl { yylval.integer = BRW_OPCODE_SHL; return SHL; } 127 shr { yylval.integer = BRW_OPCODE_SHR; return SHR; } 128 smov { yylval.integer = BRW_OPCODE_SMOV; return SMOV; } 129 subb { yylval.integer = BRW_OPCODE_SUBB; return SUBB; } 130 wait { yylval.integer = BRW_OPCODE_WAIT; return WAIT; } 131 while { yylval.integer = BRW_OPCODE_WHILE; return WHILE; } 132 xor { yylval.integer = BRW_OPCODE_XOR; return XOR; } 133 134 /* extended math functions */ 135 cos { yylval.integer = BRW_MATH_FUNCTION_COS; return COS; } 136 exp { yylval.integer = BRW_MATH_FUNCTION_EXP; return EXP; } 137 fdiv { yylval.integer = BRW_MATH_FUNCTION_FDIV; return FDIV; } 138 inv { yylval.integer = BRW_MATH_FUNCTION_INV; return INV; } 139 invm { yylval.integer = GFX8_MATH_FUNCTION_INVM; return INVM; } 140 intdiv { 141 yylval.integer = BRW_MATH_FUNCTION_INT_DIV_QUOTIENT; 142 return INTDIV; 143 } 144 intdivmod { 145 yylval.integer = 146 BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER; 147 return INTDIVMOD; 148 } 149 intmod { 150 yylval.integer = BRW_MATH_FUNCTION_INT_DIV_REMAINDER; 151 return INTMOD; 152 } 153 log { yylval.integer = BRW_MATH_FUNCTION_LOG; return LOG; } 154 pow { yylval.integer = BRW_MATH_FUNCTION_POW; return POW; } 155 rsq { yylval.integer = BRW_MATH_FUNCTION_RSQ; return RSQ; } 156 rsqrtm { yylval.integer = GFX8_MATH_FUNCTION_RSQRTM; return RSQRTM; } 157 sin { yylval.integer = BRW_MATH_FUNCTION_SIN; return SIN; } 158 sqrt { yylval.integer = BRW_MATH_FUNCTION_SQRT; return SQRT; } 159 sincos { yylval.integer = BRW_MATH_FUNCTION_SINCOS; return SINCOS; } 160 161 /* shared functions for send instruction */ 162 sampler { return SAMPLER; } 163 dp_sampler { return DP_SAMPLER; } 164 gateway { return GATEWAY; } 165 urb { return URB; } 166 thread_spawner { return THREAD_SPAWNER; } 167 render { return RENDER; } 168 const { return CONST; } 169 data { return DATA; } 170 cre { return CRE; } 171 math { return MATH; } 172 read { return READ; } 173 write { return WRITE; } 174 vme { return VME; } 175 "pixel interp" { return PIXEL_INTERP; } 176 "dp data 1" { return DP_DATA_1; } 177 178 ";" { return SEMICOLON; } 179 ":" { return COLON; } 180 "(" { return LPAREN; } 181 ")" { return RPAREN; } 182 "{" { return LCURLY; } 183 "}" { return RCURLY; } 184 "[" { return LSQUARE; } 185 "]" { return RSQUARE; } 186 "<" { return LANGLE; } 187 ">" { return RANGLE; } 188 "," { return COMMA; } 189 "." { return DOT; } 190 "+" { return PLUS; } 191 "-" { return MINUS; } 192 "~" { return MINUS; } 193 "(abs)" { return ABS; } 194 195 196 "VxH" { return VxH; } 197 <REG>"<" { return LANGLE; } 198 <REG>[0-9][0-9]* { 199 yylval.integer = strtoul(yytext, NULL, 10); 200 return INTEGER; 201 } 202 <REG>">" { return RANGLE; } 203 <REG>"," { return COMMA; } 204 <REG>"." { BEGIN(DOTSEL); return DOT; } 205 <REG>";" { return SEMICOLON; } 206 207 <DOTSEL>"x" { yylval.integer = BRW_CHANNEL_X; return X; } 208 <DOTSEL>"y" { yylval.integer = BRW_CHANNEL_Y; return Y; } 209 <DOTSEL>"z" { yylval.integer = BRW_CHANNEL_Z; return Z; } 210 <DOTSEL>"w" { yylval.integer = BRW_CHANNEL_W; return W; } 211 <DOTSEL>[0-9][0-9]* { 212 yylval.integer = strtoul(yytext, NULL, 10); 213 BEGIN(REG); 214 return INTEGER; 215 } 216 <DOTSEL>. { yyless(0); BEGIN(INITIAL); } 217 <REG>. { yyless(0); BEGIN(INITIAL); } 218 219 /* Access mode */ 220 "align1" { return ALIGN1; } 221 "align16" { return ALIGN16; } 222 223 /* Accumulator write control */ 224 AccWrEnable { return ACCWREN; } 225 226 /* Mask control (formerly WECtrl/Write Enable Control) */ 227 "WE_all" { return WECTRL; } 228 229 /* Compaction control */ 230 compacted { return CMPTCTRL; } 231 232 /* Debug control */ 233 breakpoint { return BREAKPOINT; } 234 235 /* Dependency control */ 236 NoDDClr { return NODDCLR; } 237 NoDDChk { return NODDCHK; } 238 239 /* End of thread */ 240 EOT { return EOT; } 241 242 /* Mask control */ 243 nomask { return MASK_DISABLE; } 244 245 /* Channel */ 246 <CHANNEL>"x" { yylval.integer = BRW_CHANNEL_X; return X; } 247 <CHANNEL>"y" { yylval.integer = BRW_CHANNEL_Y; return Y; } 248 <CHANNEL>"z" { yylval.integer = BRW_CHANNEL_Z; return Z; } 249 <CHANNEL>"w" { yylval.integer = BRW_CHANNEL_W; return W; } 250 <CHANNEL>[0-9][0-9]* { 251 yylval.integer = strtoul(yytext, NULL, 10); 252 return INTEGER; 253 } 254 <CHANNEL>"." { return DOT; } 255 <CHANNEL>. { yyless(0); BEGIN(INITIAL); } 256 257 258 /* Predicate Control */ 259 <CHANNEL>".anyv" { yylval.integer = BRW_PREDICATE_ALIGN1_ANYV; return ANYV; } 260 <CHANNEL>".allv" { yylval.integer = BRW_PREDICATE_ALIGN1_ALLV; return ALLV; } 261 <CHANNEL>".any2h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY2H; return ANY2H; } 262 <CHANNEL>".all2h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL2H; return ALL2H; } 263 <CHANNEL>".any4h" { yylval.integer = BRW_PREDICATE_ALIGN16_ANY4H; return ANY4H; } 264 <CHANNEL>".all4h" { yylval.integer = BRW_PREDICATE_ALIGN16_ALL4H; return ALL4H; } 265 <CHANNEL>".any8h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY8H; return ANY8H; } 266 <CHANNEL>".all8h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL8H; return ALL8H; } 267 <CHANNEL>".any16h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY16H; return ANY16H; } 268 <CHANNEL>".all16h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL16H; return ALL16H; } 269 <CHANNEL>".any32h" { yylval.integer = BRW_PREDICATE_ALIGN1_ANY32H; return ANY32H; } 270 <CHANNEL>".all32h" { yylval.integer = BRW_PREDICATE_ALIGN1_ALL32H; return ALL32H; } 271 272 /* Saturation */ 273 ".sat" { return SATURATE; } 274 275 /* Thread control */ 276 atomic { return ATOMIC; } 277 switch { return SWITCH; } 278 279 /* compression control */ 280 compr { return COMPR; } 281 compr4 { return COMPR4; } 282 sechalf { return SECHALF; } 283 284 /* Quarter Control */ 285 1[HNQ] { } 286 "2Q" { return QTR_2Q; } 287 "3Q" { return QTR_3Q; } 288 "4Q" { return QTR_4Q; } 289 "2H" { return QTR_2H; } 290 "2N" { return QTR_2N; } 291 "3N" { return QTR_3N; } 292 "4N" { return QTR_4N; } 293 "5N" { return QTR_5N; } 294 "6N" { return QTR_6N; } 295 "7N" { return QTR_7N; } 296 "8N" { return QTR_8N; } 297 298 /* data types */ 299 :?B { return TYPE_B; } 300 :?D { return TYPE_D; } 301 :?DF { return TYPE_DF; } 302 :?F { return TYPE_F; } 303 :?HF { return TYPE_HF; } 304 :?NF { return TYPE_NF; } 305 :?Q { return TYPE_Q; } 306 :?UB { return TYPE_UB; } 307 :?UD { return TYPE_UD; } 308 :?UW { return TYPE_UW; } 309 :?UQ { return TYPE_UQ; } 310 :?UV { return TYPE_UV; } 311 :?V { return TYPE_V; } 312 :?VF { return TYPE_VF; } 313 :?W { return TYPE_W; } 314 315 /* Address registers */ 316 "a0" { return ADDRREG; } 317 318 /* accumulator registers */ 319 "acc"[0-9]+ { yylval.integer = atoi(yytext + 3); return ACCREG; } 320 321 /* channel enable registers */ 322 "ce0" { return CHANNELENABLEREG; } 323 324 /* control registers */ 325 "cr0" { return CONTROLREG; } 326 327 /* flag registers */ 328 "f"[0|1] { BEGIN(CHANNEL); yylval.integer = atoi(yytext + 1); return FLAGREG; } 329 330 /* message control registers */ 331 "m" { return MSGREGFILE; } 332 m[0-9]+ { yylval.integer = atoi(yytext + 1); BEGIN(REG); return MSGREG; } 333 334 /* state register */ 335 sr[0-9]+ { yylval.integer = atoi(yytext + 2); return STATEREG; } 336 337 /* notification registers */ 338 "n0" { BEGIN(REG); return NOTIFYREG; } 339 340 /* IP register */ 341 "ip" { return IPREG; } 342 343 /* Thread control register */ 344 "tdr0" { return THREADREG; } 345 346 /* performance register */ 347 "tm0" { BEGIN(REG); return PERFORMANCEREG; } 348 349 [gr][0-9]+ { 350 yylval.integer = atoi(yytext + 1); 351 BEGIN(REG); return GENREG; 352 } 353 [gr] { return GENREGFILE; } 354 "mask"[0-9]+ { yylval.integer = atoi(yytext + 4); return MASKREG; } 355 356 /* Conditional modifiers */ 357 ".e" { yylval.integer = BRW_CONDITIONAL_Z; return EQUAL; } 358 ".g" { yylval.integer = BRW_CONDITIONAL_G; return GREATER; } 359 ".ge" { yylval.integer = BRW_CONDITIONAL_GE; return GREATER_EQUAL; } 360 ".l" { yylval.integer = BRW_CONDITIONAL_L; return LESS; } 361 ".le" { yylval.integer = BRW_CONDITIONAL_LE; return LESS_EQUAL; } 362 ".ne" { yylval.integer = BRW_CONDITIONAL_NZ; return NOT_EQUAL; } 363 ".nz" { yylval.integer = BRW_CONDITIONAL_NZ; return NOT_ZERO; } 364 ".o" { yylval.integer = BRW_CONDITIONAL_O; return OVERFLOW; } 365 ".r" { yylval.integer = BRW_CONDITIONAL_R; return ROUND_INCREMENT; } 366 ".u" { yylval.integer = BRW_CONDITIONAL_U; return UNORDERED; } 367 ".z" { yylval.integer = BRW_CONDITIONAL_Z; return ZERO; } 368 369 /* Eat up JIP and UIP token, their values will be parsed 370 * in numeric section 371 */ 372 "JIP: " { BEGIN(LABEL); } 373 "UIP: " { BEGIN(LABEL); } 374 "Jump: " { } 375 "Pop: " { } 376 [ \t]+ { } 377 "MsgDesc:"[^{]* { } 378 379 "0x"[0-9a-f][0-9a-f]* { 380 yylval.llint = strtoull(yytext + 2, NULL, 16); 381 return LONG; 382 } 383 [0-9][0-9]* { 384 yylval.llint = strtoll(yytext, NULL, 10); 385 return LONG; 386 } 387 388 /* jump label target */ 389 [a-zA-Z_][0-9a-zA-Z_]*":" { 390 yylval.string = ralloc_strdup(p->mem_ctx, yytext); 391 /* Stomp the trailing ':' */ 392 yylval.string[yyleng - 1] = '\0'; 393 return JUMP_LABEL_TARGET; 394 } 395 396 /* jump label */ 397 <LABEL>[a-zA-Z_][0-9a-zA-Z_]* { 398 yylval.string = ralloc_strdup(p->mem_ctx, yytext); 399 BEGIN(INITIAL); 400 return JUMP_LABEL; 401 } 402 403 \n { yycolumn = 1; } 404 405 . { 406 fprintf(stderr, "%s: %d: %s: at \"%s\"\n", 407 input_filename, yylineno, 408 "unexpected token", lex_text()); 409 } 410 %% 411 412 char * 413 lex_text(void) 414 { 415 return yytext; 416 } 417 418 #ifndef yywrap 419 int yywrap() 420 { 421 return -1; 422 } 423 #endif 424