blob: b3578e82d09782c486839761d09d644140099d18 [file] [log] [blame]
Eric Anholt22a10632006-08-22 10:15:33 -07001%{
2/*
3 * Copyright © 2006 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Eric Anholt <eric@anholt.net>
26 *
27 */
28
29#include <stdio.h>
Eric Anholtf2f18562006-08-22 12:46:37 -070030#include <string.h>
Keith Packard2d4d4012008-03-30 00:58:28 -070031#include <stdlib.h>
Damien Lespiau5e0da9f2013-01-24 12:21:13 +000032#include <stdbool.h>
Damien Lespiaue9172aa2013-01-26 22:44:45 +000033#include <stdarg.h>
Xiang, Haihao27b43032010-12-13 16:07:16 +080034#include <assert.h>
Eric Anholt22a10632006-08-22 10:15:33 -070035#include "gen4asm.h"
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +000036#include "brw_eu.h"
Eric Anholt22a10632006-08-22 10:15:33 -070037
Xiang, Haihao27b43032010-12-13 16:07:16 +080038#define DEFAULT_EXECSIZE (ffs(program_defaults.execute_size) - 1)
39#define DEFAULT_DSTREGION -1
Xiang Haihao549b7512009-06-30 10:02:33 +080040
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000041#define SWIZZLE(reg) (reg.dw1.bits.swizzle)
42
Damien Lespiaue9172aa2013-01-26 22:44:45 +000043#define YYLTYPE YYLTYPE
44typedef struct YYLTYPE
45{
46 int first_line;
47 int first_column;
48 int last_line;
49 int last_column;
50} YYLTYPE;
51
Xiang, Haihao27b43032010-12-13 16:07:16 +080052extern long int gen_level;
53extern int advanced_flag;
54extern int yylineno;
55extern int need_export;
Homer Hsing88dfdf32012-09-24 10:06:35 +080056static struct src_operand src_null_reg =
57{
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000058 .reg.file = BRW_ARCHITECTURE_REGISTER_FILE,
59 .reg.nr = BRW_ARF_NULL,
60 .reg.type = BRW_REGISTER_TYPE_UD,
Homer Hsing88dfdf32012-09-24 10:06:35 +080061};
Damien Lespiau03750732013-01-23 20:33:00 +000062static struct brw_reg dst_null_reg =
Homer Hsing88dfdf32012-09-24 10:06:35 +080063{
Damien Lespiau03750732013-01-23 20:33:00 +000064 .file = BRW_ARCHITECTURE_REGISTER_FILE,
65 .nr = BRW_ARF_NULL,
Homer Hsing88dfdf32012-09-24 10:06:35 +080066};
Damien Lespiau03750732013-01-23 20:33:00 +000067static struct brw_reg ip_dst =
Homer Hsing7e2461b2012-09-27 14:48:14 +080068{
Damien Lespiau03750732013-01-23 20:33:00 +000069 .file = BRW_ARCHITECTURE_REGISTER_FILE,
70 .nr = BRW_ARF_IP,
71 .type = BRW_REGISTER_TYPE_UD,
Homer Hsing7e2461b2012-09-27 14:48:14 +080072 .address_mode = BRW_ADDRESS_DIRECT,
Damien Lespiau03750732013-01-23 20:33:00 +000073 .hstride = 1,
74 .dw1.bits.writemask = BRW_WRITEMASK_XYZW,
Homer Hsing7e2461b2012-09-27 14:48:14 +080075};
76static struct src_operand ip_src =
77{
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000078 .reg.file = BRW_ARCHITECTURE_REGISTER_FILE,
79 .reg.nr = BRW_ARF_IP,
80 .reg.type = BRW_REGISTER_TYPE_UD,
81 .reg.address_mode = BRW_ADDRESS_DIRECT,
82 .reg.dw1.bits.swizzle = BRW_SWIZZLE_NOOP,
Homer Hsing7e2461b2012-09-27 14:48:14 +080083};
Xiang, Haihao27b43032010-12-13 16:07:16 +080084
85static int get_type_size(GLuint type);
Eric Anholtc8939ed2006-08-30 10:50:56 -070086int set_instruction_dest(struct brw_instruction *instr,
Damien Lespiau03750732013-01-23 20:33:00 +000087 struct brw_reg *dest);
Keith Packard2d4d4012008-03-30 00:58:28 -070088int set_instruction_src0(struct brw_instruction *instr,
Damien Lespiaue9172aa2013-01-26 22:44:45 +000089 struct src_operand *src,
90 YYLTYPE *location);
Eric Anholtc8939ed2006-08-30 10:50:56 -070091int set_instruction_src1(struct brw_instruction *instr,
Damien Lespiaue9172aa2013-01-26 22:44:45 +000092 struct src_operand *src,
93 YYLTYPE *location);
Homer Hsinga034bcb2012-09-07 14:38:13 +080094int set_instruction_dest_three_src(struct brw_instruction *instr,
Damien Lespiau03750732013-01-23 20:33:00 +000095 struct brw_reg *dest);
Homer Hsinga034bcb2012-09-07 14:38:13 +080096int set_instruction_src0_three_src(struct brw_instruction *instr,
97 struct src_operand *src);
98int set_instruction_src1_three_src(struct brw_instruction *instr,
99 struct src_operand *src);
100int set_instruction_src2_three_src(struct brw_instruction *instr,
101 struct src_operand *src);
Eric Anholtc8939ed2006-08-30 10:50:56 -0700102void set_instruction_options(struct brw_instruction *instr,
103 struct brw_instruction *options);
104void set_instruction_predicate(struct brw_instruction *instr,
105 struct brw_instruction *predicate);
Damien Lespiau03750732013-01-23 20:33:00 +0000106void set_direct_dst_operand(struct brw_reg *dst, struct brw_reg *reg,
Eric Anholt1e907c72006-08-31 10:21:15 -0700107 int type);
Damien Lespiaub33b8812013-01-23 16:06:49 +0000108void set_direct_src_operand(struct src_operand *src, struct brw_reg *reg,
Eric Anholtc8939ed2006-08-30 10:50:56 -0700109 int type);
110
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000111enum message_level {
112 WARN,
113 ERROR,
114};
115
116static void message(enum message_level level, YYLTYPE *location,
117 const char *fmt, ...)
118{
119 static const char *level_str[] = { "warning", "error" };
120 va_list args;
121
122 if (location)
123 fprintf(stderr, "%d:%d: %s: ", location->first_line,
124 location->first_column, level_str[level]);
125 else
126 fprintf(stderr, "%s: ", level_str[level]);
127
128 va_start(args, fmt);
129 vfprintf(stderr, fmt, args);
130 va_end(args);
131}
132
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000133#define warn(flag, l, fmt, ...) \
134 do { \
135 if (warning_flags & WARN_ ## flag) \
136 message(WARN, location, fmt, ## __VA_ARGS__); \
137 } while(0)
138
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000139#define error(l, fmt, ...) message(ERROR, location, fmt, ## __VA_ARGS__)
140
Damien Lespiau574a2492013-01-26 18:26:03 +0000141/* like strcmp, but handles NULL pointers */
142static bool strcmp0(const char *s1, const char* s2)
143{
144 if (!s1)
145 return -(s1 != s2);
146 if (!s2)
147 return s1 != s2;
148 return strcmp (s1, s2);
149}
150
151static bool region_equal(struct region *r1, struct region *r2)
152{
153 return memcmp(r1, r2, sizeof(struct region)) == 0;
154}
155
156static bool reg_equal(struct brw_reg *r1, struct brw_reg *r2)
157{
158 return memcmp(r1, r2, sizeof(struct brw_reg)) == 0;
159}
160
161static bool declared_register_equal(struct declared_register *r1,
162 struct declared_register *r2)
163{
164 if (strcmp0(r1->name, r2->name) != 0)
165 return false;
166
167 if (!reg_equal(&r1->reg, &r2->reg))
168 return false;
169
170 if (!region_equal(&r1->src_region, &r2->src_region))
171 return false;
172
173 if (r1->element_size != r2->element_size ||
174 r1->dst_region != r2->dst_region ||
175 r1->type != r2->type)
176 return false;
177
178 return true;
179}
180
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000181static void brw_program_init(struct brw_program *p)
182{
183 memset(p, 0, sizeof(struct brw_program));
184}
185
186static void brw_program_append_entry(struct brw_program *p,
187 struct brw_program_instruction *entry)
188{
189 entry->next = NULL;
190 if (p->last)
191 p->last->next = entry;
192 else
193 p->first = entry;
194 p->last = entry;
195}
196
197static void brw_program_add_instruction(struct brw_program *p,
198 struct brw_instruction *instruction)
199{
200 struct brw_program_instruction *list_entry;
201
202 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
Damien Lespiaua45a4712013-01-21 19:28:41 +0000203 list_entry->type = GEN4ASM_INSTRUCTION_GEN;
204 list_entry->instruction.gen = *instruction;
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000205 brw_program_append_entry(p, list_entry);
206}
207
Damien Lespiau79c62f12013-01-21 21:41:36 +0000208static void brw_program_add_relocatable(struct brw_program *p,
209 struct relocatable_instruction *reloc)
210{
211 struct brw_program_instruction *list_entry;
212
213 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
214 list_entry->type = GEN4ASM_INSTRUCTION_GEN_RELOCATABLE;
215 list_entry->instruction.reloc = *reloc;
216 brw_program_append_entry(p, list_entry);
217}
218
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000219static void brw_program_add_label(struct brw_program *p, const char *label)
220{
221 struct brw_program_instruction *list_entry;
222
223 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
Damien Lespiaua45a4712013-01-21 19:28:41 +0000224 list_entry->type = GEN4ASM_INSTRUCTION_LABEL;
225 list_entry->instruction.label.name = strdup(label);
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000226 brw_program_append_entry(p, list_entry);
227}
228
Damien Lespiau03750732013-01-23 20:33:00 +0000229static int resolve_dst_region(struct declared_register *reference, int region)
230{
231 int resolved = region;
232
233 if (resolved == DEFAULT_DSTREGION) {
234 if (reference)
235 resolved = reference->dst_region;
236 else
237 resolved = 1;
238 }
239
240 assert(resolved == 1 || resolved == 2 || resolved == 3);
241 return resolved;
242}
243
Damien Lespiau5e0da9f2013-01-24 12:21:13 +0000244static bool validate_dst_reg(struct brw_instruction *insn, struct brw_reg *reg)
245{
246
247 if (reg->address_mode == BRW_ADDRESS_DIRECT &&
248 insn->header.access_mode == BRW_ALIGN_1 &&
249 reg->dw1.bits.writemask != 0 &&
250 reg->dw1.bits.writemask != BRW_WRITEMASK_XYZW)
251 {
252 fprintf(stderr, "error: write mask set in align1 instruction\n");
253 return false;
254 }
255
256 return true;
257}
258
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000259static bool validate_src_reg(struct brw_instruction *insn,
260 struct brw_reg reg,
261 YYLTYPE *location)
Damien Lespiauc0592b22013-01-24 18:32:20 +0000262{
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000263 int hstride_for_reg[] = {0, 1, 2, 4};
Damien Lespiau95b12082013-01-26 23:55:01 +0000264 int vstride_for_reg[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256};
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000265 int width_for_reg[] = {1, 2, 4, 8, 16};
Damien Lespiau95b12082013-01-26 23:55:01 +0000266 int execsize_for_reg[] = {1, 2, 4, 8, 16, 32};
267 int width, hstride, vstride, execsize;
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000268
Damien Lespiauc0592b22013-01-24 18:32:20 +0000269 if (reg.file == BRW_IMMEDIATE_VALUE)
270 return true;
271
272 if (insn->header.access_mode == BRW_ALIGN_1 &&
273 SWIZZLE(reg) && SWIZZLE(reg) != BRW_SWIZZLE_NOOP)
274 {
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000275 error(location, "swizzle bits set in align1 instruction\n");
Damien Lespiauc0592b22013-01-24 18:32:20 +0000276 return false;
277 }
278
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000279 assert(reg.hstride >= 0 && reg.hstride < ARRAY_SIZE(hstride_for_reg));
280 hstride = hstride_for_reg[reg.hstride];
281
Damien Lespiau95b12082013-01-26 23:55:01 +0000282 if (reg.vstride == 0xf) {
283 vstride = -1;
284 } else {
285 assert(reg.vstride >= 0 && reg.vstride < ARRAY_SIZE(vstride_for_reg));
286 vstride = vstride_for_reg[reg.vstride];
287 }
288
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000289 assert(reg.width >= 0 && reg.width < ARRAY_SIZE(width_for_reg));
290 width = width_for_reg[reg.width];
291
Damien Lespiau95b12082013-01-26 23:55:01 +0000292 assert(insn->header.execution_size >= 0 &&
293 insn->header.execution_size < ARRAY_SIZE(execsize_for_reg));
294 execsize = execsize_for_reg[insn->header.execution_size];
295
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000296 /* Register Region Restrictions */
297
298 /* D. If Width = 1, HorzStride must be 0 regardless of the values of
299 * ExecSize and VertStride.
300 *
301 * FIXME: In "advanced mode" hstride is set to 1, this is probably a bug
302 * to fix, but it changes the generated opcodes and thus needs validation.
303 */
304 if (width == 1 && hstride != 0)
305 warn(ALL, location, "region width is 1 but horizontal stride is %d "
306 " (should be 0)\n", hstride);
307
Damien Lespiau95b12082013-01-26 23:55:01 +0000308 /* E. If ExecSize = Width = 1, both VertStride and HorzStride must be 0.
309 * This defines a scalar. */
310 if (execsize == 1 && width == 1) {
311 if (hstride != 0)
312 warn(ALL, location, "execution size and region width are 1 but "
313 "horizontal stride is %d (should be 0)\n", hstride);
314 if (vstride != 0)
315 warn(ALL, location, "execution size and region width are 1 but "
316 "vertical stride is %d (should be 0)\n", vstride);
317 }
318
Damien Lespiauc0592b22013-01-24 18:32:20 +0000319 return true;
320}
321
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000322static int get_subreg_address(GLuint regfile, GLuint type, GLuint subreg, GLuint address_mode)
323{
324 int unit_size = 1;
325
326 assert(address_mode == BRW_ADDRESS_DIRECT);
327 assert(regfile != BRW_IMMEDIATE_VALUE);
328
329 if (advanced_flag)
330 unit_size = get_type_size(type);
331
332 return subreg * unit_size;
333}
334
335/* only used in indirect address mode.
336 * input: sub-register number of an address register
337 * output: the value of AddrSubRegNum in the instruction binary code
338 *
339 * input output(advanced_flag==0) output(advanced_flag==1)
340 * a0.0 0 0
341 * a0.1 invalid input 1
342 * a0.2 1 2
343 * a0.3 invalid input 3
344 * a0.4 2 4
345 * a0.5 invalid input 5
346 * a0.6 3 6
347 * a0.7 invalid input 7
348 * a0.8 4 invalid input
349 * a0.10 5 invalid input
350 * a0.12 6 invalid input
351 * a0.14 7 invalid input
352 */
353static int get_indirect_subreg_address(GLuint subreg)
354{
355 return advanced_flag == 0 ? subreg / 2 : subreg;
356}
357
358static void resolve_subnr(struct brw_reg *reg)
359{
360 if (reg->address_mode == BRW_ADDRESS_DIRECT)
361 reg->subnr = get_subreg_address(reg->file, reg->type, reg->subnr,
362 reg->address_mode);
363 else
364 reg->subnr = get_indirect_subreg_address(reg->subnr);
365}
366
367
Eric Anholt22a10632006-08-22 10:15:33 -0700368%}
Damien Lespiaud94e8a62013-01-26 19:51:28 +0000369%locations
Eric Anholt22a10632006-08-22 10:15:33 -0700370
371%start ROOT
372
373%union {
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800374 char *string;
Eric Anholt22a10632006-08-22 10:15:33 -0700375 int integer;
376 double number;
377 struct brw_instruction instruction;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000378 struct relocatable_instruction relocatable;
Eric Anholt22a10632006-08-22 10:15:33 -0700379 struct brw_program program;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800380 struct region region;
381 struct regtype regtype;
Damien Lespiau801b4eb2013-01-23 16:20:05 +0000382 struct brw_reg reg;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800383 struct condition condition;
384 struct declared_register symbol_reg;
Keith Packard2d4d4012008-03-30 00:58:28 -0700385 imm32_t imm32;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700386
387 struct src_operand src_operand;
Eric Anholt22a10632006-08-22 10:15:33 -0700388}
389
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800390%token COLON
Eric Anholt22a10632006-08-22 10:15:33 -0700391%token SEMICOLON
392%token LPAREN RPAREN
393%token LANGLE RANGLE
394%token LCURLY RCURLY
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700395%token LSQUARE RSQUARE
Xiang, Haihao27b43032010-12-13 16:07:16 +0800396%token COMMA EQ
397%token ABS DOT
398%token PLUS MINUS MULTIPLY DIVIDE
Eric Anholt22a10632006-08-22 10:15:33 -0700399
Eric Anholtc8939ed2006-08-30 10:50:56 -0700400%token <integer> TYPE_UD TYPE_D TYPE_UW TYPE_W TYPE_UB TYPE_B
401%token <integer> TYPE_VF TYPE_HF TYPE_V TYPE_F
Eric Anholt22a10632006-08-22 10:15:33 -0700402
Eric Anholt908f37d2006-08-25 17:33:02 -0700403%token ALIGN1 ALIGN16 SECHALF COMPR SWITCH ATOMIC NODDCHK NODDCLR
Xiang, Haihao55d81c42010-10-08 13:53:22 +0800404%token MASK_DISABLE BREAKPOINT ACCWRCTRL EOT
Eric Anholt22a10632006-08-22 10:15:33 -0700405
Keith Packard2033aea2008-04-23 23:10:40 -0700406%token SEQ ANY2H ALL2H ANY4H ALL4H ANY8H ALL8H ANY16H ALL16H ANYV ALLV
407%token <integer> ZERO EQUAL NOT_ZERO NOT_EQUAL GREATER GREATER_EQUAL LESS LESS_EQUAL
408%token <integer> ROUND_INCREMENT OVERFLOW UNORDERED
Eric Anholt883408e2006-08-25 13:38:03 -0700409%token <integer> GENREG MSGREG ADDRESSREG ACCREG FLAGREG
410%token <integer> MASKREG AMASK IMASK LMASK CMASK
411%token <integer> MASKSTACKREG LMS IMS MASKSTACKDEPTHREG IMSD LMSD
412%token <integer> NOTIFYREG STATEREG CONTROLREG IPREG
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700413%token GENREGFILE MSGREGFILE
Eric Anholt22a10632006-08-22 10:15:33 -0700414
Eric Anholtf914c6a2006-08-25 11:05:10 -0700415%token <integer> MOV FRC RNDU RNDD RNDE RNDZ NOT LZD
416%token <integer> MUL MAC MACH LINE SAD2 SADA2 DP4 DPH DP3 DP2
Xiang, Haihaof1f52082010-10-19 13:26:24 +0800417%token <integer> AVG ADD SEL AND OR XOR SHR SHL ASR CMP CMPN PLN
Homer Hsing9e711a42012-09-14 08:56:36 +0800418%token <integer> ADDC BFI1 BFREV CBIT F16TO32 F32TO16 FBH FBL
Eric Anholtc8939ed2006-08-30 10:50:56 -0700419%token <integer> SEND NOP JMPI IF IFF WHILE ELSE BREAK CONT HALT MSAVE
Eric Anholtf914c6a2006-08-25 11:05:10 -0700420%token <integer> PUSH MREST POP WAIT DO ENDIF ILLEGAL
Xiang, Haihao54055322010-10-27 09:42:56 +0800421%token <integer> MATH_INST
Homer Hsingb1ef3bc2012-09-14 09:02:01 +0800422%token <integer> MAD LRP BFE BFI2 SUBB
Homer Hsinga7b1c092012-09-21 12:33:13 +0800423%token <integer> CALL RET
Homer Hsing88dfdf32012-09-24 10:06:35 +0800424%token <integer> BRD BRC
Eric Anholtf914c6a2006-08-25 11:05:10 -0700425
Zhao Yakui93f2a4f2012-10-22 16:13:51 -0400426%token NULL_TOKEN MATH SAMPLER GATEWAY READ WRITE URB THREAD_SPAWNER VME DATA_PORT CRE
Eric Anholt22a10632006-08-22 10:15:33 -0700427
428%token MSGLEN RETURNLEN
Eric Anholte8651962006-08-24 16:37:04 -0700429%token <integer> ALLOCATE USED COMPLETE TRANSPOSE INTERLEAVE
Keith Packard2d4d4012008-03-30 00:58:28 -0700430%token SATURATE
Eric Anholt22a10632006-08-22 10:15:33 -0700431
432%token <integer> INTEGER
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800433%token <string> STRING
Eric Anholt22a10632006-08-22 10:15:33 -0700434%token <number> NUMBER
435
Eric Anholt3d360792006-08-25 09:36:28 -0700436%token <integer> INV LOG EXP SQRT RSQ POW SIN COS SINCOS INTDIV INTMOD
437%token <integer> INTDIVMOD
438%token SIGNED SCALAR
439
Eric Anholt6a88ada2006-08-28 22:11:18 -0700440%token <integer> X Y Z W
441
Xiang, Haihao27b43032010-12-13 16:07:16 +0800442%token <integer> KERNEL_PRAGMA END_KERNEL_PRAGMA CODE_PRAGMA END_CODE_PRAGMA
443%token <integer> REG_COUNT_PAYLOAD_PRAGMA REG_COUNT_TOTAL_PRAGMA DECLARE_PRAGMA
444%token <integer> BASE ELEMENTSIZE SRCREGION DSTREGION TYPE
445
446%token <integer> DEFAULT_EXEC_SIZE_PRAGMA DEFAULT_REG_TYPE_PRAGMA
447%nonassoc SUBREGNUM
448%nonassoc SNDOPR
449%left PLUS MINUS
450%left MULTIPLY DIVIDE
451%right UMINUS
452%nonassoc DOT
453%nonassoc STR_SYMBOL_REG
454%nonassoc EMPTEXECSIZE
455%nonassoc LPAREN
456
457%type <integer> exp sndopr
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800458%type <integer> simple_int
Eric Anholt22a10632006-08-22 10:15:33 -0700459%type <instruction> instruction unaryinstruction binaryinstruction
Homer Hsinga034bcb2012-09-07 14:38:13 +0800460%type <instruction> binaryaccinstruction trinaryinstruction sendinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000461%type <instruction> syncinstruction
Eric Anholt2dac0a12006-08-29 15:29:31 -0700462%type <instruction> msgtarget
Eric Anholt0ed5d932006-08-28 23:05:51 -0700463%type <instruction> instoptions instoption_list predicate
Xiang, Haihao54055322010-10-27 09:42:56 +0800464%type <instruction> mathinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000465%type <instruction> nopinstruction
466%type <relocatable> relocatableinstruction breakinstruction
467%type <relocatable> ifelseinstruction loopinstruction haltinstruction
468%type <relocatable> multibranchinstruction subroutineinstruction jumpinstruction
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800469%type <string> label
Eric Anholt22a10632006-08-22 10:15:33 -0700470%type <program> instrseq
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700471%type <integer> instoption
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800472%type <integer> unaryop binaryop binaryaccop breakop
Homer Hsinga034bcb2012-09-07 14:38:13 +0800473%type <integer> trinaryop
Xiang, Haihao27b43032010-12-13 16:07:16 +0800474%type <condition> conditionalmodifier
475%type <integer> condition saturate negate abs chansel
Eric Anholt2dac0a12006-08-29 15:29:31 -0700476%type <integer> writemask_x writemask_y writemask_z writemask_w
Xiang, Haihao27b43032010-12-13 16:07:16 +0800477%type <integer> srcimmtype execsize dstregion immaddroffset
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700478%type <integer> subregnum sampler_datatype
Eric Anholte8651962006-08-24 16:37:04 -0700479%type <integer> urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt3d360792006-08-25 09:36:28 -0700480%type <integer> math_function math_signed math_scalar
Eric Anholt0ed5d932006-08-28 23:05:51 -0700481%type <integer> predctrl predstate
Xiang, Haihao27b43032010-12-13 16:07:16 +0800482%type <region> region region_wh indirectregion declare_srcregion;
483%type <regtype> regtype
Damien Lespiau801b4eb2013-01-23 16:20:05 +0000484%type <reg> directgenreg directmsgreg addrreg accreg flagreg maskreg
485%type <reg> maskstackreg notifyreg
486/* %type <reg> maskstackdepthreg */
487%type <reg> statereg controlreg ipreg nullreg
488%type <reg> dstoperandex_typed srcarchoperandex_typed
489%type <reg> sendleadreg
490%type <reg> indirectgenreg indirectmsgreg addrparam
Keith Packard2d4d4012008-03-30 00:58:28 -0700491%type <integer> mask_subreg maskstack_subreg
Xiang, Haihao27b43032010-12-13 16:07:16 +0800492%type <integer> declare_elementsize declare_dstregion declare_type
Keith Packard2d4d4012008-03-30 00:58:28 -0700493/* %type <intger> maskstackdepth_subreg */
Xiang, Haihao27b43032010-12-13 16:07:16 +0800494%type <symbol_reg> symbol_reg symbol_reg_p;
Eric Anholt22a10632006-08-22 10:15:33 -0700495%type <imm32> imm32
Damien Lespiau03750732013-01-23 20:33:00 +0000496%type <reg> dst dstoperand dstoperandex dstreg post_dst writemask
497%type <reg> declare_base
Eric Anholt6a88ada2006-08-28 22:11:18 -0700498%type <src_operand> directsrcoperand srcarchoperandex directsrcaccoperand
Eric Anholt2d298742006-08-30 09:57:20 -0700499%type <src_operand> indirectsrcoperand
Eric Anholt6a88ada2006-08-28 22:11:18 -0700500%type <src_operand> src srcimm imm32reg payload srcacc srcaccimm swizzle
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800501%type <src_operand> relativelocation relativelocation2
Eric Anholt22a10632006-08-22 10:15:33 -0700502%%
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800503simple_int: INTEGER { $$ = $1; }
504 | MINUS INTEGER { $$ = -$2;}
505;
506
Zou Nan hai5608d272009-10-20 14:51:04 +0800507exp: INTEGER { $$ = $1; }
Zou Nan hai5608d272009-10-20 14:51:04 +0800508 | exp PLUS exp { $$ = $1 + $3; }
509 | exp MINUS exp { $$ = $1 - $3; }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800510 | exp MULTIPLY exp { $$ = $1 * $3; }
511 | exp DIVIDE exp { if ($3) $$ = $1 / $3; else YYERROR;}
512 | MINUS exp %prec UMINUS { $$ = -$2;}
Zou Nan hai5608d272009-10-20 14:51:04 +0800513 | LPAREN exp RPAREN { $$ = $2; }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800514 ;
Eric Anholt22a10632006-08-22 10:15:33 -0700515
516ROOT: instrseq
517 {
518 compiled_program = $1;
519 }
520;
521
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800522
523label: STRING COLON
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800524;
525
Xiang, Haihao27b43032010-12-13 16:07:16 +0800526declare_base: BASE EQ dstreg
527 {
528 $$ = $3;
529 }
530;
531declare_elementsize: ELEMENTSIZE EQ exp
532 {
533 $$ = $3;
534 }
535;
536declare_srcregion: /* empty */
537 {
538 /* XXX is this default correct?*/
539 memset (&$$, '\0', sizeof ($$));
540 $$.vert_stride = ffs(0);
541 $$.width = ffs(1) - 1;
542 $$.horiz_stride = ffs(0);
543 }
544 | SRCREGION EQ region
545 {
546 $$ = $3;
547 }
548;
549declare_dstregion: /* empty */
550 {
551 $$ = 1;
552 }
553 | DSTREGION EQ dstregion
554 {
555 $$ = $3;
556 }
557;
558declare_type: TYPE EQ regtype
559 {
560 $$ = $3.type;
561 }
562;
563declare_pragma: DECLARE_PRAGMA STRING declare_base declare_elementsize declare_srcregion declare_dstregion declare_type
564 {
Damien Lespiau574a2492013-01-26 18:26:03 +0000565 struct declared_register reg, *found, *new_reg;
566
567 reg.name = $2;
568 reg.reg = $3;
569 reg.element_size = $4;
570 reg.src_region = $5;
571 reg.dst_region = $6;
572 reg.type = $7;
573
574 found = find_register($2);
575 if (found) {
576 if (!declared_register_equal(&reg, found)) {
577 fprintf(stderr, "Error: %s already defined and "
578 "definitions don't agree\n", $2);
579 YYERROR;
580 }
Homer Hsing2ab4c0d2012-09-20 14:04:20 +0800581 free($2); // $2 has been malloc'ed by strdup
Homer Hsinge6d61ac2012-09-17 13:34:38 +0800582 } else {
Damien Lespiau574a2492013-01-26 18:26:03 +0000583 new_reg = malloc(sizeof(struct declared_register));
584 *new_reg = reg;
585 insert_register(new_reg);
Xiang, Haihao27b43032010-12-13 16:07:16 +0800586 }
587 }
588;
589
590reg_count_total_pragma: REG_COUNT_TOTAL_PRAGMA exp
591;
592reg_count_payload_pragma: REG_COUNT_PAYLOAD_PRAGMA exp
593;
594
595default_exec_size_pragma: DEFAULT_EXEC_SIZE_PRAGMA exp
596 {
597 program_defaults.execute_size = $2;
598 }
599;
600default_reg_type_pragma: DEFAULT_REG_TYPE_PRAGMA regtype
601 {
602 program_defaults.register_type = $2.type;
603 }
604;
605pragma: reg_count_total_pragma
606 |reg_count_payload_pragma
607 |default_exec_size_pragma
608 |default_reg_type_pragma
609 |declare_pragma
610;
611
612instrseq: instrseq pragma
613 {
614 $$ = $1;
615 }
616 | instrseq instruction SEMICOLON
Eric Anholt22a10632006-08-22 10:15:33 -0700617 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000618 brw_program_add_instruction(&$1, &$2);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800619 $$ = $1;
Eric Anholt22a10632006-08-22 10:15:33 -0700620 }
621 | instruction SEMICOLON
622 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000623 brw_program_init(&$$);
624 brw_program_add_instruction(&$$, &$1);
Eric Anholt22a10632006-08-22 10:15:33 -0700625 }
Damien Lespiau79c62f12013-01-21 21:41:36 +0000626 | instrseq relocatableinstruction SEMICOLON
627 {
628 brw_program_add_relocatable(&$1, &$2);
629 $$ = $1;
630 }
631 | relocatableinstruction SEMICOLON
632 {
633 brw_program_init(&$$);
634 brw_program_add_relocatable(&$$, &$1);
635 }
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000636 | instrseq SEMICOLON
Xiang, Haihao27b43032010-12-13 16:07:16 +0800637 {
638 $$ = $1;
639 }
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000640 | instrseq label
Xiang, Haihao27b43032010-12-13 16:07:16 +0800641 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000642 brw_program_add_label(&$1, $2);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800643 $$ = $1;
644 }
645 | label
646 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000647 brw_program_init(&$$);
648 brw_program_add_label(&$$, $1);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800649 }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800650 | pragma
651 {
652 $$.first = NULL;
653 $$.last = NULL;
654 }
Chen, Yangyang66649d72010-12-13 15:36:02 +0800655 | instrseq error SEMICOLON {
656 $$ = $1;
Eric Anholt22a10632006-08-22 10:15:33 -0700657 }
658;
659
660/* 1.4.1: Instruction groups */
Homer Hsing74383f42012-09-18 13:25:53 +0800661// binaryinstruction: Source operands cannot be accumulators
662// binaryaccinstruction: Source operands can be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -0700663instruction: unaryinstruction
664 | binaryinstruction
665 | binaryaccinstruction
Homer Hsinga034bcb2012-09-07 14:38:13 +0800666 | trinaryinstruction
667 | sendinstruction
Eric Anholt1f58efa2006-09-01 11:56:12 -0700668 | syncinstruction
Xiang, Haihao54055322010-10-27 09:42:56 +0800669 | mathinstruction
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800670 | nopinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000671;
672
673/* relocatableinstruction are instructions that needs a relocation pass */
674relocatableinstruction: ifelseinstruction
675 | loopinstruction
676 | haltinstruction
677 | multibranchinstruction
678 | subroutineinstruction
679 | jumpinstruction
680 | breakinstruction
Homer Hsing88dfdf32012-09-24 10:06:35 +0800681;
682
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800683ifelseinstruction: ENDIF
684 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400685 // for Gen4
686 if(IS_GENp(6)) { // For gen6+.
Homer Hsingc56d7862012-09-28 13:46:21 +0800687 fprintf(stderr, "ENDIF Syntax error: should be 'ENDIF execsize relativelocation'\n");
688 YYERROR;
689 }
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800690 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000691 $$.gen.header.opcode = $1;
692 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
693 $$.gen.bits1.da1.dest_horiz_stride = 1;
694 $$.gen.bits1.da1.src1_reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
695 $$.gen.bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_UD;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800696 }
697 | ENDIF execsize relativelocation instoptions
698 {
Homer Hsingc56d7862012-09-28 13:46:21 +0800699 // for Gen6+
700 /* Gen6, Gen7 bspec: predication is prohibited */
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400701 if(!IS_GENp(6)) { // for gen6-
Homer Hsingc56d7862012-09-28 13:46:21 +0800702 fprintf(stderr, "ENDIF Syntax error: should be 'ENDIF'\n");
703 YYERROR;
704 }
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800705 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000706 $$.gen.header.opcode = $1;
707 $$.gen.header.execution_size = $2;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800708 $$.first_reloc_target = $3.reloc_target;
709 $$.first_reloc_offset = $3.imm32;
710 }
711 | ELSE execsize relativelocation instoptions
712 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400713 if(!IS_GENp(6)) {
714 // for Gen4, Gen5. gen_level < 60
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800715 /* Set the istack pop count, which must always be 1. */
716 $3.imm32 |= (1 << 16);
717
718 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000719 $$.gen.header.opcode = $1;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000720 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000721 ip_dst.width = $2;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000722 set_instruction_dest(&$$.gen, &ip_dst);
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000723 set_instruction_src0(&$$.gen, &ip_src, NULL);
724 set_instruction_src1(&$$.gen, &$3, NULL);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800725 $$.first_reloc_target = $3.reloc_target;
726 $$.first_reloc_offset = $3.imm32;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400727 } else if(IS_GENp(6)) {
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800728 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000729 $$.gen.header.opcode = $1;
730 $$.gen.header.execution_size = $2;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800731 $$.first_reloc_target = $3.reloc_target;
732 $$.first_reloc_offset = $3.imm32;
733 } else {
734 fprintf(stderr, "'ELSE' instruction is not implemented.\n");
735 YYERROR;
736 }
737 }
738 | predicate IF execsize relativelocation
739 {
Homer Hsing2ad18c12012-09-28 14:02:25 +0800740 /* for Gen4, Gen5 */
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800741 /* The branch instructions require that the IP register
742 * be the destination and first source operand, while the
743 * offset is the second source operand. The offset is added
744 * to the pre-incremented IP.
745 */
Homer Hsing2ad18c12012-09-28 14:02:25 +0800746 /* for Gen6 */
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400747 if(IS_GENp(7)) {
748 /* Error in Gen7+. */
Homer Hsing2ad18c12012-09-28 14:02:25 +0800749 fprintf(stderr, "Syntax error: IF should be 'IF execsize JIP UIP'\n");
750 YYERROR;
751 }
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800752 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000753 set_instruction_predicate(&$$.gen, &$1);
754 $$.gen.header.opcode = $2;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400755 if(!IS_GENp(6)) {
Damien Lespiau79c62f12013-01-21 21:41:36 +0000756 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000757 ip_dst.width = $3;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000758 set_instruction_dest(&$$.gen, &ip_dst);
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000759 set_instruction_src0(&$$.gen, &ip_src, NULL);
760 set_instruction_src1(&$$.gen, &$4, NULL);
Homer Hsing2ad18c12012-09-28 14:02:25 +0800761 }
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800762 $$.first_reloc_target = $4.reloc_target;
763 $$.first_reloc_offset = $4.imm32;
764 }
765 | predicate IF execsize relativelocation relativelocation
766 {
767 /* for Gen7+ */
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400768 if(!IS_GENp(7)) {
Homer Hsing2ad18c12012-09-28 14:02:25 +0800769 fprintf(stderr, "Syntax error: IF should be 'IF execsize relativelocation'\n");
770 YYERROR;
771 }
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800772 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000773 set_instruction_predicate(&$$.gen, &$1);
774 $$.gen.header.opcode = $2;
775 $$.gen.header.execution_size = $3;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800776 $$.first_reloc_target = $4.reloc_target;
777 $$.first_reloc_offset = $4.imm32;
778 $$.second_reloc_target = $5.reloc_target;
779 $$.second_reloc_offset = $5.imm32;
780 }
781;
782
783loopinstruction: predicate WHILE execsize relativelocation instoptions
784 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400785 if(!IS_GENp(6)) {
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800786 /* The branch instructions require that the IP register
787 * be the destination and first source operand, while the
788 * offset is the second source operand. The offset is added
789 * to the pre-incremented IP.
790 */
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000791 ip_dst.width = $3;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000792 set_instruction_dest(&$$.gen, &ip_dst);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800793 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000794 set_instruction_predicate(&$$.gen, &$1);
795 $$.gen.header.opcode = $2;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000796 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000797 set_instruction_src0(&$$.gen, &ip_src, NULL);
798 set_instruction_src1(&$$.gen, &$4, NULL);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800799 $$.first_reloc_target = $4.reloc_target;
800 $$.first_reloc_offset = $4.imm32;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400801 } else if (IS_GENp(6)) {
Homer Hsinge8cb1952012-09-28 14:05:51 +0800802 /* Gen6 spec:
803 dest must have the same element size as src0.
804 dest horizontal stride must be 1. */
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800805 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000806 set_instruction_predicate(&$$.gen, &$1);
807 $$.gen.header.opcode = $2;
808 $$.gen.header.execution_size = $3;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800809 $$.first_reloc_target = $4.reloc_target;
810 $$.first_reloc_offset = $4.imm32;
Homer Hsing72a3c192012-09-27 13:51:33 +0800811 } else {
812 fprintf(stderr, "'WHILE' instruction is not implemented!\n");
813 YYERROR;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800814 }
815 }
816 | DO
817 {
818 // deprecated
819 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000820 $$.gen.header.opcode = $1;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800821 };
822
823haltinstruction: predicate HALT execsize relativelocation relativelocation instoptions
824 {
Homer Hsingce555522012-09-27 15:44:15 +0800825 // for Gen6, Gen7
826 /* Gen6, Gen7 bspec: dst and src0 must be the null reg. */
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800827 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000828 set_instruction_predicate(&$$.gen, &$1);
829 $$.gen.header.opcode = $2;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800830 $$.first_reloc_target = $4.reloc_target;
831 $$.first_reloc_offset = $4.imm32;
832 $$.second_reloc_target = $5.reloc_target;
833 $$.second_reloc_offset = $5.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000834 dst_null_reg.width = $3;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000835 set_instruction_dest(&$$.gen, &dst_null_reg);
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000836 set_instruction_src0(&$$.gen, &src_null_reg, NULL);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800837 };
838
Homer Hsing88dfdf32012-09-24 10:06:35 +0800839multibranchinstruction:
840 predicate BRD execsize relativelocation instoptions
841 {
842 /* Gen7 bspec: dest must be null. use Switch option */
843 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000844 set_instruction_predicate(&$$.gen, &$1);
845 $$.gen.header.opcode = $2;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000846 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
Homer Hsing88dfdf32012-09-24 10:06:35 +0800847 $$.first_reloc_target = $4.reloc_target;
848 $$.first_reloc_offset = $4.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000849 dst_null_reg.width = $3;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000850 set_instruction_dest(&$$.gen, &dst_null_reg);
Homer Hsing88dfdf32012-09-24 10:06:35 +0800851 }
Homer Hsing88dfdf32012-09-24 10:06:35 +0800852 | predicate BRC execsize relativelocation relativelocation instoptions
853 {
854 /* Gen7 bspec: dest must be null. src0 must be null. use Switch option */
855 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000856 set_instruction_predicate(&$$.gen, &$1);
857 $$.gen.header.opcode = $2;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000858 $$.gen.header.thread_control |= BRW_THREAD_SWITCH;
Homer Hsing88dfdf32012-09-24 10:06:35 +0800859 $$.first_reloc_target = $4.reloc_target;
860 $$.first_reloc_offset = $4.imm32;
861 $$.second_reloc_target = $5.reloc_target;
862 $$.second_reloc_offset = $5.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000863 dst_null_reg.width = $3;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000864 set_instruction_dest(&$$.gen, &dst_null_reg);
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000865 set_instruction_src0(&$$.gen, &src_null_reg, NULL);
Homer Hsing88dfdf32012-09-24 10:06:35 +0800866 }
Homer Hsinga7b1c092012-09-21 12:33:13 +0800867;
868
869subroutineinstruction:
870 predicate CALL execsize dst relativelocation instoptions
871 {
Homer Hsing75296822012-09-27 15:31:56 +0800872 /*
873 Gen6 bspec:
874 source, dest type should be DWORD.
875 dest must be QWord aligned.
876 source0 region control must be <2,2,1>.
877 execution size must be 2.
878 QtrCtrl is prohibited.
879 JIP is an immediate operand, must be of type W.
880 Gen7 bspec:
881 source, dest type should be DWORD.
882 dest must be QWord aligned.
883 source0 region control must be <2,2,1>.
884 execution size must be 2.
885 */
Homer Hsinga7b1c092012-09-21 12:33:13 +0800886 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000887 set_instruction_predicate(&$$.gen, &$1);
888 $$.gen.header.opcode = $2;
Homer Hsing75296822012-09-27 15:31:56 +0800889
Damien Lespiau03750732013-01-23 20:33:00 +0000890 $4.type = BRW_REGISTER_TYPE_D; /* dest type should be DWORD */
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000891 $4.width = 1; /* execution size must be 2. Here 1 is encoded 2. */
Damien Lespiau79c62f12013-01-21 21:41:36 +0000892 set_instruction_dest(&$$.gen, &$4);
Homer Hsing75296822012-09-27 15:31:56 +0800893
894 struct src_operand src0;
895 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +0000896 src0.reg.type = BRW_REGISTER_TYPE_D; /* source type should be DWORD */
Homer Hsing75296822012-09-27 15:31:56 +0800897 /* source0 region control must be <2,2,1>. */
Damien Lespiau9d5a87a2013-01-23 22:29:23 +0000898 src0.reg.hstride = 1; /*encoded 1*/
899 src0.reg.width = 1; /*encoded 2*/
900 src0.reg.vstride = 2; /*encoded 2*/
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000901 set_instruction_src0(&$$.gen, &src0, NULL);
Homer Hsing75296822012-09-27 15:31:56 +0800902
Homer Hsinga7b1c092012-09-21 12:33:13 +0800903 $$.first_reloc_target = $5.reloc_target;
904 $$.first_reloc_offset = $5.imm32;
905 }
906 | predicate RET execsize dstoperandex src instoptions
907 {
Homer Hsing3de439e2012-09-27 15:39:28 +0800908 /*
909 Gen6, 7:
910 source cannot be accumulator.
911 dest must be null.
912 src0 region control must be <2,2,1> (not specified clearly. should be same as CALL)
913 */
Homer Hsinga7b1c092012-09-21 12:33:13 +0800914 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +0000915 set_instruction_predicate(&$$.gen, &$1);
916 $$.gen.header.opcode = $2;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000917 dst_null_reg.width = 1; /* execution size of RET should be 2 */
Damien Lespiau79c62f12013-01-21 21:41:36 +0000918 set_instruction_dest(&$$.gen, &dst_null_reg);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +0000919 $5.reg.type = BRW_REGISTER_TYPE_D;
920 $5.reg.hstride = 1; /*encoded 1*/
921 $5.reg.width = 1; /*encoded 2*/
922 $5.reg.vstride = 2; /*encoded 2*/
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000923 set_instruction_src0(&$$.gen, &$5, NULL);
Homer Hsinga7b1c092012-09-21 12:33:13 +0800924 }
Eric Anholt22a10632006-08-22 10:15:33 -0700925;
926
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700927unaryinstruction:
928 predicate unaryop conditionalmodifier saturate execsize
929 dst srcaccimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -0700930 {
Homer Hsing81859af2012-09-14 09:34:58 +0800931 memset(&$$, 0, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -0700932 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +0000933 $$.header.destreg__conditionalmod = $3.cond;
Eric Anholt90aea512006-08-22 14:46:39 -0700934 $$.header.saturate = $4;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000935 $6.width = $5;
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700936 set_instruction_options(&$$, &$8);
Eric Anholt0ed5d932006-08-28 23:05:51 -0700937 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -0700938 if (set_instruction_dest(&$$, &$6) != 0)
939 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000940 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -0700941 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800942
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800943 if ($3.flag_subreg_nr != -1) {
Xiang, Haihao4d75db52012-07-17 16:16:11 +0800944 if ($$.header.predicate_control != BRW_PREDICATE_NONE &&
945 ($1.bits2.da1.flag_reg_nr != $3.flag_reg_nr ||
946 $1.bits2.da1.flag_subreg_nr != $3.flag_subreg_nr))
947 fprintf(stderr, "WARNING: must use the same flag register if both prediction and conditional modifier are enabled\n");
948
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800949 $$.bits2.da1.flag_reg_nr = $3.flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +0800950 $$.bits2.da1.flag_subreg_nr = $3.flag_subreg_nr;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800951 }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800952
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400953 if (!IS_GENp(6) &&
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000954 get_type_size($$.bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
Xiang, Haihao27b43032010-12-13 16:07:16 +0800955 $$.header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -0700956 }
957;
958
Homer Hsing4285d9c2012-09-14 08:41:16 +0800959unaryop: MOV | FRC | RNDU | RNDD | RNDE | RNDZ | NOT | LZD | BFREV | CBIT
Homer Hsing9e711a42012-09-14 08:56:36 +0800960 | F16TO32 | F32TO16 | FBH | FBL
Eric Anholt22a10632006-08-22 10:15:33 -0700961;
962
Homer Hsing74383f42012-09-18 13:25:53 +0800963// Source operands cannot be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -0700964binaryinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700965 predicate binaryop conditionalmodifier saturate execsize
966 dst src srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -0700967 {
Homer Hsing81859af2012-09-14 09:34:58 +0800968 memset(&$$, 0, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -0700969 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +0000970 $$.header.destreg__conditionalmod = $3.cond;
Eric Anholt90aea512006-08-22 14:46:39 -0700971 $$.header.saturate = $4;
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700972 set_instruction_options(&$$, &$9);
Eric Anholt0ed5d932006-08-28 23:05:51 -0700973 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000974 $6.width = $5;
Eric Anholt2dac0a12006-08-29 15:29:31 -0700975 if (set_instruction_dest(&$$, &$6) != 0)
976 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000977 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -0700978 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000979 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -0700980 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800981
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800982 if ($3.flag_subreg_nr != -1) {
Xiang, Haihao4d75db52012-07-17 16:16:11 +0800983 if ($$.header.predicate_control != BRW_PREDICATE_NONE &&
984 ($1.bits2.da1.flag_reg_nr != $3.flag_reg_nr ||
985 $1.bits2.da1.flag_subreg_nr != $3.flag_subreg_nr))
986 fprintf(stderr, "WARNING: must use the same flag register if both prediction and conditional modifier are enabled\n");
987
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800988 $$.bits2.da1.flag_reg_nr = $3.flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +0800989 $$.bits2.da1.flag_subreg_nr = $3.flag_subreg_nr;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +0800990 }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800991
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400992 if (!IS_GENp(6) &&
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000993 get_type_size($$.bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
Xiang, Haihao27b43032010-12-13 16:07:16 +0800994 $$.header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -0700995 }
996;
997
Homer Hsingbebe8172012-09-18 13:47:22 +0800998/* bspec: BFI1 should not access accumulator. */
999binaryop: MUL | MAC | MACH | LINE | SAD2 | SADA2 | DP4 | DPH | DP3 | DP2 | PLN | BFI1
Eric Anholtedc82a02006-08-25 17:42:05 -07001000;
Eric Anholt22a10632006-08-22 10:15:33 -07001001
Homer Hsing74383f42012-09-18 13:25:53 +08001002// Source operands can be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -07001003binaryaccinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001004 predicate binaryaccop conditionalmodifier saturate execsize
1005 dst srcacc srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001006 {
Homer Hsing81859af2012-09-14 09:34:58 +08001007 memset(&$$, 0, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -07001008 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001009 $$.header.destreg__conditionalmod = $3.cond;
Eric Anholt90aea512006-08-22 14:46:39 -07001010 $$.header.saturate = $4;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001011 $6.width = $5;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001012 set_instruction_options(&$$, &$9);
Eric Anholt0ed5d932006-08-28 23:05:51 -07001013 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -07001014 if (set_instruction_dest(&$$, &$6) != 0)
1015 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001016 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001017 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001018 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001019 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001020
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08001021 if ($3.flag_subreg_nr != -1) {
Xiang, Haihao4d75db52012-07-17 16:16:11 +08001022 if ($$.header.predicate_control != BRW_PREDICATE_NONE &&
1023 ($1.bits2.da1.flag_reg_nr != $3.flag_reg_nr ||
1024 $1.bits2.da1.flag_subreg_nr != $3.flag_subreg_nr))
1025 fprintf(stderr, "WARNING: must use the same flag register if both prediction and conditional modifier are enabled\n");
1026
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08001027 $$.bits2.da1.flag_reg_nr = $3.flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +08001028 $$.bits2.da1.flag_subreg_nr = $3.flag_subreg_nr;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08001029 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08001030
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001031 if (!IS_GENp(6) &&
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001032 get_type_size($$.bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001033 $$.header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -07001034 }
1035;
1036
Homer Hsingbebe8172012-09-18 13:47:22 +08001037/* TODO: bspec says ADDC/SUBB/CMP/CMPN/SHL/BFI1 cannot use accumulator as dest. */
1038binaryaccop: AVG | ADD | SEL | AND | OR | XOR | SHR | SHL | ASR | CMP | CMPN | ADDC | SUBB
Eric Anholt22a10632006-08-22 10:15:33 -07001039;
1040
Homer Hsing8ca55682012-09-13 11:05:50 +08001041trinaryop: MAD | LRP | BFE | BFI2
Homer Hsinga034bcb2012-09-07 14:38:13 +08001042;
1043
1044trinaryinstruction:
1045 predicate trinaryop conditionalmodifier saturate execsize
1046 dst src src src instoptions
1047{
1048 memset(&$$, 0, sizeof($$));
1049
1050 $$.header.predicate_control = $1.header.predicate_control;
1051 $$.header.predicate_inverse = $1.header.predicate_inverse;
Damien Lespiau31259c52013-01-15 14:05:23 +00001052 $$.bits1.da3src.flag_reg_nr = $1.bits2.da1.flag_reg_nr;
1053 $$.bits1.da3src.flag_subreg_nr = $1.bits2.da1.flag_subreg_nr;
Homer Hsinga034bcb2012-09-07 14:38:13 +08001054
1055 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001056 $$.header.destreg__conditionalmod = $3.cond;
Homer Hsinga034bcb2012-09-07 14:38:13 +08001057 $$.header.saturate = $4;
1058 $$.header.execution_size = $5;
1059
1060 if (set_instruction_dest_three_src(&$$, &$6))
1061 YYERROR;
1062 if (set_instruction_src0_three_src(&$$, &$7))
1063 YYERROR;
1064 if (set_instruction_src1_three_src(&$$, &$8))
1065 YYERROR;
1066 if (set_instruction_src2_three_src(&$$, &$9))
1067 YYERROR;
1068 set_instruction_options(&$$, &$10);
1069
1070 if ($3.flag_subreg_nr != -1) {
1071 if ($$.header.predicate_control != BRW_PREDICATE_NONE &&
1072 ($1.bits2.da1.flag_reg_nr != $3.flag_reg_nr ||
1073 $1.bits2.da1.flag_subreg_nr != $3.flag_subreg_nr))
1074 fprintf(stderr, "WARNING: must use the same flag register if both prediction and conditional modifier are enabled\n");
1075 }
1076}
Eric Anholtedc82a02006-08-25 17:42:05 -07001077;
Eric Anholt22a10632006-08-22 10:15:33 -07001078
Zou Nan hai5608d272009-10-20 14:51:04 +08001079sendinstruction: predicate SEND execsize exp post_dst payload msgtarget
1080 MSGLEN exp RETURNLEN exp instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001081 {
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001082 /* Send instructions are messy. The first argument is the
1083 * post destination -- the grf register that the response
1084 * starts from. The second argument is the current
1085 * destination, which is the start of the message arguments
1086 * to the shared function, and where src0 payload is loaded
1087 * to if not null. The payload is typically based on the
1088 * grf 0 thread payload of your current thread, and is
1089 * implicitly loaded if non-null.
1090 */
Homer Hsing81859af2012-09-14 09:34:58 +08001091 memset(&$$, 0, sizeof($$));
Eric Anholtf914c6a2006-08-25 11:05:10 -07001092 $$.header.opcode = $2;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001093 $5.width = $3;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001094 $$.header.destreg__conditionalmod = $4; /* msg reg index */
Eric Anholt0ed5d932006-08-28 23:05:51 -07001095 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -07001096 if (set_instruction_dest(&$$, &$5) != 0)
1097 YYERROR;
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001098
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001099 if (IS_GENp(6)) {
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001100 struct src_operand src0;
1101
1102 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001103 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001104
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001105 if (IS_GENp(7))
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001106 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001107 else
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001108 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001109
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001110 src0.reg.type = BRW_REGISTER_TYPE_D;
1111 src0.reg.nr = $4;
1112 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001113 set_instruction_src0(&$$, &src0, NULL);
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001114 } else {
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001115 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001116 YYERROR;
1117 }
1118
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001119 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
1120 $$.bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_D;
Xiang Haihao549b7512009-06-30 10:02:33 +08001121
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001122 if (IS_GENp(5)) {
1123 if (IS_GENp(6)) {
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001124 $$.header.destreg__conditionalmod = $7.bits2.send_gen5.sfid;
Xiang, Haihao4f777e72010-10-08 15:07:51 +08001125 } else {
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001126 $$.header.destreg__conditionalmod = $4; /* msg reg index */
Xiang, Haihao4f777e72010-10-08 15:07:51 +08001127 $$.bits2.send_gen5.sfid = $7.bits2.send_gen5.sfid;
1128 $$.bits2.send_gen5.end_of_thread = $12.bits3.generic_gen5.end_of_thread;
1129 }
1130
Xiang Haihao549b7512009-06-30 10:02:33 +08001131 $$.bits3.generic_gen5 = $7.bits3.generic_gen5;
1132 $$.bits3.generic_gen5.msg_length = $9;
1133 $$.bits3.generic_gen5.response_length = $11;
1134 $$.bits3.generic_gen5.end_of_thread =
1135 $12.bits3.generic_gen5.end_of_thread;
1136 } else {
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001137 $$.header.destreg__conditionalmod = $4; /* msg reg index */
Xiang Haihao549b7512009-06-30 10:02:33 +08001138 $$.bits3.generic = $7.bits3.generic;
1139 $$.bits3.generic.msg_length = $9;
1140 $$.bits3.generic.response_length = $11;
1141 $$.bits3.generic.end_of_thread =
1142 $12.bits3.generic.end_of_thread;
1143 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001144 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001145 | predicate SEND execsize dst sendleadreg payload directsrcoperand instoptions
Feng, Boqun37d68102011-04-19 08:43:22 +08001146 {
Homer Hsing81859af2012-09-14 09:34:58 +08001147 memset(&$$, 0, sizeof($$));
Feng, Boqun37d68102011-04-19 08:43:22 +08001148 $$.header.opcode = $2;
Damien Lespiaub33b8812013-01-23 16:06:49 +00001149 $$.header.destreg__conditionalmod = $5.nr; /* msg reg index */
Feng, Boqun37d68102011-04-19 08:43:22 +08001150
1151 set_instruction_predicate(&$$, &$1);
1152
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001153 $4.width = $3;
Feng, Boqun37d68102011-04-19 08:43:22 +08001154 if (set_instruction_dest(&$$, &$4) != 0)
1155 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001156 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001157 YYERROR;
1158 /* XXX is this correct? */
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001159 if (set_instruction_src1(&$$, &$7, &@7) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001160 YYERROR;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001161
Feng, Boqun37d68102011-04-19 08:43:22 +08001162 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001163 | predicate SEND execsize dst sendleadreg payload imm32reg instoptions
Feng, Boqun37d68102011-04-19 08:43:22 +08001164 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001165 if ($7.reg.type != BRW_REGISTER_TYPE_UD &&
1166 $7.reg.type != BRW_REGISTER_TYPE_D &&
1167 $7.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001168 fprintf (stderr, "%d: non-int D/UD/V representation: %d,type=%d\n", yylineno, $7.reg.dw1.ud, $7.reg.type);
Feng, Boqun37d68102011-04-19 08:43:22 +08001169 YYERROR;
1170 }
Homer Hsing81859af2012-09-14 09:34:58 +08001171 memset(&$$, 0, sizeof($$));
Feng, Boqun37d68102011-04-19 08:43:22 +08001172 $$.header.opcode = $2;
Damien Lespiaub33b8812013-01-23 16:06:49 +00001173 $$.header.destreg__conditionalmod = $5.nr; /* msg reg index */
Feng, Boqun37d68102011-04-19 08:43:22 +08001174
1175 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001176 $4.width = $3;
Feng, Boqun37d68102011-04-19 08:43:22 +08001177 if (set_instruction_dest(&$$, &$4) != 0)
1178 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001179 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001180 YYERROR;
1181 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001182 $$.bits1.da1.src1_reg_type = $7.reg.type;
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001183 $$.bits3.ud = $7.reg.dw1.ud;
Feng, Boqun37d68102011-04-19 08:43:22 +08001184 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001185 | predicate SEND execsize dst sendleadreg sndopr imm32reg instoptions
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001186 {
1187 struct src_operand src0;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001188
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001189 if (!IS_GENp(6)) {
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001190 fprintf(stderr, "error: the syntax of send instruction\n");
1191 YYERROR;
1192 }
1193
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001194 if ($7.reg.type != BRW_REGISTER_TYPE_UD &&
1195 $7.reg.type != BRW_REGISTER_TYPE_D &&
1196 $7.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001197 fprintf (stderr, "%d: non-int D/UD/V representation: %d,type=%d\n", yylineno, $7.reg.dw1.ud, $7.reg.type);
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001198 YYERROR;
1199 }
1200
Homer Hsing81859af2012-09-14 09:34:58 +08001201 memset(&$$, 0, sizeof($$));
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001202 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001203 $$.header.destreg__conditionalmod = ($6 & EX_DESC_SFID_MASK); /* SFID */
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001204 set_instruction_predicate(&$$, &$1);
1205
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001206 $4.width = $3;
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001207 if (set_instruction_dest(&$$, &$4) != 0)
1208 YYERROR;
1209
1210 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001211 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001212
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001213 if (IS_GENp(7)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001214 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
1215 src0.reg.type = BRW_REGISTER_TYPE_UB;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001216 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001217 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
1218 src0.reg.type = BRW_REGISTER_TYPE_D;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001219 }
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001220
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001221 src0.reg.nr = $5.nr;
1222 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001223 set_instruction_src0(&$$, &src0, NULL);
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001224
1225 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001226 $$.bits1.da1.src1_reg_type = $7.reg.type;
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001227 $$.bits3.ud = $7.reg.dw1.ud;
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001228 $$.bits3.generic_gen5.end_of_thread = !!($6 & EX_DESC_EOT_MASK);
1229 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001230 | predicate SEND execsize dst sendleadreg sndopr directsrcoperand instoptions
1231 {
1232 struct src_operand src0;
1233
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001234 if (!IS_GENp(6)) {
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001235 fprintf(stderr, "error: the syntax of send instruction\n");
1236 YYERROR;
1237 }
1238
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001239 if ($7.reg.file != BRW_ARCHITECTURE_REGISTER_FILE ||
1240 ($7.reg.nr & 0xF0) != BRW_ARF_ADDRESS ||
1241 ($7.reg.nr & 0x0F) != 0 ||
1242 $7.reg.subnr != 0) {
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001243 fprintf (stderr, "%d: scalar register must be a0.0<0;1,0>:ud\n", yylineno);
1244 YYERROR;
1245 }
1246
Homer Hsing81859af2012-09-14 09:34:58 +08001247 memset(&$$, 0, sizeof($$));
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001248 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001249 $$.header.destreg__conditionalmod = ($6 & EX_DESC_SFID_MASK); /* SFID */
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001250 set_instruction_predicate(&$$, &$1);
1251
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001252 $4.width = $3;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001253 if (set_instruction_dest(&$$, &$4) != 0)
1254 YYERROR;
1255
1256 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001257 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001258
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001259 if (IS_GENp(7)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001260 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
1261 src0.reg.type = BRW_REGISTER_TYPE_UB;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001262 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001263 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
1264 src0.reg.type = BRW_REGISTER_TYPE_D;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001265 }
1266
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001267 src0.reg.nr = $5.nr;
1268 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001269 set_instruction_src0(&$$, &src0, NULL);
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001270
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001271 set_instruction_src1(&$$, &$7, &@7);
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001272 $$.bits3.generic_gen5.end_of_thread = !!($6 & EX_DESC_EOT_MASK);
1273 }
1274 | predicate SEND execsize dst sendleadreg payload sndopr imm32reg instoptions
Xiang, Haihao27b43032010-12-13 16:07:16 +08001275 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001276 if ($8.reg.type != BRW_REGISTER_TYPE_UD &&
1277 $8.reg.type != BRW_REGISTER_TYPE_D &&
1278 $8.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001279 fprintf (stderr, "%d: non-int D/UD/V representation: %d,type=%d\n", yylineno, $8.reg.dw1.ud, $8.reg.type);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001280 YYERROR;
1281 }
Homer Hsing81859af2012-09-14 09:34:58 +08001282 memset(&$$, 0, sizeof($$));
Xiang, Haihao27b43032010-12-13 16:07:16 +08001283 $$.header.opcode = $2;
Damien Lespiaub33b8812013-01-23 16:06:49 +00001284 $$.header.destreg__conditionalmod = $5.nr; /* msg reg index */
Xiang, Haihao27b43032010-12-13 16:07:16 +08001285
1286 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001287 $4.width = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001288 if (set_instruction_dest(&$$, &$4) != 0)
1289 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001290 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001291 YYERROR;
1292 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001293 $$.bits1.da1.src1_reg_type = $8.reg.type;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001294 if (IS_GENx(5)) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08001295 $$.bits2.send_gen5.sfid = ($7 & EX_DESC_SFID_MASK);
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001296 $$.bits3.ud = $8.reg.dw1.ud;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001297 $$.bits3.generic_gen5.end_of_thread = !!($7 & EX_DESC_EOT_MASK);
1298 }
1299 else
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001300 $$.bits3.ud = $8.reg.dw1.ud;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001301 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001302 | predicate SEND execsize dst sendleadreg payload exp directsrcoperand instoptions
Xiang, Haihao27b43032010-12-13 16:07:16 +08001303 {
Homer Hsing81859af2012-09-14 09:34:58 +08001304 memset(&$$, 0, sizeof($$));
Xiang, Haihao27b43032010-12-13 16:07:16 +08001305 $$.header.opcode = $2;
Damien Lespiaub33b8812013-01-23 16:06:49 +00001306 $$.header.destreg__conditionalmod = $5.nr; /* msg reg index */
Xiang, Haihao27b43032010-12-13 16:07:16 +08001307
1308 set_instruction_predicate(&$$, &$1);
1309
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001310 $4.width = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001311 if (set_instruction_dest(&$$, &$4) != 0)
1312 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001313 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001314 YYERROR;
1315 /* XXX is this correct? */
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001316 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001317 YYERROR;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001318 if (IS_GENx(5)) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08001319 $$.bits2.send_gen5.sfid = $7;
1320 }
1321 }
1322
Eric Anholtedc82a02006-08-25 17:42:05 -07001323;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001324
Xiang, Haihao27b43032010-12-13 16:07:16 +08001325sndopr: exp %prec SNDOPR
1326 {
1327 $$ = $1;
1328 }
1329;
1330
1331jumpinstruction: predicate JMPI execsize relativelocation2
Eric Anholt1e907c72006-08-31 10:21:15 -07001332 {
Eric Anholt1e907c72006-08-31 10:21:15 -07001333 /* The jump instruction requires that the IP register
1334 * be the destination and first source operand, while the
1335 * offset is the second source operand. The next instruction
1336 * is the post-incremented IP plus the offset.
1337 */
Homer Hsing81859af2012-09-14 09:34:58 +08001338 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +00001339 $$.gen.header.opcode = $2;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001340 if(advanced_flag)
Damien Lespiau79c62f12013-01-21 21:41:36 +00001341 $$.gen.header.mask_control = BRW_MASK_DISABLE;
1342 set_instruction_predicate(&$$.gen, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001343 ip_dst.width = ffs(1) - 1;
Damien Lespiau79c62f12013-01-21 21:41:36 +00001344 set_instruction_dest(&$$.gen, &ip_dst);
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001345 set_instruction_src0(&$$.gen, &ip_src, NULL);
1346 set_instruction_src1(&$$.gen, &$4, NULL);
Homer Hsingb0b540f2012-09-21 10:06:20 +08001347 $$.first_reloc_target = $4.reloc_target;
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001348 $$.first_reloc_offset = $4.imm32;
Eric Anholt356ce762006-08-31 10:27:48 -07001349 }
1350;
1351
Xiang, Haihao54055322010-10-27 09:42:56 +08001352mathinstruction: predicate MATH_INST execsize dst src srcimm math_function instoptions
1353 {
Homer Hsing81859af2012-09-14 09:34:58 +08001354 memset(&$$, 0, sizeof($$));
Xiang, Haihao54055322010-10-27 09:42:56 +08001355 $$.header.opcode = $2;
Damien Lespiaue71f1d22013-01-14 19:13:19 +00001356 $$.header.destreg__conditionalmod = $7;
Xiang, Haihao54055322010-10-27 09:42:56 +08001357 set_instruction_options(&$$, &$8);
1358 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001359 $4.width = $3;
Xiang, Haihao54055322010-10-27 09:42:56 +08001360 if (set_instruction_dest(&$$, &$4) != 0)
1361 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001362 if (set_instruction_src0(&$$, &$5, &@5) != 0)
Xiang, Haihao54055322010-10-27 09:42:56 +08001363 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001364 if (set_instruction_src1(&$$, &$6, &@6) != 0)
Xiang, Haihao54055322010-10-27 09:42:56 +08001365 YYERROR;
1366 }
1367;
1368
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001369breakinstruction: predicate breakop execsize relativelocation relativelocation instoptions
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001370 {
Homer Hsingce555522012-09-27 15:44:15 +08001371 // for Gen6, Gen7
Homer Hsing81859af2012-09-14 09:34:58 +08001372 memset(&$$, 0, sizeof($$));
Damien Lespiau79c62f12013-01-21 21:41:36 +00001373 set_instruction_predicate(&$$.gen, &$1);
1374 $$.gen.header.opcode = $2;
1375 $$.gen.header.execution_size = $3;
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001376 $$.first_reloc_target = $4.reloc_target;
1377 $$.first_reloc_offset = $4.imm32;
1378 $$.second_reloc_target = $5.reloc_target;
1379 $$.second_reloc_offset = $5.imm32;
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001380 }
1381;
1382
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001383breakop: BREAK | CONT
Eric Anholtedc82a02006-08-25 17:42:05 -07001384;
Eric Anholtf914c6a2006-08-25 11:05:10 -07001385
Keith Packard2d4d4012008-03-30 00:58:28 -07001386/*
Eric Anholtf914c6a2006-08-25 11:05:10 -07001387maskpushop: MSAVE | PUSH
1388;
Keith Packard2d4d4012008-03-30 00:58:28 -07001389 */
Eric Anholtf914c6a2006-08-25 11:05:10 -07001390
Eric Anholt1f58efa2006-09-01 11:56:12 -07001391syncinstruction: predicate WAIT notifyreg
1392 {
Damien Lespiau03750732013-01-23 20:33:00 +00001393 struct brw_reg notify_dst;
Keith Packard2d4d4012008-03-30 00:58:28 -07001394 struct src_operand notify_src;
Eric Anholt1f58efa2006-09-01 11:56:12 -07001395
Homer Hsing81859af2012-09-14 09:34:58 +08001396 memset(&$$, 0, sizeof($$));
Eric Anholt1f58efa2006-09-01 11:56:12 -07001397 $$.header.opcode = $2;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001398 set_direct_dst_operand(&notify_dst, &$3, BRW_REGISTER_TYPE_D);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001399 notify_dst.width = ffs(1) - 1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001400 set_instruction_dest(&$$, &notify_dst);
Xiang, Haihao852216d2011-02-16 15:26:24 +08001401 set_direct_src_operand(&notify_src, &$3, BRW_REGISTER_TYPE_D);
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001402 set_instruction_src0(&$$, &notify_src, NULL);
1403 set_instruction_src1(&$$, &src_null_reg, NULL);
Eric Anholt1f58efa2006-09-01 11:56:12 -07001404 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08001405
Eric Anholt1f58efa2006-09-01 11:56:12 -07001406;
1407
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001408nopinstruction: NOP
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001409 {
Homer Hsing81859af2012-09-14 09:34:58 +08001410 memset(&$$, 0, sizeof($$));
Eric Anholtf914c6a2006-08-25 11:05:10 -07001411 $$.header.opcode = $1;
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001412 };
Eric Anholt22a10632006-08-22 10:15:33 -07001413
1414/* XXX! */
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001415payload: directsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07001416;
1417
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001418post_dst: dst
Eric Anholt22a10632006-08-22 10:15:33 -07001419;
1420
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001421msgtarget: NULL_TOKEN
1422 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001423 if (IS_GENp(5)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001424 $$.bits2.send_gen5.sfid= BRW_SFID_NULL;
Xiang Haihao549b7512009-06-30 10:02:33 +08001425 $$.bits3.generic_gen5.header_present = 0; /* ??? */
1426 } else {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001427 $$.bits3.generic.msg_target = BRW_SFID_NULL;
Xiang Haihao549b7512009-06-30 10:02:33 +08001428 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001429 }
1430 | SAMPLER LPAREN INTEGER COMMA INTEGER COMMA
1431 sampler_datatype RPAREN
1432 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001433 if (IS_GENp(7)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001434 $$.bits2.send_gen5.sfid = BRW_SFID_SAMPLER;
Xiang, Haihao67d4ed62011-05-23 13:45:04 +08001435 $$.bits3.generic_gen5.header_present = 1; /* ??? */
1436 $$.bits3.sampler_gen7.binding_table_index = $3;
1437 $$.bits3.sampler_gen7.sampler = $5;
1438 $$.bits3.sampler_gen7.simd_mode = 2; /* SIMD16, maybe we should add a new parameter */
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001439 } else if (IS_GENp(5)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001440 $$.bits2.send_gen5.sfid = BRW_SFID_SAMPLER;
Xiang Haihao549b7512009-06-30 10:02:33 +08001441 $$.bits3.generic_gen5.header_present = 1; /* ??? */
1442 $$.bits3.sampler_gen5.binding_table_index = $3;
1443 $$.bits3.sampler_gen5.sampler = $5;
1444 $$.bits3.sampler_gen5.simd_mode = 2; /* SIMD16, maybe we should add a new parameter */
1445 } else {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001446 $$.bits3.generic.msg_target = BRW_SFID_SAMPLER;
Xiang Haihao549b7512009-06-30 10:02:33 +08001447 $$.bits3.sampler.binding_table_index = $3;
1448 $$.bits3.sampler.sampler = $5;
1449 switch ($7) {
1450 case TYPE_F:
1451 $$.bits3.sampler.return_format =
1452 BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
1453 break;
1454 case TYPE_UD:
1455 $$.bits3.sampler.return_format =
1456 BRW_SAMPLER_RETURN_FORMAT_UINT32;
1457 break;
1458 case TYPE_D:
1459 $$.bits3.sampler.return_format =
1460 BRW_SAMPLER_RETURN_FORMAT_SINT32;
1461 break;
1462 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001463 }
1464 }
Eric Anholt3d360792006-08-25 09:36:28 -07001465 | MATH math_function saturate math_signed math_scalar
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001466 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001467 if (IS_GENp(6)) {
Homer Hsing5d727892012-10-23 09:21:15 +08001468 fprintf (stderr, "Gen6+ doesn't have math function\n");
Xiang, Haihao718cd6c2010-10-09 12:52:08 +08001469 YYERROR;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001470 } else if (IS_GENx(5)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001471 $$.bits2.send_gen5.sfid = BRW_SFID_MATH;
Xiang Haihao549b7512009-06-30 10:02:33 +08001472 $$.bits3.generic_gen5.header_present = 0;
1473 $$.bits3.math_gen5.function = $2;
1474 if ($3 == BRW_INSTRUCTION_SATURATE)
1475 $$.bits3.math_gen5.saturate = 1;
1476 else
1477 $$.bits3.math_gen5.saturate = 0;
1478 $$.bits3.math_gen5.int_type = $4;
1479 $$.bits3.math_gen5.precision = BRW_MATH_PRECISION_FULL;
1480 $$.bits3.math_gen5.data_type = $5;
1481 } else {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001482 $$.bits3.generic.msg_target = BRW_SFID_MATH;
Xiang Haihao549b7512009-06-30 10:02:33 +08001483 $$.bits3.math.function = $2;
1484 if ($3 == BRW_INSTRUCTION_SATURATE)
1485 $$.bits3.math.saturate = 1;
1486 else
1487 $$.bits3.math.saturate = 0;
1488 $$.bits3.math.int_type = $4;
1489 $$.bits3.math.precision = BRW_MATH_PRECISION_FULL;
1490 $$.bits3.math.data_type = $5;
1491 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001492 }
1493 | GATEWAY
1494 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001495 if (IS_GENp(5)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001496 $$.bits2.send_gen5.sfid = BRW_SFID_MESSAGE_GATEWAY;
Xiang Haihao549b7512009-06-30 10:02:33 +08001497 $$.bits3.generic_gen5.header_present = 0; /* ??? */
1498 } else {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001499 $$.bits3.generic.msg_target = BRW_SFID_MESSAGE_GATEWAY;
Xiang Haihao549b7512009-06-30 10:02:33 +08001500 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001501 }
Zou Nan hai807f8762008-06-18 15:05:19 -07001502 | READ LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1503 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001504 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001505 if (IS_GENx(7)) {
Xiang, Haihaoc8d6bf32011-05-23 13:32:32 +08001506 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001507 GEN6_SFID_DATAPORT_SAMPLER_CACHE;
Xiang, Haihaoc8d6bf32011-05-23 13:32:32 +08001508 $$.bits3.generic_gen5.header_present = 1;
Damien Lespiau8fa561d2013-01-15 18:47:05 +00001509 $$.bits3.gen7_dp.binding_table_index = $3;
1510 $$.bits3.gen7_dp.msg_control = $7;
1511 $$.bits3.gen7_dp.msg_type = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001512 } else if (IS_GENx(6)) {
Xiang, Haihaoa8458d52010-10-09 11:09:47 +08001513 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001514 GEN6_SFID_DATAPORT_SAMPLER_CACHE;
Xiang, Haihaoa8458d52010-10-09 11:09:47 +08001515 $$.bits3.generic_gen5.header_present = 1;
Damien Lespiau668e0df2013-01-15 16:40:06 +00001516 $$.bits3.gen6_dp_sampler_const_cache.binding_table_index = $3;
1517 $$.bits3.gen6_dp_sampler_const_cache.msg_control = $7;
1518 $$.bits3.gen6_dp_sampler_const_cache.msg_type = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001519 } else if (IS_GENx(5)) {
Xiang Haihao549b7512009-06-30 10:02:33 +08001520 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001521 BRW_SFID_DATAPORT_READ;
Xiang Haihao549b7512009-06-30 10:02:33 +08001522 $$.bits3.generic_gen5.header_present = 1;
1523 $$.bits3.dp_read_gen5.binding_table_index = $3;
1524 $$.bits3.dp_read_gen5.target_cache = $5;
1525 $$.bits3.dp_read_gen5.msg_control = $7;
1526 $$.bits3.dp_read_gen5.msg_type = $9;
1527 } else {
1528 $$.bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001529 BRW_SFID_DATAPORT_READ;
Xiang Haihao549b7512009-06-30 10:02:33 +08001530 $$.bits3.dp_read.binding_table_index = $3;
1531 $$.bits3.dp_read.target_cache = $5;
1532 $$.bits3.dp_read.msg_control = $7;
1533 $$.bits3.dp_read.msg_type = $9;
1534 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001535 }
Eric Anholt43313942006-08-24 15:26:10 -07001536 | WRITE LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1537 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001538 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001539 if (IS_GENx(7)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001540 $$.bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
Xiang, Haihaoc8d6bf32011-05-23 13:32:32 +08001541 $$.bits3.generic_gen5.header_present = 1;
Damien Lespiau8fa561d2013-01-15 18:47:05 +00001542 $$.bits3.gen7_dp.binding_table_index = $3;
1543 $$.bits3.gen7_dp.msg_control = $5;
1544 $$.bits3.gen7_dp.msg_type = $7;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001545 } else if (IS_GENx(6)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001546 $$.bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
Xiang, Haihao61784db2010-10-08 16:48:15 +08001547 /* Sandybridge supports headerlesss message for render target write.
1548 * Currently the GFX assembler doesn't support it. so the program must provide
1549 * message header
1550 */
1551 $$.bits3.generic_gen5.header_present = 1;
Damien Lespiaufe0bd372013-01-15 20:24:51 +00001552 $$.bits3.gen6_dp.binding_table_index = $3;
1553 $$.bits3.gen6_dp.msg_control = $5;
1554 $$.bits3.gen6_dp.msg_type = $7;
1555 $$.bits3.gen6_dp.send_commit_msg = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001556 } else if (IS_GENx(5)) {
Xiang Haihao549b7512009-06-30 10:02:33 +08001557 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001558 BRW_SFID_DATAPORT_WRITE;
Xiang Haihao549b7512009-06-30 10:02:33 +08001559 $$.bits3.generic_gen5.header_present = 1;
1560 $$.bits3.dp_write_gen5.binding_table_index = $3;
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001561 $$.bits3.dp_write_gen5.last_render_target = ($5 & 0x8) >> 3;
Xiang Haihao549b7512009-06-30 10:02:33 +08001562 $$.bits3.dp_write_gen5.msg_control = $5 & 0x7;
1563 $$.bits3.dp_write_gen5.msg_type = $7;
1564 $$.bits3.dp_write_gen5.send_commit_msg = $9;
1565 } else {
1566 $$.bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001567 BRW_SFID_DATAPORT_WRITE;
Xiang Haihao549b7512009-06-30 10:02:33 +08001568 $$.bits3.dp_write.binding_table_index = $3;
1569 /* The msg control field of brw_struct.h is split into
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001570 * msg control and last_render_target, even though
1571 * last_render_target isn't common to all write messages.
Xiang Haihao549b7512009-06-30 10:02:33 +08001572 */
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001573 $$.bits3.dp_write.last_render_target = ($5 & 0x8) >> 3;
Xiang Haihao549b7512009-06-30 10:02:33 +08001574 $$.bits3.dp_write.msg_control = $5 & 0x7;
1575 $$.bits3.dp_write.msg_type = $7;
1576 $$.bits3.dp_write.send_commit_msg = $9;
1577 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001578 }
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001579 | WRITE LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1580 INTEGER COMMA INTEGER RPAREN
1581 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001582 if (IS_GENx(7)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001583 $$.bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
Xiang, Haihaoc8d6bf32011-05-23 13:32:32 +08001584 $$.bits3.generic_gen5.header_present = ($11 != 0);
Damien Lespiau8fa561d2013-01-15 18:47:05 +00001585 $$.bits3.gen7_dp.binding_table_index = $3;
1586 $$.bits3.gen7_dp.msg_control = $5;
1587 $$.bits3.gen7_dp.msg_type = $7;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001588 } else if (IS_GENx(6)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001589 $$.bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001590 $$.bits3.generic_gen5.header_present = ($11 != 0);
Damien Lespiaufe0bd372013-01-15 20:24:51 +00001591 $$.bits3.gen6_dp.binding_table_index = $3;
1592 $$.bits3.gen6_dp.msg_control = $5;
1593 $$.bits3.gen6_dp.msg_type = $7;
1594 $$.bits3.gen6_dp.send_commit_msg = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001595 } else if (IS_GENx(5)) {
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001596 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001597 BRW_SFID_DATAPORT_WRITE;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001598 $$.bits3.generic_gen5.header_present = ($11 != 0);
1599 $$.bits3.dp_write_gen5.binding_table_index = $3;
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001600 $$.bits3.dp_write_gen5.last_render_target = ($5 & 0x8) >> 3;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001601 $$.bits3.dp_write_gen5.msg_control = $5 & 0x7;
1602 $$.bits3.dp_write_gen5.msg_type = $7;
1603 $$.bits3.dp_write_gen5.send_commit_msg = $9;
1604 } else {
1605 $$.bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001606 BRW_SFID_DATAPORT_WRITE;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001607 $$.bits3.dp_write.binding_table_index = $3;
1608 /* The msg control field of brw_struct.h is split into
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001609 * msg control and last_render_target, even though
1610 * last_render_target isn't common to all write messages.
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001611 */
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001612 $$.bits3.dp_write.last_render_target = ($5 & 0x8) >> 3;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001613 $$.bits3.dp_write.msg_control = $5 & 0x7;
1614 $$.bits3.dp_write.msg_type = $7;
1615 $$.bits3.dp_write.send_commit_msg = $9;
1616 }
1617 }
Eric Anholte8651962006-08-24 16:37:04 -07001618 | URB INTEGER urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001619 {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001620 $$.bits3.generic.msg_target = BRW_SFID_URB;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001621 if (IS_GENp(5)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001622 $$.bits2.send_gen5.sfid = BRW_SFID_URB;
Xiang Haihao549b7512009-06-30 10:02:33 +08001623 $$.bits3.generic_gen5.header_present = 1;
1624 $$.bits3.urb_gen5.opcode = BRW_URB_OPCODE_WRITE;
1625 $$.bits3.urb_gen5.offset = $2;
1626 $$.bits3.urb_gen5.swizzle_control = $3;
1627 $$.bits3.urb_gen5.pad = 0;
1628 $$.bits3.urb_gen5.allocate = $4;
1629 $$.bits3.urb_gen5.used = $5;
1630 $$.bits3.urb_gen5.complete = $6;
1631 } else {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001632 $$.bits3.generic.msg_target = BRW_SFID_URB;
Xiang Haihao549b7512009-06-30 10:02:33 +08001633 $$.bits3.urb.opcode = BRW_URB_OPCODE_WRITE;
1634 $$.bits3.urb.offset = $2;
1635 $$.bits3.urb.swizzle_control = $3;
1636 $$.bits3.urb.pad = 0;
1637 $$.bits3.urb.allocate = $4;
1638 $$.bits3.urb.used = $5;
1639 $$.bits3.urb.complete = $6;
1640 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001641 }
Zou Nan hai26afe902008-06-18 15:04:11 -07001642 | THREAD_SPAWNER LPAREN INTEGER COMMA INTEGER COMMA
1643 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001644 {
1645 $$.bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001646 BRW_SFID_THREAD_SPAWNER;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001647 if (IS_GENp(5)) {
Xiang Haihao549b7512009-06-30 10:02:33 +08001648 $$.bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001649 BRW_SFID_THREAD_SPAWNER;
Xiang Haihao549b7512009-06-30 10:02:33 +08001650 $$.bits3.generic_gen5.header_present = 0;
1651 $$.bits3.thread_spawner_gen5.opcode = $3;
1652 $$.bits3.thread_spawner_gen5.requester_type = $5;
1653 $$.bits3.thread_spawner_gen5.resource_select = $7;
1654 } else {
1655 $$.bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001656 BRW_SFID_THREAD_SPAWNER;
Xiang Haihao549b7512009-06-30 10:02:33 +08001657 $$.bits3.thread_spawner.opcode = $3;
1658 $$.bits3.thread_spawner.requester_type = $5;
1659 $$.bits3.thread_spawner.resource_select = $7;
1660 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001661 }
Zhou Chang52399862011-04-14 11:51:29 +08001662 | VME LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER RPAREN
1663 {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001664 $$.bits3.generic.msg_target = GEN6_SFID_VME;
Zhou Chang52399862011-04-14 11:51:29 +08001665
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001666 if (IS_GENp(6)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001667 $$.bits2.send_gen5.sfid = GEN6_SFID_VME;
Zhou Chang52399862011-04-14 11:51:29 +08001668 $$.bits3.vme_gen6.binding_table_index = $3;
1669 $$.bits3.vme_gen6.search_path_index = $5;
1670 $$.bits3.vme_gen6.lut_subindex = $7;
1671 $$.bits3.vme_gen6.message_type = $9;
1672 $$.bits3.generic_gen5.header_present = 1;
1673 } else {
Homer Hsing5d727892012-10-23 09:21:15 +08001674 fprintf (stderr, "Gen6- doesn't have vme function\n");
Zhou Chang52399862011-04-14 11:51:29 +08001675 YYERROR;
1676 }
1677 }
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001678 | CRE LPAREN INTEGER COMMA INTEGER RPAREN
1679 {
1680 if (gen_level < 75) {
Homer Hsing5d727892012-10-23 09:21:15 +08001681 fprintf (stderr, "Below Gen7.5 doesn't have CRE function\n");
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001682 YYERROR;
1683 }
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001684 $$.bits3.generic.msg_target = HSW_SFID_CRE;
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001685
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001686 $$.bits2.send_gen5.sfid = HSW_SFID_CRE;
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001687 $$.bits3.cre_gen75.binding_table_index = $3;
1688 $$.bits3.cre_gen75.message_type = $5;
1689 $$.bits3.generic_gen5.header_present = 1;
1690 }
Xiang, Haihao27050392011-06-10 16:04:30 +08001691
1692 | DATA_PORT LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1693 INTEGER COMMA INTEGER COMMA INTEGER RPAREN
1694 {
1695 $$.bits2.send_gen5.sfid = $3;
1696 $$.bits3.generic_gen5.header_present = ($13 != 0);
1697
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001698 if (IS_GENp(7)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001699 if ($3 != GEN6_SFID_DATAPORT_SAMPLER_CACHE &&
1700 $3 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1701 $3 != GEN6_SFID_DATAPORT_CONSTANT_CACHE &&
1702 $3 != GEN7_SFID_DATAPORT_DATA_CACHE) {
Xiang, Haihao27050392011-06-10 16:04:30 +08001703 fprintf (stderr, "error: wrong cache type\n");
1704 YYERROR;
1705 }
1706
Damien Lespiau8fa561d2013-01-15 18:47:05 +00001707 $$.bits3.gen7_dp.category = $11;
1708 $$.bits3.gen7_dp.binding_table_index = $9;
1709 $$.bits3.gen7_dp.msg_control = $7;
1710 $$.bits3.gen7_dp.msg_type = $5;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001711 } else if (IS_GENx(6)) {
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001712 if ($3 != GEN6_SFID_DATAPORT_SAMPLER_CACHE &&
1713 $3 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1714 $3 != GEN6_SFID_DATAPORT_CONSTANT_CACHE) {
Xiang, Haihao27050392011-06-10 16:04:30 +08001715 fprintf (stderr, "error: wrong cache type\n");
1716 YYERROR;
1717 }
1718
Damien Lespiau1f1ad592013-01-15 17:35:24 +00001719 $$.bits3.gen6_dp.send_commit_msg = $11;
1720 $$.bits3.gen6_dp.binding_table_index = $9;
1721 $$.bits3.gen6_dp.msg_control = $7;
1722 $$.bits3.gen6_dp.msg_type = $5;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001723 } else if (!IS_GENp(5)) {
Homer Hsing5d727892012-10-23 09:21:15 +08001724 fprintf (stderr, "Gen6- doesn't support data port for sampler/render/constant/data cache\n");
Xiang, Haihao27050392011-06-10 16:04:30 +08001725 YYERROR;
1726 }
1727 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001728;
1729
Eric Anholte8651962006-08-24 16:37:04 -07001730urb_allocate: ALLOCATE { $$ = 1; }
1731 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001732;
Eric Anholte8651962006-08-24 16:37:04 -07001733
1734urb_used: USED { $$ = 1; }
1735 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001736;
Eric Anholte8651962006-08-24 16:37:04 -07001737
1738urb_complete: COMPLETE { $$ = 1; }
1739 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001740;
Eric Anholte8651962006-08-24 16:37:04 -07001741
1742urb_swizzle: TRANSPOSE { $$ = BRW_URB_SWIZZLE_TRANSPOSE; }
1743 | INTERLEAVE { $$ = BRW_URB_SWIZZLE_INTERLEAVE; }
1744 | /* empty */ { $$ = BRW_URB_SWIZZLE_NONE; }
Eric Anholt3d360792006-08-25 09:36:28 -07001745;
Eric Anholte8651962006-08-24 16:37:04 -07001746
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001747sampler_datatype:
1748 TYPE_F
1749 | TYPE_UD
1750 | TYPE_D
Eric Anholt3d360792006-08-25 09:36:28 -07001751;
1752
1753math_function: INV | LOG | EXP | SQRT | POW | SIN | COS | SINCOS | INTDIV
1754 | INTMOD | INTDIVMOD
1755;
1756
1757math_signed: /* empty */ { $$ = 0; }
1758 | SIGNED { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001759;
Eric Anholt3d360792006-08-25 09:36:28 -07001760
1761math_scalar: /* empty */ { $$ = 0; }
1762 | SCALAR { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001763;
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001764
Eric Anholt22a10632006-08-22 10:15:33 -07001765/* 1.4.2: Destination register */
1766
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001767dst: dstoperand | dstoperandex
Eric Anholt3d360792006-08-25 09:36:28 -07001768;
Eric Anholt22a10632006-08-22 10:15:33 -07001769
Xiang, Haihao27b43032010-12-13 16:07:16 +08001770dstoperand: symbol_reg dstregion
1771 {
Damien Lespiau03750732013-01-23 20:33:00 +00001772 $$ = $1.reg;
1773 $$.hstride = resolve_dst_region(&$1, $2);
1774 $$.type = $1.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001775 }
1776 | dstreg dstregion writemask regtype
Eric Anholt22a10632006-08-22 10:15:33 -07001777 {
1778 /* Returns an instruction with just the destination register
1779 * filled in.
1780 */
Damien Lespiau03750732013-01-23 20:33:00 +00001781 $$ = $1;
1782 $$.hstride = resolve_dst_region(NULL, $2);
1783 $$.dw1.bits.writemask = $3.dw1.bits.writemask;
1784 $$.type = $4.type;
Eric Anholt22a10632006-08-22 10:15:33 -07001785 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001786;
Eric Anholt22a10632006-08-22 10:15:33 -07001787
Eric Anholt883408e2006-08-25 13:38:03 -07001788/* The dstoperandex returns an instruction with just the destination register
1789 * filled in.
1790 */
1791dstoperandex: dstoperandex_typed dstregion regtype
Eric Anholt22a10632006-08-22 10:15:33 -07001792 {
Damien Lespiau03750732013-01-23 20:33:00 +00001793 $$ = $1;
1794 $$.hstride = resolve_dst_region(NULL, $2);
1795 $$.type = $3.type;
Eric Anholt22a10632006-08-22 10:15:33 -07001796 }
Eric Anholt883408e2006-08-25 13:38:03 -07001797 | maskstackreg
1798 {
Damien Lespiau03750732013-01-23 20:33:00 +00001799 $$ = $1;
1800 $$.hstride = 1;
1801 $$.type = BRW_REGISTER_TYPE_UW;
Eric Anholt883408e2006-08-25 13:38:03 -07001802 }
1803 | controlreg
1804 {
Damien Lespiau03750732013-01-23 20:33:00 +00001805 $$ = $1;
1806 $$.hstride = 1;
1807 $$.type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -07001808 }
1809 | ipreg
1810 {
Damien Lespiau03750732013-01-23 20:33:00 +00001811 $$ = $1;
1812 $$.hstride = 1;
1813 $$.type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -07001814 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08001815 | nullreg dstregion regtype
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001816 {
Damien Lespiau03750732013-01-23 20:33:00 +00001817 $$ = $1;
1818 $$.hstride = resolve_dst_region(NULL, $2);
1819 $$.type = $3.type;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001820 }
1821;
Eric Anholt22a10632006-08-22 10:15:33 -07001822
Eric Anholt883408e2006-08-25 13:38:03 -07001823dstoperandex_typed: accreg | flagreg | addrreg | maskreg
1824;
1825
Xiang, Haihao27b43032010-12-13 16:07:16 +08001826symbol_reg: STRING %prec STR_SYMBOL_REG
1827 {
1828 struct declared_register *dcl_reg = find_register($1);
1829
1830 if (dcl_reg == NULL) {
1831 fprintf(stderr, "can't find register %s\n", $1);
1832 YYERROR;
1833 }
1834
1835 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08001836 free($1); // $1 has been malloc'ed by strdup
Xiang, Haihao27b43032010-12-13 16:07:16 +08001837 }
1838 | symbol_reg_p
1839 {
1840 $$=$1;
1841 }
1842;
1843
1844symbol_reg_p: STRING LPAREN exp RPAREN
1845 {
1846 struct declared_register *dcl_reg = find_register($1);
1847
1848 if (dcl_reg == NULL) {
1849 fprintf(stderr, "can't find register %s\n", $1);
1850 YYERROR;
1851 }
1852
1853 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Damien Lespiaucce4fc22013-01-23 15:13:55 +00001854 $$.reg.nr += $3;
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08001855 free($1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001856 }
1857 | STRING LPAREN exp COMMA exp RPAREN
1858 {
1859 struct declared_register *dcl_reg = find_register($1);
1860
1861 if (dcl_reg == NULL) {
1862 fprintf(stderr, "can't find register %s\n", $1);
1863 YYERROR;
1864 }
1865
1866 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Damien Lespiaucce4fc22013-01-23 15:13:55 +00001867 $$.reg.nr += $3;
Homer Hsing599d7d22012-10-16 14:14:25 +08001868 if(advanced_flag) {
Damien Lespiaucce4fc22013-01-23 15:13:55 +00001869 int size = get_type_size(dcl_reg->type);
1870 $$.reg.nr += ($$.reg.subnr + $5) / (32 / size);
1871 $$.reg.subnr = ($$.reg.subnr + $5) % (32 / size);
Homer Hsing599d7d22012-10-16 14:14:25 +08001872 } else {
Damien Lespiaucce4fc22013-01-23 15:13:55 +00001873 $$.reg.nr += ($$.reg.subnr + $5) / 32;
1874 $$.reg.subnr = ($$.reg.subnr + $5) % 32;
1875 }
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08001876 free($1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001877 }
1878;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001879/* Returns a partially complete destination register consisting of the
1880 * direct or indirect register addressing fields, but not stride or writemask.
1881 */
Eric Anholt22a10632006-08-22 10:15:33 -07001882dstreg: directgenreg
1883 {
Damien Lespiau03750732013-01-23 20:33:00 +00001884 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001885 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt22a10632006-08-22 10:15:33 -07001886 }
1887 | directmsgreg
Eric Anholta34d1e02006-08-22 14:52:14 -07001888 {
Damien Lespiau03750732013-01-23 20:33:00 +00001889 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001890 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholta34d1e02006-08-22 14:52:14 -07001891 }
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001892 | indirectgenreg
1893 {
Damien Lespiau03750732013-01-23 20:33:00 +00001894 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001895 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001896 }
1897 | indirectmsgreg
1898 {
Damien Lespiau03750732013-01-23 20:33:00 +00001899 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001900 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001901 }
Eric Anholt22a10632006-08-22 10:15:33 -07001902;
1903
1904/* 1.4.3: Source register */
Eric Anholt0d929b42006-08-22 13:33:41 -07001905srcaccimm: srcacc | imm32reg
Eric Anholt22a10632006-08-22 10:15:33 -07001906;
1907
Eric Anholt2d298742006-08-30 09:57:20 -07001908srcacc: directsrcaccoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07001909;
1910
Xiang, Haihao27b43032010-12-13 16:07:16 +08001911srcimm: directsrcoperand | indirectsrcoperand| imm32reg
Eric Anholtedc82a02006-08-25 17:42:05 -07001912;
Eric Anholt0d929b42006-08-22 13:33:41 -07001913
1914imm32reg: imm32 srcimmtype
Eric Anholt22a10632006-08-22 10:15:33 -07001915 {
Eric Anholt6a88ada2006-08-28 22:11:18 -07001916 union {
1917 int i;
1918 float f;
1919 } intfloat;
Keith Packard2d4d4012008-03-30 00:58:28 -07001920 uint32_t d;
Eric Anholt6a88ada2006-08-28 22:11:18 -07001921
Eric Anholt22a10632006-08-22 10:15:33 -07001922 switch ($2) {
1923 case BRW_REGISTER_TYPE_UD:
Eric Anholt22a10632006-08-22 10:15:33 -07001924 case BRW_REGISTER_TYPE_D:
Keith Packard2d4d4012008-03-30 00:58:28 -07001925 case BRW_REGISTER_TYPE_V:
Xiang, Haihao27b43032010-12-13 16:07:16 +08001926 case BRW_REGISTER_TYPE_VF:
Keith Packard2d4d4012008-03-30 00:58:28 -07001927 switch ($1.r) {
1928 case imm32_d:
1929 d = $1.u.d;
1930 break;
1931 default:
Xiang, Haihao27b43032010-12-13 16:07:16 +08001932 fprintf (stderr, "%d: non-int D/UD/V/VF representation: %d,type=%d\n", yylineno, $1.r, $2);
Keith Packard2d4d4012008-03-30 00:58:28 -07001933 YYERROR;
1934 }
Eric Anholt22a10632006-08-22 10:15:33 -07001935 break;
Eric Anholt0d929b42006-08-22 13:33:41 -07001936 case BRW_REGISTER_TYPE_UW:
Eric Anholt0d929b42006-08-22 13:33:41 -07001937 case BRW_REGISTER_TYPE_W:
Keith Packard2d4d4012008-03-30 00:58:28 -07001938 switch ($1.r) {
1939 case imm32_d:
1940 d = $1.u.d;
1941 break;
1942 default:
1943 fprintf (stderr, "non-int W/UW representation\n");
1944 YYERROR;
1945 }
1946 d &= 0xffff;
1947 d |= d << 16;
Eric Anholt0d929b42006-08-22 13:33:41 -07001948 break;
Eric Anholt22a10632006-08-22 10:15:33 -07001949 case BRW_REGISTER_TYPE_F:
Keith Packard2d4d4012008-03-30 00:58:28 -07001950 switch ($1.r) {
1951 case imm32_f:
1952 intfloat.f = $1.u.f;
1953 break;
1954 case imm32_d:
1955 intfloat.f = (float) $1.u.d;
1956 break;
1957 default:
1958 fprintf (stderr, "non-float F representation\n");
1959 YYERROR;
1960 }
1961 d = intfloat.i;
Eric Anholt22a10632006-08-22 10:15:33 -07001962 break;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001963#if 0
Keith Packard2d4d4012008-03-30 00:58:28 -07001964 case BRW_REGISTER_TYPE_VF:
1965 fprintf (stderr, "Immediate type VF not supported yet\n");
1966 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001967#endif
Eric Anholt0d929b42006-08-22 13:33:41 -07001968 default:
1969 fprintf(stderr, "unknown immediate type %d\n", $2);
1970 YYERROR;
Eric Anholt22a10632006-08-22 10:15:33 -07001971 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001972 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001973 $$.reg.file = BRW_IMMEDIATE_VALUE;
1974 $$.reg.type = $2;
Damien Lespiau9c72beb2013-01-25 15:48:58 +00001975 $$.reg.dw1.ud = d;
Eric Anholt22a10632006-08-22 10:15:33 -07001976 }
1977;
1978
Eric Anholt5297b2a2006-08-25 16:50:17 -07001979directsrcaccoperand: directsrcoperand
Xiang, Haihao27b43032010-12-13 16:07:16 +08001980 | accreg region regtype
Eric Anholt2a0f1352006-08-25 17:44:55 -07001981 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08001982 set_direct_src_operand(&$$, &$1, $3.type);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001983 $$.reg.vstride = $2.vert_stride;
1984 $$.reg.width = $2.width;
1985 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001986 $$.default_region = $2.is_default;
Eric Anholt2a0f1352006-08-25 17:44:55 -07001987 }
Eric Anholt2c787652006-08-25 13:53:48 -07001988;
1989
1990/* Returns a source operand in the src0 fields of an instruction. */
Eric Anholt5297b2a2006-08-25 16:50:17 -07001991srcarchoperandex: srcarchoperandex_typed region regtype
Eric Anholt2c787652006-08-25 13:53:48 -07001992 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001993 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001994 $$.reg.file = $1.file;
1995 $$.reg.type = $3.type;
1996 $$.reg.subnr = $1.subnr;
1997 $$.reg.nr = $1.nr;
1998 $$.reg.vstride = $2.vert_stride;
1999 $$.reg.width = $2.width;
2000 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002001 $$.default_region = $2.is_default;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002002 $$.reg.negate = 0;
2003 $$.reg.abs = 0;
Eric Anholt2c787652006-08-25 13:53:48 -07002004 }
2005 | maskstackreg
2006 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002007 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UB);
Eric Anholt2c787652006-08-25 13:53:48 -07002008 }
2009 | controlreg
2010 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002011 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002012 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002013/* | statereg
Eric Anholt2c787652006-08-25 13:53:48 -07002014 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002015 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002016 }*/
Eric Anholt2c787652006-08-25 13:53:48 -07002017 | notifyreg
2018 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002019 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002020 }
2021 | ipreg
2022 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002023 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002024 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002025 | nullreg region regtype
Eric Anholt2c787652006-08-25 13:53:48 -07002026 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002027 if ($3.is_default) {
2028 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
2029 } else {
2030 set_direct_src_operand(&$$, &$1, $3.type);
2031 }
2032 $$.default_region = 1;
Eric Anholt2c787652006-08-25 13:53:48 -07002033 }
2034;
2035
Eric Anholt5297b2a2006-08-25 16:50:17 -07002036srcarchoperandex_typed: flagreg | addrreg | maskreg
Eric Anholt22a10632006-08-22 10:15:33 -07002037;
2038
Xiang, Haihao128053f2012-06-29 16:47:10 +08002039sendleadreg: symbol_reg
2040 {
2041 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002042 $$.file = $1.reg.file;
2043 $$.nr = $1.reg.nr;
2044 $$.subnr = $1.reg.subnr;
Xiang, Haihao128053f2012-06-29 16:47:10 +08002045 }
2046 | directgenreg | directmsgreg
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08002047;
2048
Eric Anholt2d298742006-08-30 09:57:20 -07002049src: directsrcoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07002050;
2051
Xiang, Haihao27b43032010-12-13 16:07:16 +08002052directsrcoperand: negate abs symbol_reg region regtype
2053 {
2054 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002055 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2056 $$.reg.file = $3.reg.file;
2057 $$.reg.nr = $3.reg.nr;
2058 $$.reg.subnr = $3.reg.subnr;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002059 if ($5.is_default) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002060 $$.reg.type = $3.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002061 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002062 $$.reg.type = $5.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002063 }
2064 if ($4.is_default) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002065 $$.reg.vstride = $3.src_region.vert_stride;
2066 $$.reg.width = $3.src_region.width;
2067 $$.reg.hstride = $3.src_region.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002068 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002069 $$.reg.vstride = $4.vert_stride;
2070 $$.reg.width = $4.width;
2071 $$.reg.hstride = $4.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002072 }
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002073 $$.reg.negate = $1;
2074 $$.reg.abs = $2;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002075 }
2076 | statereg region regtype
2077 {
2078 if($2.is_default ==1 && $3.is_default == 1)
2079 {
2080 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
2081 }
2082 else{
2083 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002084 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2085 $$.reg.file = $1.file;
2086 $$.reg.nr = $1.nr;
2087 $$.reg.subnr = $1.subnr;
2088 $$.reg.vstride = $2.vert_stride;
2089 $$.reg.width = $2.width;
2090 $$.reg.hstride = $2.horiz_stride;
2091 $$.reg.type = $3.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002092 }
2093 }
2094 | negate abs directgenreg region regtype swizzle
Eric Anholt22a10632006-08-22 10:15:33 -07002095 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002096 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002097 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2098 $$.reg.file = $3.file;
2099 $$.reg.nr = $3.nr;
2100 $$.reg.subnr = $3.subnr;
2101 $$.reg.type = $5.type;
2102 $$.reg.vstride = $4.vert_stride;
2103 $$.reg.width = $4.width;
2104 $$.reg.hstride = $4.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002105 $$.default_region = $4.is_default;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002106 $$.reg.negate = $1;
2107 $$.reg.abs = $2;
2108 $$.reg.dw1.bits.swizzle = $6.reg.dw1.bits.swizzle;
Eric Anholt22a10632006-08-22 10:15:33 -07002109 }
Eric Anholt5297b2a2006-08-25 16:50:17 -07002110 | srcarchoperandex
Eric Anholt22a10632006-08-22 10:15:33 -07002111;
2112
Eric Anholt2d298742006-08-30 09:57:20 -07002113indirectsrcoperand:
2114 negate abs indirectgenreg indirectregion regtype swizzle
2115 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002116 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002117 $$.reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
2118 $$.reg.file = $3.file;
2119 $$.reg.subnr = $3.subnr;
2120 $$.reg.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
2121 $$.reg.type = $5.type;
2122 $$.reg.vstride = $4.vert_stride;
2123 $$.reg.width = $4.width;
2124 $$.reg.hstride = $4.horiz_stride;
2125 $$.reg.negate = $1;
2126 $$.reg.abs = $2;
2127 $$.reg.dw1.bits.swizzle = $6.reg.dw1.bits.swizzle;
Eric Anholt2d298742006-08-30 09:57:20 -07002128 }
2129;
2130
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002131/* 1.4.4: Address Registers */
Damien Lespiau801b4eb2013-01-23 16:20:05 +00002132/* Returns a partially-completed struct brw_reg consisting of the address
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002133 * register fields for register-indirect access.
2134 */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002135addrparam: addrreg COMMA immaddroffset
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002136 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002137 if ($3 < -512 || $3 > 511) {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002138 fprintf(stderr, "Address immediate offset %d out of"
Xiang, Haihao27b43032010-12-13 16:07:16 +08002139 "range %d\n", $3, yylineno);
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002140 YYERROR;
2141 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002142 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002143 $$.subnr = $1.subnr;
2144 $$.dw1.bits.indirect_offset = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002145 }
2146 | addrreg
2147 {
2148 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002149 $$.subnr = $1.subnr;
2150 $$.dw1.bits.indirect_offset = 0;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002151 }
2152;
2153
2154/* The immaddroffset provides an immediate offset value added to the addresses
2155 * from the address register in register-indirect register access.
2156 */
2157immaddroffset: /* empty */ { $$ = 0; }
Zou Nan hai5608d272009-10-20 14:51:04 +08002158 | exp
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002159;
2160
2161
Eric Anholtedc82a02006-08-25 17:42:05 -07002162/* 1.4.5: Register files and register numbers */
Zou Nan hai5608d272009-10-20 14:51:04 +08002163subregnum: DOT exp
Eric Anholt22a10632006-08-22 10:15:33 -07002164 {
2165 $$ = $2;
2166 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002167 | %prec SUBREGNUM
Eric Anholt22a10632006-08-22 10:15:33 -07002168 {
2169 /* Default to subreg 0 if unspecified. */
2170 $$ = 0;
2171 }
2172;
2173
Eric Anholt569990b2006-08-25 09:46:18 -07002174directgenreg: GENREG subregnum
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002175 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002176 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002177 $$.file = BRW_GENERAL_REGISTER_FILE;
2178 $$.nr = $1;
2179 $$.subnr = $2;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002180 }
Eric Anholtedc82a02006-08-25 17:42:05 -07002181;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002182
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002183indirectgenreg: GENREGFILE LSQUARE addrparam RSQUARE
2184 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002185 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002186 $$.file = BRW_GENERAL_REGISTER_FILE;
2187 $$.subnr = $3.subnr;
2188 $$.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002189 }
2190;
2191
Eric Anholt569990b2006-08-25 09:46:18 -07002192directmsgreg: MSGREG subregnum
Eric Anholt22a10632006-08-22 10:15:33 -07002193 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002194 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002195 $$.file = BRW_MESSAGE_REGISTER_FILE;
2196 $$.nr = $1;
2197 $$.subnr = $2;
Eric Anholt22a10632006-08-22 10:15:33 -07002198 }
2199;
2200
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002201indirectmsgreg: MSGREGFILE LSQUARE addrparam RSQUARE
2202 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002203 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002204 $$.file = BRW_MESSAGE_REGISTER_FILE;
2205 $$.subnr = $3.subnr;
2206 $$.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002207 }
2208;
2209
Eric Anholt883408e2006-08-25 13:38:03 -07002210addrreg: ADDRESSREG subregnum
2211 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002212 if ($1 != 0) {
2213 fprintf(stderr,
2214 "address register number %d out of range", $1);
2215 YYERROR;
2216 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002217 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002218 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2219 $$.nr = BRW_ARF_ADDRESS | $1;
2220 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002221 }
2222;
2223
Eric Anholt569990b2006-08-25 09:46:18 -07002224accreg: ACCREG subregnum
2225 {
Eric Anholt569990b2006-08-25 09:46:18 -07002226 if ($1 > 1) {
2227 fprintf(stderr,
2228 "accumulator register number %d out of range", $1);
2229 YYERROR;
2230 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002231 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002232 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2233 $$.nr = BRW_ARF_ACCUMULATOR | $1;
2234 $$.subnr = $2;
Eric Anholt569990b2006-08-25 09:46:18 -07002235 }
2236;
2237
Xiang, Haihaof3f6ba22012-07-17 13:46:59 +08002238flagreg: FLAGREG subregnum
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002239 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002240 if ((!IS_GENp(7) && $1) > 0 ||
2241 (IS_GENp(7) && $1 > 1)) {
Xiang, Haihaof3f6ba22012-07-17 13:46:59 +08002242 fprintf(stderr,
2243 "flag register number %d out of range\n", $1);
2244 YYERROR;
2245 }
2246
2247 if ($2 > 1) {
2248 fprintf(stderr,
2249 "flag subregister number %d out of range\n", $1);
2250 YYERROR;
2251 }
2252
Keith Packard2d4d4012008-03-30 00:58:28 -07002253 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002254 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2255 $$.nr = BRW_ARF_FLAG | $1;
2256 $$.subnr = $2;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002257 }
2258;
2259
Eric Anholt883408e2006-08-25 13:38:03 -07002260maskreg: MASKREG subregnum
2261 {
2262 if ($1 > 0) {
2263 fprintf(stderr,
2264 "mask register number %d out of range", $1);
2265 YYERROR;
2266 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002267 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002268 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2269 $$.nr = BRW_ARF_MASK;
2270 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002271 }
2272 | mask_subreg
2273 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002274 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002275 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2276 $$.nr = BRW_ARF_MASK;
2277 $$.subnr = $1;
Eric Anholt883408e2006-08-25 13:38:03 -07002278 }
2279;
2280
2281mask_subreg: AMASK | IMASK | LMASK | CMASK
2282;
2283
2284maskstackreg: MASKSTACKREG subregnum
2285 {
2286 if ($1 > 0) {
2287 fprintf(stderr,
2288 "mask stack register number %d out of range", $1);
2289 YYERROR;
2290 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002291 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002292 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2293 $$.nr = BRW_ARF_MASK_STACK;
2294 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002295 }
2296 | maskstack_subreg
2297 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002298 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002299 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2300 $$.nr = BRW_ARF_MASK_STACK;
2301 $$.subnr = $1;
Eric Anholt883408e2006-08-25 13:38:03 -07002302 }
2303;
2304
2305maskstack_subreg: IMS | LMS
2306;
2307
Keith Packard2d4d4012008-03-30 00:58:28 -07002308/*
Eric Anholt883408e2006-08-25 13:38:03 -07002309maskstackdepthreg: MASKSTACKDEPTHREG subregnum
2310 {
2311 if ($1 > 0) {
2312 fprintf(stderr,
2313 "mask stack register number %d out of range", $1);
2314 YYERROR;
2315 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002316 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07002317 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2318 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
2319 $$.subreg_nr = $2;
2320 }
2321 | maskstackdepth_subreg
2322 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002323 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07002324 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2325 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
2326 $$.subreg_nr = $1;
2327 }
2328;
2329
2330maskstackdepth_subreg: IMSD | LMSD
2331;
Keith Packard2d4d4012008-03-30 00:58:28 -07002332 */
Eric Anholt883408e2006-08-25 13:38:03 -07002333
Xiang, Haihao27b43032010-12-13 16:07:16 +08002334notifyreg: NOTIFYREG regtype
Eric Anholt883408e2006-08-25 13:38:03 -07002335 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002336 int num_notifyreg = (IS_GENp(6)) ? 3 : 2;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002337
2338 if ($1 > num_notifyreg) {
Eric Anholt883408e2006-08-25 13:38:03 -07002339 fprintf(stderr,
2340 "notification register number %d out of range",
2341 $1);
2342 YYERROR;
2343 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002344 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002345 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002346
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002347 if (IS_GENp(6)) {
Damien Lespiaub33b8812013-01-23 16:06:49 +00002348 $$.nr = BRW_ARF_NOTIFICATION_COUNT;
2349 $$.subnr = $1;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002350 } else {
Damien Lespiaub33b8812013-01-23 16:06:49 +00002351 $$.nr = BRW_ARF_NOTIFICATION_COUNT | $1;
2352 $$.subnr = 0;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002353 }
Eric Anholt883408e2006-08-25 13:38:03 -07002354 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002355/*
2356 | NOTIFYREG regtype
2357 {
2358 if ($1 > 1) {
2359 fprintf(stderr,
2360 "notification register number %d out of range",
2361 $1);
2362 YYERROR;
2363 }
2364 memset (&$$, '\0', sizeof ($$));
2365 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2366 $$.reg_nr = BRW_ARF_NOTIFICATION_COUNT;
2367 $$.subreg_nr = 0;
2368 }
2369*/
Eric Anholt883408e2006-08-25 13:38:03 -07002370;
2371
2372statereg: STATEREG subregnum
2373 {
2374 if ($1 > 0) {
2375 fprintf(stderr,
2376 "state register number %d out of range", $1);
2377 YYERROR;
2378 }
2379 if ($2 > 1) {
2380 fprintf(stderr,
2381 "state subregister number %d out of range", $1);
2382 YYERROR;
2383 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002384 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002385 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2386 $$.nr = BRW_ARF_STATE | $1;
2387 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002388 }
2389;
2390
2391controlreg: CONTROLREG subregnum
2392 {
2393 if ($1 > 0) {
2394 fprintf(stderr,
2395 "control register number %d out of range", $1);
2396 YYERROR;
2397 }
2398 if ($2 > 2) {
2399 fprintf(stderr,
2400 "control subregister number %d out of range", $1);
2401 YYERROR;
2402 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002403 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002404 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2405 $$.nr = BRW_ARF_CONTROL | $1;
2406 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002407 }
2408;
2409
Xiang, Haihao27b43032010-12-13 16:07:16 +08002410ipreg: IPREG regtype
Eric Anholt883408e2006-08-25 13:38:03 -07002411 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002412 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002413 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2414 $$.nr = BRW_ARF_IP;
2415 $$.subnr = 0;
Eric Anholt883408e2006-08-25 13:38:03 -07002416 }
2417;
2418
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002419nullreg: NULL_TOKEN
2420 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002421 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002422 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2423 $$.nr = BRW_ARF_NULL;
2424 $$.subnr = 0;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002425 }
Eric Anholt22a10632006-08-22 10:15:33 -07002426;
2427
Eric Anholt1e907c72006-08-31 10:21:15 -07002428/* 1.4.6: Relative locations */
Homer Hsingc0ebde22012-09-21 10:14:31 +08002429relativelocation:
Homer Hsing4bf84ec2012-09-24 10:12:26 +08002430 simple_int
Eric Anholt1e907c72006-08-31 10:21:15 -07002431 {
Homer Hsingc0ebde22012-09-21 10:14:31 +08002432 if (($1 > 32767) || ($1 < -32768)) {
Eric Anholt1e907c72006-08-31 10:21:15 -07002433 fprintf(stderr,
Xiang, Haihao27b43032010-12-13 16:07:16 +08002434 "error: relative offset %d out of range \n",
Homer Hsingc0ebde22012-09-21 10:14:31 +08002435 $1);
Eric Anholt1e907c72006-08-31 10:21:15 -07002436 YYERROR;
2437 }
2438
Keith Packard2d4d4012008-03-30 00:58:28 -07002439 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002440 $$.reg.file = BRW_IMMEDIATE_VALUE;
2441 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingc0ebde22012-09-21 10:14:31 +08002442 $$.imm32 = $1 & 0x0000ffff;
2443 }
2444 | STRING
2445 {
2446 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002447 $$.reg.file = BRW_IMMEDIATE_VALUE;
2448 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingc0ebde22012-09-21 10:14:31 +08002449 $$.reloc_target = $1;
Eric Anholt1e907c72006-08-31 10:21:15 -07002450 }
2451;
2452
2453relativelocation2:
Homer Hsingb0b540f2012-09-21 10:06:20 +08002454 STRING
Eric Anholt1e907c72006-08-31 10:21:15 -07002455 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002456 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002457 $$.reg.file = BRW_IMMEDIATE_VALUE;
2458 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingb0b540f2012-09-21 10:06:20 +08002459 $$.reloc_target = $1;
2460 }
2461 | exp
2462 {
2463 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002464 $$.reg.file = BRW_IMMEDIATE_VALUE;
2465 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingb0b540f2012-09-21 10:06:20 +08002466 $$.imm32 = $1;
Eric Anholt1e907c72006-08-31 10:21:15 -07002467 }
2468 | directgenreg region regtype
2469 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002470 set_direct_src_operand(&$$, &$1, $3.type);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002471 $$.reg.vstride = $2.vert_stride;
2472 $$.reg.width = $2.width;
2473 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002474 $$.default_region = $2.is_default;
2475 }
2476 | symbol_reg_p
2477 {
2478 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002479 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2480 $$.reg.file = $1.reg.file;
2481 $$.reg.nr = $1.reg.nr;
2482 $$.reg.subnr = $1.reg.subnr;
2483 $$.reg.type = $1.type;
2484 $$.reg.vstride = $1.src_region.vert_stride;
2485 $$.reg.width = $1.src_region.width;
2486 $$.reg.hstride = $1.src_region.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002487 }
2488 | indirectgenreg indirectregion regtype
2489 {
2490 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002491 $$.reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
2492 $$.reg.file = $1.file;
2493 $$.reg.subnr = $1.subnr;
2494 $$.reg.dw1.bits.indirect_offset = $1.dw1.bits.indirect_offset;
2495 $$.reg.type = $3.type;
2496 $$.reg.vstride = $2.vert_stride;
2497 $$.reg.width = $2.width;
2498 $$.reg.hstride = $2.horiz_stride;
Eric Anholt1e907c72006-08-31 10:21:15 -07002499 }
2500;
2501
Eric Anholt22a10632006-08-22 10:15:33 -07002502/* 1.4.7: Regions */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002503dstregion: /* empty */
2504 {
2505 $$ = DEFAULT_DSTREGION;
2506 }
2507 |LANGLE exp RANGLE
Eric Anholt22a10632006-08-22 10:15:33 -07002508 {
2509 /* Returns a value for a horiz_stride field of an
2510 * instruction.
2511 */
2512 if ($2 != 1 && $2 != 2 && $2 != 4) {
2513 fprintf(stderr, "Invalid horiz size %d\n", $2);
2514 }
Eric Anholt0edcb252006-08-22 13:15:38 -07002515 $$ = ffs($2);
Eric Anholt22a10632006-08-22 10:15:33 -07002516 }
2517;
2518
Xiang, Haihao27b43032010-12-13 16:07:16 +08002519region: /* empty */
2520 {
2521 /* XXX is this default value correct?*/
2522 memset (&$$, '\0', sizeof ($$));
2523 $$.vert_stride = ffs(0);
2524 $$.width = ffs(1) - 1;
2525 $$.horiz_stride = ffs(0);
2526 $$.is_default = 1;
2527 }
2528 |LANGLE exp RANGLE
2529 {
2530 /* XXX is this default value correct for accreg?*/
2531 memset (&$$, '\0', sizeof ($$));
2532 $$.vert_stride = ffs($2);
2533 $$.width = ffs(1) - 1;
2534 $$.horiz_stride = ffs(0);
2535 }
2536 |LANGLE exp COMMA exp COMMA exp RANGLE
Eric Anholt22a10632006-08-22 10:15:33 -07002537 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002538 memset (&$$, '\0', sizeof ($$));
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002539 $$.vert_stride = ffs($2);
2540 $$.width = ffs($4) - 1;
Eric Anholtd4c82e82006-08-22 13:08:26 -07002541 $$.horiz_stride = ffs($6);
Eric Anholt22a10632006-08-22 10:15:33 -07002542 }
Zou Nan haic6f2da42009-10-28 10:14:19 +08002543 | LANGLE exp SEMICOLON exp COMMA exp RANGLE
2544 {
2545 memset (&$$, '\0', sizeof ($$));
2546 $$.vert_stride = ffs($2);
2547 $$.width = ffs($4) - 1;
2548 $$.horiz_stride = ffs($6);
2549 }
Eric Anholt22a10632006-08-22 10:15:33 -07002550
Xiang, Haihao27b43032010-12-13 16:07:16 +08002551;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002552/* region_wh is used in specifying indirect operands where rather than having
2553 * a vertical stride, you use subsequent address registers to get a new base
Eric Anholt2d298742006-08-30 09:57:20 -07002554 * offset for the next row.
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002555 */
Zou Nan hai5608d272009-10-20 14:51:04 +08002556region_wh: LANGLE exp COMMA exp RANGLE
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002557 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002558 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002559 $$.vert_stride = BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL;
2560 $$.width = ffs($2) - 1;
2561 $$.horiz_stride = ffs($4);
2562 }
2563;
2564
Eric Anholt2d298742006-08-30 09:57:20 -07002565indirectregion: region | region_wh
2566;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002567
Eric Anholt22a10632006-08-22 10:15:33 -07002568/* 1.4.8: Types */
2569
2570/* regtype returns an integer register type suitable for inserting into an
2571 * instruction.
2572 */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002573regtype: /* empty */
2574 { $$.type = program_defaults.register_type;$$.is_default = 1;}
2575 | TYPE_F { $$.type = BRW_REGISTER_TYPE_F;$$.is_default = 0; }
2576 | TYPE_UD { $$.type = BRW_REGISTER_TYPE_UD;$$.is_default = 0; }
2577 | TYPE_D { $$.type = BRW_REGISTER_TYPE_D;$$.is_default = 0; }
2578 | TYPE_UW { $$.type = BRW_REGISTER_TYPE_UW;$$.is_default = 0; }
2579 | TYPE_W { $$.type = BRW_REGISTER_TYPE_W;$$.is_default = 0; }
2580 | TYPE_UB { $$.type = BRW_REGISTER_TYPE_UB;$$.is_default = 0; }
2581 | TYPE_B { $$.type = BRW_REGISTER_TYPE_B;$$.is_default = 0; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002582;
2583
Xiang, Haihao27b43032010-12-13 16:07:16 +08002584srcimmtype: /* empty */
2585 {
2586 /* XXX change to default when pragma parse is done */
2587 $$ = BRW_REGISTER_TYPE_D;
2588 }
2589 |TYPE_F { $$ = BRW_REGISTER_TYPE_F; }
Keith Packard2d4d4012008-03-30 00:58:28 -07002590 | TYPE_UD { $$ = BRW_REGISTER_TYPE_UD; }
2591 | TYPE_D { $$ = BRW_REGISTER_TYPE_D; }
2592 | TYPE_UW { $$ = BRW_REGISTER_TYPE_UW; }
2593 | TYPE_W { $$ = BRW_REGISTER_TYPE_W; }
2594 | TYPE_V { $$ = BRW_REGISTER_TYPE_V; }
2595 | TYPE_VF { $$ = BRW_REGISTER_TYPE_VF; }
Eric Anholt22a10632006-08-22 10:15:33 -07002596;
2597
Eric Anholt6a88ada2006-08-28 22:11:18 -07002598/* 1.4.10: Swizzle control */
2599/* Returns the swizzle control for an align16 instruction's source operand
2600 * in the src0 fields.
2601 */
2602swizzle: /* empty */
2603 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002604 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE_NOOP;
Eric Anholt6a88ada2006-08-28 22:11:18 -07002605 }
2606 | DOT chansel
2607 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002608 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE4($2, $2, $2, $2);
Eric Anholt6a88ada2006-08-28 22:11:18 -07002609 }
2610 | DOT chansel chansel chansel chansel
2611 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002612 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE4($2, $3, $4, $5);
Eric Anholt6a88ada2006-08-28 22:11:18 -07002613 }
2614;
2615
2616chansel: X | Y | Z | W
2617;
2618
Eric Anholt2dac0a12006-08-29 15:29:31 -07002619/* 1.4.9: Write mask */
Damien Lespiau03750732013-01-23 20:33:00 +00002620/* Returns a partially completed struct brw_reg, with just the writemask bits
Eric Anholt2dac0a12006-08-29 15:29:31 -07002621 * filled out.
2622 */
2623writemask: /* empty */
2624 {
Damien Lespiau03750732013-01-23 20:33:00 +00002625 $$.dw1.bits.writemask = BRW_WRITEMASK_XYZW;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002626 }
2627 | DOT writemask_x writemask_y writemask_z writemask_w
2628 {
Damien Lespiau03750732013-01-23 20:33:00 +00002629 $$.dw1.bits.writemask = $2 | $3 | $4 | $5;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002630 }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002631;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002632
2633writemask_x: /* empty */ { $$ = 0; }
2634 | X { $$ = 1 << BRW_CHANNEL_X; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002635;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002636
2637writemask_y: /* empty */ { $$ = 0; }
2638 | Y { $$ = 1 << BRW_CHANNEL_Y; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002639;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002640
2641writemask_z: /* empty */ { $$ = 0; }
2642 | Z { $$ = 1 << BRW_CHANNEL_Z; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002643;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002644
2645writemask_w: /* empty */ { $$ = 0; }
2646 | W { $$ = 1 << BRW_CHANNEL_W; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002647;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002648
Eric Anholtedc82a02006-08-25 17:42:05 -07002649/* 1.4.11: Immediate values */
Zou Nan hai5608d272009-10-20 14:51:04 +08002650imm32: exp { $$.r = imm32_d; $$.u.d = $1; }
Keith Packard2d4d4012008-03-30 00:58:28 -07002651 | NUMBER { $$.r = imm32_f; $$.u.f = $1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002652;
Eric Anholt22a10632006-08-22 10:15:33 -07002653
2654/* 1.4.12: Predication and modifiers */
Eric Anholt0ed5d932006-08-28 23:05:51 -07002655predicate: /* empty */
2656 {
2657 $$.header.predicate_control = BRW_PREDICATE_NONE;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08002658 $$.bits2.da1.flag_reg_nr = 0;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +08002659 $$.bits2.da1.flag_subreg_nr = 0;
Eric Anholt0ed5d932006-08-28 23:05:51 -07002660 $$.header.predicate_inverse = 0;
2661 }
2662 | LPAREN predstate flagreg predctrl RPAREN
2663 {
2664 $$.header.predicate_control = $4;
2665 /* XXX: Should deal with erroring when the user tries to
2666 * set a predicate for one flag register and conditional
2667 * modification on the other flag register.
2668 */
Damien Lespiaub33b8812013-01-23 16:06:49 +00002669 $$.bits2.da1.flag_reg_nr = ($3.nr & 0xF);
2670 $$.bits2.da1.flag_subreg_nr = $3.subnr;
Eric Anholt0ed5d932006-08-28 23:05:51 -07002671 $$.header.predicate_inverse = $2;
2672 }
2673;
2674
2675predstate: /* empty */ { $$ = 0; }
2676 | PLUS { $$ = 0; }
2677 | MINUS { $$ = 1; }
2678;
2679
Keith Packard2033aea2008-04-23 23:10:40 -07002680predctrl: /* empty */ { $$ = BRW_PREDICATE_NORMAL; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07002681 | DOT X { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_X; }
2682 | DOT Y { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Y; }
2683 | DOT Z { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Z; }
2684 | DOT W { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_W; }
Keith Packard2033aea2008-04-23 23:10:40 -07002685 | ANYV { $$ = BRW_PREDICATE_ALIGN1_ANYV; }
2686 | ALLV { $$ = BRW_PREDICATE_ALIGN1_ALLV; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07002687 | ANY2H { $$ = BRW_PREDICATE_ALIGN1_ANY2H; }
2688 | ALL2H { $$ = BRW_PREDICATE_ALIGN1_ALL2H; }
2689 | ANY4H { $$ = BRW_PREDICATE_ALIGN1_ANY4H; }
2690 | ALL4H { $$ = BRW_PREDICATE_ALIGN1_ALL4H; }
2691 | ANY8H { $$ = BRW_PREDICATE_ALIGN1_ANY8H; }
2692 | ALL8H { $$ = BRW_PREDICATE_ALIGN1_ALL8H; }
2693 | ANY16H { $$ = BRW_PREDICATE_ALIGN1_ANY16H; }
2694 | ALL16H { $$ = BRW_PREDICATE_ALIGN1_ALL16H; }
Eric Anholtdc96c562006-08-22 14:42:45 -07002695;
2696
2697negate: /* empty */ { $$ = 0; }
2698 | MINUS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002699;
Eric Anholtdc96c562006-08-22 14:42:45 -07002700
2701abs: /* empty */ { $$ = 0; }
2702 | ABS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002703;
Eric Anholt22a10632006-08-22 10:15:33 -07002704
Xiang, Haihao27b43032010-12-13 16:07:16 +08002705execsize: /* empty */ %prec EMPTEXECSIZE
2706 {
2707 $$ = ffs(program_defaults.execute_size) - 1;
2708 }
2709 |LPAREN exp RPAREN
Eric Anholt22a10632006-08-22 10:15:33 -07002710 {
2711 /* Returns a value for the execution_size field of an
2712 * instruction.
2713 */
2714 if ($2 != 1 && $2 != 2 && $2 != 4 && $2 != 8 && $2 != 16 &&
2715 $2 != 32) {
2716 fprintf(stderr, "Invalid execution size %d\n", $2);
2717 YYERROR;
2718 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002719 $$ = ffs($2) - 1;
Eric Anholt22a10632006-08-22 10:15:33 -07002720 }
2721;
2722
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002723saturate: /* empty */ { $$ = BRW_INSTRUCTION_NORMAL; }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002724 | SATURATE { $$ = BRW_INSTRUCTION_SATURATE; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002725;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002726conditionalmodifier: condition
2727 {
2728 $$.cond = $1;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08002729 $$.flag_reg_nr = 0;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +08002730 $$.flag_subreg_nr = -1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002731 }
2732 | condition DOT flagreg
2733 {
2734 $$.cond = $1;
Damien Lespiaub33b8812013-01-23 16:06:49 +00002735 $$.flag_reg_nr = ($3.nr & 0xF);
2736 $$.flag_subreg_nr = $3.subnr;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002737 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002738
Xiang, Haihao27b43032010-12-13 16:07:16 +08002739condition: /* empty */ { $$ = BRW_CONDITIONAL_NONE; }
Keith Packard2033aea2008-04-23 23:10:40 -07002740 | ZERO
2741 | EQUAL
2742 | NOT_ZERO
2743 | NOT_EQUAL
2744 | GREATER
2745 | GREATER_EQUAL
2746 | LESS
2747 | LESS_EQUAL
2748 | ROUND_INCREMENT
2749 | OVERFLOW
2750 | UNORDERED
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002751;
2752
Eric Anholt22a10632006-08-22 10:15:33 -07002753/* 1.4.13: Instruction options */
Zou Nan haic6f2da42009-10-28 10:14:19 +08002754instoptions: /* empty */
2755 { memset(&$$, 0, sizeof($$)); }
2756 | LCURLY instoption_list RCURLY
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002757 { $$ = $2; }
2758;
2759
Homer Hsing5d589db2012-09-21 12:35:35 +08002760instoption_list:instoption_list COMMA instoption
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002761 {
Homer Hsing5d589db2012-09-21 12:35:35 +08002762 $$ = $1;
2763 switch ($3) {
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002764 case ALIGN1:
2765 $$.header.access_mode = BRW_ALIGN_1;
2766 break;
2767 case ALIGN16:
2768 $$.header.access_mode = BRW_ALIGN_16;
2769 break;
Eric Anholt908f37d2006-08-25 17:33:02 -07002770 case SECHALF:
2771 $$.header.compression_control |= BRW_COMPRESSION_2NDHALF;
2772 break;
2773 case COMPR:
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002774 if (!IS_GENp(6)) {
Xiang, Haihaoc2382ca2010-10-09 13:57:48 +08002775 $$.header.compression_control |=
2776 BRW_COMPRESSION_COMPRESSED;
2777 }
Eric Anholt908f37d2006-08-25 17:33:02 -07002778 break;
2779 case SWITCH:
2780 $$.header.thread_control |= BRW_THREAD_SWITCH;
2781 break;
2782 case ATOMIC:
2783 $$.header.thread_control |= BRW_THREAD_ATOMIC;
2784 break;
2785 case NODDCHK:
2786 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCHECKED;
2787 break;
2788 case NODDCLR:
2789 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCLEARED;
2790 break;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002791 case MASK_DISABLE:
2792 $$.header.mask_control = BRW_MASK_DISABLE;
2793 break;
Eric Anholt908f37d2006-08-25 17:33:02 -07002794 case BREAKPOINT:
2795 $$.header.debug_control = BRW_DEBUG_BREAKPOINT;
2796 break;
Xiang, Haihao55d81c42010-10-08 13:53:22 +08002797 case ACCWRCTRL:
Damien Lespiau44318692013-01-18 11:52:01 +00002798 $$.header.acc_wr_control = BRW_ACCUMULATOR_WRITE_ENABLE;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002799 }
2800 }
Homer Hsing5d589db2012-09-21 12:35:35 +08002801 | instoption_list instoption
Xiang, Haihao27b43032010-12-13 16:07:16 +08002802 {
Homer Hsing5d589db2012-09-21 12:35:35 +08002803 $$ = $1;
2804 switch ($2) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002805 case ALIGN1:
2806 $$.header.access_mode = BRW_ALIGN_1;
2807 break;
2808 case ALIGN16:
2809 $$.header.access_mode = BRW_ALIGN_16;
2810 break;
2811 case SECHALF:
2812 $$.header.compression_control |= BRW_COMPRESSION_2NDHALF;
2813 break;
2814 case COMPR:
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002815 if (!IS_GENp(6)) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002816 $$.header.compression_control |=
2817 BRW_COMPRESSION_COMPRESSED;
2818 }
2819 break;
2820 case SWITCH:
2821 $$.header.thread_control |= BRW_THREAD_SWITCH;
2822 break;
2823 case ATOMIC:
2824 $$.header.thread_control |= BRW_THREAD_ATOMIC;
2825 break;
2826 case NODDCHK:
2827 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCHECKED;
2828 break;
2829 case NODDCLR:
2830 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCLEARED;
2831 break;
2832 case MASK_DISABLE:
2833 $$.header.mask_control = BRW_MASK_DISABLE;
2834 break;
2835 case BREAKPOINT:
2836 $$.header.debug_control = BRW_DEBUG_BREAKPOINT;
Xiang, Haihao55d81c42010-10-08 13:53:22 +08002837 break;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002838 case EOT:
Eric Anholt56c4ccf2006-08-24 14:35:10 -07002839 /* XXX: EOT shouldn't be an instoption, I don't think */
2840 $$.bits3.generic.end_of_thread = 1;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002841 break;
2842 }
2843 }
2844 | /* empty, header defaults to zeroes. */
Eric Anholte609d6b2006-08-24 12:36:56 -07002845 {
Homer Hsing81859af2012-09-14 09:34:58 +08002846 memset(&$$, 0, sizeof($$));
Eric Anholte609d6b2006-08-24 12:36:56 -07002847 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002848;
Eric Anholt22a10632006-08-22 10:15:33 -07002849
Eric Anholt16324212006-08-24 14:47:21 -07002850instoption: ALIGN1 { $$ = ALIGN1; }
2851 | ALIGN16 { $$ = ALIGN16; }
Eric Anholt908f37d2006-08-25 17:33:02 -07002852 | SECHALF { $$ = SECHALF; }
2853 | COMPR { $$ = COMPR; }
2854 | SWITCH { $$ = SWITCH; }
2855 | ATOMIC { $$ = ATOMIC; }
2856 | NODDCHK { $$ = NODDCHK; }
2857 | NODDCLR { $$ = NODDCLR; }
Eric Anholt16324212006-08-24 14:47:21 -07002858 | MASK_DISABLE { $$ = MASK_DISABLE; }
Eric Anholt908f37d2006-08-25 17:33:02 -07002859 | BREAKPOINT { $$ = BREAKPOINT; }
Xiang, Haihao55d81c42010-10-08 13:53:22 +08002860 | ACCWRCTRL { $$ = ACCWRCTRL; }
Eric Anholt16324212006-08-24 14:47:21 -07002861 | EOT { $$ = EOT; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002862;
Eric Anholt22a10632006-08-22 10:15:33 -07002863
2864%%
2865extern int yylineno;
Keith Packard2d4d4012008-03-30 00:58:28 -07002866extern char *input_filename;
2867
2868int errors;
Eric Anholt22a10632006-08-22 10:15:33 -07002869
2870void yyerror (char *msg)
2871{
Keith Packard2d4d4012008-03-30 00:58:28 -07002872 fprintf(stderr, "%s: %d: %s at \"%s\"\n",
2873 input_filename, yylineno, msg, lex_text());
2874 ++errors;
Eric Anholt22a10632006-08-22 10:15:33 -07002875}
2876
Xiang, Haihao27b43032010-12-13 16:07:16 +08002877static int get_type_size(GLuint type)
2878{
2879 int size = 1;
2880
2881 switch (type) {
2882 case BRW_REGISTER_TYPE_F:
2883 case BRW_REGISTER_TYPE_UD:
2884 case BRW_REGISTER_TYPE_D:
2885 size = 4;
2886 break;
2887
2888 case BRW_REGISTER_TYPE_UW:
2889 case BRW_REGISTER_TYPE_W:
2890 size = 2;
2891 break;
2892
2893 case BRW_REGISTER_TYPE_UB:
2894 case BRW_REGISTER_TYPE_B:
2895 size = 1;
2896 break;
2897
2898 default:
2899 assert(0);
2900 size = 1;
2901 break;
2902 }
2903
2904 return size;
2905}
2906
Xiang, Haihao27b43032010-12-13 16:07:16 +08002907static void reset_instruction_src_region(struct brw_instruction *instr,
2908 struct src_operand *src)
2909{
2910 if (!src->default_region)
2911 return;
2912
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002913 if (src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
2914 ((src->reg.nr & 0xF0) == BRW_ARF_ADDRESS)) {
2915 src->reg.vstride = ffs(0);
2916 src->reg.width = ffs(1) - 1;
2917 src->reg.hstride = ffs(0);
2918 } else if (src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
2919 ((src->reg.nr & 0xF0) == BRW_ARF_ACCUMULATOR)) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002920 int horiz_stride = 1, width, vert_stride;
2921 if (instr->header.compression_control == BRW_COMPRESSION_COMPRESSED) {
2922 width = 16;
2923 } else {
2924 width = 8;
2925 }
2926
2927 if (width > (1 << instr->header.execution_size))
2928 width = (1 << instr->header.execution_size);
2929
2930 vert_stride = horiz_stride * width;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002931 src->reg.vstride = ffs(vert_stride);
2932 src->reg.width = ffs(width) - 1;
2933 src->reg.hstride = ffs(horiz_stride);
2934 } else if ((src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE) &&
2935 (src->reg.nr == BRW_ARF_NULL) &&
Xiang, Haihao27b43032010-12-13 16:07:16 +08002936 (instr->header.opcode == BRW_OPCODE_SEND)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002937 src->reg.vstride = ffs(8);
2938 src->reg.width = ffs(8) - 1;
2939 src->reg.hstride = ffs(1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002940 } else {
2941
2942 int horiz_stride = 1, width, vert_stride;
2943
2944 if (instr->header.execution_size == 0) { /* scalar */
2945 horiz_stride = 0;
2946 width = 1;
2947 vert_stride = 0;
2948 } else {
2949 if ((instr->header.opcode == BRW_OPCODE_MUL) ||
2950 (instr->header.opcode == BRW_OPCODE_MAC) ||
2951 (instr->header.opcode == BRW_OPCODE_CMP) ||
2952 (instr->header.opcode == BRW_OPCODE_ASR) ||
2953 (instr->header.opcode == BRW_OPCODE_ADD) ||
2954 (instr->header.opcode == BRW_OPCODE_SHL)) {
2955 horiz_stride = 0;
2956 width = 1;
2957 vert_stride = 0;
2958 } else {
2959 width = (1 << instr->header.execution_size) / horiz_stride;
2960 vert_stride = horiz_stride * width;
Xiang, Haihaoe7f4dc62011-03-01 16:43:02 +08002961
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002962 if (get_type_size(src->reg.type) * (width + src->reg.subnr) > 32) {
Xiang, Haihaoe7f4dc62011-03-01 16:43:02 +08002963 horiz_stride = 0;
2964 width = 1;
2965 vert_stride = 0;
2966 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002967 }
2968 }
2969
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002970 src->reg.vstride = ffs(vert_stride);
2971 src->reg.width = ffs(width) - 1;
2972 src->reg.hstride = ffs(horiz_stride);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002973 }
2974}
2975
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002976/**
2977 * Fills in the destination register information in instr from the bits in dst.
2978 */
Eric Anholt2dac0a12006-08-29 15:29:31 -07002979int set_instruction_dest(struct brw_instruction *instr,
Damien Lespiau03750732013-01-23 20:33:00 +00002980 struct brw_reg *dest)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002981{
Damien Lespiau5e0da9f2013-01-24 12:21:13 +00002982 if (!validate_dst_reg(instr, dest))
2983 return 1;
2984
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00002985 /* the assembler support expressing subnr in bytes or in number of
2986 * elements. */
2987 resolve_subnr(dest);
2988
2989 brw_set_dest(&genasm_compile, instr, *dest);
Eric Anholt2dac0a12006-08-29 15:29:31 -07002990
2991 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002992}
2993
Eric Anholt6a88ada2006-08-28 22:11:18 -07002994/* Sets the first source operand for the instruction. Returns 0 on success. */
2995int set_instruction_src0(struct brw_instruction *instr,
Damien Lespiaue9172aa2013-01-26 22:44:45 +00002996 struct src_operand *src,
2997 YYLTYPE *location)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002998{
Damien Lespiauc0592b22013-01-24 18:32:20 +00002999 if (advanced_flag)
Xiang, Haihao27b43032010-12-13 16:07:16 +08003000 reset_instruction_src_region(instr, src);
Damien Lespiauc0592b22013-01-24 18:32:20 +00003001
Damien Lespiaue9172aa2013-01-26 22:44:45 +00003002 if (!validate_src_reg(instr, src->reg, location))
Damien Lespiauc0592b22013-01-24 18:32:20 +00003003 return 1;
3004
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003005 instr->bits1.da1.src0_reg_file = src->reg.file;
3006 instr->bits1.da1.src0_reg_type = src->reg.type;
3007 if (src->reg.file == BRW_IMMEDIATE_VALUE) {
Damien Lespiau9c72beb2013-01-25 15:48:58 +00003008 instr->bits3.ud = src->reg.dw1.ud;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003009 } else if (src->reg.address_mode == BRW_ADDRESS_DIRECT) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08003010 if (instr->header.access_mode == BRW_ALIGN_1) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003011 instr->bits2.da1.src0_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode);
3012 instr->bits2.da1.src0_reg_nr = src->reg.nr;
3013 instr->bits2.da1.src0_vert_stride = src->reg.vstride;
3014 instr->bits2.da1.src0_width = src->reg.width;
3015 instr->bits2.da1.src0_horiz_stride = src->reg.hstride;
3016 instr->bits2.da1.src0_negate = src->reg.negate;
3017 instr->bits2.da1.src0_abs = src->reg.abs;
3018 instr->bits2.da1.src0_address_mode = src->reg.address_mode;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003019 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003020 instr->bits2.da16.src0_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode);
3021 instr->bits2.da16.src0_reg_nr = src->reg.nr;
3022 instr->bits2.da16.src0_vert_stride = src->reg.vstride;
3023 instr->bits2.da16.src0_negate = src->reg.negate;
3024 instr->bits2.da16.src0_abs = src->reg.abs;
3025 instr->bits2.da16.src0_swz_x = BRW_GET_SWZ(SWIZZLE(src->reg), 0);
3026 instr->bits2.da16.src0_swz_y = BRW_GET_SWZ(SWIZZLE(src->reg), 1);
3027 instr->bits2.da16.src0_swz_z = BRW_GET_SWZ(SWIZZLE(src->reg), 2);
3028 instr->bits2.da16.src0_swz_w = BRW_GET_SWZ(SWIZZLE(src->reg), 3);
3029 instr->bits2.da16.src0_address_mode = src->reg.address_mode;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003030 }
3031 } else {
3032 if (instr->header.access_mode == BRW_ALIGN_1) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003033 instr->bits2.ia1.src0_indirect_offset = src->reg.dw1.bits.indirect_offset;
3034 instr->bits2.ia1.src0_subreg_nr = get_indirect_subreg_address(src->reg.subnr);
3035 instr->bits2.ia1.src0_abs = src->reg.abs;
3036 instr->bits2.ia1.src0_negate = src->reg.negate;
3037 instr->bits2.ia1.src0_address_mode = src->reg.address_mode;
3038 instr->bits2.ia1.src0_horiz_stride = src->reg.hstride;
3039 instr->bits2.ia1.src0_width = src->reg.width;
3040 instr->bits2.ia1.src0_vert_stride = src->reg.vstride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003041 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003042 instr->bits2.ia16.src0_swz_x = BRW_GET_SWZ(SWIZZLE(src->reg), 0);
3043 instr->bits2.ia16.src0_swz_y = BRW_GET_SWZ(SWIZZLE(src->reg), 1);
3044 instr->bits2.ia16.src0_swz_z = BRW_GET_SWZ(SWIZZLE(src->reg), 2);
3045 instr->bits2.ia16.src0_swz_w = BRW_GET_SWZ(SWIZZLE(src->reg), 3);
3046 instr->bits2.ia16.src0_indirect_offset = (src->reg.dw1.bits.indirect_offset >> 4); /* half register aligned */
3047 instr->bits2.ia16.src0_subreg_nr = get_indirect_subreg_address(src->reg.subnr);
3048 instr->bits2.ia16.src0_abs = src->reg.abs;
3049 instr->bits2.ia16.src0_negate = src->reg.negate;
3050 instr->bits2.ia16.src0_address_mode = src->reg.address_mode;
3051 instr->bits2.ia16.src0_vert_stride = src->reg.vstride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003052 }
3053 }
Eric Anholt6a88ada2006-08-28 22:11:18 -07003054
3055 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003056}
3057
Eric Anholt6a88ada2006-08-28 22:11:18 -07003058/* Sets the second source operand for the instruction. Returns 0 on success.
3059 */
3060int set_instruction_src1(struct brw_instruction *instr,
Damien Lespiaue9172aa2013-01-26 22:44:45 +00003061 struct src_operand *src,
3062 YYLTYPE *location)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003063{
Damien Lespiauc0592b22013-01-24 18:32:20 +00003064 if (advanced_flag)
Xiang, Haihao27b43032010-12-13 16:07:16 +08003065 reset_instruction_src_region(instr, src);
Damien Lespiauc0592b22013-01-24 18:32:20 +00003066
Damien Lespiaue9172aa2013-01-26 22:44:45 +00003067 if (!validate_src_reg(instr, src->reg, location))
Damien Lespiauc0592b22013-01-24 18:32:20 +00003068 return 1;
3069
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003070 instr->bits1.da1.src1_reg_file = src->reg.file;
3071 instr->bits1.da1.src1_reg_type = src->reg.type;
3072 if (src->reg.file == BRW_IMMEDIATE_VALUE) {
Damien Lespiau9c72beb2013-01-25 15:48:58 +00003073 instr->bits3.ud = src->reg.dw1.ud;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003074 } else if (src->reg.address_mode == BRW_ADDRESS_DIRECT) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08003075 if (instr->header.access_mode == BRW_ALIGN_1) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003076 instr->bits3.da1.src1_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode);
3077 instr->bits3.da1.src1_reg_nr = src->reg.nr;
3078 instr->bits3.da1.src1_vert_stride = src->reg.vstride;
3079 instr->bits3.da1.src1_width = src->reg.width;
3080 instr->bits3.da1.src1_horiz_stride = src->reg.hstride;
3081 instr->bits3.da1.src1_negate = src->reg.negate;
3082 instr->bits3.da1.src1_abs = src->reg.abs;
3083 instr->bits3.da1.src1_address_mode = src->reg.address_mode;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003084 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003085 instr->bits3.da16.src1_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode);
3086 instr->bits3.da16.src1_reg_nr = src->reg.nr;
3087 instr->bits3.da16.src1_vert_stride = src->reg.vstride;
3088 instr->bits3.da16.src1_negate = src->reg.negate;
3089 instr->bits3.da16.src1_abs = src->reg.abs;
3090 instr->bits3.da16.src1_swz_x = BRW_GET_SWZ(SWIZZLE(src->reg), 0);
3091 instr->bits3.da16.src1_swz_y = BRW_GET_SWZ(SWIZZLE(src->reg), 1);
3092 instr->bits3.da16.src1_swz_z = BRW_GET_SWZ(SWIZZLE(src->reg), 2);
3093 instr->bits3.da16.src1_swz_w = BRW_GET_SWZ(SWIZZLE(src->reg), 3);
3094 instr->bits3.da16.src1_address_mode = src->reg.address_mode;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003095 }
3096 } else {
3097 if (instr->header.access_mode == BRW_ALIGN_1) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003098 instr->bits3.ia1.src1_indirect_offset = src->reg.dw1.bits.indirect_offset;
3099 instr->bits3.ia1.src1_subreg_nr = get_indirect_subreg_address(src->reg.subnr);
3100 instr->bits3.ia1.src1_abs = src->reg.abs;
3101 instr->bits3.ia1.src1_negate = src->reg.negate;
3102 instr->bits3.ia1.src1_address_mode = src->reg.address_mode;
3103 instr->bits3.ia1.src1_horiz_stride = src->reg.hstride;
3104 instr->bits3.ia1.src1_width = src->reg.width;
3105 instr->bits3.ia1.src1_vert_stride = src->reg.vstride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003106 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003107 instr->bits3.ia16.src1_swz_x = BRW_GET_SWZ(SWIZZLE(src->reg), 0);
3108 instr->bits3.ia16.src1_swz_y = BRW_GET_SWZ(SWIZZLE(src->reg), 1);
3109 instr->bits3.ia16.src1_swz_z = BRW_GET_SWZ(SWIZZLE(src->reg), 2);
3110 instr->bits3.ia16.src1_swz_w = BRW_GET_SWZ(SWIZZLE(src->reg), 3);
3111 instr->bits3.ia16.src1_indirect_offset = (src->reg.dw1.bits.indirect_offset >> 4); /* half register aligned */
3112 instr->bits3.ia16.src1_subreg_nr = get_indirect_subreg_address(src->reg.subnr);
3113 instr->bits3.ia16.src1_abs = src->reg.abs;
3114 instr->bits3.ia16.src1_negate = src->reg.negate;
3115 instr->bits3.ia16.src1_address_mode = src->reg.address_mode;
3116 instr->bits3.ia16.src1_vert_stride = src->reg.vstride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08003117 }
3118 }
Eric Anholt6a88ada2006-08-28 22:11:18 -07003119
3120 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003121}
3122
Homer Hsinga034bcb2012-09-07 14:38:13 +08003123/* convert 2-src reg type to 3-src reg type
3124 *
3125 * 2-src reg type:
3126 * 000=UD 001=D 010=UW 011=W 100=UB 101=B 110=DF 111=F
3127 *
3128 * 3-src reg type:
3129 * 00=F 01=D 10=UD 11=DF
3130 */
3131static int reg_type_2_to_3(int reg_type)
3132{
3133 int r = 0;
3134 switch(reg_type) {
3135 case 7: r = 0; break;
3136 case 1: r = 1; break;
3137 case 0: r = 2; break;
3138 // TODO: supporting DF
3139 }
3140 return r;
3141}
3142
3143int set_instruction_dest_three_src(struct brw_instruction *instr,
Damien Lespiau03750732013-01-23 20:33:00 +00003144 struct brw_reg *dest)
Homer Hsinga034bcb2012-09-07 14:38:13 +08003145{
Damien Lespiau03750732013-01-23 20:33:00 +00003146 instr->bits1.da3src.dest_reg_file = dest->file;
3147 instr->bits1.da3src.dest_reg_nr = dest->nr;
3148 instr->bits1.da3src.dest_subreg_nr = get_subreg_address(dest->file, dest->type, dest->subnr, dest->address_mode) / 4; // in DWORD
3149 instr->bits1.da3src.dest_writemask = dest->dw1.bits.writemask;
3150 instr->bits1.da3src.dest_reg_type = reg_type_2_to_3(dest->type);
Homer Hsinga034bcb2012-09-07 14:38:13 +08003151 return 0;
3152}
3153
3154int set_instruction_src0_three_src(struct brw_instruction *instr,
3155 struct src_operand *src)
3156{
3157 if (advanced_flag) {
3158 reset_instruction_src_region(instr, src);
3159 }
3160 // TODO: supporting src0 swizzle, src0 modifier, src0 rep_ctrl
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003161 instr->bits1.da3src.src_reg_type = reg_type_2_to_3(src->reg.type);
3162 instr->bits2.da3src.src0_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode) / 4; // in DWORD
3163 instr->bits2.da3src.src0_reg_nr = src->reg.nr;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003164 return 0;
3165}
3166
3167int set_instruction_src1_three_src(struct brw_instruction *instr,
3168 struct src_operand *src)
3169{
3170 if (advanced_flag) {
3171 reset_instruction_src_region(instr, src);
3172 }
3173 // TODO: supporting src1 swizzle, src1 modifier, src1 rep_ctrl
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003174 int v = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode) / 4; // in DWORD
Damien Lespiau31259c52013-01-15 14:05:23 +00003175 instr->bits2.da3src.src1_subreg_nr_low = v % 4; // lower 2 bits
3176 instr->bits3.da3src.src1_subreg_nr_high = v / 4; // highest bit
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003177 instr->bits3.da3src.src1_reg_nr = src->reg.nr;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003178 return 0;
3179}
3180
3181int set_instruction_src2_three_src(struct brw_instruction *instr,
3182 struct src_operand *src)
3183{
3184 if (advanced_flag) {
3185 reset_instruction_src_region(instr, src);
3186 }
3187 // TODO: supporting src2 swizzle, src2 modifier, src2 rep_ctrl
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003188 instr->bits3.da3src.src2_subreg_nr = get_subreg_address(src->reg.file, src->reg.type, src->reg.subnr, src->reg.address_mode) / 4; // in DWORD
3189 instr->bits3.da3src.src2_reg_nr = src->reg.nr;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003190 return 0;
3191}
3192
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003193void set_instruction_options(struct brw_instruction *instr,
3194 struct brw_instruction *options)
3195{
Eric Anholt6a88ada2006-08-28 22:11:18 -07003196 /* XXX: more instr options */
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003197 instr->header.access_mode = options->header.access_mode;
3198 instr->header.mask_control = options->header.mask_control;
3199 instr->header.dependency_control = options->header.dependency_control;
3200 instr->header.compression_control =
3201 options->header.compression_control;
3202}
Eric Anholt2c787652006-08-25 13:53:48 -07003203
Eric Anholt0ed5d932006-08-28 23:05:51 -07003204void set_instruction_predicate(struct brw_instruction *instr,
3205 struct brw_instruction *predicate)
3206{
3207 instr->header.predicate_control = predicate->header.predicate_control;
3208 instr->header.predicate_inverse = predicate->header.predicate_inverse;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08003209 instr->bits2.da1.flag_reg_nr = predicate->bits2.da1.flag_reg_nr;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +08003210 instr->bits2.da1.flag_subreg_nr = predicate->bits2.da1.flag_subreg_nr;
Eric Anholt0ed5d932006-08-28 23:05:51 -07003211}
3212
Damien Lespiau03750732013-01-23 20:33:00 +00003213void set_direct_dst_operand(struct brw_reg *dst, struct brw_reg *reg,
Eric Anholt1e907c72006-08-31 10:21:15 -07003214 int type)
3215{
Damien Lespiau03750732013-01-23 20:33:00 +00003216 *dst = *reg;
Eric Anholt1e907c72006-08-31 10:21:15 -07003217 dst->address_mode = BRW_ADDRESS_DIRECT;
Damien Lespiau03750732013-01-23 20:33:00 +00003218 dst->type = type;
3219 dst->hstride = 1;
3220 dst->dw1.bits.writemask = BRW_WRITEMASK_XYZW;
Eric Anholt1e907c72006-08-31 10:21:15 -07003221}
3222
Damien Lespiaub33b8812013-01-23 16:06:49 +00003223void set_direct_src_operand(struct src_operand *src, struct brw_reg *reg,
Eric Anholt3bcf6b22006-08-29 18:31:34 -07003224 int type)
Eric Anholt2c787652006-08-25 13:53:48 -07003225{
Homer Hsing81859af2012-09-14 09:34:58 +08003226 memset(src, 0, sizeof(*src));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003227 src->reg.address_mode = BRW_ADDRESS_DIRECT;
3228 src->reg.file = reg->file;
3229 src->reg.type = type;
3230 src->reg.subnr = reg->subnr;
3231 src->reg.nr = reg->nr;
3232 src->reg.vstride = 0;
3233 src->reg.width = 0;
3234 src->reg.hstride = 0;
3235 src->reg.negate = 0;
3236 src->reg.abs = 0;
3237 SWIZZLE(src->reg) = BRW_SWIZZLE_NOOP;
Eric Anholt2c787652006-08-25 13:53:48 -07003238}