blob: d6f4a195b67474654c6682496dda88b2c1821abf [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"
Damien Lespiauaf4d37d2013-01-31 02:16:08 +000037#include "gen8_instruction.h"
Eric Anholt22a10632006-08-22 10:15:33 -070038
Xiang, Haihao27b43032010-12-13 16:07:16 +080039#define DEFAULT_EXECSIZE (ffs(program_defaults.execute_size) - 1)
40#define DEFAULT_DSTREGION -1
Xiang Haihao549b7512009-06-30 10:02:33 +080041
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000042#define SWIZZLE(reg) (reg.dw1.bits.swizzle)
43
Damien Lespiauf6e90522013-01-30 17:04:13 +000044#define GEN(i) (&(i)->insn.gen)
Damien Lespiauaf4d37d2013-01-31 02:16:08 +000045#define GEN8(i) (&(i)->insn.gen8)
Damien Lespiauf6e90522013-01-30 17:04:13 +000046
Damien Lespiaue9172aa2013-01-26 22:44:45 +000047#define YYLTYPE YYLTYPE
48typedef struct YYLTYPE
49{
50 int first_line;
51 int first_column;
52 int last_line;
53 int last_column;
54} YYLTYPE;
55
Xiang, Haihao27b43032010-12-13 16:07:16 +080056extern int need_export;
Homer Hsing88dfdf32012-09-24 10:06:35 +080057static struct src_operand src_null_reg =
58{
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000059 .reg.file = BRW_ARCHITECTURE_REGISTER_FILE,
60 .reg.nr = BRW_ARF_NULL,
61 .reg.type = BRW_REGISTER_TYPE_UD,
Homer Hsing88dfdf32012-09-24 10:06:35 +080062};
Damien Lespiau03750732013-01-23 20:33:00 +000063static struct brw_reg dst_null_reg =
Homer Hsing88dfdf32012-09-24 10:06:35 +080064{
Damien Lespiau03750732013-01-23 20:33:00 +000065 .file = BRW_ARCHITECTURE_REGISTER_FILE,
66 .nr = BRW_ARF_NULL,
Homer Hsing88dfdf32012-09-24 10:06:35 +080067};
Damien Lespiau03750732013-01-23 20:33:00 +000068static struct brw_reg ip_dst =
Homer Hsing7e2461b2012-09-27 14:48:14 +080069{
Damien Lespiau03750732013-01-23 20:33:00 +000070 .file = BRW_ARCHITECTURE_REGISTER_FILE,
71 .nr = BRW_ARF_IP,
72 .type = BRW_REGISTER_TYPE_UD,
Homer Hsing7e2461b2012-09-27 14:48:14 +080073 .address_mode = BRW_ADDRESS_DIRECT,
Damien Lespiau03750732013-01-23 20:33:00 +000074 .hstride = 1,
75 .dw1.bits.writemask = BRW_WRITEMASK_XYZW,
Homer Hsing7e2461b2012-09-27 14:48:14 +080076};
77static struct src_operand ip_src =
78{
Damien Lespiau9d5a87a2013-01-23 22:29:23 +000079 .reg.file = BRW_ARCHITECTURE_REGISTER_FILE,
80 .reg.nr = BRW_ARF_IP,
81 .reg.type = BRW_REGISTER_TYPE_UD,
82 .reg.address_mode = BRW_ADDRESS_DIRECT,
83 .reg.dw1.bits.swizzle = BRW_SWIZZLE_NOOP,
Homer Hsing7e2461b2012-09-27 14:48:14 +080084};
Xiang, Haihao27b43032010-12-13 16:07:16 +080085
Damien Lespiauf0365d42013-02-04 12:02:18 +000086static int get_type_size(unsigned type);
Damien Lespiau5d526c82013-01-30 23:39:09 +000087static void set_instruction_opcode(struct brw_program_instruction *instr,
88 unsigned opcode);
Damien Lespiauf6e90522013-01-30 17:04:13 +000089static int set_instruction_dest(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +000090 struct brw_reg *dest);
Damien Lespiauf6e90522013-01-30 17:04:13 +000091static int set_instruction_src0(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +000092 struct src_operand *src,
93 YYLTYPE *location);
Damien Lespiauf6e90522013-01-30 17:04:13 +000094static int set_instruction_src1(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +000095 struct src_operand *src,
96 YYLTYPE *location);
Damien Lespiauf6e90522013-01-30 17:04:13 +000097static int set_instruction_dest_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +000098 struct brw_reg *dest);
Damien Lespiauf6e90522013-01-30 17:04:13 +000099static int set_instruction_src0_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +0000100 struct src_operand *src);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000101static int set_instruction_src1_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +0000102 struct src_operand *src);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000103static int set_instruction_src2_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +0000104 struct src_operand *src);
Damien Lespiau49861a02013-01-31 00:26:51 +0000105static void set_instruction_saturate(struct brw_program_instruction *instr,
106 int saturate);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000107static void set_instruction_options(struct brw_program_instruction *instr,
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000108 struct options options);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000109static void set_instruction_predicate(struct brw_program_instruction *instr,
Damien Lespiaudfe6ada2013-01-30 22:32:07 +0000110 struct predicate *p);
Damien Lespiaub21c2e62013-01-31 00:18:47 +0000111static void set_instruction_pred_cond(struct brw_program_instruction *instr,
112 struct predicate *p,
113 struct condition *c,
114 YYLTYPE *location);
Damien Lespiau1d53e182013-01-27 11:05:50 +0000115static void set_direct_dst_operand(struct brw_reg *dst, struct brw_reg *reg,
116 int type);
117static void set_direct_src_operand(struct src_operand *src, struct brw_reg *reg,
118 int type);
Eric Anholtc8939ed2006-08-30 10:50:56 -0700119
Xiang, Haihao216163b2013-02-22 11:14:06 +0800120void set_branch_two_offsets(struct brw_program_instruction *insn, int jip_offset, int uip_offset);
121void set_branch_one_offset(struct brw_program_instruction *insn, int jip_offset);
122
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000123enum message_level {
124 WARN,
125 ERROR,
126};
127
128static void message(enum message_level level, YYLTYPE *location,
129 const char *fmt, ...)
130{
131 static const char *level_str[] = { "warning", "error" };
132 va_list args;
133
134 if (location)
Damien Lespiau1eb622a2013-01-27 01:32:52 +0000135 fprintf(stderr, "%s:%d:%d: %s: ", input_filename, location->first_line,
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000136 location->first_column, level_str[level]);
137 else
Damien Lespiau1eb622a2013-01-27 01:32:52 +0000138 fprintf(stderr, "%s:%s: ", input_filename, level_str[level]);
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000139
140 va_start(args, fmt);
141 vfprintf(stderr, fmt, args);
142 va_end(args);
143}
144
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000145#define warn(flag, l, fmt, ...) \
146 do { \
147 if (warning_flags & WARN_ ## flag) \
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000148 message(WARN, l, fmt, ## __VA_ARGS__); \
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000149 } while(0)
150
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000151#define error(l, fmt, ...) \
152 do { \
153 message(ERROR, l, fmt, ## __VA_ARGS__); \
154 } while(0)
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000155
Damien Lespiau574a2492013-01-26 18:26:03 +0000156/* like strcmp, but handles NULL pointers */
157static bool strcmp0(const char *s1, const char* s2)
158{
159 if (!s1)
160 return -(s1 != s2);
161 if (!s2)
162 return s1 != s2;
163 return strcmp (s1, s2);
164}
165
166static bool region_equal(struct region *r1, struct region *r2)
167{
168 return memcmp(r1, r2, sizeof(struct region)) == 0;
169}
170
171static bool reg_equal(struct brw_reg *r1, struct brw_reg *r2)
172{
173 return memcmp(r1, r2, sizeof(struct brw_reg)) == 0;
174}
175
176static bool declared_register_equal(struct declared_register *r1,
177 struct declared_register *r2)
178{
179 if (strcmp0(r1->name, r2->name) != 0)
180 return false;
181
182 if (!reg_equal(&r1->reg, &r2->reg))
183 return false;
184
185 if (!region_equal(&r1->src_region, &r2->src_region))
186 return false;
187
188 if (r1->element_size != r2->element_size ||
Damien Lespiau2de8b402013-02-01 13:59:32 +0000189 r1->dst_region != r2->dst_region)
Damien Lespiau574a2492013-01-26 18:26:03 +0000190 return false;
191
192 return true;
193}
194
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000195static void brw_program_init(struct brw_program *p)
196{
197 memset(p, 0, sizeof(struct brw_program));
198}
199
200static void brw_program_append_entry(struct brw_program *p,
201 struct brw_program_instruction *entry)
202{
203 entry->next = NULL;
204 if (p->last)
205 p->last->next = entry;
206 else
207 p->first = entry;
208 p->last = entry;
209}
210
Damien Lespiauf6e90522013-01-30 17:04:13 +0000211static void
212brw_program_add_instruction(struct brw_program *p,
213 struct brw_program_instruction *instruction)
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000214{
215 struct brw_program_instruction *list_entry;
216
217 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
Damien Lespiaua45a4712013-01-21 19:28:41 +0000218 list_entry->type = GEN4ASM_INSTRUCTION_GEN;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000219 list_entry->insn.gen = instruction->insn.gen;
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000220 brw_program_append_entry(p, list_entry);
221}
222
Damien Lespiau9b78f742013-01-30 17:09:17 +0000223static void
224brw_program_add_relocatable(struct brw_program *p,
225 struct brw_program_instruction *instruction)
Damien Lespiau79c62f12013-01-21 21:41:36 +0000226{
227 struct brw_program_instruction *list_entry;
228
229 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
230 list_entry->type = GEN4ASM_INSTRUCTION_GEN_RELOCATABLE;
Damien Lespiau9b78f742013-01-30 17:09:17 +0000231 list_entry->insn.gen = instruction->insn.gen;
232 list_entry->reloc = instruction->reloc;
Damien Lespiau79c62f12013-01-21 21:41:36 +0000233 brw_program_append_entry(p, list_entry);
234}
235
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000236static void brw_program_add_label(struct brw_program *p, const char *label)
237{
238 struct brw_program_instruction *list_entry;
239
240 list_entry = calloc(sizeof(struct brw_program_instruction), 1);
Damien Lespiaua45a4712013-01-21 19:28:41 +0000241 list_entry->type = GEN4ASM_INSTRUCTION_LABEL;
Damien Lespiaud0080642013-01-30 12:31:45 +0000242 list_entry->insn.label.name = strdup(label);
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000243 brw_program_append_entry(p, list_entry);
244}
245
Damien Lespiau03750732013-01-23 20:33:00 +0000246static int resolve_dst_region(struct declared_register *reference, int region)
247{
248 int resolved = region;
249
250 if (resolved == DEFAULT_DSTREGION) {
251 if (reference)
252 resolved = reference->dst_region;
253 else
254 resolved = 1;
255 }
256
257 assert(resolved == 1 || resolved == 2 || resolved == 3);
258 return resolved;
259}
260
Damien Lespiau42d8d572013-01-31 01:55:48 +0000261static inline int access_mode(struct brw_program_instruction *insn)
262{
263 if (IS_GENp(8))
264 return gen8_access_mode(GEN8(insn));
265 else
266 return GEN(insn)->header.access_mode;
267}
268
269static inline int exec_size(struct brw_program_instruction *insn)
270{
271 if (IS_GENp(8))
272 return gen8_exec_size(GEN8(insn));
273 else
274 return GEN(insn)->header.execution_size;
275}
276
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +0000277static void set_execsize(struct brw_program_instruction *insn, int execsize)
278{
279 if (IS_GENp(8))
280 gen8_set_exec_size(GEN8(insn), execsize);
281 else
282 GEN(insn)->header.execution_size = execsize;
283}
284
Damien Lespiau42d8d572013-01-31 01:55:48 +0000285static bool validate_dst_reg(struct brw_program_instruction *insn, struct brw_reg *reg)
Damien Lespiau5e0da9f2013-01-24 12:21:13 +0000286{
287
288 if (reg->address_mode == BRW_ADDRESS_DIRECT &&
Damien Lespiau42d8d572013-01-31 01:55:48 +0000289 access_mode(insn) == BRW_ALIGN_1 &&
Damien Lespiau5e0da9f2013-01-24 12:21:13 +0000290 reg->dw1.bits.writemask != 0 &&
291 reg->dw1.bits.writemask != BRW_WRITEMASK_XYZW)
292 {
293 fprintf(stderr, "error: write mask set in align1 instruction\n");
294 return false;
295 }
296
Zhao Yakui88e5f1f2013-04-09 09:59:15 +0800297 if (reg->address_mode == BRW_ADDRESS_REGISTER_INDIRECT_REGISTER &&
298 access_mode(insn) == BRW_ALIGN_16) {
299 fprintf(stderr, "error: indirect Dst addr mode in align16 instruction\n");
300 return false;
301 }
302
Damien Lespiau5e0da9f2013-01-24 12:21:13 +0000303 return true;
304}
305
Damien Lespiau42d8d572013-01-31 01:55:48 +0000306static bool validate_src_reg(struct brw_program_instruction *insn,
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000307 struct brw_reg reg,
308 YYLTYPE *location)
Damien Lespiauc0592b22013-01-24 18:32:20 +0000309{
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000310 int hstride_for_reg[] = {0, 1, 2, 4};
Damien Lespiau95b12082013-01-26 23:55:01 +0000311 int vstride_for_reg[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256};
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000312 int width_for_reg[] = {1, 2, 4, 8, 16};
Damien Lespiau95b12082013-01-26 23:55:01 +0000313 int execsize_for_reg[] = {1, 2, 4, 8, 16, 32};
314 int width, hstride, vstride, execsize;
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000315
Damien Lespiauc0592b22013-01-24 18:32:20 +0000316 if (reg.file == BRW_IMMEDIATE_VALUE)
317 return true;
318
Damien Lespiau42d8d572013-01-31 01:55:48 +0000319 if (access_mode(insn) == BRW_ALIGN_1 &&
Damien Lespiauc0592b22013-01-24 18:32:20 +0000320 SWIZZLE(reg) && SWIZZLE(reg) != BRW_SWIZZLE_NOOP)
321 {
Damien Lespiaue9172aa2013-01-26 22:44:45 +0000322 error(location, "swizzle bits set in align1 instruction\n");
Damien Lespiauc0592b22013-01-24 18:32:20 +0000323 return false;
324 }
325
Zhao Yakui88e5f1f2013-04-09 09:59:15 +0800326 if (reg.address_mode == BRW_ADDRESS_REGISTER_INDIRECT_REGISTER &&
327 access_mode(insn) == BRW_ALIGN_16) {
328 fprintf(stderr, "error: indirect Source addr mode in align16 instruction\n");
329 return false;
330 }
331
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000332 assert(reg.hstride >= 0 && reg.hstride < ARRAY_SIZE(hstride_for_reg));
333 hstride = hstride_for_reg[reg.hstride];
334
Damien Lespiau95b12082013-01-26 23:55:01 +0000335 if (reg.vstride == 0xf) {
336 vstride = -1;
337 } else {
338 assert(reg.vstride >= 0 && reg.vstride < ARRAY_SIZE(vstride_for_reg));
339 vstride = vstride_for_reg[reg.vstride];
340 }
341
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000342 assert(reg.width >= 0 && reg.width < ARRAY_SIZE(width_for_reg));
343 width = width_for_reg[reg.width];
344
Damien Lespiau42d8d572013-01-31 01:55:48 +0000345 assert(exec_size(insn) >= 0 &&
346 exec_size(insn) < ARRAY_SIZE(execsize_for_reg));
347 execsize = execsize_for_reg[exec_size(insn)];
Damien Lespiau95b12082013-01-26 23:55:01 +0000348
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000349 /* Register Region Restrictions */
350
Damien Lespiaue7cca1a2013-01-27 02:06:22 +0000351 /* B. If ExecSize = Width and HorzStride ≠ 0, VertStride must be set to
352 * Width * HorzStride. */
353 if (execsize == width && hstride != 0) {
Thomas Woode6737b82014-02-07 17:03:38 +0000354 if (vstride != -1 && vstride != width * hstride)
Damien Lespiaue7cca1a2013-01-27 02:06:22 +0000355 warn(ALL, location, "execution size == width and hstride != 0 but "
356 "vstride is not width * hstride\n");
357 }
358
Damien Lespiaud70e9f82013-01-26 23:09:42 +0000359 /* D. If Width = 1, HorzStride must be 0 regardless of the values of
360 * ExecSize and VertStride.
361 *
362 * FIXME: In "advanced mode" hstride is set to 1, this is probably a bug
363 * to fix, but it changes the generated opcodes and thus needs validation.
364 */
365 if (width == 1 && hstride != 0)
366 warn(ALL, location, "region width is 1 but horizontal stride is %d "
367 " (should be 0)\n", hstride);
368
Damien Lespiau95b12082013-01-26 23:55:01 +0000369 /* E. If ExecSize = Width = 1, both VertStride and HorzStride must be 0.
370 * This defines a scalar. */
371 if (execsize == 1 && width == 1) {
372 if (hstride != 0)
373 warn(ALL, location, "execution size and region width are 1 but "
374 "horizontal stride is %d (should be 0)\n", hstride);
375 if (vstride != 0)
376 warn(ALL, location, "execution size and region width are 1 but "
377 "vertical stride is %d (should be 0)\n", vstride);
378 }
379
Damien Lespiauc0592b22013-01-24 18:32:20 +0000380 return true;
381}
382
Damien Lespiauf0365d42013-02-04 12:02:18 +0000383static int get_subreg_address(unsigned regfile, unsigned type, unsigned subreg, unsigned address_mode)
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000384{
385 int unit_size = 1;
386
387 assert(address_mode == BRW_ADDRESS_DIRECT);
388 assert(regfile != BRW_IMMEDIATE_VALUE);
389
390 if (advanced_flag)
391 unit_size = get_type_size(type);
392
393 return subreg * unit_size;
394}
395
396/* only used in indirect address mode.
397 * input: sub-register number of an address register
398 * output: the value of AddrSubRegNum in the instruction binary code
399 *
400 * input output(advanced_flag==0) output(advanced_flag==1)
401 * a0.0 0 0
402 * a0.1 invalid input 1
403 * a0.2 1 2
404 * a0.3 invalid input 3
405 * a0.4 2 4
406 * a0.5 invalid input 5
407 * a0.6 3 6
408 * a0.7 invalid input 7
409 * a0.8 4 invalid input
410 * a0.10 5 invalid input
411 * a0.12 6 invalid input
412 * a0.14 7 invalid input
413 */
Damien Lespiauf0365d42013-02-04 12:02:18 +0000414static int get_indirect_subreg_address(unsigned subreg)
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000415{
416 return advanced_flag == 0 ? subreg / 2 : subreg;
417}
418
419static void resolve_subnr(struct brw_reg *reg)
420{
Damien Lespiaue7cca1a2013-01-27 02:06:22 +0000421 if (reg->file == BRW_IMMEDIATE_VALUE)
422 return;
423
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000424 if (reg->address_mode == BRW_ADDRESS_DIRECT)
425 reg->subnr = get_subreg_address(reg->file, reg->type, reg->subnr,
426 reg->address_mode);
427 else
428 reg->subnr = get_indirect_subreg_address(reg->subnr);
429}
430
431
Eric Anholt22a10632006-08-22 10:15:33 -0700432%}
Damien Lespiaud94e8a62013-01-26 19:51:28 +0000433%locations
Eric Anholt22a10632006-08-22 10:15:33 -0700434
435%start ROOT
436
437%union {
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800438 char *string;
Eric Anholt22a10632006-08-22 10:15:33 -0700439 int integer;
440 double number;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000441 struct brw_program_instruction instruction;
Eric Anholt22a10632006-08-22 10:15:33 -0700442 struct brw_program program;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800443 struct region region;
444 struct regtype regtype;
Damien Lespiau801b4eb2013-01-23 16:20:05 +0000445 struct brw_reg reg;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800446 struct condition condition;
Damien Lespiaudfe6ada2013-01-30 22:32:07 +0000447 struct predicate predicate;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000448 struct options options;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800449 struct declared_register symbol_reg;
Keith Packard2d4d4012008-03-30 00:58:28 -0700450 imm32_t imm32;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700451
452 struct src_operand src_operand;
Eric Anholt22a10632006-08-22 10:15:33 -0700453}
454
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800455%token COLON
Eric Anholt22a10632006-08-22 10:15:33 -0700456%token SEMICOLON
457%token LPAREN RPAREN
458%token LANGLE RANGLE
459%token LCURLY RCURLY
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700460%token LSQUARE RSQUARE
Xiang, Haihao27b43032010-12-13 16:07:16 +0800461%token COMMA EQ
462%token ABS DOT
463%token PLUS MINUS MULTIPLY DIVIDE
Eric Anholt22a10632006-08-22 10:15:33 -0700464
Eric Anholtc8939ed2006-08-30 10:50:56 -0700465%token <integer> TYPE_UD TYPE_D TYPE_UW TYPE_W TYPE_UB TYPE_B
466%token <integer> TYPE_VF TYPE_HF TYPE_V TYPE_F
Eric Anholt22a10632006-08-22 10:15:33 -0700467
Eric Anholt908f37d2006-08-25 17:33:02 -0700468%token ALIGN1 ALIGN16 SECHALF COMPR SWITCH ATOMIC NODDCHK NODDCLR
Xiang, Haihao55d81c42010-10-08 13:53:22 +0800469%token MASK_DISABLE BREAKPOINT ACCWRCTRL EOT
Eric Anholt22a10632006-08-22 10:15:33 -0700470
Keith Packard2033aea2008-04-23 23:10:40 -0700471%token SEQ ANY2H ALL2H ANY4H ALL4H ANY8H ALL8H ANY16H ALL16H ANYV ALLV
472%token <integer> ZERO EQUAL NOT_ZERO NOT_EQUAL GREATER GREATER_EQUAL LESS LESS_EQUAL
473%token <integer> ROUND_INCREMENT OVERFLOW UNORDERED
Eric Anholt883408e2006-08-25 13:38:03 -0700474%token <integer> GENREG MSGREG ADDRESSREG ACCREG FLAGREG
475%token <integer> MASKREG AMASK IMASK LMASK CMASK
476%token <integer> MASKSTACKREG LMS IMS MASKSTACKDEPTHREG IMSD LMSD
477%token <integer> NOTIFYREG STATEREG CONTROLREG IPREG
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700478%token GENREGFILE MSGREGFILE
Eric Anholt22a10632006-08-22 10:15:33 -0700479
Eric Anholtf914c6a2006-08-25 11:05:10 -0700480%token <integer> MOV FRC RNDU RNDD RNDE RNDZ NOT LZD
481%token <integer> MUL MAC MACH LINE SAD2 SADA2 DP4 DPH DP3 DP2
Xiang, Haihaof1f52082010-10-19 13:26:24 +0800482%token <integer> AVG ADD SEL AND OR XOR SHR SHL ASR CMP CMPN PLN
Homer Hsing9e711a42012-09-14 08:56:36 +0800483%token <integer> ADDC BFI1 BFREV CBIT F16TO32 F32TO16 FBH FBL
Matt Turner160feaf2013-04-29 10:58:26 -0700484%token <integer> SEND SENDC NOP JMPI IF IFF WHILE ELSE BREAK CONT HALT MSAVE
Eric Anholtf914c6a2006-08-25 11:05:10 -0700485%token <integer> PUSH MREST POP WAIT DO ENDIF ILLEGAL
Xiang, Haihao54055322010-10-27 09:42:56 +0800486%token <integer> MATH_INST
Homer Hsingb1ef3bc2012-09-14 09:02:01 +0800487%token <integer> MAD LRP BFE BFI2 SUBB
Homer Hsinga7b1c092012-09-21 12:33:13 +0800488%token <integer> CALL RET
Homer Hsing88dfdf32012-09-24 10:06:35 +0800489%token <integer> BRD BRC
Eric Anholtf914c6a2006-08-25 11:05:10 -0700490
Zhao Yakui93f2a4f2012-10-22 16:13:51 -0400491%token NULL_TOKEN MATH SAMPLER GATEWAY READ WRITE URB THREAD_SPAWNER VME DATA_PORT CRE
Eric Anholt22a10632006-08-22 10:15:33 -0700492
493%token MSGLEN RETURNLEN
Eric Anholte8651962006-08-24 16:37:04 -0700494%token <integer> ALLOCATE USED COMPLETE TRANSPOSE INTERLEAVE
Keith Packard2d4d4012008-03-30 00:58:28 -0700495%token SATURATE
Eric Anholt22a10632006-08-22 10:15:33 -0700496
497%token <integer> INTEGER
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800498%token <string> STRING
Eric Anholt22a10632006-08-22 10:15:33 -0700499%token <number> NUMBER
500
Eric Anholt3d360792006-08-25 09:36:28 -0700501%token <integer> INV LOG EXP SQRT RSQ POW SIN COS SINCOS INTDIV INTMOD
502%token <integer> INTDIVMOD
503%token SIGNED SCALAR
504
Eric Anholt6a88ada2006-08-28 22:11:18 -0700505%token <integer> X Y Z W
506
Xiang, Haihao27b43032010-12-13 16:07:16 +0800507%token <integer> KERNEL_PRAGMA END_KERNEL_PRAGMA CODE_PRAGMA END_CODE_PRAGMA
508%token <integer> REG_COUNT_PAYLOAD_PRAGMA REG_COUNT_TOTAL_PRAGMA DECLARE_PRAGMA
509%token <integer> BASE ELEMENTSIZE SRCREGION DSTREGION TYPE
510
511%token <integer> DEFAULT_EXEC_SIZE_PRAGMA DEFAULT_REG_TYPE_PRAGMA
marius vladbdad74d2016-05-16 13:39:10 +0300512%precedence SUBREGNUM
513%precedence SNDOPR
Xiang, Haihao27b43032010-12-13 16:07:16 +0800514%left PLUS MINUS
515%left MULTIPLY DIVIDE
marius vladbdad74d2016-05-16 13:39:10 +0300516%precedence UMINUS
517%precedence DOT
518%precedence STR_SYMBOL_REG
519%precedence EMPTEXECSIZE
520%precedence LPAREN
Xiang, Haihao27b43032010-12-13 16:07:16 +0800521
522%type <integer> exp sndopr
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800523%type <integer> simple_int
Eric Anholt22a10632006-08-22 10:15:33 -0700524%type <instruction> instruction unaryinstruction binaryinstruction
Homer Hsinga034bcb2012-09-07 14:38:13 +0800525%type <instruction> binaryaccinstruction trinaryinstruction sendinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000526%type <instruction> syncinstruction
Eric Anholt2dac0a12006-08-29 15:29:31 -0700527%type <instruction> msgtarget
Xiang, Haihao54055322010-10-27 09:42:56 +0800528%type <instruction> mathinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000529%type <instruction> nopinstruction
Damien Lespiauf6e90522013-01-30 17:04:13 +0000530%type <instruction> relocatableinstruction breakinstruction
531%type <instruction> ifelseinstruction loopinstruction haltinstruction
532%type <instruction> multibranchinstruction subroutineinstruction jumpinstruction
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800533%type <string> label
Eric Anholt22a10632006-08-22 10:15:33 -0700534%type <program> instrseq
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700535%type <integer> instoption
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800536%type <integer> unaryop binaryop binaryaccop breakop
Homer Hsinga034bcb2012-09-07 14:38:13 +0800537%type <integer> trinaryop
Matt Turner160feaf2013-04-29 10:58:26 -0700538%type <integer> sendop
Xiang, Haihao27b43032010-12-13 16:07:16 +0800539%type <condition> conditionalmodifier
Damien Lespiaudfe6ada2013-01-30 22:32:07 +0000540%type <predicate> predicate
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000541%type <options> instoptions instoption_list
Xiang, Haihao27b43032010-12-13 16:07:16 +0800542%type <integer> condition saturate negate abs chansel
Eric Anholt2dac0a12006-08-29 15:29:31 -0700543%type <integer> writemask_x writemask_y writemask_z writemask_w
Xiang, Haihao27b43032010-12-13 16:07:16 +0800544%type <integer> srcimmtype execsize dstregion immaddroffset
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700545%type <integer> subregnum sampler_datatype
Eric Anholte8651962006-08-24 16:37:04 -0700546%type <integer> urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt3d360792006-08-25 09:36:28 -0700547%type <integer> math_function math_signed math_scalar
Eric Anholt0ed5d932006-08-28 23:05:51 -0700548%type <integer> predctrl predstate
Xiang, Haihao27b43032010-12-13 16:07:16 +0800549%type <region> region region_wh indirectregion declare_srcregion;
550%type <regtype> regtype
Damien Lespiau801b4eb2013-01-23 16:20:05 +0000551%type <reg> directgenreg directmsgreg addrreg accreg flagreg maskreg
552%type <reg> maskstackreg notifyreg
553/* %type <reg> maskstackdepthreg */
554%type <reg> statereg controlreg ipreg nullreg
555%type <reg> dstoperandex_typed srcarchoperandex_typed
556%type <reg> sendleadreg
557%type <reg> indirectgenreg indirectmsgreg addrparam
Keith Packard2d4d4012008-03-30 00:58:28 -0700558%type <integer> mask_subreg maskstack_subreg
Xiang, Haihao27b43032010-12-13 16:07:16 +0800559%type <integer> declare_elementsize declare_dstregion declare_type
Keith Packard2d4d4012008-03-30 00:58:28 -0700560/* %type <intger> maskstackdepth_subreg */
Xiang, Haihao27b43032010-12-13 16:07:16 +0800561%type <symbol_reg> symbol_reg symbol_reg_p;
Eric Anholt22a10632006-08-22 10:15:33 -0700562%type <imm32> imm32
Damien Lespiau03750732013-01-23 20:33:00 +0000563%type <reg> dst dstoperand dstoperandex dstreg post_dst writemask
564%type <reg> declare_base
Eric Anholt6a88ada2006-08-28 22:11:18 -0700565%type <src_operand> directsrcoperand srcarchoperandex directsrcaccoperand
Eric Anholt2d298742006-08-30 09:57:20 -0700566%type <src_operand> indirectsrcoperand
Eric Anholt6a88ada2006-08-28 22:11:18 -0700567%type <src_operand> src srcimm imm32reg payload srcacc srcaccimm swizzle
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800568%type <src_operand> relativelocation relativelocation2
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000569
570%code {
571
572#undef error
573#define error(l, fmt, ...) \
574 do { \
575 message(ERROR, l, fmt, ## __VA_ARGS__); \
576 YYERROR; \
577 } while(0)
578
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000579static void add_option(struct options *options, int option)
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000580{
581 switch (option) {
582 case ALIGN1:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000583 options->access_mode = BRW_ALIGN_1;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000584 break;
585 case ALIGN16:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000586 options->access_mode = BRW_ALIGN_16;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000587 break;
588 case SECHALF:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000589 options->compression_control |= BRW_COMPRESSION_2NDHALF;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000590 break;
591 case COMPR:
592 if (!IS_GENp(6))
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000593 options->compression_control |= BRW_COMPRESSION_COMPRESSED;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000594 break;
595 case SWITCH:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000596 options->thread_control |= BRW_THREAD_SWITCH;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000597 break;
598 case ATOMIC:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000599 options->thread_control |= BRW_THREAD_ATOMIC;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000600 break;
601 case NODDCHK:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000602 options->dependency_control |= BRW_DEPENDENCY_NOTCHECKED;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000603 break;
604 case NODDCLR:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000605 options->dependency_control |= BRW_DEPENDENCY_NOTCLEARED;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000606 break;
607 case MASK_DISABLE:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000608 options->mask_control = BRW_MASK_DISABLE;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000609 break;
610 case BREAKPOINT:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000611 options->debug_control = BRW_DEBUG_BREAKPOINT;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000612 break;
613 case ACCWRCTRL:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000614 options->acc_wr_control = BRW_ACCUMULATOR_WRITE_ENABLE;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000615 break;
616 case EOT:
Damien Lespiau6bf3aa82013-01-30 23:25:19 +0000617 options->end_of_thread = 1;
Damien Lespiaubca2ff22013-01-30 23:00:26 +0000618 break;
619 }
620}
621
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000622}
623
Eric Anholt22a10632006-08-22 10:15:33 -0700624%%
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800625simple_int: INTEGER { $$ = $1; }
626 | MINUS INTEGER { $$ = -$2;}
627;
628
Zou Nan hai5608d272009-10-20 14:51:04 +0800629exp: INTEGER { $$ = $1; }
Zou Nan hai5608d272009-10-20 14:51:04 +0800630 | exp PLUS exp { $$ = $1 + $3; }
631 | exp MINUS exp { $$ = $1 - $3; }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800632 | exp MULTIPLY exp { $$ = $1 * $3; }
633 | exp DIVIDE exp { if ($3) $$ = $1 / $3; else YYERROR;}
634 | MINUS exp %prec UMINUS { $$ = -$2;}
Zou Nan hai5608d272009-10-20 14:51:04 +0800635 | LPAREN exp RPAREN { $$ = $2; }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800636 ;
Eric Anholt22a10632006-08-22 10:15:33 -0700637
638ROOT: instrseq
639 {
640 compiled_program = $1;
641 }
642;
643
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800644
645label: STRING COLON
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800646;
647
Xiang, Haihao27b43032010-12-13 16:07:16 +0800648declare_base: BASE EQ dstreg
649 {
650 $$ = $3;
651 }
652;
653declare_elementsize: ELEMENTSIZE EQ exp
654 {
655 $$ = $3;
656 }
657;
marius vladbdad74d2016-05-16 13:39:10 +0300658declare_srcregion: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +0800659 {
660 /* XXX is this default correct?*/
661 memset (&$$, '\0', sizeof ($$));
662 $$.vert_stride = ffs(0);
Damien Lespiau2f502bc2013-02-01 14:09:41 +0000663 $$.width = BRW_WIDTH_1;
Xiang, Haihao27b43032010-12-13 16:07:16 +0800664 $$.horiz_stride = ffs(0);
665 }
666 | SRCREGION EQ region
667 {
668 $$ = $3;
669 }
670;
marius vladbdad74d2016-05-16 13:39:10 +0300671declare_dstregion: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +0800672 {
673 $$ = 1;
674 }
675 | DSTREGION EQ dstregion
676 {
677 $$ = $3;
678 }
679;
680declare_type: TYPE EQ regtype
681 {
682 $$ = $3.type;
683 }
684;
685declare_pragma: DECLARE_PRAGMA STRING declare_base declare_elementsize declare_srcregion declare_dstregion declare_type
686 {
Damien Lespiau574a2492013-01-26 18:26:03 +0000687 struct declared_register reg, *found, *new_reg;
688
689 reg.name = $2;
690 reg.reg = $3;
691 reg.element_size = $4;
692 reg.src_region = $5;
693 reg.dst_region = $6;
Damien Lespiau2de8b402013-02-01 13:59:32 +0000694 reg.reg.type = $7;
Damien Lespiau574a2492013-01-26 18:26:03 +0000695
696 found = find_register($2);
697 if (found) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000698 if (!declared_register_equal(&reg, found))
699 error(&@1, "%s already defined and definitions "
700 "don't agree\n", $2);
Homer Hsing2ab4c0d2012-09-20 14:04:20 +0800701 free($2); // $2 has been malloc'ed by strdup
Homer Hsinge6d61ac2012-09-17 13:34:38 +0800702 } else {
Damien Lespiau574a2492013-01-26 18:26:03 +0000703 new_reg = malloc(sizeof(struct declared_register));
704 *new_reg = reg;
705 insert_register(new_reg);
Xiang, Haihao27b43032010-12-13 16:07:16 +0800706 }
707 }
708;
709
710reg_count_total_pragma: REG_COUNT_TOTAL_PRAGMA exp
711;
712reg_count_payload_pragma: REG_COUNT_PAYLOAD_PRAGMA exp
713;
714
715default_exec_size_pragma: DEFAULT_EXEC_SIZE_PRAGMA exp
716 {
717 program_defaults.execute_size = $2;
718 }
719;
720default_reg_type_pragma: DEFAULT_REG_TYPE_PRAGMA regtype
721 {
722 program_defaults.register_type = $2.type;
723 }
724;
725pragma: reg_count_total_pragma
726 |reg_count_payload_pragma
727 |default_exec_size_pragma
728 |default_reg_type_pragma
729 |declare_pragma
730;
731
732instrseq: instrseq pragma
733 {
734 $$ = $1;
735 }
736 | instrseq instruction SEMICOLON
Eric Anholt22a10632006-08-22 10:15:33 -0700737 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000738 brw_program_add_instruction(&$1, &$2);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800739 $$ = $1;
Eric Anholt22a10632006-08-22 10:15:33 -0700740 }
741 | instruction SEMICOLON
742 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000743 brw_program_init(&$$);
744 brw_program_add_instruction(&$$, &$1);
Eric Anholt22a10632006-08-22 10:15:33 -0700745 }
Damien Lespiau79c62f12013-01-21 21:41:36 +0000746 | instrseq relocatableinstruction SEMICOLON
747 {
748 brw_program_add_relocatable(&$1, &$2);
749 $$ = $1;
750 }
751 | relocatableinstruction SEMICOLON
752 {
753 brw_program_init(&$$);
754 brw_program_add_relocatable(&$$, &$1);
755 }
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000756 | instrseq SEMICOLON
Xiang, Haihao27b43032010-12-13 16:07:16 +0800757 {
758 $$ = $1;
759 }
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000760 | instrseq label
Xiang, Haihao27b43032010-12-13 16:07:16 +0800761 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000762 brw_program_add_label(&$1, $2);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800763 $$ = $1;
764 }
765 | label
766 {
Damien Lespiau73d58ed2013-01-21 17:07:28 +0000767 brw_program_init(&$$);
768 brw_program_add_label(&$$, $1);
Zou Nan haidb8aedc2010-04-21 11:02:21 +0800769 }
Xiang, Haihao27b43032010-12-13 16:07:16 +0800770 | pragma
771 {
772 $$.first = NULL;
773 $$.last = NULL;
774 }
Chen, Yangyang66649d72010-12-13 15:36:02 +0800775 | instrseq error SEMICOLON {
776 $$ = $1;
Eric Anholt22a10632006-08-22 10:15:33 -0700777 }
778;
779
780/* 1.4.1: Instruction groups */
Homer Hsing74383f42012-09-18 13:25:53 +0800781// binaryinstruction: Source operands cannot be accumulators
782// binaryaccinstruction: Source operands can be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -0700783instruction: unaryinstruction
784 | binaryinstruction
785 | binaryaccinstruction
Homer Hsinga034bcb2012-09-07 14:38:13 +0800786 | trinaryinstruction
787 | sendinstruction
Eric Anholt1f58efa2006-09-01 11:56:12 -0700788 | syncinstruction
Xiang, Haihao54055322010-10-27 09:42:56 +0800789 | mathinstruction
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800790 | nopinstruction
Damien Lespiau79c62f12013-01-21 21:41:36 +0000791;
792
793/* relocatableinstruction are instructions that needs a relocation pass */
794relocatableinstruction: ifelseinstruction
795 | loopinstruction
796 | haltinstruction
797 | multibranchinstruction
798 | subroutineinstruction
799 | jumpinstruction
800 | breakinstruction
Homer Hsing88dfdf32012-09-24 10:06:35 +0800801;
802
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800803ifelseinstruction: ENDIF
804 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400805 // for Gen4
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000806 if(IS_GENp(6)) // For gen6+.
807 error(&@1, "should be 'ENDIF execsize relativelocation'\n");
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800808 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +0000809 set_instruction_opcode(&$$, $1);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000810 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
811 GEN(&$$)->bits1.da1.dest_horiz_stride = 1;
812 GEN(&$$)->bits1.da1.src1_reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
813 GEN(&$$)->bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_UD;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800814 }
815 | ENDIF execsize relativelocation instoptions
816 {
Homer Hsingc56d7862012-09-28 13:46:21 +0800817 // for Gen6+
818 /* Gen6, Gen7 bspec: predication is prohibited */
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000819 if(!IS_GENp(6)) // for gen6-
820 error(&@1, "ENDIF Syntax error: should be 'ENDIF'\n");
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800821 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +0000822 set_instruction_opcode(&$$, $1);
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +0000823 set_execsize(&$$, $2);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000824 $$.reloc.first_reloc_target = $3.reloc_target;
825 $$.reloc.first_reloc_offset = $3.imm32;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800826 }
827 | ELSE execsize relativelocation instoptions
828 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400829 if(!IS_GENp(6)) {
830 // for Gen4, Gen5. gen_level < 60
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800831 /* Set the istack pop count, which must always be 1. */
832 $3.imm32 |= (1 << 16);
833
834 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +0000835 set_instruction_opcode(&$$, $1);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000836 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000837 ip_dst.width = $2;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000838 set_instruction_dest(&$$, &ip_dst);
839 set_instruction_src0(&$$, &ip_src, NULL);
840 set_instruction_src1(&$$, &$3, NULL);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000841 $$.reloc.first_reloc_target = $3.reloc_target;
842 $$.reloc.first_reloc_offset = $3.imm32;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400843 } else if(IS_GENp(6)) {
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800844 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +0000845 set_instruction_opcode(&$$, $1);
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +0000846 set_execsize(&$$, $2);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000847 $$.reloc.first_reloc_target = $3.reloc_target;
848 $$.reloc.first_reloc_offset = $3.imm32;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800849 } else {
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000850 error(&@1, "'ELSE' instruction is not implemented.\n");
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800851 }
852 }
853 | predicate IF execsize relativelocation
854 {
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800855 /* The branch instructions require that the IP register
856 * be the destination and first source operand, while the
857 * offset is the second source operand. The offset is added
858 * to the pre-incremented IP.
859 */
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000860 if(IS_GENp(7)) /* Error in Gen7+. */
861 error(&@2, "IF should be 'IF execsize JIP UIP'\n");
862
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800863 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000864 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000865 set_instruction_opcode(&$$, $2);
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400866 if(!IS_GENp(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +0000867 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000868 ip_dst.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000869 set_instruction_dest(&$$, &ip_dst);
870 set_instruction_src0(&$$, &ip_src, NULL);
871 set_instruction_src1(&$$, &$4, NULL);
Homer Hsing2ad18c12012-09-28 14:02:25 +0800872 }
Damien Lespiau9b78f742013-01-30 17:09:17 +0000873 $$.reloc.first_reloc_target = $4.reloc_target;
874 $$.reloc.first_reloc_offset = $4.imm32;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800875 }
876 | predicate IF execsize relativelocation relativelocation
877 {
878 /* for Gen7+ */
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000879 if(!IS_GENp(7))
880 error(&@2, "IF should be 'IF execsize relativelocation'\n");
881
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800882 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000883 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000884 set_instruction_opcode(&$$, $2);
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +0000885 set_execsize(&$$, $3);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000886 $$.reloc.first_reloc_target = $4.reloc_target;
887 $$.reloc.first_reloc_offset = $4.imm32;
888 $$.reloc.second_reloc_target = $5.reloc_target;
889 $$.reloc.second_reloc_offset = $5.imm32;
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800890 }
891;
892
893loopinstruction: predicate WHILE execsize relativelocation instoptions
894 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400895 if(!IS_GENp(6)) {
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800896 /* The branch instructions require that the IP register
897 * be the destination and first source operand, while the
898 * offset is the second source operand. The offset is added
899 * to the pre-incremented IP.
900 */
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000901 ip_dst.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000902 set_instruction_dest(&$$, &ip_dst);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800903 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000904 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000905 set_instruction_opcode(&$$, $2);
Damien Lespiauf6e90522013-01-30 17:04:13 +0000906 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
907 set_instruction_src0(&$$, &ip_src, NULL);
908 set_instruction_src1(&$$, &$4, NULL);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000909 $$.reloc.first_reloc_target = $4.reloc_target;
910 $$.reloc.first_reloc_offset = $4.imm32;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -0400911 } else if (IS_GENp(6)) {
Homer Hsinge8cb1952012-09-28 14:05:51 +0800912 /* Gen6 spec:
913 dest must have the same element size as src0.
914 dest horizontal stride must be 1. */
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800915 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000916 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000917 set_instruction_opcode(&$$, $2);
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +0000918 set_execsize(&$$, $3);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000919 $$.reloc.first_reloc_target = $4.reloc_target;
920 $$.reloc.first_reloc_offset = $4.imm32;
Homer Hsing72a3c192012-09-27 13:51:33 +0800921 } else {
Damien Lespiau6d3d3692013-01-27 10:41:23 +0000922 error(&@2, "'WHILE' instruction is not implemented!\n");
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800923 }
924 }
925 | DO
926 {
927 // deprecated
928 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +0000929 set_instruction_opcode(&$$, $1);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800930 };
931
932haltinstruction: predicate HALT execsize relativelocation relativelocation instoptions
933 {
Homer Hsingce555522012-09-27 15:44:15 +0800934 // for Gen6, Gen7
935 /* Gen6, Gen7 bspec: dst and src0 must be the null reg. */
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800936 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000937 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000938 set_instruction_opcode(&$$, $2);
Damien Lespiau9b78f742013-01-30 17:09:17 +0000939 $$.reloc.first_reloc_target = $4.reloc_target;
940 $$.reloc.first_reloc_offset = $4.imm32;
941 $$.reloc.second_reloc_target = $5.reloc_target;
942 $$.reloc.second_reloc_offset = $5.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000943 dst_null_reg.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000944 set_instruction_dest(&$$, &dst_null_reg);
945 set_instruction_src0(&$$, &src_null_reg, NULL);
Homer Hsing4bf84ec2012-09-24 10:12:26 +0800946 };
947
Homer Hsing88dfdf32012-09-24 10:06:35 +0800948multibranchinstruction:
949 predicate BRD execsize relativelocation instoptions
950 {
951 /* Gen7 bspec: dest must be null. use Switch option */
952 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000953 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000954 set_instruction_opcode(&$$, $2);
Xiang, Haihao9d0287c2013-02-22 11:14:07 +0800955 if (IS_GENp(8))
956 gen8_set_thread_control(GEN8(&$$), gen8_thread_control(GEN8(&$$)) | BRW_THREAD_SWITCH);
957 else
958 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9b78f742013-01-30 17:09:17 +0000959 $$.reloc.first_reloc_target = $4.reloc_target;
960 $$.reloc.first_reloc_offset = $4.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000961 dst_null_reg.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000962 set_instruction_dest(&$$, &dst_null_reg);
Homer Hsing88dfdf32012-09-24 10:06:35 +0800963 }
Homer Hsing88dfdf32012-09-24 10:06:35 +0800964 | predicate BRC execsize relativelocation relativelocation instoptions
965 {
966 /* Gen7 bspec: dest must be null. src0 must be null. use Switch option */
967 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +0000968 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +0000969 set_instruction_opcode(&$$, $2);
Xiang, Haihao9d0287c2013-02-22 11:14:07 +0800970 if (IS_GENp(8))
971 gen8_set_thread_control(GEN8(&$$), gen8_thread_control(GEN8(&$$)) | BRW_THREAD_SWITCH);
972 else
973 GEN(&$$)->header.thread_control |= BRW_THREAD_SWITCH;
Damien Lespiau9b78f742013-01-30 17:09:17 +0000974 $$.reloc.first_reloc_target = $4.reloc_target;
975 $$.reloc.first_reloc_offset = $4.imm32;
976 $$.reloc.second_reloc_target = $5.reloc_target;
977 $$.reloc.second_reloc_offset = $5.imm32;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +0000978 dst_null_reg.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +0000979 set_instruction_dest(&$$, &dst_null_reg);
980 set_instruction_src0(&$$, &src_null_reg, NULL);
Homer Hsing88dfdf32012-09-24 10:06:35 +0800981 }
Homer Hsinga7b1c092012-09-21 12:33:13 +0800982;
983
984subroutineinstruction:
985 predicate CALL execsize dst relativelocation instoptions
986 {
Homer Hsing75296822012-09-27 15:31:56 +0800987 /*
988 Gen6 bspec:
989 source, dest type should be DWORD.
990 dest must be QWord aligned.
991 source0 region control must be <2,2,1>.
992 execution size must be 2.
993 QtrCtrl is prohibited.
994 JIP is an immediate operand, must be of type W.
995 Gen7 bspec:
996 source, dest type should be DWORD.
997 dest must be QWord aligned.
998 source0 region control must be <2,2,1>.
999 execution size must be 2.
1000 */
Homer Hsinga7b1c092012-09-21 12:33:13 +08001001 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +00001002 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +00001003 set_instruction_opcode(&$$, $2);
Homer Hsing75296822012-09-27 15:31:56 +08001004
Damien Lespiau03750732013-01-23 20:33:00 +00001005 $4.type = BRW_REGISTER_TYPE_D; /* dest type should be DWORD */
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001006 $4.width = BRW_WIDTH_2; /* execution size must be 2. */
Damien Lespiauf6e90522013-01-30 17:04:13 +00001007 set_instruction_dest(&$$, &$4);
Homer Hsing75296822012-09-27 15:31:56 +08001008
1009 struct src_operand src0;
1010 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001011 src0.reg.type = BRW_REGISTER_TYPE_D; /* source type should be DWORD */
Homer Hsing75296822012-09-27 15:31:56 +08001012 /* source0 region control must be <2,2,1>. */
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001013 src0.reg.hstride = 1; /*encoded 1*/
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001014 src0.reg.width = BRW_WIDTH_2;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001015 src0.reg.vstride = 2; /*encoded 2*/
Damien Lespiauf6e90522013-01-30 17:04:13 +00001016 set_instruction_src0(&$$, &src0, NULL);
Homer Hsing75296822012-09-27 15:31:56 +08001017
Damien Lespiau9b78f742013-01-30 17:09:17 +00001018 $$.reloc.first_reloc_target = $5.reloc_target;
1019 $$.reloc.first_reloc_offset = $5.imm32;
Homer Hsinga7b1c092012-09-21 12:33:13 +08001020 }
1021 | predicate RET execsize dstoperandex src instoptions
1022 {
Homer Hsing3de439e2012-09-27 15:39:28 +08001023 /*
1024 Gen6, 7:
1025 source cannot be accumulator.
1026 dest must be null.
1027 src0 region control must be <2,2,1> (not specified clearly. should be same as CALL)
1028 */
Homer Hsinga7b1c092012-09-21 12:33:13 +08001029 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +00001030 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +00001031 set_instruction_opcode(&$$, $2);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001032 dst_null_reg.width = BRW_WIDTH_2; /* execution size of RET should be 2 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00001033 set_instruction_dest(&$$, &dst_null_reg);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001034 $5.reg.type = BRW_REGISTER_TYPE_D;
1035 $5.reg.hstride = 1; /*encoded 1*/
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001036 $5.reg.width = BRW_WIDTH_2;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001037 $5.reg.vstride = 2; /*encoded 2*/
Damien Lespiauf6e90522013-01-30 17:04:13 +00001038 set_instruction_src0(&$$, &$5, NULL);
Homer Hsinga7b1c092012-09-21 12:33:13 +08001039 }
Eric Anholt22a10632006-08-22 10:15:33 -07001040;
1041
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001042unaryinstruction:
1043 predicate unaryop conditionalmodifier saturate execsize
1044 dst srcaccimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001045 {
Homer Hsing81859af2012-09-14 09:34:58 +08001046 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001047 set_instruction_opcode(&$$, $2);
Damien Lespiau49861a02013-01-31 00:26:51 +00001048 set_instruction_saturate(&$$, $4);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001049 $6.width = $5;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001050 set_instruction_options(&$$, $8);
Damien Lespiaub21c2e62013-01-31 00:18:47 +00001051 set_instruction_pred_cond(&$$, &$1, &$3, &@3);
Eric Anholt2dac0a12006-08-29 15:29:31 -07001052 if (set_instruction_dest(&$$, &$6) != 0)
1053 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001054 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001055 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001056
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001057 if (!IS_GENp(6) &&
Damien Lespiauf6e90522013-01-30 17:04:13 +00001058 get_type_size(GEN(&$$)->bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
1059 GEN(&$$)->header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -07001060 }
1061;
1062
Homer Hsing4285d9c2012-09-14 08:41:16 +08001063unaryop: MOV | FRC | RNDU | RNDD | RNDE | RNDZ | NOT | LZD | BFREV | CBIT
Homer Hsing9e711a42012-09-14 08:56:36 +08001064 | F16TO32 | F32TO16 | FBH | FBL
Eric Anholt22a10632006-08-22 10:15:33 -07001065;
1066
Homer Hsing74383f42012-09-18 13:25:53 +08001067// Source operands cannot be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -07001068binaryinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001069 predicate binaryop conditionalmodifier saturate execsize
1070 dst src srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001071 {
Homer Hsing81859af2012-09-14 09:34:58 +08001072 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001073 set_instruction_opcode(&$$, $2);
Damien Lespiau49861a02013-01-31 00:26:51 +00001074 set_instruction_saturate(&$$, $4);
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001075 set_instruction_options(&$$, $9);
Damien Lespiaub21c2e62013-01-31 00:18:47 +00001076 set_instruction_pred_cond(&$$, &$1, &$3, &@3);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001077 $6.width = $5;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001078 if (set_instruction_dest(&$$, &$6) != 0)
1079 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001080 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001081 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001082 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001083 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001084
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001085 if (!IS_GENp(6) &&
Damien Lespiauf6e90522013-01-30 17:04:13 +00001086 get_type_size(GEN(&$$)->bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
1087 GEN(&$$)->header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -07001088 }
1089;
1090
Homer Hsingbebe8172012-09-18 13:47:22 +08001091/* bspec: BFI1 should not access accumulator. */
1092binaryop: MUL | MAC | MACH | LINE | SAD2 | SADA2 | DP4 | DPH | DP3 | DP2 | PLN | BFI1
Eric Anholtedc82a02006-08-25 17:42:05 -07001093;
Eric Anholt22a10632006-08-22 10:15:33 -07001094
Homer Hsing74383f42012-09-18 13:25:53 +08001095// Source operands can be accumulators
Eric Anholt22a10632006-08-22 10:15:33 -07001096binaryaccinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001097 predicate binaryaccop conditionalmodifier saturate execsize
1098 dst srcacc srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001099 {
Homer Hsing81859af2012-09-14 09:34:58 +08001100 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001101 set_instruction_opcode(&$$, $2);
Damien Lespiau49861a02013-01-31 00:26:51 +00001102 set_instruction_saturate(&$$, $4);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001103 $6.width = $5;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001104 set_instruction_options(&$$, $9);
Damien Lespiaub21c2e62013-01-31 00:18:47 +00001105 set_instruction_pred_cond(&$$, &$1, &$3, &@3);
Eric Anholt2dac0a12006-08-29 15:29:31 -07001106 if (set_instruction_dest(&$$, &$6) != 0)
1107 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001108 if (set_instruction_src0(&$$, &$7, &@7) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001109 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001110 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Eric Anholt6a88ada2006-08-28 22:11:18 -07001111 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001112
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001113 if (!IS_GENp(6) &&
Damien Lespiauf6e90522013-01-30 17:04:13 +00001114 get_type_size(GEN(&$$)->bits1.da1.dest_reg_type) * (1 << $6.width) == 64)
1115 GEN(&$$)->header.compression_control = BRW_COMPRESSION_COMPRESSED;
Eric Anholt22a10632006-08-22 10:15:33 -07001116 }
1117;
1118
Homer Hsingbebe8172012-09-18 13:47:22 +08001119/* TODO: bspec says ADDC/SUBB/CMP/CMPN/SHL/BFI1 cannot use accumulator as dest. */
1120binaryaccop: AVG | ADD | SEL | AND | OR | XOR | SHR | SHL | ASR | CMP | CMPN | ADDC | SUBB
Eric Anholt22a10632006-08-22 10:15:33 -07001121;
1122
Homer Hsing8ca55682012-09-13 11:05:50 +08001123trinaryop: MAD | LRP | BFE | BFI2
Homer Hsinga034bcb2012-09-07 14:38:13 +08001124;
1125
1126trinaryinstruction:
1127 predicate trinaryop conditionalmodifier saturate execsize
1128 dst src src src instoptions
1129{
1130 memset(&$$, 0, sizeof($$));
1131
Damien Lespiaub21c2e62013-01-31 00:18:47 +00001132 set_instruction_pred_cond(&$$, &$1, &$3, &@3);
Homer Hsinga034bcb2012-09-07 14:38:13 +08001133
Damien Lespiau5d526c82013-01-30 23:39:09 +00001134 set_instruction_opcode(&$$, $2);
Damien Lespiau49861a02013-01-31 00:26:51 +00001135 set_instruction_saturate(&$$, $4);
Kristian H. Kristensen5444a9a2016-11-29 17:13:17 -08001136 set_instruction_options(&$$, $10);
Homer Hsinga034bcb2012-09-07 14:38:13 +08001137
Damien Lespiau26da3752013-01-31 01:28:15 +00001138 $6.width = $5;
Homer Hsinga034bcb2012-09-07 14:38:13 +08001139 if (set_instruction_dest_three_src(&$$, &$6))
1140 YYERROR;
1141 if (set_instruction_src0_three_src(&$$, &$7))
1142 YYERROR;
1143 if (set_instruction_src1_three_src(&$$, &$8))
1144 YYERROR;
1145 if (set_instruction_src2_three_src(&$$, &$9))
1146 YYERROR;
Homer Hsinga034bcb2012-09-07 14:38:13 +08001147}
Eric Anholtedc82a02006-08-25 17:42:05 -07001148;
Eric Anholt22a10632006-08-22 10:15:33 -07001149
Matt Turner160feaf2013-04-29 10:58:26 -07001150sendop: SEND | SENDC
1151;
1152
1153sendinstruction: predicate sendop execsize exp post_dst payload msgtarget
Zou Nan hai5608d272009-10-20 14:51:04 +08001154 MSGLEN exp RETURNLEN exp instoptions
Eric Anholt22a10632006-08-22 10:15:33 -07001155 {
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001156 /* Send instructions are messy. The first argument is the
1157 * post destination -- the grf register that the response
1158 * starts from. The second argument is the current
1159 * destination, which is the start of the message arguments
1160 * to the shared function, and where src0 payload is loaded
1161 * to if not null. The payload is typically based on the
1162 * grf 0 thread payload of your current thread, and is
1163 * implicitly loaded if non-null.
1164 */
Homer Hsing81859af2012-09-14 09:34:58 +08001165 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001166 set_instruction_opcode(&$$, $2);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001167 $5.width = $3;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001168 GEN(&$$)->header.destreg__conditionalmod = $4; /* msg reg index */
Eric Anholt0ed5d932006-08-28 23:05:51 -07001169 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -07001170 if (set_instruction_dest(&$$, &$5) != 0)
1171 YYERROR;
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001172
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001173 if (IS_GENp(6)) {
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001174 struct src_operand src0;
1175
1176 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001177 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001178
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001179 if (IS_GENp(7))
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001180 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001181 else
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001182 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001183
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001184 src0.reg.type = BRW_REGISTER_TYPE_D;
1185 src0.reg.nr = $4;
1186 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001187 set_instruction_src0(&$$, &src0, NULL);
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001188 } else {
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001189 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihaodcdde532010-10-21 14:33:35 +08001190 YYERROR;
1191 }
1192
Zhao Yakui8dc95202014-01-23 13:26:12 +08001193 if (IS_GENp(9)) {
1194 gen8_set_src1_reg_file(GEN8(&$$), BRW_IMMEDIATE_VALUE);
1195 gen8_set_src1_reg_type(GEN8(&$$), BRW_REGISTER_TYPE_D);
1196 gen9_set_send_extdesc(GEN8(&$$), 0);
1197 } else if (IS_GENp(8)) {
Damien Lespiauf9e74fb2013-01-31 18:25:45 +00001198 gen8_set_src1_reg_file(GEN8(&$$), BRW_IMMEDIATE_VALUE);
1199 gen8_set_src1_reg_type(GEN8(&$$), BRW_REGISTER_TYPE_D);
1200 } else {
1201 GEN(&$$)->bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
1202 GEN(&$$)->bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_D;
1203 }
Xiang Haihao549b7512009-06-30 10:02:33 +08001204
Damien Lespiauf9e74fb2013-01-31 18:25:45 +00001205 if (IS_GENp(8)) {
1206 GEN8(&$$)->data[3] = GEN8(&$7)->data[3];
1207 gen8_set_sfid(GEN8(&$$), gen8_sfid(GEN8(&$7)));
1208 gen8_set_mlen(GEN8(&$$), $9);
1209 gen8_set_rlen(GEN8(&$$), $11);
1210 gen8_set_eot(GEN8(&$$), $12.end_of_thread);
1211 } else if (IS_GENp(5)) {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001212 if (IS_GENp(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001213 GEN(&$$)->header.destreg__conditionalmod = GEN(&$7)->bits2.send_gen5.sfid;
Xiang, Haihao4f777e72010-10-08 15:07:51 +08001214 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001215 GEN(&$$)->header.destreg__conditionalmod = $4; /* msg reg index */
1216 GEN(&$$)->bits2.send_gen5.sfid = GEN(&$7)->bits2.send_gen5.sfid;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001217 GEN(&$$)->bits2.send_gen5.end_of_thread = $12.end_of_thread;
Xiang, Haihao4f777e72010-10-08 15:07:51 +08001218 }
1219
Damien Lespiauf6e90522013-01-30 17:04:13 +00001220 GEN(&$$)->bits3.generic_gen5 = GEN(&$7)->bits3.generic_gen5;
1221 GEN(&$$)->bits3.generic_gen5.msg_length = $9;
1222 GEN(&$$)->bits3.generic_gen5.response_length = $11;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001223 GEN(&$$)->bits3.generic_gen5.end_of_thread = $12.end_of_thread;
Xiang Haihao549b7512009-06-30 10:02:33 +08001224 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001225 GEN(&$$)->header.destreg__conditionalmod = $4; /* msg reg index */
1226 GEN(&$$)->bits3.generic = GEN(&$7)->bits3.generic;
1227 GEN(&$$)->bits3.generic.msg_length = $9;
1228 GEN(&$$)->bits3.generic.response_length = $11;
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001229 GEN(&$$)->bits3.generic.end_of_thread = $12.end_of_thread;
Xiang Haihao549b7512009-06-30 10:02:33 +08001230 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001231 }
Matt Turner160feaf2013-04-29 10:58:26 -07001232 | predicate sendop execsize dst sendleadreg payload directsrcoperand instoptions
Feng, Boqun37d68102011-04-19 08:43:22 +08001233 {
Xiang, Haihao62298322013-08-14 14:21:16 -07001234 if (IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001235 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao62298322013-08-14 14:21:16 -07001236
Homer Hsing81859af2012-09-14 09:34:58 +08001237 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001238 set_instruction_opcode(&$$, $2);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001239 GEN(&$$)->header.destreg__conditionalmod = $5.nr; /* msg reg index */
Feng, Boqun37d68102011-04-19 08:43:22 +08001240
1241 set_instruction_predicate(&$$, &$1);
1242
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001243 $4.width = $3;
Feng, Boqun37d68102011-04-19 08:43:22 +08001244 if (set_instruction_dest(&$$, &$4) != 0)
1245 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001246 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001247 YYERROR;
1248 /* XXX is this correct? */
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001249 if (set_instruction_src1(&$$, &$7, &@7) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001250 YYERROR;
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001251
Feng, Boqun37d68102011-04-19 08:43:22 +08001252 }
Matt Turner160feaf2013-04-29 10:58:26 -07001253 | predicate sendop execsize dst sendleadreg payload imm32reg instoptions
Feng, Boqun37d68102011-04-19 08:43:22 +08001254 {
Xiang, Haihao62298322013-08-14 14:21:16 -07001255 if (IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001256 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao62298322013-08-14 14:21:16 -07001257
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001258 if ($7.reg.type != BRW_REGISTER_TYPE_UD &&
1259 $7.reg.type != BRW_REGISTER_TYPE_D &&
1260 $7.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001261 error (&@7, "non-int D/UD/V representation: %d,"
1262 "type=%d\n", $7.reg.dw1.ud, $7.reg.type);
Feng, Boqun37d68102011-04-19 08:43:22 +08001263 }
Homer Hsing81859af2012-09-14 09:34:58 +08001264 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001265 set_instruction_opcode(&$$, $2);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001266 GEN(&$$)->header.destreg__conditionalmod = $5.nr; /* msg reg index */
Feng, Boqun37d68102011-04-19 08:43:22 +08001267
1268 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001269 $4.width = $3;
Feng, Boqun37d68102011-04-19 08:43:22 +08001270 if (set_instruction_dest(&$$, &$4) != 0)
1271 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001272 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Feng, Boqun37d68102011-04-19 08:43:22 +08001273 YYERROR;
Damien Lespiaufa2b6792013-01-31 18:22:49 +00001274 if (set_instruction_src1(&$$, &$7, &@7) != 0)
1275 YYERROR;
Feng, Boqun37d68102011-04-19 08:43:22 +08001276 }
Matt Turner160feaf2013-04-29 10:58:26 -07001277 | predicate sendop execsize dst sendleadreg sndopr imm32reg instoptions
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001278 {
1279 struct src_operand src0;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001280
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001281 if (!IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001282 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001283
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001284 if ($7.reg.type != BRW_REGISTER_TYPE_UD &&
1285 $7.reg.type != BRW_REGISTER_TYPE_D &&
1286 $7.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001287 error(&@7,"non-int D/UD/V representation: %d,"
1288 "type=%d\n", $7.reg.dw1.ud, $7.reg.type);
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001289 }
1290
Homer Hsing81859af2012-09-14 09:34:58 +08001291 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001292 set_instruction_opcode(&$$, $2);
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001293 set_instruction_predicate(&$$, &$1);
1294
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001295 $4.width = $3;
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001296 if (set_instruction_dest(&$$, &$4) != 0)
1297 YYERROR;
1298
1299 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001300 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001301
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001302 if (IS_GENp(7)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001303 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
1304 src0.reg.type = BRW_REGISTER_TYPE_UB;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001305 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001306 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
1307 src0.reg.type = BRW_REGISTER_TYPE_D;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001308 }
Xiang, Haihao46ffdd52011-05-25 14:29:14 +08001309
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001310 src0.reg.nr = $5.nr;
1311 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001312 set_instruction_src0(&$$, &src0, NULL);
Damien Lespiaufa2b6792013-01-31 18:22:49 +00001313 set_instruction_src1(&$$, &$7, NULL);
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001314
Zhao Yakui8dc95202014-01-23 13:26:12 +08001315 if (IS_GENp(9)) {
1316 gen8_set_sfid(GEN8(&$$), $6 & EX_DESC_SFID_MASK);
1317 gen8_set_eot(GEN8(&$$), !!($6 & EX_DESC_EOT_MASK));
1318 gen9_set_send_extdesc(GEN8(&$$), $6 & EX_DESC_FUNC_MASK);
1319 } else if (IS_GENp(8)) {
Xiang, Haihao60c9b412013-02-22 11:14:13 +08001320 gen8_set_sfid(GEN8(&$$), $6 & EX_DESC_SFID_MASK);
1321 gen8_set_eot(GEN8(&$$), !!($6 & EX_DESC_EOT_MASK));
1322 } else {
1323 GEN(&$$)->header.destreg__conditionalmod = ($6 & EX_DESC_SFID_MASK); /* SFID */
1324 GEN(&$$)->bits3.generic_gen5.end_of_thread = !!($6 & EX_DESC_EOT_MASK);
1325 }
Xiang, Haihao85da7b92011-02-17 13:24:11 +08001326 }
Matt Turner160feaf2013-04-29 10:58:26 -07001327 | predicate sendop execsize dst sendleadreg sndopr directsrcoperand instoptions
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001328 {
1329 struct src_operand src0;
1330
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001331 if (!IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001332 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001333
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001334 if ($7.reg.file != BRW_ARCHITECTURE_REGISTER_FILE ||
1335 ($7.reg.nr & 0xF0) != BRW_ARF_ADDRESS ||
1336 ($7.reg.nr & 0x0F) != 0 ||
1337 $7.reg.subnr != 0) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001338 error (&@7, "scalar register must be a0.0<0;1,0>:ud\n");
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001339 }
1340
Homer Hsing81859af2012-09-14 09:34:58 +08001341 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001342 set_instruction_opcode(&$$, $2);
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001343 set_instruction_predicate(&$$, &$1);
1344
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001345 $4.width = $3;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001346 if (set_instruction_dest(&$$, &$4) != 0)
1347 YYERROR;
1348
1349 memset(&src0, 0, sizeof(src0));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001350 src0.reg.address_mode = BRW_ADDRESS_DIRECT;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001351
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001352 if (IS_GENp(7)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001353 src0.reg.file = BRW_GENERAL_REGISTER_FILE;
1354 src0.reg.type = BRW_REGISTER_TYPE_UB;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001355 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001356 src0.reg.file = BRW_MESSAGE_REGISTER_FILE;
1357 src0.reg.type = BRW_REGISTER_TYPE_D;
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001358 }
1359
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001360 src0.reg.nr = $5.nr;
1361 src0.reg.subnr = 0;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001362 set_instruction_src0(&$$, &src0, NULL);
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001363
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001364 set_instruction_src1(&$$, &$7, &@7);
Xiang, Haihao60c9b412013-02-22 11:14:13 +08001365
1366 if (IS_GENp(8)) {
1367 gen8_set_sfid(GEN8(&$$), $6 & EX_DESC_SFID_MASK);
1368 gen8_set_eot(GEN8(&$$), !!($6 & EX_DESC_EOT_MASK));
Zhao Yakui8dc95202014-01-23 13:26:12 +08001369 gen9_set_send_extdesc(GEN8(&$$), $6 & EX_DESC_FUNC_MASK);
1370 } else if (IS_GENp(8)) {
1371 gen8_set_sfid(GEN8(&$$), $6 & EX_DESC_SFID_MASK);
1372 gen8_set_eot(GEN8(&$$), !!($6 & EX_DESC_EOT_MASK));
Xiang, Haihao60c9b412013-02-22 11:14:13 +08001373 } else {
1374 GEN(&$$)->header.destreg__conditionalmod = ($6 & EX_DESC_SFID_MASK); /* SFID */
1375 GEN(&$$)->bits3.generic_gen5.end_of_thread = !!($6 & EX_DESC_EOT_MASK);
1376 }
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08001377 }
Matt Turner160feaf2013-04-29 10:58:26 -07001378 | predicate sendop execsize dst sendleadreg payload sndopr imm32reg instoptions
Xiang, Haihao27b43032010-12-13 16:07:16 +08001379 {
Xiang, Haihao62298322013-08-14 14:21:16 -07001380 if (IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001381 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao62298322013-08-14 14:21:16 -07001382
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00001383 if ($8.reg.type != BRW_REGISTER_TYPE_UD &&
1384 $8.reg.type != BRW_REGISTER_TYPE_D &&
1385 $8.reg.type != BRW_REGISTER_TYPE_V) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001386 error(&@8, "non-int D/UD/V representation: %d,"
1387 "type=%d\n", $8.reg.dw1.ud, $8.reg.type);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001388 }
Homer Hsing81859af2012-09-14 09:34:58 +08001389 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001390 set_instruction_opcode(&$$, $2);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001391 GEN(&$$)->header.destreg__conditionalmod = $5.nr; /* msg reg index */
Xiang, Haihao27b43032010-12-13 16:07:16 +08001392
1393 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001394 $4.width = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001395 if (set_instruction_dest(&$$, &$4) != 0)
1396 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001397 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001398 YYERROR;
Damien Lespiaufa2b6792013-01-31 18:22:49 +00001399 if (set_instruction_src1(&$$, &$8, &@8) != 0)
1400 YYERROR;
1401
Ben Widawsky3d8d0942013-08-16 15:24:25 -07001402 if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001403 GEN(&$$)->bits2.send_gen5.sfid = ($7 & EX_DESC_SFID_MASK);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001404 GEN(&$$)->bits3.generic_gen5.end_of_thread = !!($7 & EX_DESC_EOT_MASK);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001405 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08001406 }
Matt Turner160feaf2013-04-29 10:58:26 -07001407 | predicate sendop execsize dst sendleadreg payload exp directsrcoperand instoptions
Xiang, Haihao27b43032010-12-13 16:07:16 +08001408 {
Xiang, Haihao62298322013-08-14 14:21:16 -07001409 if (IS_GENp(6))
Damien Lespiau5959b8b2013-08-20 14:25:52 +01001410 error(&@2, "invalid syntax for send on gen6+\n");
Xiang, Haihao62298322013-08-14 14:21:16 -07001411
Homer Hsing81859af2012-09-14 09:34:58 +08001412 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001413 set_instruction_opcode(&$$, $2);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001414 GEN(&$$)->header.destreg__conditionalmod = $5.nr; /* msg reg index */
Xiang, Haihao27b43032010-12-13 16:07:16 +08001415
1416 set_instruction_predicate(&$$, &$1);
1417
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001418 $4.width = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001419 if (set_instruction_dest(&$$, &$4) != 0)
1420 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001421 if (set_instruction_src0(&$$, &$6, &@6) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001422 YYERROR;
1423 /* XXX is this correct? */
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001424 if (set_instruction_src1(&$$, &$8, &@8) != 0)
Xiang, Haihao27b43032010-12-13 16:07:16 +08001425 YYERROR;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001426 if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001427 GEN(&$$)->bits2.send_gen5.sfid = $7;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001428 }
1429 }
1430
Eric Anholtedc82a02006-08-25 17:42:05 -07001431;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001432
Xiang, Haihao27b43032010-12-13 16:07:16 +08001433sndopr: exp %prec SNDOPR
1434 {
1435 $$ = $1;
1436 }
1437;
1438
1439jumpinstruction: predicate JMPI execsize relativelocation2
Eric Anholt1e907c72006-08-31 10:21:15 -07001440 {
Eric Anholt1e907c72006-08-31 10:21:15 -07001441 /* The jump instruction requires that the IP register
1442 * be the destination and first source operand, while the
1443 * offset is the second source operand. The next instruction
1444 * is the post-incremented IP plus the offset.
1445 */
Homer Hsing81859af2012-09-14 09:34:58 +08001446 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001447 set_instruction_opcode(&$$, $2);
Xiang, Haihao2df4d312013-02-22 11:14:05 +08001448 if(advanced_flag) {
1449 if (IS_GENp(8))
1450 gen8_set_mask_control(GEN8(&$$), BRW_MASK_DISABLE);
1451 else
1452 GEN(&$$)->header.mask_control = BRW_MASK_DISABLE;
1453 }
Damien Lespiauf6e90522013-01-30 17:04:13 +00001454 set_instruction_predicate(&$$, &$1);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001455 ip_dst.width = BRW_WIDTH_1;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001456 set_instruction_dest(&$$, &ip_dst);
1457 set_instruction_src0(&$$, &ip_src, NULL);
1458 set_instruction_src1(&$$, &$4, NULL);
Damien Lespiau9b78f742013-01-30 17:09:17 +00001459 $$.reloc.first_reloc_target = $4.reloc_target;
1460 $$.reloc.first_reloc_offset = $4.imm32;
Eric Anholt356ce762006-08-31 10:27:48 -07001461 }
1462;
1463
Xiang, Haihao54055322010-10-27 09:42:56 +08001464mathinstruction: predicate MATH_INST execsize dst src srcimm math_function instoptions
1465 {
Homer Hsing81859af2012-09-14 09:34:58 +08001466 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001467 set_instruction_opcode(&$$, $2);
Xiang, Haihao220f1652013-02-22 11:14:04 +08001468
1469 if (IS_GENp(8))
1470 gen8_set_math_function(GEN8(&$$), $7);
1471 else
1472 GEN(&$$)->header.destreg__conditionalmod = $7;
1473
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00001474 set_instruction_options(&$$, $8);
Xiang, Haihao54055322010-10-27 09:42:56 +08001475 set_instruction_predicate(&$$, &$1);
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00001476 $4.width = $3;
Xiang, Haihao54055322010-10-27 09:42:56 +08001477 if (set_instruction_dest(&$$, &$4) != 0)
1478 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001479 if (set_instruction_src0(&$$, &$5, &@5) != 0)
Xiang, Haihao54055322010-10-27 09:42:56 +08001480 YYERROR;
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001481 if (set_instruction_src1(&$$, &$6, &@6) != 0)
Xiang, Haihao54055322010-10-27 09:42:56 +08001482 YYERROR;
1483 }
1484;
1485
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001486breakinstruction: predicate breakop execsize relativelocation relativelocation instoptions
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001487 {
Homer Hsingce555522012-09-27 15:44:15 +08001488 // for Gen6, Gen7
Homer Hsing81859af2012-09-14 09:34:58 +08001489 memset(&$$, 0, sizeof($$));
Damien Lespiauf6e90522013-01-30 17:04:13 +00001490 set_instruction_predicate(&$$, &$1);
Damien Lespiau5d526c82013-01-30 23:39:09 +00001491 set_instruction_opcode(&$$, $2);
Damien Lespiau9cf8e1b2013-02-05 11:34:10 +00001492 set_execsize(&$$, $3);
Damien Lespiau9b78f742013-01-30 17:09:17 +00001493 $$.reloc.first_reloc_target = $4.reloc_target;
1494 $$.reloc.first_reloc_offset = $4.imm32;
1495 $$.reloc.second_reloc_target = $5.reloc_target;
1496 $$.reloc.second_reloc_offset = $5.imm32;
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001497 }
1498;
1499
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001500breakop: BREAK | CONT
Eric Anholtedc82a02006-08-25 17:42:05 -07001501;
Eric Anholtf914c6a2006-08-25 11:05:10 -07001502
Keith Packard2d4d4012008-03-30 00:58:28 -07001503/*
Eric Anholtf914c6a2006-08-25 11:05:10 -07001504maskpushop: MSAVE | PUSH
1505;
Keith Packard2d4d4012008-03-30 00:58:28 -07001506 */
Eric Anholtf914c6a2006-08-25 11:05:10 -07001507
Eric Anholt1f58efa2006-09-01 11:56:12 -07001508syncinstruction: predicate WAIT notifyreg
1509 {
Damien Lespiau03750732013-01-23 20:33:00 +00001510 struct brw_reg notify_dst;
Keith Packard2d4d4012008-03-30 00:58:28 -07001511 struct src_operand notify_src;
Eric Anholt1f58efa2006-09-01 11:56:12 -07001512
Homer Hsing81859af2012-09-14 09:34:58 +08001513 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001514 set_instruction_opcode(&$$, $2);
Xiang, Haihao27b43032010-12-13 16:07:16 +08001515 set_direct_dst_operand(&notify_dst, &$3, BRW_REGISTER_TYPE_D);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00001516 notify_dst.width = BRW_WIDTH_1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08001517 set_instruction_dest(&$$, &notify_dst);
Xiang, Haihao852216d2011-02-16 15:26:24 +08001518 set_direct_src_operand(&notify_src, &$3, BRW_REGISTER_TYPE_D);
Damien Lespiaue9172aa2013-01-26 22:44:45 +00001519 set_instruction_src0(&$$, &notify_src, NULL);
1520 set_instruction_src1(&$$, &src_null_reg, NULL);
Eric Anholt1f58efa2006-09-01 11:56:12 -07001521 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08001522
Eric Anholt1f58efa2006-09-01 11:56:12 -07001523;
1524
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001525nopinstruction: NOP
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001526 {
Homer Hsing81859af2012-09-14 09:34:58 +08001527 memset(&$$, 0, sizeof($$));
Damien Lespiau5d526c82013-01-30 23:39:09 +00001528 set_instruction_opcode(&$$, $1);
Homer Hsing4bf84ec2012-09-24 10:12:26 +08001529 };
Eric Anholt22a10632006-08-22 10:15:33 -07001530
1531/* XXX! */
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001532payload: directsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07001533;
1534
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001535post_dst: dst
Eric Anholt22a10632006-08-22 10:15:33 -07001536;
1537
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001538msgtarget: NULL_TOKEN
1539 {
Damien Lespiauf9e74fb2013-01-31 18:25:45 +00001540 if (IS_GENp(8)) {
1541 gen8_set_sfid(GEN8(&$$), BRW_SFID_NULL);
1542 gen8_set_header_present(GEN8(&$$), 0);
1543 } else if (IS_GENp(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001544 GEN(&$$)->bits2.send_gen5.sfid= BRW_SFID_NULL;
1545 GEN(&$$)->bits3.generic_gen5.header_present = 0; /* ??? */
Xiang Haihao549b7512009-06-30 10:02:33 +08001546 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001547 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_NULL;
Xiang Haihao549b7512009-06-30 10:02:33 +08001548 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001549 }
1550 | SAMPLER LPAREN INTEGER COMMA INTEGER COMMA
1551 sampler_datatype RPAREN
1552 {
Damien Lespiauf9e74fb2013-01-31 18:25:45 +00001553 if (IS_GENp(8)) {
1554 gen8_set_sfid(GEN8(&$$), BRW_SFID_SAMPLER);
1555 gen8_set_header_present(GEN8(&$$), 1); /* ??? */
1556 gen8_set_binding_table_index(GEN8(&$$), $3);
1557 gen8_set_sampler(GEN8(&$$), $5);
1558 gen8_set_sampler_simd_mode(GEN8(&$$), 2); /* SIMD16 */
1559 } else if (IS_GENp(7)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001560 GEN(&$$)->bits2.send_gen5.sfid = BRW_SFID_SAMPLER;
1561 GEN(&$$)->bits3.generic_gen5.header_present = 1; /* ??? */
1562 GEN(&$$)->bits3.sampler_gen7.binding_table_index = $3;
1563 GEN(&$$)->bits3.sampler_gen7.sampler = $5;
1564 GEN(&$$)->bits3.sampler_gen7.simd_mode = 2; /* SIMD16, maybe we should add a new parameter */
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001565 } else if (IS_GENp(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001566 GEN(&$$)->bits2.send_gen5.sfid = BRW_SFID_SAMPLER;
1567 GEN(&$$)->bits3.generic_gen5.header_present = 1; /* ??? */
1568 GEN(&$$)->bits3.sampler_gen5.binding_table_index = $3;
1569 GEN(&$$)->bits3.sampler_gen5.sampler = $5;
1570 GEN(&$$)->bits3.sampler_gen5.simd_mode = 2; /* SIMD16, maybe we should add a new parameter */
Xiang Haihao549b7512009-06-30 10:02:33 +08001571 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001572 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_SAMPLER;
1573 GEN(&$$)->bits3.sampler.binding_table_index = $3;
1574 GEN(&$$)->bits3.sampler.sampler = $5;
Xiang Haihao549b7512009-06-30 10:02:33 +08001575 switch ($7) {
1576 case TYPE_F:
Damien Lespiauf6e90522013-01-30 17:04:13 +00001577 GEN(&$$)->bits3.sampler.return_format =
Xiang Haihao549b7512009-06-30 10:02:33 +08001578 BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
1579 break;
1580 case TYPE_UD:
Damien Lespiauf6e90522013-01-30 17:04:13 +00001581 GEN(&$$)->bits3.sampler.return_format =
Xiang Haihao549b7512009-06-30 10:02:33 +08001582 BRW_SAMPLER_RETURN_FORMAT_UINT32;
1583 break;
1584 case TYPE_D:
Damien Lespiauf6e90522013-01-30 17:04:13 +00001585 GEN(&$$)->bits3.sampler.return_format =
Xiang Haihao549b7512009-06-30 10:02:33 +08001586 BRW_SAMPLER_RETURN_FORMAT_SINT32;
1587 break;
1588 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001589 }
1590 }
Eric Anholt3d360792006-08-25 09:36:28 -07001591 | MATH math_function saturate math_signed math_scalar
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001592 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001593 if (IS_GENp(6)) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001594 error (&@1, "Gen6+ doesn't have math function\n");
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001595 } else if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001596 GEN(&$$)->bits2.send_gen5.sfid = BRW_SFID_MATH;
1597 GEN(&$$)->bits3.generic_gen5.header_present = 0;
1598 GEN(&$$)->bits3.math_gen5.function = $2;
Damien Lespiau49861a02013-01-31 00:26:51 +00001599 set_instruction_saturate(&$$, $3);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001600 GEN(&$$)->bits3.math_gen5.int_type = $4;
1601 GEN(&$$)->bits3.math_gen5.precision = BRW_MATH_PRECISION_FULL;
1602 GEN(&$$)->bits3.math_gen5.data_type = $5;
Xiang Haihao549b7512009-06-30 10:02:33 +08001603 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001604 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_MATH;
1605 GEN(&$$)->bits3.math.function = $2;
Damien Lespiau49861a02013-01-31 00:26:51 +00001606 set_instruction_saturate(&$$, $3);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001607 GEN(&$$)->bits3.math.int_type = $4;
1608 GEN(&$$)->bits3.math.precision = BRW_MATH_PRECISION_FULL;
1609 GEN(&$$)->bits3.math.data_type = $5;
Xiang Haihao549b7512009-06-30 10:02:33 +08001610 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001611 }
1612 | GATEWAY
1613 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001614 if (IS_GENp(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001615 GEN(&$$)->bits2.send_gen5.sfid = BRW_SFID_MESSAGE_GATEWAY;
1616 GEN(&$$)->bits3.generic_gen5.header_present = 0; /* ??? */
Xiang Haihao549b7512009-06-30 10:02:33 +08001617 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001618 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_MESSAGE_GATEWAY;
Xiang Haihao549b7512009-06-30 10:02:33 +08001619 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001620 }
Zou Nan hai807f8762008-06-18 15:05:19 -07001621 | READ LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1622 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001623 {
Zhao Yakuie4866692014-01-23 13:26:10 +08001624 if (IS_GENp(9)) {
1625 if ($5 != 0 &&
1626 $5 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1627 $5 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1628 $5 != HSW_SFID_DATAPORT_DATA_CACHE1 &&
1629 $5 != SKL_SFID_DATAPORT_DCR0 &&
1630 $5 != SKL_SFID_DATAPORT_DATA_CACHE2) {
1631 error (&@9, "error: wrong cache type\n");
1632 }
1633
1634 if ($5 == 0)
1635 gen8_set_sfid(GEN8(&$$), HSW_SFID_DATAPORT_DATA_CACHE1);
1636 else
1637 gen8_set_sfid(GEN8(&$$), $5);
1638
1639 gen8_set_header_present(GEN8(&$$), 1);
1640 gen8_set_dp_binding_table_index(GEN8(&$$), $3);
1641 gen8_set_dp_message_control(GEN8(&$$), $7);
1642 gen8_set_dp_message_type(GEN8(&$$), $9);
1643 gen8_set_dp_category(GEN8(&$$), 0);
1644 } else if (IS_GENp(8)) {
Xiang, Haihao01c96542013-02-22 11:14:08 +08001645 gen8_set_sfid(GEN8(&$$), GEN6_SFID_DATAPORT_SAMPLER_CACHE);
1646 gen8_set_header_present(GEN8(&$$), 1);
1647 gen8_set_dp_binding_table_index(GEN8(&$$), $3);
1648 gen8_set_dp_message_control(GEN8(&$$), $7);
1649 gen8_set_dp_message_type(GEN8(&$$), $9);
1650 gen8_set_dp_category(GEN8(&$$), 0);
1651 } else if (IS_GENx(7)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001652 GEN(&$$)->bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001653 GEN6_SFID_DATAPORT_SAMPLER_CACHE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001654 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1655 GEN(&$$)->bits3.gen7_dp.binding_table_index = $3;
1656 GEN(&$$)->bits3.gen7_dp.msg_control = $7;
1657 GEN(&$$)->bits3.gen7_dp.msg_type = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001658 } else if (IS_GENx(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001659 GEN(&$$)->bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001660 GEN6_SFID_DATAPORT_SAMPLER_CACHE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001661 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1662 GEN(&$$)->bits3.gen6_dp_sampler_const_cache.binding_table_index = $3;
1663 GEN(&$$)->bits3.gen6_dp_sampler_const_cache.msg_control = $7;
1664 GEN(&$$)->bits3.gen6_dp_sampler_const_cache.msg_type = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001665 } else if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001666 GEN(&$$)->bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001667 BRW_SFID_DATAPORT_READ;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001668 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1669 GEN(&$$)->bits3.dp_read_gen5.binding_table_index = $3;
1670 GEN(&$$)->bits3.dp_read_gen5.target_cache = $5;
1671 GEN(&$$)->bits3.dp_read_gen5.msg_control = $7;
1672 GEN(&$$)->bits3.dp_read_gen5.msg_type = $9;
Xiang Haihao549b7512009-06-30 10:02:33 +08001673 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001674 GEN(&$$)->bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001675 BRW_SFID_DATAPORT_READ;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001676 GEN(&$$)->bits3.dp_read.binding_table_index = $3;
1677 GEN(&$$)->bits3.dp_read.target_cache = $5;
1678 GEN(&$$)->bits3.dp_read.msg_control = $7;
1679 GEN(&$$)->bits3.dp_read.msg_type = $9;
Xiang Haihao549b7512009-06-30 10:02:33 +08001680 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001681 }
Eric Anholt43313942006-08-24 15:26:10 -07001682 | WRITE LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1683 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001684 {
Xiang, Haihao01c96542013-02-22 11:14:08 +08001685 if (IS_GENp(8)) {
Zhao Yakuid6ff0b32014-01-23 13:26:11 +08001686 if (IS_GENp(9)) {
1687 if ($9 != 0 &&
1688 $9 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1689 $9 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1690 $9 != HSW_SFID_DATAPORT_DATA_CACHE1 &&
1691 $9 != SKL_SFID_DATAPORT_DATA_CACHE2) {
1692 error (&@9, "error: wrong cache type\n");
1693 }
1694 } else {
1695 if ($9 != 0 &&
1696 $9 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1697 $9 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1698 $9 != HSW_SFID_DATAPORT_DATA_CACHE1) {
1699 error (&@9, "error: wrong cache type\n");
1700 }
Xiang, Haihao3906a502013-12-06 09:16:58 +08001701 }
1702
1703 if ($9 == 0)
1704 gen8_set_sfid(GEN8(&$$), GEN6_SFID_DATAPORT_RENDER_CACHE);
1705 else
1706 gen8_set_sfid(GEN8(&$$), $9);
1707
Xiang, Haihao01c96542013-02-22 11:14:08 +08001708 gen8_set_header_present(GEN8(&$$), 1);
1709 gen8_set_dp_binding_table_index(GEN8(&$$), $3);
1710 gen8_set_dp_message_control(GEN8(&$$), $5);
1711 gen8_set_dp_message_type(GEN8(&$$), $7);
1712 gen8_set_dp_category(GEN8(&$$), 0);
1713 } else if (IS_GENx(7)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001714 GEN(&$$)->bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
1715 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1716 GEN(&$$)->bits3.gen7_dp.binding_table_index = $3;
1717 GEN(&$$)->bits3.gen7_dp.msg_control = $5;
1718 GEN(&$$)->bits3.gen7_dp.msg_type = $7;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001719 } else if (IS_GENx(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001720 GEN(&$$)->bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
Xiang, Haihao61784db2010-10-08 16:48:15 +08001721 /* Sandybridge supports headerlesss message for render target write.
1722 * Currently the GFX assembler doesn't support it. so the program must provide
1723 * message header
1724 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00001725 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1726 GEN(&$$)->bits3.gen6_dp.binding_table_index = $3;
1727 GEN(&$$)->bits3.gen6_dp.msg_control = $5;
1728 GEN(&$$)->bits3.gen6_dp.msg_type = $7;
1729 GEN(&$$)->bits3.gen6_dp.send_commit_msg = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001730 } else if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001731 GEN(&$$)->bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001732 BRW_SFID_DATAPORT_WRITE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001733 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1734 GEN(&$$)->bits3.dp_write_gen5.binding_table_index = $3;
1735 GEN(&$$)->bits3.dp_write_gen5.last_render_target = ($5 & 0x8) >> 3;
1736 GEN(&$$)->bits3.dp_write_gen5.msg_control = $5 & 0x7;
1737 GEN(&$$)->bits3.dp_write_gen5.msg_type = $7;
1738 GEN(&$$)->bits3.dp_write_gen5.send_commit_msg = $9;
Xiang Haihao549b7512009-06-30 10:02:33 +08001739 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001740 GEN(&$$)->bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001741 BRW_SFID_DATAPORT_WRITE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001742 GEN(&$$)->bits3.dp_write.binding_table_index = $3;
Xiang Haihao549b7512009-06-30 10:02:33 +08001743 /* The msg control field of brw_struct.h is split into
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001744 * msg control and last_render_target, even though
1745 * last_render_target isn't common to all write messages.
Xiang Haihao549b7512009-06-30 10:02:33 +08001746 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00001747 GEN(&$$)->bits3.dp_write.last_render_target = ($5 & 0x8) >> 3;
1748 GEN(&$$)->bits3.dp_write.msg_control = $5 & 0x7;
1749 GEN(&$$)->bits3.dp_write.msg_type = $7;
1750 GEN(&$$)->bits3.dp_write.send_commit_msg = $9;
Xiang Haihao549b7512009-06-30 10:02:33 +08001751 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001752 }
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001753 | WRITE LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1754 INTEGER COMMA INTEGER RPAREN
1755 {
Xiang, Haihao01c96542013-02-22 11:14:08 +08001756 if (IS_GENp(8)) {
Zhao Yakuid6ff0b32014-01-23 13:26:11 +08001757 if (IS_GENp(9)) {
1758 if ($9 != 0 &&
1759 $9 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1760 $9 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1761 $9 != HSW_SFID_DATAPORT_DATA_CACHE1 &&
1762 $9 != SKL_SFID_DATAPORT_DATA_CACHE2) {
1763 error (&@9, "error: wrong cache type\n");
1764 }
1765 } else {
1766 if ($9 != 0 &&
1767 $9 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1768 $9 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1769 $9 != HSW_SFID_DATAPORT_DATA_CACHE1) {
1770 error (&@9, "error: wrong cache type\n");
1771 }
Xiang, Haihao3906a502013-12-06 09:16:58 +08001772 }
1773
1774 if ($9 == 0)
1775 gen8_set_sfid(GEN8(&$$), GEN6_SFID_DATAPORT_RENDER_CACHE);
1776 else
1777 gen8_set_sfid(GEN8(&$$), $9);
1778
Xiang, Haihao01c96542013-02-22 11:14:08 +08001779 gen8_set_header_present(GEN8(&$$), ($11 != 0));
1780 gen8_set_dp_binding_table_index(GEN8(&$$), $3);
1781 gen8_set_dp_message_control(GEN8(&$$), $5);
1782 gen8_set_dp_message_type(GEN8(&$$), $7);
1783 gen8_set_dp_category(GEN8(&$$), 0);
1784 } else if (IS_GENx(7)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001785 GEN(&$$)->bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
1786 GEN(&$$)->bits3.generic_gen5.header_present = ($11 != 0);
1787 GEN(&$$)->bits3.gen7_dp.binding_table_index = $3;
1788 GEN(&$$)->bits3.gen7_dp.msg_control = $5;
1789 GEN(&$$)->bits3.gen7_dp.msg_type = $7;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001790 } else if (IS_GENx(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001791 GEN(&$$)->bits2.send_gen5.sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
1792 GEN(&$$)->bits3.generic_gen5.header_present = ($11 != 0);
1793 GEN(&$$)->bits3.gen6_dp.binding_table_index = $3;
1794 GEN(&$$)->bits3.gen6_dp.msg_control = $5;
1795 GEN(&$$)->bits3.gen6_dp.msg_type = $7;
1796 GEN(&$$)->bits3.gen6_dp.send_commit_msg = $9;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001797 } else if (IS_GENx(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001798 GEN(&$$)->bits2.send_gen5.sfid =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001799 BRW_SFID_DATAPORT_WRITE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001800 GEN(&$$)->bits3.generic_gen5.header_present = ($11 != 0);
1801 GEN(&$$)->bits3.dp_write_gen5.binding_table_index = $3;
1802 GEN(&$$)->bits3.dp_write_gen5.last_render_target = ($5 & 0x8) >> 3;
1803 GEN(&$$)->bits3.dp_write_gen5.msg_control = $5 & 0x7;
1804 GEN(&$$)->bits3.dp_write_gen5.msg_type = $7;
1805 GEN(&$$)->bits3.dp_write_gen5.send_commit_msg = $9;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001806 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001807 GEN(&$$)->bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001808 BRW_SFID_DATAPORT_WRITE;
Damien Lespiauf6e90522013-01-30 17:04:13 +00001809 GEN(&$$)->bits3.dp_write.binding_table_index = $3;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001810 /* The msg control field of brw_struct.h is split into
Damien Lespiau0fde3dd2013-01-15 20:34:50 +00001811 * msg control and last_render_target, even though
1812 * last_render_target isn't common to all write messages.
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001813 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00001814 GEN(&$$)->bits3.dp_write.last_render_target = ($5 & 0x8) >> 3;
1815 GEN(&$$)->bits3.dp_write.msg_control = $5 & 0x7;
1816 GEN(&$$)->bits3.dp_write.msg_type = $7;
1817 GEN(&$$)->bits3.dp_write.send_commit_msg = $9;
Xiang, Haihao14c0bd02010-11-01 16:16:25 +08001818 }
1819 }
Eric Anholte8651962006-08-24 16:37:04 -07001820 | URB INTEGER urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001821 {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001822 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_URB;
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04001823 if (IS_GENp(5)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001824 GEN(&$$)->bits2.send_gen5.sfid = BRW_SFID_URB;
1825 GEN(&$$)->bits3.generic_gen5.header_present = 1;
Damien Lespiau5d526c82013-01-30 23:39:09 +00001826 set_instruction_opcode(&$$, BRW_URB_OPCODE_WRITE);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001827 GEN(&$$)->bits3.urb_gen5.offset = $2;
1828 GEN(&$$)->bits3.urb_gen5.swizzle_control = $3;
1829 GEN(&$$)->bits3.urb_gen5.pad = 0;
1830 GEN(&$$)->bits3.urb_gen5.allocate = $4;
1831 GEN(&$$)->bits3.urb_gen5.used = $5;
1832 GEN(&$$)->bits3.urb_gen5.complete = $6;
Xiang Haihao549b7512009-06-30 10:02:33 +08001833 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001834 GEN(&$$)->bits3.generic.msg_target = BRW_SFID_URB;
Damien Lespiau5d526c82013-01-30 23:39:09 +00001835 set_instruction_opcode(&$$, BRW_URB_OPCODE_WRITE);
Damien Lespiauf6e90522013-01-30 17:04:13 +00001836 GEN(&$$)->bits3.urb.offset = $2;
1837 GEN(&$$)->bits3.urb.swizzle_control = $3;
1838 GEN(&$$)->bits3.urb.pad = 0;
1839 GEN(&$$)->bits3.urb.allocate = $4;
1840 GEN(&$$)->bits3.urb.used = $5;
1841 GEN(&$$)->bits3.urb.complete = $6;
Xiang Haihao549b7512009-06-30 10:02:33 +08001842 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001843 }
Zou Nan hai26afe902008-06-18 15:04:11 -07001844 | THREAD_SPAWNER LPAREN INTEGER COMMA INTEGER COMMA
1845 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001846 {
Xiang, Haihaobf003ea2013-02-22 11:14:09 +08001847 if (IS_GENp(8)) {
1848 gen8_set_sfid(GEN8(&$$), BRW_SFID_THREAD_SPAWNER);
1849 gen8_set_header_present(GEN8(&$$), 0); /* Must be 0 */
1850 gen8_set_ts_opcode(GEN8(&$$), $3);
1851 gen8_set_ts_request_type(GEN8(&$$), $5);
1852 gen8_set_ts_resource_select(GEN8(&$$), $7);
Xiang Haihao549b7512009-06-30 10:02:33 +08001853 } else {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001854 GEN(&$$)->bits3.generic.msg_target =
Damien Lespiau5e7e3f42013-01-18 11:04:37 +00001855 BRW_SFID_THREAD_SPAWNER;
Xiang, Haihaobf003ea2013-02-22 11:14:09 +08001856 if (IS_GENp(5)) {
1857 GEN(&$$)->bits2.send_gen5.sfid =
1858 BRW_SFID_THREAD_SPAWNER;
1859 GEN(&$$)->bits3.generic_gen5.header_present = 0;
1860 GEN(&$$)->bits3.thread_spawner_gen5.opcode = $3;
1861 GEN(&$$)->bits3.thread_spawner_gen5.requester_type = $5;
1862 GEN(&$$)->bits3.thread_spawner_gen5.resource_select = $7;
1863 } else {
1864 GEN(&$$)->bits3.generic.msg_target =
1865 BRW_SFID_THREAD_SPAWNER;
1866 GEN(&$$)->bits3.thread_spawner.opcode = $3;
1867 GEN(&$$)->bits3.thread_spawner.requester_type = $5;
1868 GEN(&$$)->bits3.thread_spawner.resource_select = $7;
1869 }
Xiang Haihao549b7512009-06-30 10:02:33 +08001870 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001871 }
Zhou Chang52399862011-04-14 11:51:29 +08001872 | VME LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA INTEGER RPAREN
1873 {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001874 GEN(&$$)->bits3.generic.msg_target = GEN6_SFID_VME;
Zhou Chang52399862011-04-14 11:51:29 +08001875
Xiang, Haihaob6a33bd2013-02-22 11:14:10 +08001876 if (IS_GENp(8)) {
1877 gen8_set_sfid(GEN8(&$$), GEN6_SFID_VME);
1878 gen8_set_header_present(GEN8(&$$), 1); /* Must be 1 */
1879 gen8_set_vme_binding_table_index(GEN8(&$$), $3);
1880 gen8_set_vme_message_type(GEN8(&$$), $9);
1881 } else if (IS_GENp(6)) {
Damien Lespiauf6e90522013-01-30 17:04:13 +00001882 GEN(&$$)->bits2.send_gen5.sfid = GEN6_SFID_VME;
1883 GEN(&$$)->bits3.vme_gen6.binding_table_index = $3;
1884 GEN(&$$)->bits3.vme_gen6.search_path_index = $5;
1885 GEN(&$$)->bits3.vme_gen6.lut_subindex = $7;
1886 GEN(&$$)->bits3.vme_gen6.message_type = $9;
1887 GEN(&$$)->bits3.generic_gen5.header_present = 1;
Zhou Chang52399862011-04-14 11:51:29 +08001888 } else {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001889 error (&@1, "Gen6- doesn't have vme function\n");
Zhou Chang52399862011-04-14 11:51:29 +08001890 }
1891 }
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001892 | CRE LPAREN INTEGER COMMA INTEGER RPAREN
1893 {
Xiang, Haihaobf05bd52013-02-22 11:14:11 +08001894 if (IS_GENp(8)) {
1895 gen8_set_sfid(GEN8(&$$), HSW_SFID_CRE);
1896 gen8_set_header_present(GEN8(&$$), 1); /* Must be 1 */
1897 gen8_set_cre_binding_table_index(GEN8(&$$), $3);
1898 gen8_set_cre_message_type(GEN8(&$$), $5);
1899 } else {
1900 if (gen_level < 75)
1901 error (&@1, "Below Gen7.5 doesn't have CRE function\n");
Damien Lespiau6d3d3692013-01-27 10:41:23 +00001902
Xiang, Haihaobf05bd52013-02-22 11:14:11 +08001903 GEN(&$$)->bits3.generic.msg_target = HSW_SFID_CRE;
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001904
Xiang, Haihaobf05bd52013-02-22 11:14:11 +08001905 GEN(&$$)->bits2.send_gen5.sfid = HSW_SFID_CRE;
1906 GEN(&$$)->bits3.cre_gen75.binding_table_index = $3;
1907 GEN(&$$)->bits3.cre_gen75.message_type = $5;
1908 GEN(&$$)->bits3.generic_gen5.header_present = 1;
1909 }
Zhao Yakui93f2a4f2012-10-22 16:13:51 -04001910 }
Xiang, Haihao27050392011-06-10 16:04:30 +08001911
1912 | DATA_PORT LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
1913 INTEGER COMMA INTEGER COMMA INTEGER RPAREN
1914 {
Xiang, Haihao01c96542013-02-22 11:14:08 +08001915 if (IS_GENp(8)) {
1916 if ($3 != GEN6_SFID_DATAPORT_SAMPLER_CACHE &&
1917 $3 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1918 $3 != GEN6_SFID_DATAPORT_CONSTANT_CACHE &&
Zhao Yakui66783e42013-04-09 09:59:16 +08001919 $3 != GEN7_SFID_DATAPORT_DATA_CACHE &&
1920 $3 != HSW_SFID_DATAPORT_DATA_CACHE1) {
Xiang, Haihao01c96542013-02-22 11:14:08 +08001921 error (&@3, "error: wrong cache type\n");
1922 }
Xiang, Haihao27050392011-06-10 16:04:30 +08001923
Xiang, Haihao01c96542013-02-22 11:14:08 +08001924 gen8_set_sfid(GEN8(&$$), $3);
1925 gen8_set_header_present(GEN8(&$$), ($13 != 0));
1926 gen8_set_dp_binding_table_index(GEN8(&$$), $9);
1927 gen8_set_dp_message_control(GEN8(&$$), $7);
1928 gen8_set_dp_message_type(GEN8(&$$), $5);
1929 gen8_set_dp_category(GEN8(&$$), $11);
1930 } else {
1931 GEN(&$$)->bits2.send_gen5.sfid = $3;
1932 GEN(&$$)->bits3.generic_gen5.header_present = ($13 != 0);
Xiang, Haihao27050392011-06-10 16:04:30 +08001933
Xiang, Haihao01c96542013-02-22 11:14:08 +08001934 if (IS_GENp(7)) {
1935 if ($3 != GEN6_SFID_DATAPORT_SAMPLER_CACHE &&
1936 $3 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1937 $3 != GEN6_SFID_DATAPORT_CONSTANT_CACHE &&
1938 $3 != GEN7_SFID_DATAPORT_DATA_CACHE) {
1939 error (&@3, "error: wrong cache type\n");
1940 }
Xiang, Haihao27050392011-06-10 16:04:30 +08001941
Xiang, Haihao01c96542013-02-22 11:14:08 +08001942 GEN(&$$)->bits3.gen7_dp.category = $11;
1943 GEN(&$$)->bits3.gen7_dp.binding_table_index = $9;
1944 GEN(&$$)->bits3.gen7_dp.msg_control = $7;
1945 GEN(&$$)->bits3.gen7_dp.msg_type = $5;
1946 } else if (IS_GENx(6)) {
1947 if ($3 != GEN6_SFID_DATAPORT_SAMPLER_CACHE &&
1948 $3 != GEN6_SFID_DATAPORT_RENDER_CACHE &&
1949 $3 != GEN6_SFID_DATAPORT_CONSTANT_CACHE) {
1950 error (&@3, "error: wrong cache type\n");
1951 }
1952
1953 GEN(&$$)->bits3.gen6_dp.send_commit_msg = $11;
1954 GEN(&$$)->bits3.gen6_dp.binding_table_index = $9;
1955 GEN(&$$)->bits3.gen6_dp.msg_control = $7;
1956 GEN(&$$)->bits3.gen6_dp.msg_type = $5;
1957 } else if (!IS_GENp(5)) {
1958 error (&@1, "Gen6- doesn't support data port for sampler/render/constant/data cache\n");
1959 }
1960 }
Xiang, Haihao27050392011-06-10 16:04:30 +08001961 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001962;
1963
Eric Anholte8651962006-08-24 16:37:04 -07001964urb_allocate: ALLOCATE { $$ = 1; }
marius vladbdad74d2016-05-16 13:39:10 +03001965 | %empty /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001966;
Eric Anholte8651962006-08-24 16:37:04 -07001967
1968urb_used: USED { $$ = 1; }
marius vladbdad74d2016-05-16 13:39:10 +03001969 | %empty /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001970;
Eric Anholte8651962006-08-24 16:37:04 -07001971
1972urb_complete: COMPLETE { $$ = 1; }
marius vladbdad74d2016-05-16 13:39:10 +03001973 | %empty /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001974;
Eric Anholte8651962006-08-24 16:37:04 -07001975
1976urb_swizzle: TRANSPOSE { $$ = BRW_URB_SWIZZLE_TRANSPOSE; }
1977 | INTERLEAVE { $$ = BRW_URB_SWIZZLE_INTERLEAVE; }
marius vladbdad74d2016-05-16 13:39:10 +03001978 | %empty /* empty */ { $$ = BRW_URB_SWIZZLE_NONE; }
Eric Anholt3d360792006-08-25 09:36:28 -07001979;
Eric Anholte8651962006-08-24 16:37:04 -07001980
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001981sampler_datatype:
1982 TYPE_F
1983 | TYPE_UD
1984 | TYPE_D
Eric Anholt3d360792006-08-25 09:36:28 -07001985;
1986
1987math_function: INV | LOG | EXP | SQRT | POW | SIN | COS | SINCOS | INTDIV
Kristian H. Kristensen96395772016-11-29 17:14:13 -08001988 | INTMOD | INTDIVMOD | RSQ
Eric Anholt3d360792006-08-25 09:36:28 -07001989;
1990
marius vladbdad74d2016-05-16 13:39:10 +03001991math_signed: %empty /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001992 | SIGNED { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001993;
Eric Anholt3d360792006-08-25 09:36:28 -07001994
marius vladbdad74d2016-05-16 13:39:10 +03001995math_scalar: %empty /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -07001996 | SCALAR { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001997;
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001998
Eric Anholt22a10632006-08-22 10:15:33 -07001999/* 1.4.2: Destination register */
2000
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002001dst: dstoperand | dstoperandex
Eric Anholt3d360792006-08-25 09:36:28 -07002002;
Eric Anholt22a10632006-08-22 10:15:33 -07002003
Xiang, Haihao27b43032010-12-13 16:07:16 +08002004dstoperand: symbol_reg dstregion
2005 {
Damien Lespiau03750732013-01-23 20:33:00 +00002006 $$ = $1.reg;
2007 $$.hstride = resolve_dst_region(&$1, $2);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002008 }
2009 | dstreg dstregion writemask regtype
Eric Anholt22a10632006-08-22 10:15:33 -07002010 {
2011 /* Returns an instruction with just the destination register
2012 * filled in.
2013 */
Damien Lespiau03750732013-01-23 20:33:00 +00002014 $$ = $1;
2015 $$.hstride = resolve_dst_region(NULL, $2);
2016 $$.dw1.bits.writemask = $3.dw1.bits.writemask;
2017 $$.type = $4.type;
Eric Anholt22a10632006-08-22 10:15:33 -07002018 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002019;
Eric Anholt22a10632006-08-22 10:15:33 -07002020
Eric Anholt883408e2006-08-25 13:38:03 -07002021/* The dstoperandex returns an instruction with just the destination register
2022 * filled in.
2023 */
2024dstoperandex: dstoperandex_typed dstregion regtype
Eric Anholt22a10632006-08-22 10:15:33 -07002025 {
Damien Lespiau03750732013-01-23 20:33:00 +00002026 $$ = $1;
2027 $$.hstride = resolve_dst_region(NULL, $2);
2028 $$.type = $3.type;
Eric Anholt22a10632006-08-22 10:15:33 -07002029 }
Eric Anholt883408e2006-08-25 13:38:03 -07002030 | maskstackreg
2031 {
Damien Lespiau03750732013-01-23 20:33:00 +00002032 $$ = $1;
2033 $$.hstride = 1;
2034 $$.type = BRW_REGISTER_TYPE_UW;
Eric Anholt883408e2006-08-25 13:38:03 -07002035 }
2036 | controlreg
2037 {
Damien Lespiau03750732013-01-23 20:33:00 +00002038 $$ = $1;
2039 $$.hstride = 1;
2040 $$.type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -07002041 }
2042 | ipreg
2043 {
Damien Lespiau03750732013-01-23 20:33:00 +00002044 $$ = $1;
2045 $$.hstride = 1;
2046 $$.type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -07002047 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002048 | nullreg dstregion regtype
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002049 {
Damien Lespiau03750732013-01-23 20:33:00 +00002050 $$ = $1;
2051 $$.hstride = resolve_dst_region(NULL, $2);
2052 $$.type = $3.type;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002053 }
2054;
Eric Anholt22a10632006-08-22 10:15:33 -07002055
Eric Anholt883408e2006-08-25 13:38:03 -07002056dstoperandex_typed: accreg | flagreg | addrreg | maskreg
2057;
2058
Xiang, Haihao27b43032010-12-13 16:07:16 +08002059symbol_reg: STRING %prec STR_SYMBOL_REG
2060 {
2061 struct declared_register *dcl_reg = find_register($1);
2062
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002063 if (dcl_reg == NULL)
2064 error(&@1, "can't find register %s\n", $1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002065
2066 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08002067 free($1); // $1 has been malloc'ed by strdup
Xiang, Haihao27b43032010-12-13 16:07:16 +08002068 }
2069 | symbol_reg_p
2070 {
2071 $$=$1;
2072 }
2073;
2074
2075symbol_reg_p: STRING LPAREN exp RPAREN
2076 {
2077 struct declared_register *dcl_reg = find_register($1);
2078
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002079 if (dcl_reg == NULL)
2080 error(&@1, "can't find register %s\n", $1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002081
2082 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Damien Lespiaucce4fc22013-01-23 15:13:55 +00002083 $$.reg.nr += $3;
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08002084 free($1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002085 }
2086 | STRING LPAREN exp COMMA exp RPAREN
2087 {
2088 struct declared_register *dcl_reg = find_register($1);
2089
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002090 if (dcl_reg == NULL)
2091 error(&@1, "can't find register %s\n", $1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002092
2093 memcpy(&$$, dcl_reg, sizeof(*dcl_reg));
Damien Lespiaucce4fc22013-01-23 15:13:55 +00002094 $$.reg.nr += $3;
Homer Hsing599d7d22012-10-16 14:14:25 +08002095 if(advanced_flag) {
Damien Lespiau2de8b402013-02-01 13:59:32 +00002096 int size = get_type_size(dcl_reg->reg.type);
Damien Lespiaucce4fc22013-01-23 15:13:55 +00002097 $$.reg.nr += ($$.reg.subnr + $5) / (32 / size);
2098 $$.reg.subnr = ($$.reg.subnr + $5) % (32 / size);
Homer Hsing599d7d22012-10-16 14:14:25 +08002099 } else {
Damien Lespiaucce4fc22013-01-23 15:13:55 +00002100 $$.reg.nr += ($$.reg.subnr + $5) / 32;
2101 $$.reg.subnr = ($$.reg.subnr + $5) % 32;
2102 }
Homer Hsing2ab4c0d2012-09-20 14:04:20 +08002103 free($1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002104 }
2105;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002106/* Returns a partially complete destination register consisting of the
2107 * direct or indirect register addressing fields, but not stride or writemask.
2108 */
Eric Anholt22a10632006-08-22 10:15:33 -07002109dstreg: directgenreg
2110 {
Damien Lespiau03750732013-01-23 20:33:00 +00002111 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002112 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt22a10632006-08-22 10:15:33 -07002113 }
2114 | directmsgreg
Eric Anholta34d1e02006-08-22 14:52:14 -07002115 {
Damien Lespiau03750732013-01-23 20:33:00 +00002116 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002117 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholta34d1e02006-08-22 14:52:14 -07002118 }
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002119 | indirectgenreg
2120 {
Damien Lespiau03750732013-01-23 20:33:00 +00002121 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002122 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002123 }
2124 | indirectmsgreg
2125 {
Damien Lespiau03750732013-01-23 20:33:00 +00002126 $$ = $1;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002127 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002128 }
Eric Anholt22a10632006-08-22 10:15:33 -07002129;
2130
2131/* 1.4.3: Source register */
Eric Anholt0d929b42006-08-22 13:33:41 -07002132srcaccimm: srcacc | imm32reg
Eric Anholt22a10632006-08-22 10:15:33 -07002133;
2134
Eric Anholt2d298742006-08-30 09:57:20 -07002135srcacc: directsrcaccoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07002136;
2137
Xiang, Haihao27b43032010-12-13 16:07:16 +08002138srcimm: directsrcoperand | indirectsrcoperand| imm32reg
Eric Anholtedc82a02006-08-25 17:42:05 -07002139;
Eric Anholt0d929b42006-08-22 13:33:41 -07002140
2141imm32reg: imm32 srcimmtype
Eric Anholt22a10632006-08-22 10:15:33 -07002142 {
Eric Anholt6a88ada2006-08-28 22:11:18 -07002143 union {
2144 int i;
2145 float f;
2146 } intfloat;
Keith Packard2d4d4012008-03-30 00:58:28 -07002147 uint32_t d;
Eric Anholt6a88ada2006-08-28 22:11:18 -07002148
Eric Anholt22a10632006-08-22 10:15:33 -07002149 switch ($2) {
2150 case BRW_REGISTER_TYPE_UD:
Eric Anholt22a10632006-08-22 10:15:33 -07002151 case BRW_REGISTER_TYPE_D:
Keith Packard2d4d4012008-03-30 00:58:28 -07002152 case BRW_REGISTER_TYPE_V:
Xiang, Haihao27b43032010-12-13 16:07:16 +08002153 case BRW_REGISTER_TYPE_VF:
Keith Packard2d4d4012008-03-30 00:58:28 -07002154 switch ($1.r) {
2155 case imm32_d:
2156 d = $1.u.d;
2157 break;
2158 default:
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002159 error (&@2, "non-int D/UD/V/VF representation: %d,type=%d\n", $1.r, $2);
Keith Packard2d4d4012008-03-30 00:58:28 -07002160 }
Eric Anholt22a10632006-08-22 10:15:33 -07002161 break;
Eric Anholt0d929b42006-08-22 13:33:41 -07002162 case BRW_REGISTER_TYPE_UW:
Eric Anholt0d929b42006-08-22 13:33:41 -07002163 case BRW_REGISTER_TYPE_W:
Keith Packard2d4d4012008-03-30 00:58:28 -07002164 switch ($1.r) {
2165 case imm32_d:
2166 d = $1.u.d;
2167 break;
2168 default:
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002169 error (&@2, "non-int W/UW representation\n");
Keith Packard2d4d4012008-03-30 00:58:28 -07002170 }
2171 d &= 0xffff;
2172 d |= d << 16;
Eric Anholt0d929b42006-08-22 13:33:41 -07002173 break;
Eric Anholt22a10632006-08-22 10:15:33 -07002174 case BRW_REGISTER_TYPE_F:
Keith Packard2d4d4012008-03-30 00:58:28 -07002175 switch ($1.r) {
2176 case imm32_f:
2177 intfloat.f = $1.u.f;
2178 break;
2179 case imm32_d:
2180 intfloat.f = (float) $1.u.d;
2181 break;
2182 default:
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002183 error (&@2, "non-float F representation\n");
Keith Packard2d4d4012008-03-30 00:58:28 -07002184 }
2185 d = intfloat.i;
Eric Anholt22a10632006-08-22 10:15:33 -07002186 break;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002187#if 0
Keith Packard2d4d4012008-03-30 00:58:28 -07002188 case BRW_REGISTER_TYPE_VF:
2189 fprintf (stderr, "Immediate type VF not supported yet\n");
2190 YYERROR;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002191#endif
Eric Anholt0d929b42006-08-22 13:33:41 -07002192 default:
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002193 error(&@2, "unknown immediate type %d\n", $2);
Eric Anholt22a10632006-08-22 10:15:33 -07002194 }
Keith Packard2d4d4012008-03-30 00:58:28 -07002195 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002196 $$.reg.file = BRW_IMMEDIATE_VALUE;
2197 $$.reg.type = $2;
Damien Lespiau9c72beb2013-01-25 15:48:58 +00002198 $$.reg.dw1.ud = d;
Eric Anholt22a10632006-08-22 10:15:33 -07002199 }
2200;
2201
Eric Anholt5297b2a2006-08-25 16:50:17 -07002202directsrcaccoperand: directsrcoperand
Xiang, Haihao27b43032010-12-13 16:07:16 +08002203 | accreg region regtype
Eric Anholt2a0f1352006-08-25 17:44:55 -07002204 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002205 set_direct_src_operand(&$$, &$1, $3.type);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002206 $$.reg.vstride = $2.vert_stride;
2207 $$.reg.width = $2.width;
2208 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002209 $$.default_region = $2.is_default;
Eric Anholt2a0f1352006-08-25 17:44:55 -07002210 }
Eric Anholt2c787652006-08-25 13:53:48 -07002211;
2212
2213/* Returns a source operand in the src0 fields of an instruction. */
Eric Anholt5297b2a2006-08-25 16:50:17 -07002214srcarchoperandex: srcarchoperandex_typed region regtype
Eric Anholt2c787652006-08-25 13:53:48 -07002215 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002216 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002217 $$.reg.file = $1.file;
2218 $$.reg.type = $3.type;
2219 $$.reg.subnr = $1.subnr;
2220 $$.reg.nr = $1.nr;
2221 $$.reg.vstride = $2.vert_stride;
2222 $$.reg.width = $2.width;
2223 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002224 $$.default_region = $2.is_default;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002225 $$.reg.negate = 0;
2226 $$.reg.abs = 0;
Eric Anholt2c787652006-08-25 13:53:48 -07002227 }
2228 | maskstackreg
2229 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002230 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UB);
Eric Anholt2c787652006-08-25 13:53:48 -07002231 }
2232 | controlreg
2233 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002234 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002235 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002236/* | statereg
Eric Anholt2c787652006-08-25 13:53:48 -07002237 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002238 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002239 }*/
Eric Anholt2c787652006-08-25 13:53:48 -07002240 | notifyreg
2241 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002242 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002243 }
2244 | ipreg
2245 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002246 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -07002247 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002248 | nullreg region regtype
Eric Anholt2c787652006-08-25 13:53:48 -07002249 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002250 if ($3.is_default) {
2251 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
2252 } else {
2253 set_direct_src_operand(&$$, &$1, $3.type);
2254 }
2255 $$.default_region = 1;
Eric Anholt2c787652006-08-25 13:53:48 -07002256 }
2257;
2258
Eric Anholt5297b2a2006-08-25 16:50:17 -07002259srcarchoperandex_typed: flagreg | addrreg | maskreg
Eric Anholt22a10632006-08-22 10:15:33 -07002260;
2261
Xiang, Haihao128053f2012-06-29 16:47:10 +08002262sendleadreg: symbol_reg
2263 {
2264 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002265 $$.file = $1.reg.file;
2266 $$.nr = $1.reg.nr;
2267 $$.subnr = $1.reg.subnr;
Xiang, Haihao128053f2012-06-29 16:47:10 +08002268 }
2269 | directgenreg | directmsgreg
Xiang, Haihao0b5f7fa2011-08-11 15:35:14 +08002270;
2271
Eric Anholt2d298742006-08-30 09:57:20 -07002272src: directsrcoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -07002273;
2274
Xiang, Haihao27b43032010-12-13 16:07:16 +08002275directsrcoperand: negate abs symbol_reg region regtype
2276 {
2277 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002278 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2279 $$.reg.file = $3.reg.file;
2280 $$.reg.nr = $3.reg.nr;
2281 $$.reg.subnr = $3.reg.subnr;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002282 if ($5.is_default) {
Damien Lespiau2de8b402013-02-01 13:59:32 +00002283 $$.reg.type = $3.reg.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002284 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002285 $$.reg.type = $5.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002286 }
2287 if ($4.is_default) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002288 $$.reg.vstride = $3.src_region.vert_stride;
2289 $$.reg.width = $3.src_region.width;
2290 $$.reg.hstride = $3.src_region.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002291 } else {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002292 $$.reg.vstride = $4.vert_stride;
2293 $$.reg.width = $4.width;
2294 $$.reg.hstride = $4.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002295 }
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002296 $$.reg.negate = $1;
2297 $$.reg.abs = $2;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002298 }
2299 | statereg region regtype
2300 {
2301 if($2.is_default ==1 && $3.is_default == 1)
2302 {
2303 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
2304 }
2305 else{
2306 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002307 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2308 $$.reg.file = $1.file;
2309 $$.reg.nr = $1.nr;
2310 $$.reg.subnr = $1.subnr;
2311 $$.reg.vstride = $2.vert_stride;
2312 $$.reg.width = $2.width;
2313 $$.reg.hstride = $2.horiz_stride;
2314 $$.reg.type = $3.type;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002315 }
2316 }
Xiang, Haihao881afff2014-03-25 13:41:25 +08002317 | negate abs directgenreg region swizzle regtype
Eric Anholt22a10632006-08-22 10:15:33 -07002318 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002319 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002320 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2321 $$.reg.file = $3.file;
2322 $$.reg.nr = $3.nr;
2323 $$.reg.subnr = $3.subnr;
Xiang, Haihao881afff2014-03-25 13:41:25 +08002324 $$.reg.type = $6.type;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002325 $$.reg.vstride = $4.vert_stride;
2326 $$.reg.width = $4.width;
2327 $$.reg.hstride = $4.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002328 $$.default_region = $4.is_default;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002329 $$.reg.negate = $1;
2330 $$.reg.abs = $2;
Xiang, Haihao881afff2014-03-25 13:41:25 +08002331 $$.reg.dw1.bits.swizzle = $5.reg.dw1.bits.swizzle;
Eric Anholt22a10632006-08-22 10:15:33 -07002332 }
Eric Anholt5297b2a2006-08-25 16:50:17 -07002333 | srcarchoperandex
Eric Anholt22a10632006-08-22 10:15:33 -07002334;
2335
Eric Anholt2d298742006-08-30 09:57:20 -07002336indirectsrcoperand:
2337 negate abs indirectgenreg indirectregion regtype swizzle
2338 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002339 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002340 $$.reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
2341 $$.reg.file = $3.file;
2342 $$.reg.subnr = $3.subnr;
2343 $$.reg.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
2344 $$.reg.type = $5.type;
2345 $$.reg.vstride = $4.vert_stride;
2346 $$.reg.width = $4.width;
2347 $$.reg.hstride = $4.horiz_stride;
2348 $$.reg.negate = $1;
2349 $$.reg.abs = $2;
2350 $$.reg.dw1.bits.swizzle = $6.reg.dw1.bits.swizzle;
Eric Anholt2d298742006-08-30 09:57:20 -07002351 }
2352;
2353
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002354/* 1.4.4: Address Registers */
Damien Lespiau801b4eb2013-01-23 16:20:05 +00002355/* Returns a partially-completed struct brw_reg consisting of the address
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002356 * register fields for register-indirect access.
2357 */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002358addrparam: addrreg COMMA immaddroffset
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002359 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002360 if ($3 < -512 || $3 > 511)
2361 error(&@3, "Address immediate offset %d out of range\n", $3);
Keith Packard2d4d4012008-03-30 00:58:28 -07002362 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002363 $$.subnr = $1.subnr;
2364 $$.dw1.bits.indirect_offset = $3;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002365 }
2366 | addrreg
2367 {
2368 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002369 $$.subnr = $1.subnr;
2370 $$.dw1.bits.indirect_offset = 0;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002371 }
2372;
2373
2374/* The immaddroffset provides an immediate offset value added to the addresses
2375 * from the address register in register-indirect register access.
2376 */
marius vladbdad74d2016-05-16 13:39:10 +03002377immaddroffset: %empty /* empty */ { $$ = 0; }
Zou Nan hai5608d272009-10-20 14:51:04 +08002378 | exp
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002379;
2380
2381
Eric Anholtedc82a02006-08-25 17:42:05 -07002382/* 1.4.5: Register files and register numbers */
Zou Nan hai5608d272009-10-20 14:51:04 +08002383subregnum: DOT exp
Eric Anholt22a10632006-08-22 10:15:33 -07002384 {
2385 $$ = $2;
2386 }
marius vladbdad74d2016-05-16 13:39:10 +03002387 | %empty %prec SUBREGNUM
Eric Anholt22a10632006-08-22 10:15:33 -07002388 {
2389 /* Default to subreg 0 if unspecified. */
2390 $$ = 0;
2391 }
2392;
2393
Eric Anholt569990b2006-08-25 09:46:18 -07002394directgenreg: GENREG subregnum
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002395 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002396 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002397 $$.file = BRW_GENERAL_REGISTER_FILE;
2398 $$.nr = $1;
2399 $$.subnr = $2;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002400 }
Eric Anholtedc82a02006-08-25 17:42:05 -07002401;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002402
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002403indirectgenreg: GENREGFILE LSQUARE addrparam RSQUARE
2404 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002405 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002406 $$.file = BRW_GENERAL_REGISTER_FILE;
2407 $$.subnr = $3.subnr;
2408 $$.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002409 }
2410;
2411
Eric Anholt569990b2006-08-25 09:46:18 -07002412directmsgreg: MSGREG subregnum
Eric Anholt22a10632006-08-22 10:15:33 -07002413 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002414 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002415 $$.file = BRW_MESSAGE_REGISTER_FILE;
2416 $$.nr = $1;
2417 $$.subnr = $2;
Eric Anholt22a10632006-08-22 10:15:33 -07002418 }
2419;
2420
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002421indirectmsgreg: MSGREGFILE LSQUARE addrparam RSQUARE
2422 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002423 memset (&$$, '\0', sizeof ($$));
Damien Lespiau36f8f652013-01-23 16:17:28 +00002424 $$.file = BRW_MESSAGE_REGISTER_FILE;
2425 $$.subnr = $3.subnr;
2426 $$.dw1.bits.indirect_offset = $3.dw1.bits.indirect_offset;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002427 }
2428;
2429
Eric Anholt883408e2006-08-25 13:38:03 -07002430addrreg: ADDRESSREG subregnum
2431 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002432 if ($1 != 0)
2433 error(&@2, "address register number %d out of range", $1);
2434
Keith Packard2d4d4012008-03-30 00:58:28 -07002435 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002436 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2437 $$.nr = BRW_ARF_ADDRESS | $1;
2438 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002439 }
2440;
2441
Eric Anholt569990b2006-08-25 09:46:18 -07002442accreg: ACCREG subregnum
2443 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002444 if ($1 > 1)
2445 error(&@1, "accumulator register number %d out of range", $1);
Keith Packard2d4d4012008-03-30 00:58:28 -07002446 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002447 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2448 $$.nr = BRW_ARF_ACCUMULATOR | $1;
2449 $$.subnr = $2;
Eric Anholt569990b2006-08-25 09:46:18 -07002450 }
2451;
2452
Xiang, Haihaof3f6ba22012-07-17 13:46:59 +08002453flagreg: FLAGREG subregnum
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002454 {
Damien Lespiau8eb30d92013-01-27 11:23:38 +00002455 if ((!IS_GENp(7) && $1 > 0) ||
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002456 (IS_GENp(7) && $1 > 1)) {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002457 error(&@2, "flag register number %d out of range\n", $1);
Xiang, Haihaof3f6ba22012-07-17 13:46:59 +08002458 }
2459
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002460 if ($2 > 1)
2461 error(&@2, "flag subregister number %d out of range\n", $1);
Xiang, Haihaof3f6ba22012-07-17 13:46:59 +08002462
Keith Packard2d4d4012008-03-30 00:58:28 -07002463 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002464 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2465 $$.nr = BRW_ARF_FLAG | $1;
2466 $$.subnr = $2;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002467 }
2468;
2469
Eric Anholt883408e2006-08-25 13:38:03 -07002470maskreg: MASKREG subregnum
2471 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002472 if ($1 > 0)
2473 error(&@1, "mask register number %d out of range", $1);
2474
Keith Packard2d4d4012008-03-30 00:58:28 -07002475 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002476 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2477 $$.nr = BRW_ARF_MASK;
2478 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002479 }
2480 | mask_subreg
2481 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002482 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002483 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2484 $$.nr = BRW_ARF_MASK;
2485 $$.subnr = $1;
Eric Anholt883408e2006-08-25 13:38:03 -07002486 }
2487;
2488
2489mask_subreg: AMASK | IMASK | LMASK | CMASK
2490;
2491
2492maskstackreg: MASKSTACKREG subregnum
2493 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002494 if ($1 > 0)
2495 error(&@1, "mask stack register number %d out of range", $1);
Keith Packard2d4d4012008-03-30 00:58:28 -07002496 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002497 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2498 $$.nr = BRW_ARF_MASK_STACK;
2499 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002500 }
2501 | maskstack_subreg
2502 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002503 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002504 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2505 $$.nr = BRW_ARF_MASK_STACK;
2506 $$.subnr = $1;
Eric Anholt883408e2006-08-25 13:38:03 -07002507 }
2508;
2509
2510maskstack_subreg: IMS | LMS
2511;
2512
Keith Packard2d4d4012008-03-30 00:58:28 -07002513/*
Eric Anholt883408e2006-08-25 13:38:03 -07002514maskstackdepthreg: MASKSTACKDEPTHREG subregnum
2515 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002516 if ($1 > 0)
2517 error(&@1, "mask stack register number %d out of range", $1);
Keith Packard2d4d4012008-03-30 00:58:28 -07002518 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07002519 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2520 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
2521 $$.subreg_nr = $2;
2522 }
2523 | maskstackdepth_subreg
2524 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002525 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07002526 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2527 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
2528 $$.subreg_nr = $1;
2529 }
2530;
2531
2532maskstackdepth_subreg: IMSD | LMSD
2533;
Keith Packard2d4d4012008-03-30 00:58:28 -07002534 */
Eric Anholt883408e2006-08-25 13:38:03 -07002535
Xiang, Haihao27b43032010-12-13 16:07:16 +08002536notifyreg: NOTIFYREG regtype
Eric Anholt883408e2006-08-25 13:38:03 -07002537 {
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002538 int num_notifyreg = (IS_GENp(6)) ? 3 : 2;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002539
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002540 if ($1 > num_notifyreg)
2541 error(&@1, "notification register number %d out of range",
2542 $1);
2543
Keith Packard2d4d4012008-03-30 00:58:28 -07002544 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002545 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002546
Gwenole Beauchesne8aa95282012-10-22 16:13:51 -04002547 if (IS_GENp(6)) {
Damien Lespiaub33b8812013-01-23 16:06:49 +00002548 $$.nr = BRW_ARF_NOTIFICATION_COUNT;
2549 $$.subnr = $1;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002550 } else {
Damien Lespiaub33b8812013-01-23 16:06:49 +00002551 $$.nr = BRW_ARF_NOTIFICATION_COUNT | $1;
2552 $$.subnr = 0;
Xiang, Haihao852216d2011-02-16 15:26:24 +08002553 }
Eric Anholt883408e2006-08-25 13:38:03 -07002554 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002555/*
2556 | NOTIFYREG regtype
2557 {
2558 if ($1 > 1) {
2559 fprintf(stderr,
2560 "notification register number %d out of range",
2561 $1);
2562 YYERROR;
2563 }
2564 memset (&$$, '\0', sizeof ($$));
2565 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
2566 $$.reg_nr = BRW_ARF_NOTIFICATION_COUNT;
2567 $$.subreg_nr = 0;
2568 }
2569*/
Eric Anholt883408e2006-08-25 13:38:03 -07002570;
2571
2572statereg: STATEREG subregnum
2573 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002574 if ($1 > 0)
2575 error(&@1, "state register number %d out of range", $1);
2576
2577 if ($2 > 1)
2578 error(&@2, "state subregister number %d out of range", $1);
2579
Keith Packard2d4d4012008-03-30 00:58:28 -07002580 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002581 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2582 $$.nr = BRW_ARF_STATE | $1;
2583 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002584 }
2585;
2586
2587controlreg: CONTROLREG subregnum
2588 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002589 if ($1 > 0)
2590 error(&@1, "control register number %d out of range", $1);
2591
2592 if ($2 > 2)
2593 error(&@2, "control subregister number %d out of range", $1);
Keith Packard2d4d4012008-03-30 00:58:28 -07002594 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002595 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2596 $$.nr = BRW_ARF_CONTROL | $1;
2597 $$.subnr = $2;
Eric Anholt883408e2006-08-25 13:38:03 -07002598 }
2599;
2600
Xiang, Haihao27b43032010-12-13 16:07:16 +08002601ipreg: IPREG regtype
Eric Anholt883408e2006-08-25 13:38:03 -07002602 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002603 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002604 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2605 $$.nr = BRW_ARF_IP;
2606 $$.subnr = 0;
Eric Anholt883408e2006-08-25 13:38:03 -07002607 }
2608;
2609
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002610nullreg: NULL_TOKEN
2611 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002612 memset (&$$, '\0', sizeof ($$));
Damien Lespiaub33b8812013-01-23 16:06:49 +00002613 $$.file = BRW_ARCHITECTURE_REGISTER_FILE;
2614 $$.nr = BRW_ARF_NULL;
2615 $$.subnr = 0;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002616 }
Eric Anholt22a10632006-08-22 10:15:33 -07002617;
2618
Eric Anholt1e907c72006-08-31 10:21:15 -07002619/* 1.4.6: Relative locations */
Homer Hsingc0ebde22012-09-21 10:14:31 +08002620relativelocation:
Homer Hsing4bf84ec2012-09-24 10:12:26 +08002621 simple_int
Eric Anholt1e907c72006-08-31 10:21:15 -07002622 {
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002623 if (($1 > 32767) || ($1 < -32768))
2624 error(&@1, "error: relative offset %d out of range \n", $1);
Eric Anholt1e907c72006-08-31 10:21:15 -07002625
Keith Packard2d4d4012008-03-30 00:58:28 -07002626 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002627 $$.reg.file = BRW_IMMEDIATE_VALUE;
2628 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingc0ebde22012-09-21 10:14:31 +08002629 $$.imm32 = $1 & 0x0000ffff;
2630 }
2631 | STRING
2632 {
2633 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002634 $$.reg.file = BRW_IMMEDIATE_VALUE;
2635 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingc0ebde22012-09-21 10:14:31 +08002636 $$.reloc_target = $1;
Eric Anholt1e907c72006-08-31 10:21:15 -07002637 }
2638;
2639
2640relativelocation2:
Homer Hsingb0b540f2012-09-21 10:06:20 +08002641 STRING
Eric Anholt1e907c72006-08-31 10:21:15 -07002642 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002643 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002644 $$.reg.file = BRW_IMMEDIATE_VALUE;
2645 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingb0b540f2012-09-21 10:06:20 +08002646 $$.reloc_target = $1;
2647 }
2648 | exp
2649 {
2650 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002651 $$.reg.file = BRW_IMMEDIATE_VALUE;
2652 $$.reg.type = BRW_REGISTER_TYPE_D;
Homer Hsingb0b540f2012-09-21 10:06:20 +08002653 $$.imm32 = $1;
Eric Anholt1e907c72006-08-31 10:21:15 -07002654 }
2655 | directgenreg region regtype
2656 {
Xiang, Haihao27b43032010-12-13 16:07:16 +08002657 set_direct_src_operand(&$$, &$1, $3.type);
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002658 $$.reg.vstride = $2.vert_stride;
2659 $$.reg.width = $2.width;
2660 $$.reg.hstride = $2.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002661 $$.default_region = $2.is_default;
2662 }
2663 | symbol_reg_p
2664 {
2665 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002666 $$.reg.address_mode = BRW_ADDRESS_DIRECT;
2667 $$.reg.file = $1.reg.file;
2668 $$.reg.nr = $1.reg.nr;
2669 $$.reg.subnr = $1.reg.subnr;
Damien Lespiau2de8b402013-02-01 13:59:32 +00002670 $$.reg.type = $1.reg.type;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002671 $$.reg.vstride = $1.src_region.vert_stride;
2672 $$.reg.width = $1.src_region.width;
2673 $$.reg.hstride = $1.src_region.horiz_stride;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002674 }
2675 | indirectgenreg indirectregion regtype
2676 {
2677 memset (&$$, '\0', sizeof ($$));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002678 $$.reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
2679 $$.reg.file = $1.file;
2680 $$.reg.subnr = $1.subnr;
2681 $$.reg.dw1.bits.indirect_offset = $1.dw1.bits.indirect_offset;
2682 $$.reg.type = $3.type;
2683 $$.reg.vstride = $2.vert_stride;
2684 $$.reg.width = $2.width;
2685 $$.reg.hstride = $2.horiz_stride;
Eric Anholt1e907c72006-08-31 10:21:15 -07002686 }
2687;
2688
Eric Anholt22a10632006-08-22 10:15:33 -07002689/* 1.4.7: Regions */
marius vladbdad74d2016-05-16 13:39:10 +03002690dstregion: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002691 {
2692 $$ = DEFAULT_DSTREGION;
2693 }
2694 |LANGLE exp RANGLE
Eric Anholt22a10632006-08-22 10:15:33 -07002695 {
2696 /* Returns a value for a horiz_stride field of an
2697 * instruction.
2698 */
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002699 if ($2 != 1 && $2 != 2 && $2 != 4)
2700 error(&@2, "Invalid horiz size %d\n", $2);
2701
Eric Anholt0edcb252006-08-22 13:15:38 -07002702 $$ = ffs($2);
Eric Anholt22a10632006-08-22 10:15:33 -07002703 }
2704;
2705
marius vladbdad74d2016-05-16 13:39:10 +03002706region: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002707 {
2708 /* XXX is this default value correct?*/
2709 memset (&$$, '\0', sizeof ($$));
2710 $$.vert_stride = ffs(0);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00002711 $$.width = BRW_WIDTH_1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002712 $$.horiz_stride = ffs(0);
2713 $$.is_default = 1;
2714 }
2715 |LANGLE exp RANGLE
2716 {
2717 /* XXX is this default value correct for accreg?*/
2718 memset (&$$, '\0', sizeof ($$));
2719 $$.vert_stride = ffs($2);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00002720 $$.width = BRW_WIDTH_1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002721 $$.horiz_stride = ffs(0);
2722 }
2723 |LANGLE exp COMMA exp COMMA exp RANGLE
Eric Anholt22a10632006-08-22 10:15:33 -07002724 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002725 memset (&$$, '\0', sizeof ($$));
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002726 $$.vert_stride = ffs($2);
2727 $$.width = ffs($4) - 1;
Eric Anholtd4c82e82006-08-22 13:08:26 -07002728 $$.horiz_stride = ffs($6);
Eric Anholt22a10632006-08-22 10:15:33 -07002729 }
Zou Nan haic6f2da42009-10-28 10:14:19 +08002730 | LANGLE exp SEMICOLON exp COMMA exp RANGLE
2731 {
2732 memset (&$$, '\0', sizeof ($$));
2733 $$.vert_stride = ffs($2);
2734 $$.width = ffs($4) - 1;
2735 $$.horiz_stride = ffs($6);
2736 }
Eric Anholt22a10632006-08-22 10:15:33 -07002737
Xiang, Haihao27b43032010-12-13 16:07:16 +08002738;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002739/* region_wh is used in specifying indirect operands where rather than having
2740 * a vertical stride, you use subsequent address registers to get a new base
Eric Anholt2d298742006-08-30 09:57:20 -07002741 * offset for the next row.
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002742 */
Zou Nan hai5608d272009-10-20 14:51:04 +08002743region_wh: LANGLE exp COMMA exp RANGLE
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002744 {
Keith Packard2d4d4012008-03-30 00:58:28 -07002745 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002746 $$.vert_stride = BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL;
2747 $$.width = ffs($2) - 1;
2748 $$.horiz_stride = ffs($4);
2749 }
2750;
2751
Eric Anholt2d298742006-08-30 09:57:20 -07002752indirectregion: region | region_wh
2753;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07002754
Eric Anholt22a10632006-08-22 10:15:33 -07002755/* 1.4.8: Types */
2756
2757/* regtype returns an integer register type suitable for inserting into an
2758 * instruction.
2759 */
marius vladbdad74d2016-05-16 13:39:10 +03002760regtype: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002761 { $$.type = program_defaults.register_type;$$.is_default = 1;}
2762 | TYPE_F { $$.type = BRW_REGISTER_TYPE_F;$$.is_default = 0; }
2763 | TYPE_UD { $$.type = BRW_REGISTER_TYPE_UD;$$.is_default = 0; }
2764 | TYPE_D { $$.type = BRW_REGISTER_TYPE_D;$$.is_default = 0; }
2765 | TYPE_UW { $$.type = BRW_REGISTER_TYPE_UW;$$.is_default = 0; }
2766 | TYPE_W { $$.type = BRW_REGISTER_TYPE_W;$$.is_default = 0; }
2767 | TYPE_UB { $$.type = BRW_REGISTER_TYPE_UB;$$.is_default = 0; }
2768 | TYPE_B { $$.type = BRW_REGISTER_TYPE_B;$$.is_default = 0; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002769;
2770
marius vladbdad74d2016-05-16 13:39:10 +03002771srcimmtype: %empty /* empty */
Xiang, Haihao27b43032010-12-13 16:07:16 +08002772 {
2773 /* XXX change to default when pragma parse is done */
2774 $$ = BRW_REGISTER_TYPE_D;
2775 }
2776 |TYPE_F { $$ = BRW_REGISTER_TYPE_F; }
Keith Packard2d4d4012008-03-30 00:58:28 -07002777 | TYPE_UD { $$ = BRW_REGISTER_TYPE_UD; }
2778 | TYPE_D { $$ = BRW_REGISTER_TYPE_D; }
2779 | TYPE_UW { $$ = BRW_REGISTER_TYPE_UW; }
2780 | TYPE_W { $$ = BRW_REGISTER_TYPE_W; }
2781 | TYPE_V { $$ = BRW_REGISTER_TYPE_V; }
2782 | TYPE_VF { $$ = BRW_REGISTER_TYPE_VF; }
Eric Anholt22a10632006-08-22 10:15:33 -07002783;
2784
Eric Anholt6a88ada2006-08-28 22:11:18 -07002785/* 1.4.10: Swizzle control */
2786/* Returns the swizzle control for an align16 instruction's source operand
2787 * in the src0 fields.
2788 */
marius vladbdad74d2016-05-16 13:39:10 +03002789swizzle: %empty /* empty */
Eric Anholt6a88ada2006-08-28 22:11:18 -07002790 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002791 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE_NOOP;
Eric Anholt6a88ada2006-08-28 22:11:18 -07002792 }
2793 | DOT chansel
2794 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002795 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE4($2, $2, $2, $2);
Eric Anholt6a88ada2006-08-28 22:11:18 -07002796 }
2797 | DOT chansel chansel chansel chansel
2798 {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00002799 $$.reg.dw1.bits.swizzle = BRW_SWIZZLE4($2, $3, $4, $5);
Eric Anholt6a88ada2006-08-28 22:11:18 -07002800 }
2801;
2802
2803chansel: X | Y | Z | W
2804;
2805
Eric Anholt2dac0a12006-08-29 15:29:31 -07002806/* 1.4.9: Write mask */
Damien Lespiau03750732013-01-23 20:33:00 +00002807/* Returns a partially completed struct brw_reg, with just the writemask bits
Eric Anholt2dac0a12006-08-29 15:29:31 -07002808 * filled out.
2809 */
marius vladbdad74d2016-05-16 13:39:10 +03002810writemask: %empty /* empty */
Eric Anholt2dac0a12006-08-29 15:29:31 -07002811 {
Damien Lespiau03750732013-01-23 20:33:00 +00002812 $$.dw1.bits.writemask = BRW_WRITEMASK_XYZW;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002813 }
2814 | DOT writemask_x writemask_y writemask_z writemask_w
2815 {
Damien Lespiau03750732013-01-23 20:33:00 +00002816 $$.dw1.bits.writemask = $2 | $3 | $4 | $5;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002817 }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002818;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002819
marius vladbdad74d2016-05-16 13:39:10 +03002820writemask_x: %empty /* empty */ { $$ = 0; }
Eric Anholt2dac0a12006-08-29 15:29:31 -07002821 | X { $$ = 1 << BRW_CHANNEL_X; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002822;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002823
marius vladbdad74d2016-05-16 13:39:10 +03002824writemask_y: %empty /* empty */ { $$ = 0; }
Eric Anholt2dac0a12006-08-29 15:29:31 -07002825 | Y { $$ = 1 << BRW_CHANNEL_Y; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002826;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002827
marius vladbdad74d2016-05-16 13:39:10 +03002828writemask_z: %empty /* empty */ { $$ = 0; }
Eric Anholt2dac0a12006-08-29 15:29:31 -07002829 | Z { $$ = 1 << BRW_CHANNEL_Z; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002830;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002831
marius vladbdad74d2016-05-16 13:39:10 +03002832writemask_w: %empty /* empty */ { $$ = 0; }
Eric Anholt2dac0a12006-08-29 15:29:31 -07002833 | W { $$ = 1 << BRW_CHANNEL_W; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07002834;
Eric Anholt2dac0a12006-08-29 15:29:31 -07002835
Eric Anholtedc82a02006-08-25 17:42:05 -07002836/* 1.4.11: Immediate values */
Zou Nan hai5608d272009-10-20 14:51:04 +08002837imm32: exp { $$.r = imm32_d; $$.u.d = $1; }
Keith Packard2d4d4012008-03-30 00:58:28 -07002838 | NUMBER { $$.r = imm32_f; $$.u.f = $1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002839;
Eric Anholt22a10632006-08-22 10:15:33 -07002840
2841/* 1.4.12: Predication and modifiers */
marius vladbdad74d2016-05-16 13:39:10 +03002842predicate: %empty /* empty */
Eric Anholt0ed5d932006-08-28 23:05:51 -07002843 {
Damien Lespiaudfe6ada2013-01-30 22:32:07 +00002844 $$.pred_control = BRW_PREDICATE_NONE;
2845 $$.flag_reg_nr = 0;
2846 $$.flag_subreg_nr = 0;
2847 $$.pred_inverse = 0;
Eric Anholt0ed5d932006-08-28 23:05:51 -07002848 }
2849 | LPAREN predstate flagreg predctrl RPAREN
2850 {
Damien Lespiaudfe6ada2013-01-30 22:32:07 +00002851 $$.pred_control = $4;
Damien Lespiaudfe6ada2013-01-30 22:32:07 +00002852 $$.flag_reg_nr = $3.nr;
2853 $$.flag_subreg_nr = $3.subnr;
2854 $$.pred_inverse = $2;
Eric Anholt0ed5d932006-08-28 23:05:51 -07002855 }
2856;
2857
marius vladbdad74d2016-05-16 13:39:10 +03002858predstate: %empty /* empty */ { $$ = 0; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07002859 | PLUS { $$ = 0; }
2860 | MINUS { $$ = 1; }
2861;
2862
marius vladbdad74d2016-05-16 13:39:10 +03002863predctrl: %empty /* empty */ { $$ = BRW_PREDICATE_NORMAL; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07002864 | DOT X { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_X; }
2865 | DOT Y { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Y; }
2866 | DOT Z { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Z; }
2867 | DOT W { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_W; }
Keith Packard2033aea2008-04-23 23:10:40 -07002868 | ANYV { $$ = BRW_PREDICATE_ALIGN1_ANYV; }
2869 | ALLV { $$ = BRW_PREDICATE_ALIGN1_ALLV; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07002870 | ANY2H { $$ = BRW_PREDICATE_ALIGN1_ANY2H; }
2871 | ALL2H { $$ = BRW_PREDICATE_ALIGN1_ALL2H; }
2872 | ANY4H { $$ = BRW_PREDICATE_ALIGN1_ANY4H; }
2873 | ALL4H { $$ = BRW_PREDICATE_ALIGN1_ALL4H; }
2874 | ANY8H { $$ = BRW_PREDICATE_ALIGN1_ANY8H; }
2875 | ALL8H { $$ = BRW_PREDICATE_ALIGN1_ALL8H; }
2876 | ANY16H { $$ = BRW_PREDICATE_ALIGN1_ANY16H; }
2877 | ALL16H { $$ = BRW_PREDICATE_ALIGN1_ALL16H; }
Eric Anholtdc96c562006-08-22 14:42:45 -07002878;
2879
marius vladbdad74d2016-05-16 13:39:10 +03002880negate: %empty /* empty */ { $$ = 0; }
Eric Anholtdc96c562006-08-22 14:42:45 -07002881 | MINUS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002882;
Eric Anholtdc96c562006-08-22 14:42:45 -07002883
marius vladbdad74d2016-05-16 13:39:10 +03002884abs: %empty /* empty */ { $$ = 0; }
Eric Anholtdc96c562006-08-22 14:42:45 -07002885 | ABS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07002886;
Eric Anholt22a10632006-08-22 10:15:33 -07002887
marius vladbdad74d2016-05-16 13:39:10 +03002888execsize: %empty /* empty */ %prec EMPTEXECSIZE
Xiang, Haihao27b43032010-12-13 16:07:16 +08002889 {
2890 $$ = ffs(program_defaults.execute_size) - 1;
2891 }
2892 |LPAREN exp RPAREN
Eric Anholt22a10632006-08-22 10:15:33 -07002893 {
2894 /* Returns a value for the execution_size field of an
2895 * instruction.
2896 */
2897 if ($2 != 1 && $2 != 2 && $2 != 4 && $2 != 8 && $2 != 16 &&
Damien Lespiau6d3d3692013-01-27 10:41:23 +00002898 $2 != 32)
2899 error(&@2, "Invalid execution size %d\n", $2);
2900
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002901 $$ = ffs($2) - 1;
Eric Anholt22a10632006-08-22 10:15:33 -07002902 }
2903;
2904
marius vladbdad74d2016-05-16 13:39:10 +03002905saturate: %empty /* empty */ { $$ = BRW_INSTRUCTION_NORMAL; }
Xiang, Haihao27b43032010-12-13 16:07:16 +08002906 | SATURATE { $$ = BRW_INSTRUCTION_SATURATE; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002907;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002908conditionalmodifier: condition
2909 {
2910 $$.cond = $1;
Xiang, Haihao3ffbe962012-07-17 15:05:31 +08002911 $$.flag_reg_nr = 0;
Xiang, Haihao2f772dd2012-07-17 14:18:54 +08002912 $$.flag_subreg_nr = -1;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002913 }
2914 | condition DOT flagreg
2915 {
2916 $$.cond = $1;
Damien Lespiaub33b8812013-01-23 16:06:49 +00002917 $$.flag_reg_nr = ($3.nr & 0xF);
2918 $$.flag_subreg_nr = $3.subnr;
Xiang, Haihao27b43032010-12-13 16:07:16 +08002919 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002920
marius vladbdad74d2016-05-16 13:39:10 +03002921condition: %empty /* empty */ { $$ = BRW_CONDITIONAL_NONE; }
Keith Packard2033aea2008-04-23 23:10:40 -07002922 | ZERO
2923 | EQUAL
2924 | NOT_ZERO
2925 | NOT_EQUAL
2926 | GREATER
2927 | GREATER_EQUAL
2928 | LESS
2929 | LESS_EQUAL
2930 | ROUND_INCREMENT
2931 | OVERFLOW
2932 | UNORDERED
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002933;
2934
Eric Anholt22a10632006-08-22 10:15:33 -07002935/* 1.4.13: Instruction options */
marius vladbdad74d2016-05-16 13:39:10 +03002936instoptions: %empty /* empty */
Zou Nan haic6f2da42009-10-28 10:14:19 +08002937 { memset(&$$, 0, sizeof($$)); }
2938 | LCURLY instoption_list RCURLY
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002939 { $$ = $2; }
2940;
2941
Homer Hsing5d589db2012-09-21 12:35:35 +08002942instoption_list:instoption_list COMMA instoption
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002943 {
Homer Hsing5d589db2012-09-21 12:35:35 +08002944 $$ = $1;
Damien Lespiaubca2ff22013-01-30 23:00:26 +00002945 add_option(&$$, $3);
Xiang, Haihao27b43032010-12-13 16:07:16 +08002946 }
Homer Hsing5d589db2012-09-21 12:35:35 +08002947 | instoption_list instoption
Xiang, Haihao27b43032010-12-13 16:07:16 +08002948 {
Homer Hsing5d589db2012-09-21 12:35:35 +08002949 $$ = $1;
Damien Lespiaubca2ff22013-01-30 23:00:26 +00002950 add_option(&$$, $2);
Eric Anholt19f1c1c2006-08-22 12:41:09 -07002951 }
marius vladbdad74d2016-05-16 13:39:10 +03002952 | %empty /* empty, header defaults to zeroes. */
Eric Anholte609d6b2006-08-24 12:36:56 -07002953 {
Homer Hsing81859af2012-09-14 09:34:58 +08002954 memset(&$$, 0, sizeof($$));
Eric Anholte609d6b2006-08-24 12:36:56 -07002955 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002956;
Eric Anholt22a10632006-08-22 10:15:33 -07002957
Eric Anholt16324212006-08-24 14:47:21 -07002958instoption: ALIGN1 { $$ = ALIGN1; }
2959 | ALIGN16 { $$ = ALIGN16; }
Eric Anholt908f37d2006-08-25 17:33:02 -07002960 | SECHALF { $$ = SECHALF; }
2961 | COMPR { $$ = COMPR; }
2962 | SWITCH { $$ = SWITCH; }
2963 | ATOMIC { $$ = ATOMIC; }
2964 | NODDCHK { $$ = NODDCHK; }
2965 | NODDCLR { $$ = NODDCLR; }
Eric Anholt16324212006-08-24 14:47:21 -07002966 | MASK_DISABLE { $$ = MASK_DISABLE; }
Eric Anholt908f37d2006-08-25 17:33:02 -07002967 | BREAKPOINT { $$ = BREAKPOINT; }
Xiang, Haihao55d81c42010-10-08 13:53:22 +08002968 | ACCWRCTRL { $$ = ACCWRCTRL; }
Eric Anholt16324212006-08-24 14:47:21 -07002969 | EOT { $$ = EOT; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07002970;
Eric Anholt22a10632006-08-22 10:15:33 -07002971
2972%%
2973extern int yylineno;
2974
2975void yyerror (char *msg)
2976{
Keith Packard2d4d4012008-03-30 00:58:28 -07002977 fprintf(stderr, "%s: %d: %s at \"%s\"\n",
2978 input_filename, yylineno, msg, lex_text());
2979 ++errors;
Eric Anholt22a10632006-08-22 10:15:33 -07002980}
2981
Damien Lespiauf0365d42013-02-04 12:02:18 +00002982static int get_type_size(unsigned type)
Xiang, Haihao27b43032010-12-13 16:07:16 +08002983{
2984 int size = 1;
2985
2986 switch (type) {
2987 case BRW_REGISTER_TYPE_F:
2988 case BRW_REGISTER_TYPE_UD:
2989 case BRW_REGISTER_TYPE_D:
2990 size = 4;
2991 break;
2992
2993 case BRW_REGISTER_TYPE_UW:
2994 case BRW_REGISTER_TYPE_W:
2995 size = 2;
2996 break;
2997
2998 case BRW_REGISTER_TYPE_UB:
2999 case BRW_REGISTER_TYPE_B:
3000 size = 1;
3001 break;
3002
3003 default:
3004 assert(0);
3005 size = 1;
3006 break;
3007 }
3008
3009 return size;
3010}
3011
Xiang, Haihao27b43032010-12-13 16:07:16 +08003012static void reset_instruction_src_region(struct brw_instruction *instr,
3013 struct src_operand *src)
3014{
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003015 if (IS_GENp(8))
3016 return;
3017
Xiang, Haihao27b43032010-12-13 16:07:16 +08003018 if (!src->default_region)
3019 return;
3020
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003021 if (src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
3022 ((src->reg.nr & 0xF0) == BRW_ARF_ADDRESS)) {
3023 src->reg.vstride = ffs(0);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00003024 src->reg.width = BRW_WIDTH_1;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003025 src->reg.hstride = ffs(0);
3026 } else if (src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
3027 ((src->reg.nr & 0xF0) == BRW_ARF_ACCUMULATOR)) {
Xiang, Haihao27b43032010-12-13 16:07:16 +08003028 int horiz_stride = 1, width, vert_stride;
3029 if (instr->header.compression_control == BRW_COMPRESSION_COMPRESSED) {
3030 width = 16;
3031 } else {
3032 width = 8;
3033 }
3034
3035 if (width > (1 << instr->header.execution_size))
3036 width = (1 << instr->header.execution_size);
3037
3038 vert_stride = horiz_stride * width;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003039 src->reg.vstride = ffs(vert_stride);
3040 src->reg.width = ffs(width) - 1;
3041 src->reg.hstride = ffs(horiz_stride);
3042 } else if ((src->reg.file == BRW_ARCHITECTURE_REGISTER_FILE) &&
3043 (src->reg.nr == BRW_ARF_NULL) &&
Xiang, Haihao27b43032010-12-13 16:07:16 +08003044 (instr->header.opcode == BRW_OPCODE_SEND)) {
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003045 src->reg.vstride = ffs(8);
Damien Lespiau2f502bc2013-02-01 14:09:41 +00003046 src->reg.width = BRW_WIDTH_8;
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003047 src->reg.hstride = ffs(1);
Xiang, Haihao27b43032010-12-13 16:07:16 +08003048 } else {
3049
3050 int horiz_stride = 1, width, vert_stride;
3051
3052 if (instr->header.execution_size == 0) { /* scalar */
3053 horiz_stride = 0;
3054 width = 1;
3055 vert_stride = 0;
3056 } else {
3057 if ((instr->header.opcode == BRW_OPCODE_MUL) ||
3058 (instr->header.opcode == BRW_OPCODE_MAC) ||
3059 (instr->header.opcode == BRW_OPCODE_CMP) ||
3060 (instr->header.opcode == BRW_OPCODE_ASR) ||
3061 (instr->header.opcode == BRW_OPCODE_ADD) ||
3062 (instr->header.opcode == BRW_OPCODE_SHL)) {
3063 horiz_stride = 0;
3064 width = 1;
3065 vert_stride = 0;
3066 } else {
3067 width = (1 << instr->header.execution_size) / horiz_stride;
3068 vert_stride = horiz_stride * width;
Xiang, Haihaoe7f4dc62011-03-01 16:43:02 +08003069
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003070 if (get_type_size(src->reg.type) * (width + src->reg.subnr) > 32) {
Xiang, Haihaoe7f4dc62011-03-01 16:43:02 +08003071 horiz_stride = 0;
3072 width = 1;
3073 vert_stride = 0;
3074 }
Xiang, Haihao27b43032010-12-13 16:07:16 +08003075 }
3076 }
3077
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003078 src->reg.vstride = ffs(vert_stride);
3079 src->reg.width = ffs(width) - 1;
3080 src->reg.hstride = ffs(horiz_stride);
Xiang, Haihao27b43032010-12-13 16:07:16 +08003081 }
3082}
3083
Damien Lespiau5d526c82013-01-30 23:39:09 +00003084static void set_instruction_opcode(struct brw_program_instruction *instr,
3085 unsigned opcode)
3086{
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003087 if (IS_GENp(8))
3088 gen8_set_opcode(GEN8(instr), opcode);
3089 else
3090 GEN(instr)->header.opcode = opcode;
Damien Lespiau5d526c82013-01-30 23:39:09 +00003091}
3092
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003093/**
3094 * Fills in the destination register information in instr from the bits in dst.
3095 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00003096static int set_instruction_dest(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003097 struct brw_reg *dest)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003098{
Damien Lespiau42d8d572013-01-31 01:55:48 +00003099 if (!validate_dst_reg(instr, dest))
Damien Lespiau5e0da9f2013-01-24 12:21:13 +00003100 return 1;
3101
Damien Lespiau9fcc1bd2013-01-24 16:16:35 +00003102 /* the assembler support expressing subnr in bytes or in number of
3103 * elements. */
3104 resolve_subnr(dest);
3105
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003106 if (IS_GENp(8)) {
3107 gen8_set_exec_size(GEN8(instr), dest->width);
3108 gen8_set_dst(GEN8(instr), *dest);
3109 } else {
3110 brw_set_dest(&genasm_compile, GEN(instr), *dest);
3111 }
Eric Anholt2dac0a12006-08-29 15:29:31 -07003112
3113 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003114}
3115
Eric Anholt6a88ada2006-08-28 22:11:18 -07003116/* Sets the first source operand for the instruction. Returns 0 on success. */
Damien Lespiauf6e90522013-01-30 17:04:13 +00003117static int set_instruction_src0(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003118 struct src_operand *src,
3119 YYLTYPE *location)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003120{
Damien Lespiaue7cca1a2013-01-27 02:06:22 +00003121
Damien Lespiauc0592b22013-01-24 18:32:20 +00003122 if (advanced_flag)
Damien Lespiauf6e90522013-01-30 17:04:13 +00003123 reset_instruction_src_region(GEN(instr), src);
Damien Lespiauc0592b22013-01-24 18:32:20 +00003124
Damien Lespiau42d8d572013-01-31 01:55:48 +00003125 if (!validate_src_reg(instr, src->reg, location))
Damien Lespiauc0592b22013-01-24 18:32:20 +00003126 return 1;
3127
Damien Lespiaue7cca1a2013-01-27 02:06:22 +00003128 /* the assembler support expressing subnr in bytes or in number of
3129 * elements. */
3130 resolve_subnr(&src->reg);
3131
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003132 if (IS_GENp(8))
3133 gen8_set_src0(GEN8(instr), src->reg);
3134 else
3135 brw_set_src0(&genasm_compile, GEN(instr), src->reg);
Eric Anholt6a88ada2006-08-28 22:11:18 -07003136
3137 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003138}
3139
Eric Anholt6a88ada2006-08-28 22:11:18 -07003140/* Sets the second source operand for the instruction. Returns 0 on success.
3141 */
Damien Lespiauf6e90522013-01-30 17:04:13 +00003142static int set_instruction_src1(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003143 struct src_operand *src,
3144 YYLTYPE *location)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003145{
Damien Lespiauc0592b22013-01-24 18:32:20 +00003146 if (advanced_flag)
Damien Lespiauf6e90522013-01-30 17:04:13 +00003147 reset_instruction_src_region(GEN(instr), src);
Damien Lespiauc0592b22013-01-24 18:32:20 +00003148
Damien Lespiau42d8d572013-01-31 01:55:48 +00003149 if (!validate_src_reg(instr, src->reg, location))
Damien Lespiauc0592b22013-01-24 18:32:20 +00003150 return 1;
3151
Damien Lespiau888b2dc2013-01-28 15:29:26 +00003152 /* the assembler support expressing subnr in bytes or in number of
3153 * elements. */
3154 resolve_subnr(&src->reg);
3155
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003156 if (IS_GENp(8))
3157 gen8_set_src1(GEN8(instr), src->reg);
3158 else
3159 brw_set_src1(&genasm_compile, GEN(instr), src->reg);
Eric Anholt6a88ada2006-08-28 22:11:18 -07003160
3161 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003162}
3163
Damien Lespiauf6e90522013-01-30 17:04:13 +00003164static int set_instruction_dest_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003165 struct brw_reg *dest)
Homer Hsinga034bcb2012-09-07 14:38:13 +08003166{
Damien Lespiau26da3752013-01-31 01:28:15 +00003167 resolve_subnr(dest);
3168 brw_set_3src_dest(&genasm_compile, GEN(instr), *dest);
3169 return 0;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003170}
3171
Damien Lespiauf6e90522013-01-30 17:04:13 +00003172static int set_instruction_src0_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003173 struct src_operand *src)
Homer Hsinga034bcb2012-09-07 14:38:13 +08003174{
Damien Lespiau26da3752013-01-31 01:28:15 +00003175 if (advanced_flag)
3176 reset_instruction_src_region(GEN(instr), src);
3177
3178 resolve_subnr(&src->reg);
3179
3180 // TODO: src0 modifier, src0 rep_ctrl
3181 brw_set_3src_src0(&genasm_compile, GEN(instr), src->reg);
3182 return 0;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003183}
3184
Damien Lespiauf6e90522013-01-30 17:04:13 +00003185static int set_instruction_src1_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003186 struct src_operand *src)
Homer Hsinga034bcb2012-09-07 14:38:13 +08003187{
Damien Lespiau26da3752013-01-31 01:28:15 +00003188 if (advanced_flag)
3189 reset_instruction_src_region(GEN(instr), src);
3190
3191 resolve_subnr(&src->reg);
3192
3193 // TODO: src1 modifier, src1 rep_ctrl
3194 brw_set_3src_src1(&genasm_compile, GEN(instr), src->reg);
3195 return 0;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003196}
3197
Damien Lespiauf6e90522013-01-30 17:04:13 +00003198static int set_instruction_src2_three_src(struct brw_program_instruction *instr,
Damien Lespiau1d53e182013-01-27 11:05:50 +00003199 struct src_operand *src)
Homer Hsinga034bcb2012-09-07 14:38:13 +08003200{
Damien Lespiau26da3752013-01-31 01:28:15 +00003201 if (advanced_flag)
3202 reset_instruction_src_region(GEN(instr), src);
3203
3204 resolve_subnr(&src->reg);
3205
3206 // TODO: src2 modifier, src2 rep_ctrl
3207 brw_set_3src_src2(&genasm_compile, GEN(instr), src->reg);
3208 return 0;
Homer Hsinga034bcb2012-09-07 14:38:13 +08003209}
3210
Damien Lespiau49861a02013-01-31 00:26:51 +00003211static void set_instruction_saturate(struct brw_program_instruction *instr,
3212 int saturate)
3213{
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003214 if (IS_GENp(8))
3215 gen8_set_saturate(GEN8(instr), saturate);
3216 else
3217 GEN(instr)->header.saturate = saturate;
Damien Lespiau49861a02013-01-31 00:26:51 +00003218}
3219
Damien Lespiauf6e90522013-01-30 17:04:13 +00003220static void set_instruction_options(struct brw_program_instruction *instr,
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00003221 struct options options)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003222{
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003223 if (IS_GENp(8)) {
3224 gen8_set_access_mode(GEN8(instr), options.access_mode);
3225 gen8_set_thread_control(GEN8(instr), options.thread_control);
3226 gen8_set_dep_control(GEN8(instr), options.dependency_control);
3227 gen8_set_mask_control(GEN8(instr), options.mask_control);
3228 gen8_set_debug_control(GEN8(instr), options.debug_control);
3229 gen8_set_acc_wr_control(GEN8(instr), options.acc_wr_control);
3230 gen8_set_eot(GEN8(instr), options.end_of_thread);
3231 } else {
Damien Lespiau6bf3aa82013-01-30 23:25:19 +00003232 GEN(instr)->header.access_mode = options.access_mode;
3233 GEN(instr)->header.compression_control = options.compression_control;
3234 GEN(instr)->header.thread_control = options.thread_control;
3235 GEN(instr)->header.dependency_control = options.dependency_control;
3236 GEN(instr)->header.mask_control = options.mask_control;
3237 GEN(instr)->header.debug_control = options.debug_control;
3238 GEN(instr)->header.acc_wr_control = options.acc_wr_control;
3239 GEN(instr)->bits3.generic.end_of_thread = options.end_of_thread;
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003240 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07003241}
Eric Anholt2c787652006-08-25 13:53:48 -07003242
Damien Lespiauf6e90522013-01-30 17:04:13 +00003243static void set_instruction_predicate(struct brw_program_instruction *instr,
Damien Lespiaudfe6ada2013-01-30 22:32:07 +00003244 struct predicate *p)
Eric Anholt0ed5d932006-08-28 23:05:51 -07003245{
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003246 if (IS_GENp(8)) {
3247 gen8_set_pred_control(GEN8(instr), p->pred_control);
3248 gen8_set_pred_inv(GEN8(instr), p->pred_inverse);
3249 gen8_set_flag_reg_nr(GEN8(instr), p->flag_reg_nr);
3250 gen8_set_flag_subreg_nr(GEN8(instr), p->flag_subreg_nr);
3251 } else {
Damien Lespiaudfe6ada2013-01-30 22:32:07 +00003252 GEN(instr)->header.predicate_control = p->pred_control;
3253 GEN(instr)->header.predicate_inverse = p->pred_inverse;
3254 GEN(instr)->bits2.da1.flag_reg_nr = p->flag_reg_nr;
3255 GEN(instr)->bits2.da1.flag_subreg_nr = p->flag_subreg_nr;
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003256 }
Eric Anholt0ed5d932006-08-28 23:05:51 -07003257}
3258
Damien Lespiaub21c2e62013-01-31 00:18:47 +00003259static void set_instruction_pred_cond(struct brw_program_instruction *instr,
3260 struct predicate *p,
3261 struct condition *c,
3262 YYLTYPE *location)
3263{
3264 set_instruction_predicate(instr, p);
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003265
3266 if (IS_GENp(8))
3267 gen8_set_cond_modifier(GEN8(instr), c->cond);
3268 else
3269 GEN(instr)->header.destreg__conditionalmod = c->cond;
Damien Lespiaub21c2e62013-01-31 00:18:47 +00003270
3271 if (c->flag_subreg_nr == -1)
3272 return;
3273
3274 if (p->pred_control != BRW_PREDICATE_NONE &&
3275 (p->flag_reg_nr != c->flag_reg_nr ||
3276 p->flag_subreg_nr != c->flag_subreg_nr))
3277 {
3278 warn(ALWAYS, location, "must use the same flag register if both "
3279 "prediction and conditional modifier are enabled\n");
3280 }
3281
Damien Lespiauaf4d37d2013-01-31 02:16:08 +00003282 if (IS_GENp(8)) {
3283 gen8_set_flag_reg_nr(GEN8(instr), c->flag_reg_nr);
3284 gen8_set_flag_subreg_nr(GEN8(instr), c->flag_subreg_nr);
3285 } else {
3286 GEN(instr)->bits2.da1.flag_reg_nr = c->flag_reg_nr;
3287 GEN(instr)->bits2.da1.flag_subreg_nr = c->flag_subreg_nr;
3288 }
Damien Lespiaub21c2e62013-01-31 00:18:47 +00003289}
3290
Damien Lespiau1d53e182013-01-27 11:05:50 +00003291static void set_direct_dst_operand(struct brw_reg *dst, struct brw_reg *reg,
3292 int type)
Eric Anholt1e907c72006-08-31 10:21:15 -07003293{
Damien Lespiau03750732013-01-23 20:33:00 +00003294 *dst = *reg;
Eric Anholt1e907c72006-08-31 10:21:15 -07003295 dst->address_mode = BRW_ADDRESS_DIRECT;
Damien Lespiau03750732013-01-23 20:33:00 +00003296 dst->type = type;
3297 dst->hstride = 1;
3298 dst->dw1.bits.writemask = BRW_WRITEMASK_XYZW;
Eric Anholt1e907c72006-08-31 10:21:15 -07003299}
3300
Damien Lespiau1d53e182013-01-27 11:05:50 +00003301static void set_direct_src_operand(struct src_operand *src, struct brw_reg *reg,
3302 int type)
Eric Anholt2c787652006-08-25 13:53:48 -07003303{
Homer Hsing81859af2012-09-14 09:34:58 +08003304 memset(src, 0, sizeof(*src));
Damien Lespiau9d5a87a2013-01-23 22:29:23 +00003305 src->reg.address_mode = BRW_ADDRESS_DIRECT;
3306 src->reg.file = reg->file;
3307 src->reg.type = type;
3308 src->reg.subnr = reg->subnr;
3309 src->reg.nr = reg->nr;
3310 src->reg.vstride = 0;
3311 src->reg.width = 0;
3312 src->reg.hstride = 0;
3313 src->reg.negate = 0;
3314 src->reg.abs = 0;
3315 SWIZZLE(src->reg) = BRW_SWIZZLE_NOOP;
Eric Anholt2c787652006-08-25 13:53:48 -07003316}
Xiang, Haihao216163b2013-02-22 11:14:06 +08003317
3318static inline int instruction_opcode(struct brw_program_instruction *insn)
3319{
3320 if (IS_GENp(8))
3321 return gen8_opcode(GEN8(insn));
3322 else
3323 return GEN(insn)->header.opcode;
3324}
3325
3326/*
3327 * return the offset used in native flow control (branch) instructions
3328 */
3329static inline int branch_offset(struct brw_program_instruction *insn, int offset)
3330{
3331 /*
3332 * bspec: Unlike other flow control instructions, the offset used by JMPI
3333 * is relative to the incremented instruction pointer rather than the IP
3334 * value for the instruction itself.
3335 */
3336 if (instruction_opcode(insn) == BRW_OPCODE_JMPI)
3337 offset--;
3338
3339 /*
3340 * Gen4- bspec: the jump distance is in number of sixteen-byte units
3341 * Gen5+ bspec: the jump distance is in number of eight-byte units
3342 * Gen7.5+: the offset is in unit of 8bits for JMPI, 64bits for other flow
3343 * control instructions
3344 */
3345 if (gen_level >= 75 &&
3346 (instruction_opcode(insn) == BRW_OPCODE_JMPI))
3347 offset *= 16;
3348 else if (gen_level >= 50)
3349 offset *= 2;
3350
3351 return offset;
3352}
3353
3354void set_branch_two_offsets(struct brw_program_instruction *insn, int jip_offset, int uip_offset)
3355{
3356 int jip = branch_offset(insn, jip_offset);
3357 int uip = branch_offset(insn, uip_offset);
3358
3359 assert(instruction_opcode(insn) != BRW_OPCODE_JMPI);
3360
3361 if (IS_GENp(8)) {
3362 gen8_set_jip(GEN8(insn), jip);
3363 gen8_set_uip(GEN8(insn), uip);
3364 } else {
3365 GEN(insn)->bits3.break_cont.jip = jip;
3366 GEN(insn)->bits3.break_cont.uip = uip;
3367 }
3368}
3369
3370void set_branch_one_offset(struct brw_program_instruction *insn, int jip_offset)
3371{
3372 int jip = branch_offset(insn, jip_offset);
3373
3374 if (IS_GENp(8)) {
3375 gen8_set_jip(GEN8(insn), jip);
3376 } else if (IS_GENx(7)) {
3377 /* Gen7 JMPI Restrictions in bspec:
3378 * The JIP data type must be Signed DWord
3379 */
3380 if (instruction_opcode(insn) == BRW_OPCODE_JMPI)
3381 GEN(insn)->bits3.JIP = jip;
3382 else
3383 GEN(insn)->bits3.break_cont.jip = jip;
3384 } else if (IS_GENx(6)) {
3385 if ((instruction_opcode(insn) == BRW_OPCODE_CALL) ||
3386 (instruction_opcode(insn) == BRW_OPCODE_JMPI))
3387 GEN(insn)->bits3.JIP = jip;
3388 else
3389 GEN(insn)->bits1.branch_gen6.jump_count = jip; // for CASE,ELSE,FORK,IF,WHILE
3390 } else {
3391 GEN(insn)->bits3.JIP = jip;
3392
3393 if (instruction_opcode(insn) == BRW_OPCODE_ELSE)
3394 GEN(insn)->bits3.break_cont.uip = 1; // Set the istack pop count, which must always be 1.
3395 }
3396}