blob: 74a97233574ed4225d1c0a8eb61f6065df4cb239 [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>
Eric Anholt22a10632006-08-22 10:15:33 -070032#include "gen4asm.h"
33#include "brw_defines.h"
34
Xiang Haihao549b7512009-06-30 10:02:33 +080035extern long int gen_level;
36
Eric Anholtc8939ed2006-08-30 10:50:56 -070037int set_instruction_dest(struct brw_instruction *instr,
38 struct dst_operand *dest);
Keith Packard2d4d4012008-03-30 00:58:28 -070039int set_instruction_src0(struct brw_instruction *instr,
Eric Anholtc8939ed2006-08-30 10:50:56 -070040 struct src_operand *src);
41int set_instruction_src1(struct brw_instruction *instr,
42 struct src_operand *src);
43void set_instruction_options(struct brw_instruction *instr,
44 struct brw_instruction *options);
45void set_instruction_predicate(struct brw_instruction *instr,
46 struct brw_instruction *predicate);
47void set_instruction_predicate(struct brw_instruction *instr,
48 struct brw_instruction *predicate);
Eric Anholt1e907c72006-08-31 10:21:15 -070049void set_direct_dst_operand(struct dst_operand *dst, struct direct_reg *reg,
50 int type);
Eric Anholtc8939ed2006-08-30 10:50:56 -070051void set_direct_src_operand(struct src_operand *src, struct direct_reg *reg,
52 int type);
53
Eric Anholt22a10632006-08-22 10:15:33 -070054%}
55
56%start ROOT
57
58%union {
Zou Nanhaibe9bcee2008-12-09 18:38:54 -080059 char *string;
Eric Anholt22a10632006-08-22 10:15:33 -070060 int integer;
61 double number;
62 struct brw_instruction instruction;
63 struct brw_program program;
64 struct region {
65 int vert_stride, width, horiz_stride;
66 } region;
Eric Anholt74c81af2006-08-30 11:10:45 -070067 struct direct_reg direct_reg;
68 struct indirect_reg indirect_reg;
Eric Anholt3bcf6b22006-08-29 18:31:34 -070069
Keith Packard2d4d4012008-03-30 00:58:28 -070070 imm32_t imm32;
Eric Anholt6a88ada2006-08-28 22:11:18 -070071
Eric Anholt2dac0a12006-08-29 15:29:31 -070072 struct dst_operand dst_operand;
Eric Anholt6a88ada2006-08-28 22:11:18 -070073 struct src_operand src_operand;
Eric Anholt22a10632006-08-22 10:15:33 -070074}
75
Zou Nanhaibe9bcee2008-12-09 18:38:54 -080076%token COLON
Eric Anholt22a10632006-08-22 10:15:33 -070077%token SEMICOLON
78%token LPAREN RPAREN
79%token LANGLE RANGLE
80%token LCURLY RCURLY
Eric Anholt3bcf6b22006-08-29 18:31:34 -070081%token LSQUARE RSQUARE
Eric Anholt22a10632006-08-22 10:15:33 -070082%token COMMA
83%token DOT
Eric Anholt0ed5d932006-08-28 23:05:51 -070084%token PLUS MINUS ABS
Eric Anholt22a10632006-08-22 10:15:33 -070085
Eric Anholtc8939ed2006-08-30 10:50:56 -070086%token <integer> TYPE_UD TYPE_D TYPE_UW TYPE_W TYPE_UB TYPE_B
87%token <integer> TYPE_VF TYPE_HF TYPE_V TYPE_F
Eric Anholt22a10632006-08-22 10:15:33 -070088
Eric Anholt908f37d2006-08-25 17:33:02 -070089%token ALIGN1 ALIGN16 SECHALF COMPR SWITCH ATOMIC NODDCHK NODDCLR
90%token MASK_DISABLE BREAKPOINT EOT
Eric Anholt22a10632006-08-22 10:15:33 -070091
Keith Packard2033aea2008-04-23 23:10:40 -070092%token SEQ ANY2H ALL2H ANY4H ALL4H ANY8H ALL8H ANY16H ALL16H ANYV ALLV
93%token <integer> ZERO EQUAL NOT_ZERO NOT_EQUAL GREATER GREATER_EQUAL LESS LESS_EQUAL
94%token <integer> ROUND_INCREMENT OVERFLOW UNORDERED
Eric Anholt883408e2006-08-25 13:38:03 -070095%token <integer> GENREG MSGREG ADDRESSREG ACCREG FLAGREG
96%token <integer> MASKREG AMASK IMASK LMASK CMASK
97%token <integer> MASKSTACKREG LMS IMS MASKSTACKDEPTHREG IMSD LMSD
98%token <integer> NOTIFYREG STATEREG CONTROLREG IPREG
Eric Anholt3bcf6b22006-08-29 18:31:34 -070099%token GENREGFILE MSGREGFILE
Eric Anholt22a10632006-08-22 10:15:33 -0700100
Eric Anholtf914c6a2006-08-25 11:05:10 -0700101%token <integer> MOV FRC RNDU RNDD RNDE RNDZ NOT LZD
102%token <integer> MUL MAC MACH LINE SAD2 SADA2 DP4 DPH DP3 DP2
103%token <integer> AVG ADD SEL AND OR XOR SHR SHL ASR CMP CMPN
Eric Anholtc8939ed2006-08-30 10:50:56 -0700104%token <integer> SEND NOP JMPI IF IFF WHILE ELSE BREAK CONT HALT MSAVE
Eric Anholtf914c6a2006-08-25 11:05:10 -0700105%token <integer> PUSH MREST POP WAIT DO ENDIF ILLEGAL
106
107%token NULL_TOKEN MATH SAMPLER GATEWAY READ WRITE URB THREAD_SPAWNER
Eric Anholt22a10632006-08-22 10:15:33 -0700108
109%token MSGLEN RETURNLEN
Eric Anholte8651962006-08-24 16:37:04 -0700110%token <integer> ALLOCATE USED COMPLETE TRANSPOSE INTERLEAVE
Keith Packard2d4d4012008-03-30 00:58:28 -0700111%token SATURATE
Eric Anholt22a10632006-08-22 10:15:33 -0700112
113%token <integer> INTEGER
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800114%token <string> STRING
Eric Anholt22a10632006-08-22 10:15:33 -0700115%token <number> NUMBER
116
Eric Anholt3d360792006-08-25 09:36:28 -0700117%token <integer> INV LOG EXP SQRT RSQ POW SIN COS SINCOS INTDIV INTMOD
118%token <integer> INTDIVMOD
119%token SIGNED SCALAR
120
Eric Anholt6a88ada2006-08-28 22:11:18 -0700121%token <integer> X Y Z W
122
Eric Anholt22a10632006-08-22 10:15:33 -0700123%type <instruction> instruction unaryinstruction binaryinstruction
124%type <instruction> binaryaccinstruction triinstruction sendinstruction
Eric Anholt356ce762006-08-31 10:27:48 -0700125%type <instruction> jumpinstruction branchloopinstruction elseinstruction
Eric Anholt4ee9c3d2006-09-01 13:37:51 -0700126%type <instruction> breakinstruction syncinstruction specialinstruction
Eric Anholt2dac0a12006-08-29 15:29:31 -0700127%type <instruction> msgtarget
Eric Anholt0ed5d932006-08-28 23:05:51 -0700128%type <instruction> instoptions instoption_list predicate
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800129%type <string> label
Eric Anholt22a10632006-08-22 10:15:33 -0700130%type <program> instrseq
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700131%type <integer> instoption
Eric Anholt4ee9c3d2006-09-01 13:37:51 -0700132%type <integer> unaryop binaryop binaryaccop branchloopop breakop
Eric Anholt6a88ada2006-08-28 22:11:18 -0700133%type <integer> conditionalmodifier saturate negate abs chansel
Eric Anholt2dac0a12006-08-29 15:29:31 -0700134%type <integer> writemask_x writemask_y writemask_z writemask_w
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700135%type <integer> regtype srcimmtype execsize dstregion immaddroffset
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700136%type <integer> subregnum sampler_datatype
Eric Anholte8651962006-08-24 16:37:04 -0700137%type <integer> urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt3d360792006-08-25 09:36:28 -0700138%type <integer> math_function math_signed math_scalar
Eric Anholt0ed5d932006-08-28 23:05:51 -0700139%type <integer> predctrl predstate
Eric Anholt2d298742006-08-30 09:57:20 -0700140%type <region> region region_wh indirectregion
Eric Anholt1d7d0422006-08-25 16:52:09 -0700141%type <direct_reg> directgenreg directmsgreg addrreg accreg flagreg maskreg
Keith Packard2d4d4012008-03-30 00:58:28 -0700142%type <direct_reg> maskstackreg notifyreg
143/* %type <direct_reg> maskstackdepthreg */
Eric Anholt1d7d0422006-08-25 16:52:09 -0700144%type <direct_reg> statereg controlreg ipreg nullreg
145%type <direct_reg> dstoperandex_typed srcarchoperandex_typed
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700146%type <indirect_reg> indirectgenreg indirectmsgreg addrparam
Keith Packard2d4d4012008-03-30 00:58:28 -0700147%type <integer> mask_subreg maskstack_subreg
148/* %type <intger> maskstackdepth_subreg */
Eric Anholt22a10632006-08-22 10:15:33 -0700149%type <imm32> imm32
Eric Anholt2dac0a12006-08-29 15:29:31 -0700150%type <dst_operand> dst dstoperand dstoperandex dstreg post_dst writemask
Eric Anholt6a88ada2006-08-28 22:11:18 -0700151%type <src_operand> directsrcoperand srcarchoperandex directsrcaccoperand
Eric Anholt2d298742006-08-30 09:57:20 -0700152%type <src_operand> indirectsrcoperand
Eric Anholt6a88ada2006-08-28 22:11:18 -0700153%type <src_operand> src srcimm imm32reg payload srcacc srcaccimm swizzle
Eric Anholt4ee9c3d2006-09-01 13:37:51 -0700154%type <src_operand> relativelocation relativelocation2 locationstackcontrol
Eric Anholt22a10632006-08-22 10:15:33 -0700155%%
156
157ROOT: instrseq
158 {
159 compiled_program = $1;
160 }
161;
162
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800163
164label: STRING COLON
165 {
166 $$ = $1;
167 }
168;
169
Eric Anholt22a10632006-08-22 10:15:33 -0700170instrseq: instruction SEMICOLON instrseq
171 {
172 struct brw_program_instruction *list_entry =
173 calloc(sizeof(struct brw_program_instruction), 1);
174 list_entry->instruction = $1;
175
176 list_entry->next = $3.first;
177 $3.first = list_entry;
178
179 $$ = $3;
180 }
181 | instruction SEMICOLON
182 {
183 struct brw_program_instruction *list_entry =
184 calloc(sizeof(struct brw_program_instruction), 1);
185 list_entry->instruction = $1;
186
187 list_entry->next = NULL;
188
189 $$.first = list_entry;
190 }
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800191 | label instrseq
192 {
193 struct brw_program_instruction *list_entry =
194 calloc(sizeof(struct brw_program_instruction), 1);
195 list_entry->string = $1;
196 list_entry->islabel = 1;
197 list_entry->next = $2.first;
198 $2.first = list_entry;
199 $$ = $2;
200 }
Eric Anholt22a10632006-08-22 10:15:33 -0700201 | error SEMICOLON instrseq
202 {
203 $$ = $3;
204 }
205;
206
207/* 1.4.1: Instruction groups */
208instruction: unaryinstruction
209 | binaryinstruction
210 | binaryaccinstruction
211 | triinstruction
Eric Anholt1e907c72006-08-31 10:21:15 -0700212 | jumpinstruction
213 | branchloopinstruction
Eric Anholt356ce762006-08-31 10:27:48 -0700214 | elseinstruction
Eric Anholt4ee9c3d2006-09-01 13:37:51 -0700215 | breakinstruction
Eric Anholt1f58efa2006-09-01 11:56:12 -0700216 | syncinstruction
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700217 | specialinstruction
Eric Anholt22a10632006-08-22 10:15:33 -0700218;
219
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700220unaryinstruction:
221 predicate unaryop conditionalmodifier saturate execsize
222 dst srcaccimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -0700223 {
Eric Anholt56b50b62006-08-24 10:51:48 -0700224 bzero(&$$, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -0700225 $$.header.opcode = $2;
Eric Anholt90aea512006-08-22 14:46:39 -0700226 $$.header.destreg__conditionalmod = $3;
227 $$.header.saturate = $4;
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700228 $$.header.execution_size = $5;
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700229 set_instruction_options(&$$, &$8);
Eric Anholt0ed5d932006-08-28 23:05:51 -0700230 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -0700231 if (set_instruction_dest(&$$, &$6) != 0)
232 YYERROR;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700233 if (set_instruction_src0(&$$, &$7) != 0)
234 YYERROR;
Eric Anholt22a10632006-08-22 10:15:33 -0700235 }
236;
237
Eric Anholtf914c6a2006-08-25 11:05:10 -0700238unaryop: MOV | FRC | RNDU | RNDD | RNDE | RNDZ | NOT | LZD
Eric Anholt22a10632006-08-22 10:15:33 -0700239;
240
241binaryinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700242 predicate binaryop conditionalmodifier saturate execsize
243 dst src srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -0700244 {
Eric Anholt56b50b62006-08-24 10:51:48 -0700245 bzero(&$$, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -0700246 $$.header.opcode = $2;
Eric Anholt90aea512006-08-22 14:46:39 -0700247 $$.header.destreg__conditionalmod = $3;
248 $$.header.saturate = $4;
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700249 $$.header.execution_size = $5;
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700250 set_instruction_options(&$$, &$9);
Eric Anholt0ed5d932006-08-28 23:05:51 -0700251 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -0700252 if (set_instruction_dest(&$$, &$6) != 0)
253 YYERROR;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700254 if (set_instruction_src0(&$$, &$7) != 0)
255 YYERROR;
256 if (set_instruction_src1(&$$, &$8) != 0)
257 YYERROR;
Eric Anholt22a10632006-08-22 10:15:33 -0700258 }
259;
260
Eric Anholtf914c6a2006-08-25 11:05:10 -0700261binaryop: MUL | MAC | MACH | LINE | SAD2 | SADA2 | DP4 | DPH | DP3 | DP2
Eric Anholtedc82a02006-08-25 17:42:05 -0700262;
Eric Anholt22a10632006-08-22 10:15:33 -0700263
264binaryaccinstruction:
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700265 predicate binaryaccop conditionalmodifier saturate execsize
266 dst srcacc srcimm instoptions
Eric Anholt22a10632006-08-22 10:15:33 -0700267 {
Eric Anholt56b50b62006-08-24 10:51:48 -0700268 bzero(&$$, sizeof($$));
Eric Anholt22a10632006-08-22 10:15:33 -0700269 $$.header.opcode = $2;
Eric Anholt90aea512006-08-22 14:46:39 -0700270 $$.header.destreg__conditionalmod = $3;
271 $$.header.saturate = $4;
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700272 $$.header.execution_size = $5;
Eric Anholt19f1c1c2006-08-22 12:41:09 -0700273 set_instruction_options(&$$, &$9);
Eric Anholt0ed5d932006-08-28 23:05:51 -0700274 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -0700275 if (set_instruction_dest(&$$, &$6) != 0)
276 YYERROR;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700277 if (set_instruction_src0(&$$, &$7) != 0)
278 YYERROR;
279 if (set_instruction_src1(&$$, &$8) != 0)
280 YYERROR;
Eric Anholt22a10632006-08-22 10:15:33 -0700281 }
282;
283
Eric Anholtf914c6a2006-08-25 11:05:10 -0700284binaryaccop: AVG | ADD | SEL | AND | OR | XOR | SHR | SHL | ASR | CMP | CMPN
Eric Anholt22a10632006-08-22 10:15:33 -0700285;
286
287triinstruction: sendinstruction
Eric Anholtedc82a02006-08-25 17:42:05 -0700288;
Eric Anholt22a10632006-08-22 10:15:33 -0700289
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700290sendinstruction: predicate SEND execsize INTEGER post_dst payload msgtarget
Eric Anholt22a10632006-08-22 10:15:33 -0700291 MSGLEN INTEGER RETURNLEN INTEGER instoptions
292 {
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700293 /* Send instructions are messy. The first argument is the
294 * post destination -- the grf register that the response
295 * starts from. The second argument is the current
296 * destination, which is the start of the message arguments
297 * to the shared function, and where src0 payload is loaded
298 * to if not null. The payload is typically based on the
299 * grf 0 thread payload of your current thread, and is
300 * implicitly loaded if non-null.
301 */
Eric Anholt56b50b62006-08-24 10:51:48 -0700302 bzero(&$$, sizeof($$));
Eric Anholtf914c6a2006-08-25 11:05:10 -0700303 $$.header.opcode = $2;
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700304 $$.header.execution_size = $3;
305 $$.header.destreg__conditionalmod = $4; /* msg reg index */
Eric Anholt0ed5d932006-08-28 23:05:51 -0700306 set_instruction_predicate(&$$, &$1);
Eric Anholt2dac0a12006-08-29 15:29:31 -0700307 if (set_instruction_dest(&$$, &$5) != 0)
308 YYERROR;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700309 if (set_instruction_src0(&$$, &$6) != 0)
310 YYERROR;
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700311 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
312 $$.bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_D;
Xiang Haihao549b7512009-06-30 10:02:33 +0800313
314 if (gen_level == 5) {
315 $$.bits2.send_gen5.sfid = $7.bits2.send_gen5.sfid;
316 $$.bits2.send_gen5.end_of_thread = $12.bits3.generic_gen5.end_of_thread;
317 $$.bits3.generic_gen5 = $7.bits3.generic_gen5;
318 $$.bits3.generic_gen5.msg_length = $9;
319 $$.bits3.generic_gen5.response_length = $11;
320 $$.bits3.generic_gen5.end_of_thread =
321 $12.bits3.generic_gen5.end_of_thread;
322 } else {
323 $$.bits3.generic = $7.bits3.generic;
324 $$.bits3.generic.msg_length = $9;
325 $$.bits3.generic.response_length = $11;
326 $$.bits3.generic.end_of_thread =
327 $12.bits3.generic.end_of_thread;
328 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700329 }
Eric Anholtedc82a02006-08-25 17:42:05 -0700330;
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700331
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800332jumpinstruction: predicate JMPI relativelocation2
Eric Anholt1e907c72006-08-31 10:21:15 -0700333 {
334 struct direct_reg dst;
335 struct dst_operand ip_dst;
336 struct src_operand ip_src;
337
338 /* The jump instruction requires that the IP register
339 * be the destination and first source operand, while the
340 * offset is the second source operand. The next instruction
341 * is the post-incremented IP plus the offset.
342 */
Eric Anholt56cdee42006-08-31 15:28:10 -0700343 dst.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
344 dst.reg_nr = BRW_ARF_IP;
345 dst.subreg_nr = 0;
Eric Anholt1e907c72006-08-31 10:21:15 -0700346
347 bzero(&$$, sizeof($$));
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800348 $$.header.opcode = $2;
Eric Anholt1e907c72006-08-31 10:21:15 -0700349 set_direct_dst_operand(&ip_dst, &dst, BRW_REGISTER_TYPE_UD);
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800350 set_instruction_predicate(&$$, &$1);
Eric Anholt1e907c72006-08-31 10:21:15 -0700351 set_instruction_dest(&$$, &ip_dst);
352 set_direct_src_operand(&ip_src, &dst, BRW_REGISTER_TYPE_UD);
353 set_instruction_src0(&$$, &ip_src);
Zou Nanhaibe9bcee2008-12-09 18:38:54 -0800354 set_instruction_src1(&$$, &$3);
355 }
356 | predicate JMPI STRING
357 {
358 struct direct_reg dst;
359 struct dst_operand ip_dst;
360 struct src_operand ip_src;
361 struct src_operand imm;
362
363 /* The jump instruction requires that the IP register
364 * be the destination and first source operand, while the
365 * offset is the second source operand. The next instruction
366 is the post-incremented IP plus the offset.
367 */
368 dst.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
369 dst.reg_nr = BRW_ARF_IP;
370 dst.subreg_nr = 0;
371 memset (&imm, '\0', sizeof (imm));
372 imm.reg_file = BRW_IMMEDIATE_VALUE;
373 imm.reg_type = BRW_REGISTER_TYPE_D;
374 imm.imm32 = 0;
375
376 bzero(&$$, sizeof($$));
377 $$.header.opcode = $2;
378 set_direct_dst_operand(&ip_dst, &dst, BRW_REGISTER_TYPE_UD);
379 set_instruction_dest(&$$, &ip_dst);
380 set_instruction_predicate(&$$, &$1);
381 set_direct_src_operand(&ip_src, &dst, BRW_REGISTER_TYPE_UD);
382 set_instruction_src0(&$$, &ip_src);
383 set_instruction_src1(&$$, &imm);
384 $$.reloc_target = $3;
Eric Anholt1e907c72006-08-31 10:21:15 -0700385 }
386;
387
388branchloopinstruction:
389 predicate branchloopop relativelocation
390 {
391 struct direct_reg dst;
392 struct dst_operand ip_dst;
393 struct src_operand ip_src;
394
395 /* The branch instructions require that the IP register
396 * be the destination and first source operand, while the
397 * offset is the second source operand. The offset is added
398 * to the pre-incremented IP.
399 */
Eric Anholt56cdee42006-08-31 15:28:10 -0700400 dst.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
401 dst.reg_nr = BRW_ARF_IP;
402 dst.subreg_nr = 0;
Eric Anholt1e907c72006-08-31 10:21:15 -0700403
404 bzero(&$$, sizeof($$));
405 $$.header.opcode = $2;
406 set_instruction_predicate(&$$, &$1);
407 set_direct_dst_operand(&ip_dst, &dst, BRW_REGISTER_TYPE_UD);
408 set_instruction_dest(&$$, &ip_dst);
409 set_direct_src_operand(&ip_src, &dst, BRW_REGISTER_TYPE_UD);
410 set_instruction_src0(&$$, &ip_src);
411 set_instruction_src1(&$$, &$3);
412 }
413;
414
Eric Anholtf914c6a2006-08-25 11:05:10 -0700415branchloopop: IF | IFF | WHILE
416;
417
Eric Anholt356ce762006-08-31 10:27:48 -0700418elseinstruction: ELSE relativelocation
419 {
420 struct direct_reg dst;
421 struct dst_operand ip_dst;
422 struct src_operand ip_src;
423
424 /* The jump instruction requires that the IP register
425 * be the destination and first source operand, while the
426 * offset is the second source operand. The offset is added
427 * to the IP pre-increment.
428 */
Eric Anholt960ca002006-09-01 12:11:55 -0700429 dst.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
430 dst.reg_nr = BRW_ARF_IP;
431 dst.subreg_nr = 0;
432
433 /* Set the istack pop count, which must always be 1. */
434 $2.imm32 |= (1 << 16);
Eric Anholt356ce762006-08-31 10:27:48 -0700435
436 bzero(&$$, sizeof($$));
437 $$.header.opcode = $1;
438 set_direct_dst_operand(&ip_dst, &dst, BRW_REGISTER_TYPE_UD);
439 set_instruction_dest(&$$, &ip_dst);
440 set_direct_src_operand(&ip_src, &dst, BRW_REGISTER_TYPE_UD);
441 set_instruction_src0(&$$, &ip_src);
442 set_instruction_src1(&$$, &$2);
443 }
444;
445
Eric Anholt4ee9c3d2006-09-01 13:37:51 -0700446breakinstruction: breakop locationstackcontrol
447 {
448 struct direct_reg dst;
449 struct dst_operand ip_dst;
450 struct src_operand ip_src;
451
452 /* The jump instruction requires that the IP register
453 * be the destination and first source operand, while the
454 * offset is the second source operand. The offset is added
455 * to the IP pre-increment.
456 */
457 dst.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
458 dst.reg_nr = BRW_ARF_IP;
459 dst.subreg_nr = 0;
460
461 bzero(&$$, sizeof($$));
462 $$.header.opcode = $1;
463 set_direct_dst_operand(&ip_dst, &dst, BRW_REGISTER_TYPE_UD);
464 set_instruction_dest(&$$, &ip_dst);
465 set_direct_src_operand(&ip_src, &dst, BRW_REGISTER_TYPE_UD);
466 set_instruction_src0(&$$, &ip_src);
467 set_instruction_src1(&$$, &$2);
468 }
469;
470
471breakop: BREAK | CONT | HALT
Eric Anholtedc82a02006-08-25 17:42:05 -0700472;
Eric Anholtf914c6a2006-08-25 11:05:10 -0700473
Keith Packard2d4d4012008-03-30 00:58:28 -0700474/*
Eric Anholtf914c6a2006-08-25 11:05:10 -0700475maskpushop: MSAVE | PUSH
476;
Keith Packard2d4d4012008-03-30 00:58:28 -0700477 */
Eric Anholtf914c6a2006-08-25 11:05:10 -0700478
Eric Anholt1f58efa2006-09-01 11:56:12 -0700479syncinstruction: predicate WAIT notifyreg
480 {
481 struct direct_reg null;
482 struct dst_operand null_dst;
483 struct src_operand null_src;
Keith Packard2d4d4012008-03-30 00:58:28 -0700484 struct src_operand notify_src;
Eric Anholt1f58efa2006-09-01 11:56:12 -0700485
486 null.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
487 null.reg_nr = BRW_ARF_NULL;
488 null.subreg_nr = 0;
Keith Packard2d4d4012008-03-30 00:58:28 -0700489
490 notify_src.reg_file = $3.reg_file;
491 notify_src.reg_nr = $3.reg_nr;
492 notify_src.subreg_nr = $3.subreg_nr;
493 notify_src.reg_type = BRW_REGISTER_TYPE_UD;
Eric Anholt1f58efa2006-09-01 11:56:12 -0700494
495 bzero(&$$, sizeof($$));
496 $$.header.opcode = $2;
497 set_direct_dst_operand(&null_dst, &null, BRW_REGISTER_TYPE_UD);
498 set_instruction_dest(&$$, &null_dst);
499 set_direct_src_operand(&null_src, &null, BRW_REGISTER_TYPE_UD);
Keith Packard2d4d4012008-03-30 00:58:28 -0700500 set_instruction_src0(&$$, &notify_src);
Eric Anholt1f58efa2006-09-01 11:56:12 -0700501 set_instruction_src1(&$$, &null_src);
502 }
503;
504
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700505specialinstruction: NOP
506 {
Eric Anholt56b50b62006-08-24 10:51:48 -0700507 bzero(&$$, sizeof($$));
Eric Anholtf914c6a2006-08-25 11:05:10 -0700508 $$.header.opcode = $1;
Eric Anholt22a10632006-08-22 10:15:33 -0700509 }
Eric Anholtd7771292006-08-30 11:40:05 -0700510 | DO
511 {
512 bzero(&$$, sizeof($$));
513 $$.header.opcode = $1;
514 }
515 | ENDIF
516 {
517 bzero(&$$, sizeof($$));
518 $$.header.opcode = $1;
519 $$.bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE;
Eric Anholtf45ac8b2006-09-01 12:29:23 -0700520 $$.bits1.da1.src1_reg_type = BRW_REGISTER_TYPE_D;
Eric Anholtd7771292006-08-30 11:40:05 -0700521 $$.bits3.if_else.pop_count = 1;
522 }
Eric Anholtedc82a02006-08-25 17:42:05 -0700523;
Eric Anholt22a10632006-08-22 10:15:33 -0700524
525/* XXX! */
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700526payload: directsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -0700527;
528
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700529post_dst: dst
Eric Anholt22a10632006-08-22 10:15:33 -0700530;
531
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700532msgtarget: NULL_TOKEN
533 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800534 if (gen_level == 5) {
535 $$.bits2.send_gen5.sfid= BRW_MESSAGE_TARGET_NULL;
536 $$.bits3.generic_gen5.header_present = 0; /* ??? */
537 } else {
538 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_NULL;
539 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700540 }
541 | SAMPLER LPAREN INTEGER COMMA INTEGER COMMA
542 sampler_datatype RPAREN
543 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800544 if (gen_level == 5) {
545 $$.bits2.send_gen5.sfid = BRW_MESSAGE_TARGET_SAMPLER;
546 $$.bits3.generic_gen5.header_present = 1; /* ??? */
547 $$.bits3.sampler_gen5.binding_table_index = $3;
548 $$.bits3.sampler_gen5.sampler = $5;
549 $$.bits3.sampler_gen5.simd_mode = 2; /* SIMD16, maybe we should add a new parameter */
550 } else {
551 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_SAMPLER;
552 $$.bits3.sampler.binding_table_index = $3;
553 $$.bits3.sampler.sampler = $5;
554 switch ($7) {
555 case TYPE_F:
556 $$.bits3.sampler.return_format =
557 BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
558 break;
559 case TYPE_UD:
560 $$.bits3.sampler.return_format =
561 BRW_SAMPLER_RETURN_FORMAT_UINT32;
562 break;
563 case TYPE_D:
564 $$.bits3.sampler.return_format =
565 BRW_SAMPLER_RETURN_FORMAT_SINT32;
566 break;
567 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700568 }
569 }
Eric Anholt3d360792006-08-25 09:36:28 -0700570 | MATH math_function saturate math_signed math_scalar
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700571 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800572 if (gen_level == 5) {
573 $$.bits2.send_gen5.sfid = BRW_MESSAGE_TARGET_MATH;
574 $$.bits3.generic_gen5.header_present = 0;
575 $$.bits3.math_gen5.function = $2;
576 if ($3 == BRW_INSTRUCTION_SATURATE)
577 $$.bits3.math_gen5.saturate = 1;
578 else
579 $$.bits3.math_gen5.saturate = 0;
580 $$.bits3.math_gen5.int_type = $4;
581 $$.bits3.math_gen5.precision = BRW_MATH_PRECISION_FULL;
582 $$.bits3.math_gen5.data_type = $5;
583 } else {
584 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_MATH;
585 $$.bits3.math.function = $2;
586 if ($3 == BRW_INSTRUCTION_SATURATE)
587 $$.bits3.math.saturate = 1;
588 else
589 $$.bits3.math.saturate = 0;
590 $$.bits3.math.int_type = $4;
591 $$.bits3.math.precision = BRW_MATH_PRECISION_FULL;
592 $$.bits3.math.data_type = $5;
593 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700594 }
595 | GATEWAY
596 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800597 if (gen_level == 5) {
598 $$.bits2.send_gen5.sfid = BRW_MESSAGE_TARGET_GATEWAY;
599 $$.bits3.generic_gen5.header_present = 0; /* ??? */
600 } else {
601 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_GATEWAY;
602 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700603 }
Zou Nan hai807f8762008-06-18 15:05:19 -0700604 | READ LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
605 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700606 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800607 if (gen_level == 5) {
608 $$.bits2.send_gen5.sfid =
609 BRW_MESSAGE_TARGET_DATAPORT_READ;
610 $$.bits3.generic_gen5.header_present = 1;
611 $$.bits3.dp_read_gen5.binding_table_index = $3;
612 $$.bits3.dp_read_gen5.target_cache = $5;
613 $$.bits3.dp_read_gen5.msg_control = $7;
614 $$.bits3.dp_read_gen5.msg_type = $9;
615 } else {
616 $$.bits3.generic.msg_target =
617 BRW_MESSAGE_TARGET_DATAPORT_READ;
618 $$.bits3.dp_read.binding_table_index = $3;
619 $$.bits3.dp_read.target_cache = $5;
620 $$.bits3.dp_read.msg_control = $7;
621 $$.bits3.dp_read.msg_type = $9;
622 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700623 }
Eric Anholt43313942006-08-24 15:26:10 -0700624 | WRITE LPAREN INTEGER COMMA INTEGER COMMA INTEGER COMMA
625 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700626 {
Xiang Haihao549b7512009-06-30 10:02:33 +0800627 if (gen_level == 5) {
628 $$.bits2.send_gen5.sfid =
629 BRW_MESSAGE_TARGET_DATAPORT_WRITE;
630 $$.bits3.generic_gen5.header_present = 1;
631 $$.bits3.dp_write_gen5.binding_table_index = $3;
632 $$.bits3.dp_write_gen5.pixel_scoreboard_clear = ($5 & 0x8) >> 3;
633 $$.bits3.dp_write_gen5.msg_control = $5 & 0x7;
634 $$.bits3.dp_write_gen5.msg_type = $7;
635 $$.bits3.dp_write_gen5.send_commit_msg = $9;
636 } else {
637 $$.bits3.generic.msg_target =
638 BRW_MESSAGE_TARGET_DATAPORT_WRITE;
639 $$.bits3.dp_write.binding_table_index = $3;
640 /* The msg control field of brw_struct.h is split into
641 * msg control and pixel_scoreboard_clear, even though
642 * pixel_scoreboard_clear isn't common to all write messages.
643 */
644 $$.bits3.dp_write.pixel_scoreboard_clear = ($5 & 0x8) >> 3;
645 $$.bits3.dp_write.msg_control = $5 & 0x7;
646 $$.bits3.dp_write.msg_type = $7;
647 $$.bits3.dp_write.send_commit_msg = $9;
648 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700649 }
Eric Anholte8651962006-08-24 16:37:04 -0700650 | URB INTEGER urb_swizzle urb_allocate urb_used urb_complete
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700651 {
652 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_URB;
Xiang Haihao549b7512009-06-30 10:02:33 +0800653 if (gen_level == 5) {
654 $$.bits2.send_gen5.sfid = BRW_MESSAGE_TARGET_URB;
655 $$.bits3.generic_gen5.header_present = 1;
656 $$.bits3.urb_gen5.opcode = BRW_URB_OPCODE_WRITE;
657 $$.bits3.urb_gen5.offset = $2;
658 $$.bits3.urb_gen5.swizzle_control = $3;
659 $$.bits3.urb_gen5.pad = 0;
660 $$.bits3.urb_gen5.allocate = $4;
661 $$.bits3.urb_gen5.used = $5;
662 $$.bits3.urb_gen5.complete = $6;
663 } else {
664 $$.bits3.generic.msg_target = BRW_MESSAGE_TARGET_URB;
665 $$.bits3.urb.opcode = BRW_URB_OPCODE_WRITE;
666 $$.bits3.urb.offset = $2;
667 $$.bits3.urb.swizzle_control = $3;
668 $$.bits3.urb.pad = 0;
669 $$.bits3.urb.allocate = $4;
670 $$.bits3.urb.used = $5;
671 $$.bits3.urb.complete = $6;
672 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700673 }
Zou Nan hai26afe902008-06-18 15:04:11 -0700674 | THREAD_SPAWNER LPAREN INTEGER COMMA INTEGER COMMA
675 INTEGER RPAREN
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700676 {
677 $$.bits3.generic.msg_target =
678 BRW_MESSAGE_TARGET_THREAD_SPAWNER;
Xiang Haihao549b7512009-06-30 10:02:33 +0800679 if (gen_level == 5) {
680 $$.bits2.send_gen5.sfid =
681 BRW_MESSAGE_TARGET_THREAD_SPAWNER;
682 $$.bits3.generic_gen5.header_present = 0;
683 $$.bits3.thread_spawner_gen5.opcode = $3;
684 $$.bits3.thread_spawner_gen5.requester_type = $5;
685 $$.bits3.thread_spawner_gen5.resource_select = $7;
686 } else {
687 $$.bits3.generic.msg_target =
688 BRW_MESSAGE_TARGET_THREAD_SPAWNER;
689 $$.bits3.thread_spawner.opcode = $3;
690 $$.bits3.thread_spawner.requester_type = $5;
691 $$.bits3.thread_spawner.resource_select = $7;
692 }
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700693 }
694;
695
Eric Anholte8651962006-08-24 16:37:04 -0700696urb_allocate: ALLOCATE { $$ = 1; }
697 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -0700698;
Eric Anholte8651962006-08-24 16:37:04 -0700699
700urb_used: USED { $$ = 1; }
701 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -0700702;
Eric Anholte8651962006-08-24 16:37:04 -0700703
704urb_complete: COMPLETE { $$ = 1; }
705 | /* empty */ { $$ = 0; }
Eric Anholt3d360792006-08-25 09:36:28 -0700706;
Eric Anholte8651962006-08-24 16:37:04 -0700707
708urb_swizzle: TRANSPOSE { $$ = BRW_URB_SWIZZLE_TRANSPOSE; }
709 | INTERLEAVE { $$ = BRW_URB_SWIZZLE_INTERLEAVE; }
710 | /* empty */ { $$ = BRW_URB_SWIZZLE_NONE; }
Eric Anholt3d360792006-08-25 09:36:28 -0700711;
Eric Anholte8651962006-08-24 16:37:04 -0700712
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700713sampler_datatype:
714 TYPE_F
715 | TYPE_UD
716 | TYPE_D
Eric Anholt3d360792006-08-25 09:36:28 -0700717;
718
719math_function: INV | LOG | EXP | SQRT | POW | SIN | COS | SINCOS | INTDIV
720 | INTMOD | INTDIVMOD
721;
722
723math_signed: /* empty */ { $$ = 0; }
724 | SIGNED { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -0700725;
Eric Anholt3d360792006-08-25 09:36:28 -0700726
727math_scalar: /* empty */ { $$ = 0; }
728 | SCALAR { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -0700729;
Eric Anholt56c4ccf2006-08-24 14:35:10 -0700730
Eric Anholt22a10632006-08-22 10:15:33 -0700731/* 1.4.2: Destination register */
732
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700733dst: dstoperand | dstoperandex
Eric Anholt3d360792006-08-25 09:36:28 -0700734;
Eric Anholt22a10632006-08-22 10:15:33 -0700735
Eric Anholt2dac0a12006-08-29 15:29:31 -0700736dstoperand: dstreg dstregion writemask regtype
Eric Anholt22a10632006-08-22 10:15:33 -0700737 {
738 /* Returns an instruction with just the destination register
739 * filled in.
740 */
Keith Packard2d4d4012008-03-30 00:58:28 -0700741 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700742 $$.reg_file = $1.reg_file;
743 $$.reg_nr = $1.reg_nr;
744 $$.subreg_nr = $1.subreg_nr;
745 $$.horiz_stride = $2;
746 $$.writemask_set = $3.writemask_set;
747 $$.writemask = $3.writemask;
748 $$.reg_type = $4;
Eric Anholt22a10632006-08-22 10:15:33 -0700749 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700750;
Eric Anholt22a10632006-08-22 10:15:33 -0700751
Eric Anholt883408e2006-08-25 13:38:03 -0700752/* The dstoperandex returns an instruction with just the destination register
753 * filled in.
754 */
755dstoperandex: dstoperandex_typed dstregion regtype
Eric Anholt22a10632006-08-22 10:15:33 -0700756 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700757 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700758 $$.reg_file = $1.reg_file;
759 $$.reg_nr = $1.reg_nr;
760 $$.subreg_nr = $1.subreg_nr;
761 $$.horiz_stride = $2;
762 $$.reg_type = $3;
Eric Anholt22a10632006-08-22 10:15:33 -0700763 }
Eric Anholt883408e2006-08-25 13:38:03 -0700764 | maskstackreg
765 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700766 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700767 $$.reg_file = $1.reg_file;
768 $$.reg_nr = $1.reg_nr;
769 $$.subreg_nr = $1.subreg_nr;
770 $$.horiz_stride = 1;
771 $$.reg_type = BRW_REGISTER_TYPE_UW;
Eric Anholt883408e2006-08-25 13:38:03 -0700772 }
773 | controlreg
774 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700775 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700776 $$.reg_file = $1.reg_file;
777 $$.reg_nr = $1.reg_nr;
778 $$.subreg_nr = $1.subreg_nr;
779 $$.horiz_stride = 1;
780 $$.reg_type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -0700781 }
782 | ipreg
783 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700784 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700785 $$.reg_file = $1.reg_file;
786 $$.reg_nr = $1.reg_nr;
787 $$.subreg_nr = $1.subreg_nr;
788 $$.horiz_stride = 1;
789 $$.reg_type = BRW_REGISTER_TYPE_UD;
Eric Anholt883408e2006-08-25 13:38:03 -0700790 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700791 | nullreg
792 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700793 memset (&$$, '\0', sizeof ($$));
Eric Anholt2dac0a12006-08-29 15:29:31 -0700794 $$.reg_file = $1.reg_file;
795 $$.reg_nr = $1.reg_nr;
796 $$.subreg_nr = $1.subreg_nr;
797 $$.horiz_stride = 1;
798 $$.reg_type = BRW_REGISTER_TYPE_F;
Eric Anholt6c98c8d2006-08-22 11:54:19 -0700799 }
800;
Eric Anholt22a10632006-08-22 10:15:33 -0700801
Eric Anholt883408e2006-08-25 13:38:03 -0700802dstoperandex_typed: accreg | flagreg | addrreg | maskreg
803;
804
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700805/* Returns a partially complete destination register consisting of the
806 * direct or indirect register addressing fields, but not stride or writemask.
807 */
Eric Anholt22a10632006-08-22 10:15:33 -0700808dstreg: directgenreg
809 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700810 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700811 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt2dac0a12006-08-29 15:29:31 -0700812 $$.reg_file = $1.reg_file;
813 $$.reg_nr = $1.reg_nr;
814 $$.subreg_nr = $1.subreg_nr;
Eric Anholt22a10632006-08-22 10:15:33 -0700815 }
816 | directmsgreg
Eric Anholta34d1e02006-08-22 14:52:14 -0700817 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700818 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700819 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt2dac0a12006-08-29 15:29:31 -0700820 $$.reg_file = $1.reg_file;
821 $$.reg_nr = $1.reg_nr;
822 $$.subreg_nr = $1.subreg_nr;
Eric Anholta34d1e02006-08-22 14:52:14 -0700823 }
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700824 | indirectgenreg
825 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700826 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700827 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
828 $$.reg_file = $1.reg_file;
829 $$.address_subreg_nr = $1.address_subreg_nr;
830 $$.indirect_offset = $1.indirect_offset;
831 }
832 | indirectmsgreg
833 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700834 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700835 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
836 $$.reg_file = $1.reg_file;
837 $$.address_subreg_nr = $1.address_subreg_nr;
838 $$.indirect_offset = $1.indirect_offset;
839 }
Eric Anholt22a10632006-08-22 10:15:33 -0700840;
841
842/* 1.4.3: Source register */
Eric Anholt0d929b42006-08-22 13:33:41 -0700843srcaccimm: srcacc | imm32reg
Eric Anholt22a10632006-08-22 10:15:33 -0700844;
845
Eric Anholt2d298742006-08-30 09:57:20 -0700846srcacc: directsrcaccoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -0700847;
848
Eric Anholt0d929b42006-08-22 13:33:41 -0700849srcimm: directsrcoperand | imm32reg
Eric Anholtedc82a02006-08-25 17:42:05 -0700850;
Eric Anholt0d929b42006-08-22 13:33:41 -0700851
852imm32reg: imm32 srcimmtype
Eric Anholt22a10632006-08-22 10:15:33 -0700853 {
Eric Anholt6a88ada2006-08-28 22:11:18 -0700854 union {
855 int i;
856 float f;
857 } intfloat;
Keith Packard2d4d4012008-03-30 00:58:28 -0700858 uint32_t d;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700859
Eric Anholt22a10632006-08-22 10:15:33 -0700860 switch ($2) {
861 case BRW_REGISTER_TYPE_UD:
Eric Anholt22a10632006-08-22 10:15:33 -0700862 case BRW_REGISTER_TYPE_D:
Keith Packard2d4d4012008-03-30 00:58:28 -0700863 case BRW_REGISTER_TYPE_V:
864 switch ($1.r) {
865 case imm32_d:
866 d = $1.u.d;
867 break;
868 default:
869 fprintf (stderr, "non-int D/UD/V representation\n");
870 YYERROR;
871 }
Eric Anholt22a10632006-08-22 10:15:33 -0700872 break;
Eric Anholt0d929b42006-08-22 13:33:41 -0700873 case BRW_REGISTER_TYPE_UW:
Eric Anholt0d929b42006-08-22 13:33:41 -0700874 case BRW_REGISTER_TYPE_W:
Keith Packard2d4d4012008-03-30 00:58:28 -0700875 switch ($1.r) {
876 case imm32_d:
877 d = $1.u.d;
878 break;
879 default:
880 fprintf (stderr, "non-int W/UW representation\n");
881 YYERROR;
882 }
883 d &= 0xffff;
884 d |= d << 16;
Eric Anholt0d929b42006-08-22 13:33:41 -0700885 break;
Eric Anholt22a10632006-08-22 10:15:33 -0700886 case BRW_REGISTER_TYPE_F:
Keith Packard2d4d4012008-03-30 00:58:28 -0700887 switch ($1.r) {
888 case imm32_f:
889 intfloat.f = $1.u.f;
890 break;
891 case imm32_d:
892 intfloat.f = (float) $1.u.d;
893 break;
894 default:
895 fprintf (stderr, "non-float F representation\n");
896 YYERROR;
897 }
898 d = intfloat.i;
Eric Anholt22a10632006-08-22 10:15:33 -0700899 break;
Keith Packard2d4d4012008-03-30 00:58:28 -0700900 case BRW_REGISTER_TYPE_VF:
901 fprintf (stderr, "Immediate type VF not supported yet\n");
902 YYERROR;
Eric Anholt0d929b42006-08-22 13:33:41 -0700903 default:
904 fprintf(stderr, "unknown immediate type %d\n", $2);
905 YYERROR;
Eric Anholt22a10632006-08-22 10:15:33 -0700906 }
Keith Packard2d4d4012008-03-30 00:58:28 -0700907 memset (&$$, '\0', sizeof ($$));
908 $$.reg_file = BRW_IMMEDIATE_VALUE;
909 $$.reg_type = $2;
910 $$.imm32 = d;
Eric Anholt22a10632006-08-22 10:15:33 -0700911 }
912;
913
Eric Anholt5297b2a2006-08-25 16:50:17 -0700914directsrcaccoperand: directsrcoperand
Eric Anholt2a0f1352006-08-25 17:44:55 -0700915 | accreg regtype
916 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700917 set_direct_src_operand(&$$, &$1, $2);
Eric Anholt2a0f1352006-08-25 17:44:55 -0700918 }
Eric Anholt2c787652006-08-25 13:53:48 -0700919;
920
921/* Returns a source operand in the src0 fields of an instruction. */
Eric Anholt5297b2a2006-08-25 16:50:17 -0700922srcarchoperandex: srcarchoperandex_typed region regtype
Eric Anholt2c787652006-08-25 13:53:48 -0700923 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700924 memset (&$$, '\0', sizeof ($$));
Eric Anholt6a88ada2006-08-28 22:11:18 -0700925 $$.reg_file = $1.reg_file;
926 $$.reg_type = $3;
927 $$.subreg_nr = $1.subreg_nr;
928 $$.reg_nr = $1.reg_nr;
929 $$.vert_stride = $2.vert_stride;
930 $$.width = $2.width;
931 $$.horiz_stride = $2.horiz_stride;
932 $$.negate = 0;
933 $$.abs = 0;
Eric Anholt2c787652006-08-25 13:53:48 -0700934 }
935 | maskstackreg
936 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700937 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UB);
Eric Anholt2c787652006-08-25 13:53:48 -0700938 }
939 | controlreg
940 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700941 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -0700942 }
943 | statereg
944 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700945 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -0700946 }
947 | notifyreg
948 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700949 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -0700950 }
951 | ipreg
952 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700953 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -0700954 }
955 | nullreg
956 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -0700957 set_direct_src_operand(&$$, &$1, BRW_REGISTER_TYPE_UD);
Eric Anholt2c787652006-08-25 13:53:48 -0700958 }
959;
960
Eric Anholt5297b2a2006-08-25 16:50:17 -0700961srcarchoperandex_typed: flagreg | addrreg | maskreg
Eric Anholt22a10632006-08-22 10:15:33 -0700962;
963
Eric Anholt2d298742006-08-30 09:57:20 -0700964src: directsrcoperand | indirectsrcoperand
Eric Anholt22a10632006-08-22 10:15:33 -0700965;
966
Eric Anholtdc96c562006-08-22 14:42:45 -0700967directsrcoperand:
Eric Anholt6a88ada2006-08-28 22:11:18 -0700968 negate abs directgenreg region regtype swizzle
Eric Anholt22a10632006-08-22 10:15:33 -0700969 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700970 memset (&$$, '\0', sizeof ($$));
Eric Anholt2d298742006-08-30 09:57:20 -0700971 $$.address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt6a88ada2006-08-28 22:11:18 -0700972 $$.reg_file = $3.reg_file;
973 $$.reg_nr = $3.reg_nr;
974 $$.subreg_nr = $3.subreg_nr;
975 $$.reg_type = $5;
976 $$.vert_stride = $4.vert_stride;
977 $$.width = $4.width;
978 $$.horiz_stride = $4.horiz_stride;
979 $$.negate = $1;
980 $$.abs = $2;
981 $$.swizzle_set = $6.swizzle_set;
982 $$.swizzle_x = $6.swizzle_x;
983 $$.swizzle_y = $6.swizzle_y;
984 $$.swizzle_z = $6.swizzle_z;
985 $$.swizzle_w = $6.swizzle_w;
Eric Anholt22a10632006-08-22 10:15:33 -0700986 }
Eric Anholt5297b2a2006-08-25 16:50:17 -0700987 | srcarchoperandex
Eric Anholt22a10632006-08-22 10:15:33 -0700988;
989
Eric Anholt2d298742006-08-30 09:57:20 -0700990indirectsrcoperand:
991 negate abs indirectgenreg indirectregion regtype swizzle
992 {
Keith Packard2d4d4012008-03-30 00:58:28 -0700993 memset (&$$, '\0', sizeof ($$));
Eric Anholt2d298742006-08-30 09:57:20 -0700994 $$.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
995 $$.reg_file = $3.reg_file;
996 $$.address_subreg_nr = $3.address_subreg_nr;
997 $$.indirect_offset = $3.indirect_offset;
998 $$.reg_type = $5;
999 $$.vert_stride = $4.vert_stride;
1000 $$.width = $4.width;
1001 $$.horiz_stride = $4.horiz_stride;
1002 $$.negate = $1;
1003 $$.abs = $2;
1004 $$.swizzle_set = $6.swizzle_set;
1005 $$.swizzle_x = $6.swizzle_x;
1006 $$.swizzle_y = $6.swizzle_y;
1007 $$.swizzle_z = $6.swizzle_z;
1008 $$.swizzle_w = $6.swizzle_w;
1009 }
1010;
1011
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001012/* 1.4.4: Address Registers */
1013/* Returns a partially-completed indirect_reg consisting of the address
1014 * register fields for register-indirect access.
1015 */
1016addrparam: addrreg immaddroffset
1017 {
1018 if ($2 < -512 || $2 > 511) {
1019 fprintf(stderr, "Address immediate offset %d out of"
1020 "range\n", $2);
1021 YYERROR;
1022 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001023 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001024 $$.address_subreg_nr = $1.subreg_nr;
1025 $$.indirect_offset = $2;
1026 }
1027;
1028
1029/* The immaddroffset provides an immediate offset value added to the addresses
1030 * from the address register in register-indirect register access.
1031 */
1032immaddroffset: /* empty */ { $$ = 0; }
1033 | INTEGER
1034;
1035
1036
Eric Anholtedc82a02006-08-25 17:42:05 -07001037/* 1.4.5: Register files and register numbers */
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001038subregnum: DOT INTEGER
Eric Anholt22a10632006-08-22 10:15:33 -07001039 {
1040 $$ = $2;
1041 }
1042 |
1043 {
1044 /* Default to subreg 0 if unspecified. */
1045 $$ = 0;
1046 }
1047;
1048
Eric Anholt569990b2006-08-25 09:46:18 -07001049directgenreg: GENREG subregnum
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001050 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001051 memset (&$$, '\0', sizeof ($$));
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001052 $$.reg_file = BRW_GENERAL_REGISTER_FILE;
Eric Anholt569990b2006-08-25 09:46:18 -07001053 $$.reg_nr = $1;
1054 $$.subreg_nr = $2;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001055 }
Eric Anholtedc82a02006-08-25 17:42:05 -07001056;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001057
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001058indirectgenreg: GENREGFILE LSQUARE addrparam RSQUARE
1059 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001060 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001061 $$.reg_file = BRW_GENERAL_REGISTER_FILE;
1062 $$.address_subreg_nr = $3.address_subreg_nr;
1063 $$.indirect_offset = $3.indirect_offset;
1064 }
1065;
1066
Eric Anholt569990b2006-08-25 09:46:18 -07001067directmsgreg: MSGREG subregnum
Eric Anholt22a10632006-08-22 10:15:33 -07001068 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001069 memset (&$$, '\0', sizeof ($$));
Eric Anholta34d1e02006-08-22 14:52:14 -07001070 $$.reg_file = BRW_MESSAGE_REGISTER_FILE;
Eric Anholt569990b2006-08-25 09:46:18 -07001071 $$.reg_nr = $1;
1072 $$.subreg_nr = $2;
Eric Anholt22a10632006-08-22 10:15:33 -07001073 }
1074;
1075
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001076indirectmsgreg: MSGREGFILE LSQUARE addrparam RSQUARE
1077 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001078 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001079 $$.reg_file = BRW_MESSAGE_REGISTER_FILE;
1080 $$.address_subreg_nr = $3.address_subreg_nr;
1081 $$.indirect_offset = $3.indirect_offset;
1082 }
1083;
1084
Eric Anholt883408e2006-08-25 13:38:03 -07001085addrreg: ADDRESSREG subregnum
1086 {
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001087 if ($1 != 0) {
1088 fprintf(stderr,
1089 "address register number %d out of range", $1);
1090 YYERROR;
1091 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001092 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001093 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1094 $$.reg_nr = BRW_ARF_ADDRESS | $1;
1095 $$.subreg_nr = $2;
1096 }
1097;
1098
Eric Anholt569990b2006-08-25 09:46:18 -07001099accreg: ACCREG subregnum
1100 {
Eric Anholt569990b2006-08-25 09:46:18 -07001101 if ($1 > 1) {
1102 fprintf(stderr,
1103 "accumulator register number %d out of range", $1);
1104 YYERROR;
1105 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001106 memset (&$$, '\0', sizeof ($$));
Eric Anholt569990b2006-08-25 09:46:18 -07001107 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1108 $$.reg_nr = BRW_ARF_ACCUMULATOR | $1;
1109 $$.subreg_nr = $2;
1110 }
1111;
1112
Eric Anholtde1a8892006-08-29 09:30:32 -07001113flagreg: FLAGREG
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001114 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001115 memset (&$$, '\0', sizeof ($$));
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001116 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
Eric Anholtde1a8892006-08-29 09:30:32 -07001117 $$.reg_nr = BRW_ARF_FLAG | 0;
1118 $$.subreg_nr = $1;
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001119 }
1120;
1121
Eric Anholt883408e2006-08-25 13:38:03 -07001122maskreg: MASKREG subregnum
1123 {
1124 if ($1 > 0) {
1125 fprintf(stderr,
1126 "mask register number %d out of range", $1);
1127 YYERROR;
1128 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001129 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001130 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1131 $$.reg_nr = BRW_ARF_MASK;
1132 $$.subreg_nr = $2;
1133 }
1134 | mask_subreg
1135 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001136 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001137 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1138 $$.reg_nr = BRW_ARF_MASK;
1139 $$.subreg_nr = $1;
1140 }
1141;
1142
1143mask_subreg: AMASK | IMASK | LMASK | CMASK
1144;
1145
1146maskstackreg: MASKSTACKREG subregnum
1147 {
1148 if ($1 > 0) {
1149 fprintf(stderr,
1150 "mask stack register number %d out of range", $1);
1151 YYERROR;
1152 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001153 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001154 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1155 $$.reg_nr = BRW_ARF_MASK_STACK;
1156 $$.subreg_nr = $2;
1157 }
1158 | maskstack_subreg
1159 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001160 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001161 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1162 $$.reg_nr = BRW_ARF_MASK_STACK;
1163 $$.subreg_nr = $1;
1164 }
1165;
1166
1167maskstack_subreg: IMS | LMS
1168;
1169
Keith Packard2d4d4012008-03-30 00:58:28 -07001170/*
Eric Anholt883408e2006-08-25 13:38:03 -07001171maskstackdepthreg: MASKSTACKDEPTHREG subregnum
1172 {
1173 if ($1 > 0) {
1174 fprintf(stderr,
1175 "mask stack register number %d out of range", $1);
1176 YYERROR;
1177 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001178 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001179 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1180 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
1181 $$.subreg_nr = $2;
1182 }
1183 | maskstackdepth_subreg
1184 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001185 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001186 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1187 $$.reg_nr = BRW_ARF_MASK_STACK_DEPTH;
1188 $$.subreg_nr = $1;
1189 }
1190;
1191
1192maskstackdepth_subreg: IMSD | LMSD
1193;
Keith Packard2d4d4012008-03-30 00:58:28 -07001194 */
Eric Anholt883408e2006-08-25 13:38:03 -07001195
1196notifyreg: NOTIFYREG
1197 {
1198 if ($1 > 1) {
1199 fprintf(stderr,
1200 "notification register number %d out of range",
1201 $1);
1202 YYERROR;
1203 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001204 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001205 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1206 $$.reg_nr = BRW_ARF_NOTIFICATION_COUNT;
1207 $$.subreg_nr = 0;
1208 }
1209;
1210
1211statereg: STATEREG subregnum
1212 {
1213 if ($1 > 0) {
1214 fprintf(stderr,
1215 "state register number %d out of range", $1);
1216 YYERROR;
1217 }
1218 if ($2 > 1) {
1219 fprintf(stderr,
1220 "state subregister number %d out of range", $1);
1221 YYERROR;
1222 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001223 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001224 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1225 $$.reg_nr = BRW_ARF_STATE | $1;
1226 $$.subreg_nr = $2;
1227 }
1228;
1229
1230controlreg: CONTROLREG subregnum
1231 {
1232 if ($1 > 0) {
1233 fprintf(stderr,
1234 "control register number %d out of range", $1);
1235 YYERROR;
1236 }
1237 if ($2 > 2) {
1238 fprintf(stderr,
1239 "control subregister number %d out of range", $1);
1240 YYERROR;
1241 }
Keith Packard2d4d4012008-03-30 00:58:28 -07001242 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001243 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1244 $$.reg_nr = BRW_ARF_CONTROL | $1;
1245 $$.subreg_nr = $2;
1246 }
1247;
1248
1249ipreg: IPREG
1250 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001251 memset (&$$, '\0', sizeof ($$));
Eric Anholt883408e2006-08-25 13:38:03 -07001252 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1253 $$.reg_nr = BRW_ARF_IP;
1254 $$.subreg_nr = 0;
1255 }
1256;
1257
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001258nullreg: NULL_TOKEN
1259 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001260 memset (&$$, '\0', sizeof ($$));
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001261 $$.reg_file = BRW_ARCHITECTURE_REGISTER_FILE;
1262 $$.reg_nr = BRW_ARF_NULL;
1263 $$.subreg_nr = 0;
1264 }
Eric Anholt22a10632006-08-22 10:15:33 -07001265;
1266
Eric Anholt1e907c72006-08-31 10:21:15 -07001267/* 1.4.6: Relative locations */
1268relativelocation: imm32
1269 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001270 if ($1.r != imm32_d) {
1271 fprintf (stderr,
1272 "error: non-int offset representation\n");
1273 YYERROR;
1274 }
1275
1276 if ($1.u.d > 32767 || $1.u.d < -32768) {
Eric Anholt1e907c72006-08-31 10:21:15 -07001277 fprintf(stderr,
Keith Packard2d4d4012008-03-30 00:58:28 -07001278 "error: relative offset %d out of range\n", $1.u.d);
Eric Anholt1e907c72006-08-31 10:21:15 -07001279 YYERROR;
1280 }
1281
Keith Packard2d4d4012008-03-30 00:58:28 -07001282 memset (&$$, '\0', sizeof ($$));
Eric Anholt1e907c72006-08-31 10:21:15 -07001283 $$.reg_file = BRW_IMMEDIATE_VALUE;
1284 $$.reg_type = BRW_REGISTER_TYPE_D;
Keith Packard2d4d4012008-03-30 00:58:28 -07001285 $$.imm32 = $1.u.d & 0x0000ffff;
Eric Anholt1e907c72006-08-31 10:21:15 -07001286 }
1287;
1288
1289relativelocation2:
1290 imm32
1291 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001292 if ($1.r != imm32_d) {
1293 fprintf (stderr,
1294 "error: non-int location representation\n");
1295 YYERROR;
1296 }
1297 memset (&$$, '\0', sizeof ($$));
Eric Anholt1e907c72006-08-31 10:21:15 -07001298 $$.reg_file = BRW_IMMEDIATE_VALUE;
1299 $$.reg_type = BRW_REGISTER_TYPE_D;
Keith Packard2d4d4012008-03-30 00:58:28 -07001300 $$.imm32 = $1.u.d;
Eric Anholt1e907c72006-08-31 10:21:15 -07001301 }
1302 | directgenreg region regtype
1303 {
1304 set_direct_src_operand(&$$, &$1, $3);
1305 $$.vert_stride = $2.vert_stride;
1306 $$.width = $2.width;
1307 $$.horiz_stride = $2.horiz_stride;
1308 }
1309;
1310
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001311locationstackcontrol:
1312 imm32
1313 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001314 if ($1.r != imm32_d) {
1315 fprintf (stderr,
1316 "error: non-int stack control representation\n");
1317 YYERROR;
1318 }
1319 memset (&$$, '\0', sizeof ($$));
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001320 $$.reg_file = BRW_IMMEDIATE_VALUE;
1321 $$.reg_type = BRW_REGISTER_TYPE_D;
Keith Packard2d4d4012008-03-30 00:58:28 -07001322 $$.imm32 = $1.u.d;
Eric Anholt4ee9c3d2006-09-01 13:37:51 -07001323 }
1324;
1325
Eric Anholt22a10632006-08-22 10:15:33 -07001326/* 1.4.7: Regions */
1327dstregion: LANGLE INTEGER RANGLE
1328 {
1329 /* Returns a value for a horiz_stride field of an
1330 * instruction.
1331 */
1332 if ($2 != 1 && $2 != 2 && $2 != 4) {
1333 fprintf(stderr, "Invalid horiz size %d\n", $2);
1334 }
Eric Anholt0edcb252006-08-22 13:15:38 -07001335 $$ = ffs($2);
Eric Anholt22a10632006-08-22 10:15:33 -07001336 }
1337;
1338
1339region: LANGLE INTEGER COMMA INTEGER COMMA INTEGER RANGLE
1340 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001341 memset (&$$, '\0', sizeof ($$));
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001342 $$.vert_stride = ffs($2);
1343 $$.width = ffs($4) - 1;
Eric Anholtd4c82e82006-08-22 13:08:26 -07001344 $$.horiz_stride = ffs($6);
Eric Anholt22a10632006-08-22 10:15:33 -07001345 }
1346;
1347
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001348/* region_wh is used in specifying indirect operands where rather than having
1349 * a vertical stride, you use subsequent address registers to get a new base
Eric Anholt2d298742006-08-30 09:57:20 -07001350 * offset for the next row.
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001351 */
1352region_wh: LANGLE INTEGER COMMA INTEGER RANGLE
1353 {
Keith Packard2d4d4012008-03-30 00:58:28 -07001354 memset (&$$, '\0', sizeof ($$));
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001355 $$.vert_stride = BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL;
1356 $$.width = ffs($2) - 1;
1357 $$.horiz_stride = ffs($4);
1358 }
1359;
1360
Eric Anholt2d298742006-08-30 09:57:20 -07001361indirectregion: region | region_wh
1362;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001363
Eric Anholt22a10632006-08-22 10:15:33 -07001364/* 1.4.8: Types */
1365
1366/* regtype returns an integer register type suitable for inserting into an
1367 * instruction.
1368 */
1369regtype: TYPE_F { $$ = BRW_REGISTER_TYPE_F; }
1370 | TYPE_UD { $$ = BRW_REGISTER_TYPE_UD; }
1371 | TYPE_D { $$ = BRW_REGISTER_TYPE_D; }
1372 | TYPE_UW { $$ = BRW_REGISTER_TYPE_UW; }
Eric Anholt0d929b42006-08-22 13:33:41 -07001373 | TYPE_W { $$ = BRW_REGISTER_TYPE_W; }
Eric Anholt22a10632006-08-22 10:15:33 -07001374 | TYPE_UB { $$ = BRW_REGISTER_TYPE_UB; }
1375 | TYPE_B { $$ = BRW_REGISTER_TYPE_B; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001376;
1377
Keith Packard2d4d4012008-03-30 00:58:28 -07001378srcimmtype: TYPE_F { $$ = BRW_REGISTER_TYPE_F; }
1379 | TYPE_UD { $$ = BRW_REGISTER_TYPE_UD; }
1380 | TYPE_D { $$ = BRW_REGISTER_TYPE_D; }
1381 | TYPE_UW { $$ = BRW_REGISTER_TYPE_UW; }
1382 | TYPE_W { $$ = BRW_REGISTER_TYPE_W; }
1383 | TYPE_V { $$ = BRW_REGISTER_TYPE_V; }
1384 | TYPE_VF { $$ = BRW_REGISTER_TYPE_VF; }
Eric Anholt22a10632006-08-22 10:15:33 -07001385;
1386
Eric Anholt6a88ada2006-08-28 22:11:18 -07001387/* 1.4.10: Swizzle control */
1388/* Returns the swizzle control for an align16 instruction's source operand
1389 * in the src0 fields.
1390 */
1391swizzle: /* empty */
1392 {
1393 $$.swizzle_set = 0;
1394 $$.swizzle_x = BRW_CHANNEL_X;
1395 $$.swizzle_y = BRW_CHANNEL_Y;
1396 $$.swizzle_z = BRW_CHANNEL_Z;
1397 $$.swizzle_w = BRW_CHANNEL_W;
1398 }
1399 | DOT chansel
1400 {
1401 $$.swizzle_set = 1;
1402 $$.swizzle_x = $2;
1403 $$.swizzle_y = $2;
1404 $$.swizzle_z = $2;
1405 $$.swizzle_w = $2;
1406 }
1407 | DOT chansel chansel chansel chansel
1408 {
1409 $$.swizzle_set = 1;
1410 $$.swizzle_x = $2;
1411 $$.swizzle_y = $3;
1412 $$.swizzle_z = $4;
1413 $$.swizzle_w = $5;
1414 }
1415;
1416
1417chansel: X | Y | Z | W
1418;
1419
Eric Anholt2dac0a12006-08-29 15:29:31 -07001420/* 1.4.9: Write mask */
1421/* Returns a partially completed dst_operand, with just the writemask bits
1422 * filled out.
1423 */
1424writemask: /* empty */
1425 {
1426 $$.writemask_set = 0;
1427 $$.writemask = 0xf;
1428 }
1429 | DOT writemask_x writemask_y writemask_z writemask_w
1430 {
1431 $$.writemask_set = 1;
1432 $$.writemask = $2 | $3 | $4 | $5;
1433 }
Eric Anholtc8939ed2006-08-30 10:50:56 -07001434;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001435
1436writemask_x: /* empty */ { $$ = 0; }
1437 | X { $$ = 1 << BRW_CHANNEL_X; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07001438;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001439
1440writemask_y: /* empty */ { $$ = 0; }
1441 | Y { $$ = 1 << BRW_CHANNEL_Y; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07001442;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001443
1444writemask_z: /* empty */ { $$ = 0; }
1445 | Z { $$ = 1 << BRW_CHANNEL_Z; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07001446;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001447
1448writemask_w: /* empty */ { $$ = 0; }
1449 | W { $$ = 1 << BRW_CHANNEL_W; }
Eric Anholtc8939ed2006-08-30 10:50:56 -07001450;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001451
Eric Anholtedc82a02006-08-25 17:42:05 -07001452/* 1.4.11: Immediate values */
Keith Packard2d4d4012008-03-30 00:58:28 -07001453imm32: INTEGER { $$.r = imm32_d; $$.u.d = $1; }
1454 | MINUS INTEGER { $$.r = imm32_d; $$.u.d = -$2; }
1455 | NUMBER { $$.r = imm32_f; $$.u.f = $1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001456;
Eric Anholt22a10632006-08-22 10:15:33 -07001457
1458/* 1.4.12: Predication and modifiers */
Eric Anholt0ed5d932006-08-28 23:05:51 -07001459predicate: /* empty */
1460 {
1461 $$.header.predicate_control = BRW_PREDICATE_NONE;
1462 $$.bits2.da1.flag_reg_nr = 0;
1463 $$.header.predicate_inverse = 0;
1464 }
1465 | LPAREN predstate flagreg predctrl RPAREN
1466 {
1467 $$.header.predicate_control = $4;
1468 /* XXX: Should deal with erroring when the user tries to
1469 * set a predicate for one flag register and conditional
1470 * modification on the other flag register.
1471 */
1472 $$.bits2.da1.flag_reg_nr = $3.subreg_nr;
1473 $$.header.predicate_inverse = $2;
1474 }
1475;
1476
1477predstate: /* empty */ { $$ = 0; }
1478 | PLUS { $$ = 0; }
1479 | MINUS { $$ = 1; }
1480;
1481
Keith Packard2033aea2008-04-23 23:10:40 -07001482predctrl: /* empty */ { $$ = BRW_PREDICATE_NORMAL; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07001483 | DOT X { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_X; }
1484 | DOT Y { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Y; }
1485 | DOT Z { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_Z; }
1486 | DOT W { $$ = BRW_PREDICATE_ALIGN16_REPLICATE_W; }
Keith Packard2033aea2008-04-23 23:10:40 -07001487 | ANYV { $$ = BRW_PREDICATE_ALIGN1_ANYV; }
1488 | ALLV { $$ = BRW_PREDICATE_ALIGN1_ALLV; }
Eric Anholt0ed5d932006-08-28 23:05:51 -07001489 | ANY2H { $$ = BRW_PREDICATE_ALIGN1_ANY2H; }
1490 | ALL2H { $$ = BRW_PREDICATE_ALIGN1_ALL2H; }
1491 | ANY4H { $$ = BRW_PREDICATE_ALIGN1_ANY4H; }
1492 | ALL4H { $$ = BRW_PREDICATE_ALIGN1_ALL4H; }
1493 | ANY8H { $$ = BRW_PREDICATE_ALIGN1_ANY8H; }
1494 | ALL8H { $$ = BRW_PREDICATE_ALIGN1_ALL8H; }
1495 | ANY16H { $$ = BRW_PREDICATE_ALIGN1_ANY16H; }
1496 | ALL16H { $$ = BRW_PREDICATE_ALIGN1_ALL16H; }
Eric Anholtdc96c562006-08-22 14:42:45 -07001497;
1498
1499negate: /* empty */ { $$ = 0; }
1500 | MINUS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001501;
Eric Anholtdc96c562006-08-22 14:42:45 -07001502
1503abs: /* empty */ { $$ = 0; }
1504 | ABS { $$ = 1; }
Eric Anholtedc82a02006-08-25 17:42:05 -07001505;
Eric Anholt22a10632006-08-22 10:15:33 -07001506
1507execsize: LPAREN INTEGER RPAREN
1508 {
1509 /* Returns a value for the execution_size field of an
1510 * instruction.
1511 */
1512 if ($2 != 1 && $2 != 2 && $2 != 4 && $2 != 8 && $2 != 16 &&
1513 $2 != 32) {
1514 fprintf(stderr, "Invalid execution size %d\n", $2);
1515 YYERROR;
1516 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001517 $$ = ffs($2) - 1;
Eric Anholt22a10632006-08-22 10:15:33 -07001518 }
1519;
1520
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001521saturate: /* empty */ { $$ = BRW_INSTRUCTION_NORMAL; }
1522 | DOT SATURATE { $$ = BRW_INSTRUCTION_SATURATE; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001523;
1524
Keith Packard2033aea2008-04-23 23:10:40 -07001525conditionalmodifier: /* empty */ { $$ = BRW_CONDITIONAL_NONE; }
1526 | ZERO
1527 | EQUAL
1528 | NOT_ZERO
1529 | NOT_EQUAL
1530 | GREATER
1531 | GREATER_EQUAL
1532 | LESS
1533 | LESS_EQUAL
1534 | ROUND_INCREMENT
1535 | OVERFLOW
1536 | UNORDERED
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001537;
1538
Eric Anholt22a10632006-08-22 10:15:33 -07001539/* 1.4.13: Instruction options */
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001540instoptions: LCURLY instoption_list RCURLY
1541 { $$ = $2; }
1542;
1543
1544instoption_list: instoption instoption_list
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001545 {
1546 $$ = $2;
1547 switch ($1) {
1548 case ALIGN1:
1549 $$.header.access_mode = BRW_ALIGN_1;
1550 break;
1551 case ALIGN16:
1552 $$.header.access_mode = BRW_ALIGN_16;
1553 break;
Eric Anholt908f37d2006-08-25 17:33:02 -07001554 case SECHALF:
1555 $$.header.compression_control |= BRW_COMPRESSION_2NDHALF;
1556 break;
1557 case COMPR:
1558 $$.header.compression_control |=
1559 BRW_COMPRESSION_COMPRESSED;
1560 break;
1561 case SWITCH:
1562 $$.header.thread_control |= BRW_THREAD_SWITCH;
1563 break;
1564 case ATOMIC:
1565 $$.header.thread_control |= BRW_THREAD_ATOMIC;
1566 break;
1567 case NODDCHK:
1568 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCHECKED;
1569 break;
1570 case NODDCLR:
1571 $$.header.dependency_control |= BRW_DEPENDENCY_NOTCLEARED;
1572 break;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001573 case MASK_DISABLE:
1574 $$.header.mask_control = BRW_MASK_DISABLE;
1575 break;
Eric Anholt908f37d2006-08-25 17:33:02 -07001576 case BREAKPOINT:
1577 $$.header.debug_control = BRW_DEBUG_BREAKPOINT;
1578 break;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001579 case EOT:
Eric Anholt56c4ccf2006-08-24 14:35:10 -07001580 /* XXX: EOT shouldn't be an instoption, I don't think */
1581 $$.bits3.generic.end_of_thread = 1;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001582 break;
1583 }
1584 }
1585 | /* empty, header defaults to zeroes. */
Eric Anholte609d6b2006-08-24 12:36:56 -07001586 {
1587 bzero(&$$, sizeof($$));
1588 }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001589;
Eric Anholt22a10632006-08-22 10:15:33 -07001590
Eric Anholt16324212006-08-24 14:47:21 -07001591instoption: ALIGN1 { $$ = ALIGN1; }
1592 | ALIGN16 { $$ = ALIGN16; }
Eric Anholt908f37d2006-08-25 17:33:02 -07001593 | SECHALF { $$ = SECHALF; }
1594 | COMPR { $$ = COMPR; }
1595 | SWITCH { $$ = SWITCH; }
1596 | ATOMIC { $$ = ATOMIC; }
1597 | NODDCHK { $$ = NODDCHK; }
1598 | NODDCLR { $$ = NODDCLR; }
Eric Anholt16324212006-08-24 14:47:21 -07001599 | MASK_DISABLE { $$ = MASK_DISABLE; }
Eric Anholt908f37d2006-08-25 17:33:02 -07001600 | BREAKPOINT { $$ = BREAKPOINT; }
Eric Anholt16324212006-08-24 14:47:21 -07001601 | EOT { $$ = EOT; }
Eric Anholt6c98c8d2006-08-22 11:54:19 -07001602;
Eric Anholt22a10632006-08-22 10:15:33 -07001603
1604%%
1605extern int yylineno;
Keith Packard2d4d4012008-03-30 00:58:28 -07001606extern char *input_filename;
1607
1608int errors;
Eric Anholt22a10632006-08-22 10:15:33 -07001609
1610void yyerror (char *msg)
1611{
Keith Packard2d4d4012008-03-30 00:58:28 -07001612 fprintf(stderr, "%s: %d: %s at \"%s\"\n",
1613 input_filename, yylineno, msg, lex_text());
1614 ++errors;
Eric Anholt22a10632006-08-22 10:15:33 -07001615}
1616
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001617/**
1618 * Fills in the destination register information in instr from the bits in dst.
1619 */
Eric Anholt2dac0a12006-08-29 15:29:31 -07001620int set_instruction_dest(struct brw_instruction *instr,
1621 struct dst_operand *dest)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001622{
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001623 if (dest->address_mode == BRW_ADDRESS_DIRECT &&
1624 instr->header.access_mode == BRW_ALIGN_1) {
Eric Anholt2dac0a12006-08-29 15:29:31 -07001625 instr->bits1.da1.dest_reg_file = dest->reg_file;
1626 instr->bits1.da1.dest_reg_type = dest->reg_type;
1627 instr->bits1.da1.dest_subreg_nr = dest->subreg_nr;
1628 instr->bits1.da1.dest_reg_nr = dest->reg_nr;
1629 instr->bits1.da1.dest_horiz_stride = dest->horiz_stride;
1630 instr->bits1.da1.dest_address_mode = dest->address_mode;
1631 if (dest->writemask_set) {
1632 fprintf(stderr, "error: write mask set in align1 "
1633 "instruction\n");
1634 return 1;
1635 }
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001636 } else if (dest->address_mode == BRW_ADDRESS_DIRECT) {
Eric Anholt2dac0a12006-08-29 15:29:31 -07001637 instr->bits1.da16.dest_reg_file = dest->reg_file;
1638 instr->bits1.da16.dest_reg_type = dest->reg_type;
1639 instr->bits1.da16.dest_subreg_nr = dest->subreg_nr;
1640 instr->bits1.da16.dest_reg_nr = dest->reg_nr;
1641 instr->bits1.da16.dest_address_mode = dest->address_mode;
1642 instr->bits1.da16.dest_writemask = dest->writemask;
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001643 } else if (instr->header.access_mode == BRW_ALIGN_1) {
1644 instr->bits1.ia1.dest_reg_file = dest->reg_file;
1645 instr->bits1.ia1.dest_reg_type = dest->reg_type;
1646 instr->bits1.ia1.dest_subreg_nr = dest->address_subreg_nr;
1647 instr->bits1.ia1.dest_horiz_stride = dest->horiz_stride;
1648 instr->bits1.ia1.dest_indirect_offset = dest->indirect_offset;
1649 instr->bits1.ia1.dest_address_mode = dest->address_mode;
1650 if (dest->writemask_set) {
1651 fprintf(stderr, "error: write mask set in align1 "
1652 "instruction\n");
1653 return 1;
1654 }
1655 } else {
1656 instr->bits1.ia16.dest_reg_file = dest->reg_file;
1657 instr->bits1.ia16.dest_reg_type = dest->reg_type;
1658 instr->bits1.ia16.dest_subreg_nr = dest->address_subreg_nr;
1659 instr->bits1.ia16.dest_writemask = dest->writemask;
1660 instr->bits1.ia16.dest_indirect_offset = dest->indirect_offset;
1661 instr->bits1.ia16.dest_address_mode = dest->address_mode;
Eric Anholt2dac0a12006-08-29 15:29:31 -07001662 }
1663
1664 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001665}
1666
Eric Anholt6a88ada2006-08-28 22:11:18 -07001667/* Sets the first source operand for the instruction. Returns 0 on success. */
1668int set_instruction_src0(struct brw_instruction *instr,
1669 struct src_operand *src)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001670{
Eric Anholt6a88ada2006-08-28 22:11:18 -07001671 instr->bits1.da1.src0_reg_file = src->reg_file;
1672 instr->bits1.da1.src0_reg_type = src->reg_type;
1673 if (src->reg_file == BRW_IMMEDIATE_VALUE) {
1674 instr->bits3.ud = src->imm32;
1675 } else if (instr->header.access_mode == BRW_ALIGN_1) {
1676 instr->bits2.da1.src0_subreg_nr = src->subreg_nr;
1677 instr->bits2.da1.src0_reg_nr = src->reg_nr;
1678 instr->bits2.da1.src0_vert_stride = src->vert_stride;
1679 instr->bits2.da1.src0_width = src->width;
1680 instr->bits2.da1.src0_horiz_stride = src->horiz_stride;
1681 instr->bits2.da1.src0_negate = src->negate;
1682 instr->bits2.da1.src0_abs = src->abs;
1683 instr->bits2.da1.src0_address_mode = src->address_mode;
1684 if (src->swizzle_set) {
1685 fprintf(stderr, "error: swizzle bits set in align1 "
1686 "instruction\n");
1687 return 1;
1688 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001689 } else {
Eric Anholt6a88ada2006-08-28 22:11:18 -07001690 instr->bits2.da16.src0_subreg_nr = src->subreg_nr;
1691 instr->bits2.da16.src0_reg_nr = src->reg_nr;
1692 instr->bits2.da16.src0_vert_stride = src->vert_stride;
1693 instr->bits2.da16.src0_negate = src->negate;
1694 instr->bits2.da16.src0_abs = src->abs;
1695 instr->bits2.da16.src0_swz_x = src->swizzle_x;
1696 instr->bits2.da16.src0_swz_y = src->swizzle_y;
1697 instr->bits2.da16.src0_swz_z = src->swizzle_z;
1698 instr->bits2.da16.src0_swz_w = src->swizzle_w;
1699 instr->bits2.da16.src0_address_mode = src->address_mode;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001700 }
Eric Anholt6a88ada2006-08-28 22:11:18 -07001701
1702 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001703}
1704
Eric Anholt6a88ada2006-08-28 22:11:18 -07001705/* Sets the second source operand for the instruction. Returns 0 on success.
1706 */
1707int set_instruction_src1(struct brw_instruction *instr,
1708 struct src_operand *src)
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001709{
Eric Anholt6a88ada2006-08-28 22:11:18 -07001710 instr->bits1.da1.src1_reg_file = src->reg_file;
1711 instr->bits1.da1.src1_reg_type = src->reg_type;
1712 if (src->reg_file == BRW_IMMEDIATE_VALUE) {
1713 instr->bits3.ud = src->imm32;
1714 } else if (instr->header.access_mode == BRW_ALIGN_1) {
1715 instr->bits3.da1.src1_subreg_nr = src->subreg_nr;
1716 instr->bits3.da1.src1_reg_nr = src->reg_nr;
1717 instr->bits3.da1.src1_vert_stride = src->vert_stride;
1718 instr->bits3.da1.src1_width = src->width;
1719 instr->bits3.da1.src1_horiz_stride = src->horiz_stride;
1720 instr->bits3.da1.src1_negate = src->negate;
1721 instr->bits3.da1.src1_abs = src->abs;
1722 if (src->address_mode != BRW_ADDRESS_DIRECT) {
1723 fprintf(stderr, "error: swizzle bits set in align1 "
1724 "instruction\n");
1725 return 1;
1726 }
1727 if (src->swizzle_set) {
1728 fprintf(stderr, "error: swizzle bits set in align1 "
1729 "instruction\n");
1730 return 1;
1731 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001732 } else {
Eric Anholt6a88ada2006-08-28 22:11:18 -07001733 instr->bits3.da16.src1_subreg_nr = src->subreg_nr;
1734 instr->bits3.da16.src1_reg_nr = src->reg_nr;
1735 instr->bits3.da16.src1_vert_stride = src->vert_stride;
1736 instr->bits3.da16.src1_negate = src->negate;
1737 instr->bits3.da16.src1_abs = src->abs;
1738 instr->bits3.da16.src1_swz_x = src->swizzle_x;
1739 instr->bits3.da16.src1_swz_y = src->swizzle_y;
1740 instr->bits3.da16.src1_swz_z = src->swizzle_z;
1741 instr->bits3.da16.src1_swz_w = src->swizzle_w;
1742 if (src->address_mode != BRW_ADDRESS_DIRECT) {
1743 fprintf(stderr, "error: swizzle bits set in align1 "
1744 "instruction\n");
1745 return 1;
1746 }
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001747 }
Eric Anholt6a88ada2006-08-28 22:11:18 -07001748
1749 return 0;
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001750}
1751
1752void set_instruction_options(struct brw_instruction *instr,
1753 struct brw_instruction *options)
1754{
Eric Anholt6a88ada2006-08-28 22:11:18 -07001755 /* XXX: more instr options */
Eric Anholt19f1c1c2006-08-22 12:41:09 -07001756 instr->header.access_mode = options->header.access_mode;
1757 instr->header.mask_control = options->header.mask_control;
1758 instr->header.dependency_control = options->header.dependency_control;
1759 instr->header.compression_control =
1760 options->header.compression_control;
1761}
Eric Anholt2c787652006-08-25 13:53:48 -07001762
Eric Anholt0ed5d932006-08-28 23:05:51 -07001763void set_instruction_predicate(struct brw_instruction *instr,
1764 struct brw_instruction *predicate)
1765{
1766 instr->header.predicate_control = predicate->header.predicate_control;
1767 instr->header.predicate_inverse = predicate->header.predicate_inverse;
1768 instr->bits2.da1.flag_reg_nr = predicate->bits2.da1.flag_reg_nr;
1769}
1770
Eric Anholt1e907c72006-08-31 10:21:15 -07001771void set_direct_dst_operand(struct dst_operand *dst, struct direct_reg *reg,
1772 int type)
1773{
1774 bzero(dst, sizeof(*dst));
1775 dst->address_mode = BRW_ADDRESS_DIRECT;
1776 dst->reg_file = reg->reg_file;
1777 dst->reg_nr = reg->reg_nr;
1778 dst->subreg_nr = reg->subreg_nr;
1779 dst->reg_type = type;
1780 dst->horiz_stride = 1;
1781 dst->writemask_set = 0;
1782 dst->writemask = 0xf;
1783}
1784
Eric Anholt3bcf6b22006-08-29 18:31:34 -07001785void set_direct_src_operand(struct src_operand *src, struct direct_reg *reg,
1786 int type)
Eric Anholt2c787652006-08-25 13:53:48 -07001787{
Eric Anholt6a88ada2006-08-28 22:11:18 -07001788 bzero(src, sizeof(*src));
Eric Anholt1e907c72006-08-31 10:21:15 -07001789 src->address_mode = BRW_ADDRESS_DIRECT;
Eric Anholt6a88ada2006-08-28 22:11:18 -07001790 src->reg_file = reg->reg_file;
1791 src->reg_type = type;
1792 src->subreg_nr = reg->subreg_nr;
1793 src->reg_nr = reg->reg_nr;
1794 src->vert_stride = 0;
1795 src->width = 0;
Keith Packard2033aea2008-04-23 23:10:40 -07001796 src->horiz_stride = 0;
Eric Anholt6a88ada2006-08-28 22:11:18 -07001797 src->negate = 0;
1798 src->abs = 0;
Eric Anholt1e907c72006-08-31 10:21:15 -07001799 src->swizzle_set = 0;
1800 src->swizzle_x = BRW_CHANNEL_X;
1801 src->swizzle_y = BRW_CHANNEL_Y;
1802 src->swizzle_z = BRW_CHANNEL_Z;
1803 src->swizzle_w = BRW_CHANNEL_W;
Eric Anholt2c787652006-08-25 13:53:48 -07001804}