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