i965: Move next_offset() to brw_eu.h for use elsewhere.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_eu.h
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32
33 #ifndef BRW_EU_H
34 #define BRW_EU_H
35
36 #include <stdbool.h>
37 #include "brw_structs.h"
38 #include "brw_defines.h"
39 #include "brw_reg.h"
40 #include "intel_asm_printer.h"
41 #include "program/prog_instruction.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #define BRW_EU_MAX_INSN_STACK 5
48
49 struct brw_compile {
50 struct brw_instruction *store;
51 int store_size;
52 unsigned nr_insn;
53 unsigned int next_insn_offset;
54
55 void *mem_ctx;
56
57 /* Allow clients to push/pop instruction state:
58 */
59 struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
60 bool compressed_stack[BRW_EU_MAX_INSN_STACK];
61 struct brw_instruction *current;
62
63 unsigned flag_value;
64 bool single_program_flow;
65 bool compressed;
66 struct brw_context *brw;
67
68 /* Control flow stacks:
69 * - if_stack contains IF and ELSE instructions which must be patched
70 * (and popped) once the matching ENDIF instruction is encountered.
71 *
72 * Just store the instruction pointer(an index).
73 */
74 int *if_stack;
75 int if_stack_depth;
76 int if_stack_array_size;
77
78 /**
79 * loop_stack contains the instruction pointers of the starts of loops which
80 * must be patched (and popped) once the matching WHILE instruction is
81 * encountered.
82 */
83 int *loop_stack;
84 /**
85 * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
86 * blocks they were popping out of, to fix up the mask stack. This tracks
87 * the IF/ENDIF nesting in each current nested loop level.
88 */
89 int *if_depth_in_loop;
90 int loop_stack_depth;
91 int loop_stack_array_size;
92 };
93
94 void brw_pop_insn_state( struct brw_compile *p );
95 void brw_push_insn_state( struct brw_compile *p );
96 void brw_set_mask_control( struct brw_compile *p, unsigned value );
97 void brw_set_saturate( struct brw_compile *p, bool enable );
98 void brw_set_access_mode( struct brw_compile *p, unsigned access_mode );
99 void brw_set_compression_control(struct brw_compile *p, enum brw_compression c);
100 void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value );
101 void brw_set_predicate_control( struct brw_compile *p, unsigned pc );
102 void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
103 void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional );
104 void brw_set_flag_reg(struct brw_compile *p, int reg, int subreg);
105 void brw_set_acc_write_control(struct brw_compile *p, unsigned value);
106
107 void brw_init_compile(struct brw_context *, struct brw_compile *p,
108 void *mem_ctx);
109 void brw_disassemble(struct brw_context *brw, void *assembly,
110 int start, int end, FILE *out);
111 const unsigned *brw_get_program( struct brw_compile *p, unsigned *sz );
112
113 struct brw_instruction *brw_next_insn(struct brw_compile *p, unsigned opcode);
114 void brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
115 struct brw_reg dest);
116 void brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
117 struct brw_reg reg);
118
119 void gen6_resolve_implied_move(struct brw_compile *p,
120 struct brw_reg *src,
121 unsigned msg_reg_nr);
122
123 /* Helpers for regular instructions:
124 */
125 #define ALU1(OP) \
126 struct brw_instruction *brw_##OP(struct brw_compile *p, \
127 struct brw_reg dest, \
128 struct brw_reg src0);
129
130 #define ALU2(OP) \
131 struct brw_instruction *brw_##OP(struct brw_compile *p, \
132 struct brw_reg dest, \
133 struct brw_reg src0, \
134 struct brw_reg src1);
135
136 #define ALU3(OP) \
137 struct brw_instruction *brw_##OP(struct brw_compile *p, \
138 struct brw_reg dest, \
139 struct brw_reg src0, \
140 struct brw_reg src1, \
141 struct brw_reg src2);
142
143 #define ROUND(OP) \
144 void brw_##OP(struct brw_compile *p, struct brw_reg dest, struct brw_reg src0);
145
146 ALU1(MOV)
147 ALU2(SEL)
148 ALU1(NOT)
149 ALU2(AND)
150 ALU2(OR)
151 ALU2(XOR)
152 ALU2(SHR)
153 ALU2(SHL)
154 ALU2(ASR)
155 ALU1(F32TO16)
156 ALU1(F16TO32)
157 ALU2(JMPI)
158 ALU2(ADD)
159 ALU2(AVG)
160 ALU2(MUL)
161 ALU1(FRC)
162 ALU1(RNDD)
163 ALU2(MAC)
164 ALU2(MACH)
165 ALU1(LZD)
166 ALU2(DP4)
167 ALU2(DPH)
168 ALU2(DP3)
169 ALU2(DP2)
170 ALU2(LINE)
171 ALU2(PLN)
172 ALU3(MAD)
173 ALU3(LRP)
174 ALU1(BFREV)
175 ALU3(BFE)
176 ALU2(BFI1)
177 ALU3(BFI2)
178 ALU1(FBH)
179 ALU1(FBL)
180 ALU1(CBIT)
181 ALU2(ADDC)
182 ALU2(SUBB)
183 ALU2(MAC)
184
185 ROUND(RNDZ)
186 ROUND(RNDE)
187
188 #undef ALU1
189 #undef ALU2
190 #undef ALU3
191 #undef ROUND
192
193
194 /* Helpers for SEND instruction:
195 */
196 void brw_set_sampler_message(struct brw_compile *p,
197 struct brw_instruction *insn,
198 unsigned binding_table_index,
199 unsigned sampler,
200 unsigned msg_type,
201 unsigned response_length,
202 unsigned msg_length,
203 unsigned header_present,
204 unsigned simd_mode,
205 unsigned return_format);
206
207 void brw_set_dp_read_message(struct brw_compile *p,
208 struct brw_instruction *insn,
209 unsigned binding_table_index,
210 unsigned msg_control,
211 unsigned msg_type,
212 unsigned target_cache,
213 unsigned msg_length,
214 bool header_present,
215 unsigned response_length);
216
217 void brw_set_dp_write_message(struct brw_compile *p,
218 struct brw_instruction *insn,
219 unsigned binding_table_index,
220 unsigned msg_control,
221 unsigned msg_type,
222 unsigned msg_length,
223 bool header_present,
224 unsigned last_render_target,
225 unsigned response_length,
226 unsigned end_of_thread,
227 unsigned send_commit_msg);
228
229 void brw_urb_WRITE(struct brw_compile *p,
230 struct brw_reg dest,
231 unsigned msg_reg_nr,
232 struct brw_reg src0,
233 enum brw_urb_write_flags flags,
234 unsigned msg_length,
235 unsigned response_length,
236 unsigned offset,
237 unsigned swizzle);
238
239 void brw_ff_sync(struct brw_compile *p,
240 struct brw_reg dest,
241 unsigned msg_reg_nr,
242 struct brw_reg src0,
243 bool allocate,
244 unsigned response_length,
245 bool eot);
246
247 void brw_svb_write(struct brw_compile *p,
248 struct brw_reg dest,
249 unsigned msg_reg_nr,
250 struct brw_reg src0,
251 unsigned binding_table_index,
252 bool send_commit_msg);
253
254 void brw_fb_WRITE(struct brw_compile *p,
255 int dispatch_width,
256 unsigned msg_reg_nr,
257 struct brw_reg src0,
258 unsigned msg_control,
259 unsigned binding_table_index,
260 unsigned msg_length,
261 unsigned response_length,
262 bool eot,
263 bool header_present);
264
265 void brw_SAMPLE(struct brw_compile *p,
266 struct brw_reg dest,
267 unsigned msg_reg_nr,
268 struct brw_reg src0,
269 unsigned binding_table_index,
270 unsigned sampler,
271 unsigned msg_type,
272 unsigned response_length,
273 unsigned msg_length,
274 unsigned header_present,
275 unsigned simd_mode,
276 unsigned return_format);
277
278 void brw_math( struct brw_compile *p,
279 struct brw_reg dest,
280 unsigned function,
281 unsigned msg_reg_nr,
282 struct brw_reg src,
283 unsigned data_type,
284 unsigned precision );
285
286 void brw_math2(struct brw_compile *p,
287 struct brw_reg dest,
288 unsigned function,
289 struct brw_reg src0,
290 struct brw_reg src1);
291
292 void brw_oword_block_read(struct brw_compile *p,
293 struct brw_reg dest,
294 struct brw_reg mrf,
295 uint32_t offset,
296 uint32_t bind_table_index);
297
298 void brw_oword_block_read_scratch(struct brw_compile *p,
299 struct brw_reg dest,
300 struct brw_reg mrf,
301 int num_regs,
302 unsigned offset);
303
304 void brw_oword_block_write_scratch(struct brw_compile *p,
305 struct brw_reg mrf,
306 int num_regs,
307 unsigned offset);
308
309 void gen7_block_read_scratch(struct brw_compile *p,
310 struct brw_reg dest,
311 int num_regs,
312 unsigned offset);
313
314 void brw_shader_time_add(struct brw_compile *p,
315 struct brw_reg payload,
316 uint32_t surf_index);
317
318 /* If/else/endif. Works by manipulating the execution flags on each
319 * channel.
320 */
321 struct brw_instruction *brw_IF(struct brw_compile *p,
322 unsigned execute_size);
323 struct brw_instruction *gen6_IF(struct brw_compile *p, uint32_t conditional,
324 struct brw_reg src0, struct brw_reg src1);
325
326 void brw_ELSE(struct brw_compile *p);
327 void brw_ENDIF(struct brw_compile *p);
328
329 /* DO/WHILE loops:
330 */
331 struct brw_instruction *brw_DO(struct brw_compile *p,
332 unsigned execute_size);
333
334 struct brw_instruction *brw_WHILE(struct brw_compile *p);
335
336 struct brw_instruction *brw_BREAK(struct brw_compile *p);
337 struct brw_instruction *brw_CONT(struct brw_compile *p);
338 struct brw_instruction *gen6_CONT(struct brw_compile *p);
339 struct brw_instruction *gen6_HALT(struct brw_compile *p);
340 /* Forward jumps:
341 */
342 void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx);
343
344
345
346 void brw_NOP(struct brw_compile *p);
347
348 void brw_WAIT(struct brw_compile *p);
349
350 /* Special case: there is never a destination, execution size will be
351 * taken from src0:
352 */
353 void brw_CMP(struct brw_compile *p,
354 struct brw_reg dest,
355 unsigned conditional,
356 struct brw_reg src0,
357 struct brw_reg src1);
358
359 void
360 brw_untyped_atomic(struct brw_compile *p,
361 struct brw_reg dest,
362 struct brw_reg mrf,
363 unsigned atomic_op,
364 unsigned bind_table_index,
365 unsigned msg_length,
366 unsigned response_length);
367
368 void
369 brw_untyped_surface_read(struct brw_compile *p,
370 struct brw_reg dest,
371 struct brw_reg mrf,
372 unsigned bind_table_index,
373 unsigned msg_length,
374 unsigned response_length);
375
376 /***********************************************************************
377 * brw_eu_util.c:
378 */
379
380 void brw_copy_indirect_to_indirect(struct brw_compile *p,
381 struct brw_indirect dst_ptr,
382 struct brw_indirect src_ptr,
383 unsigned count);
384
385 void brw_copy_from_indirect(struct brw_compile *p,
386 struct brw_reg dst,
387 struct brw_indirect ptr,
388 unsigned count);
389
390 void brw_copy4(struct brw_compile *p,
391 struct brw_reg dst,
392 struct brw_reg src,
393 unsigned count);
394
395 void brw_copy8(struct brw_compile *p,
396 struct brw_reg dst,
397 struct brw_reg src,
398 unsigned count);
399
400 void brw_math_invert( struct brw_compile *p,
401 struct brw_reg dst,
402 struct brw_reg src);
403
404 void brw_set_src1(struct brw_compile *p,
405 struct brw_instruction *insn,
406 struct brw_reg reg);
407
408 void brw_set_uip_jip(struct brw_compile *p);
409
410 uint32_t brw_swap_cmod(uint32_t cmod);
411
412 /* brw_eu_compact.c */
413 void brw_init_compaction_tables(struct brw_context *brw);
414 void brw_compact_instructions(struct brw_compile *p, int start_offset,
415 int num_annotations, struct annotation *annotation);
416 void brw_uncompact_instruction(struct brw_context *brw,
417 struct brw_instruction *dst,
418 struct brw_compact_instruction *src);
419 bool brw_try_compact_instruction(struct brw_compile *p,
420 struct brw_compact_instruction *dst,
421 struct brw_instruction *src);
422
423 void brw_debug_compact_uncompact(struct brw_context *brw,
424 struct brw_instruction *orig,
425 struct brw_instruction *uncompacted);
426
427 static inline int
428 next_offset(void *store, int offset)
429 {
430 struct brw_instruction *insn =
431 (struct brw_instruction *)((char *)store + offset);
432
433 if (insn->header.cmpt_control)
434 return offset + 8;
435 else
436 return offset + 16;
437 }
438
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #endif