tests: remove unused getopt header includes
[platform/upstream/intel-gpu-tools.git] / assembler / brw_eu.h
1 /*
2  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) 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 <keith@tungstengraphics.com>
30   */
31
32
33 #ifndef BRW_EU_H
34 #define BRW_EU_H
35
36 #include <stdbool.h>
37 #include <stdio.h>
38 #include "brw_context.h"
39 #include "brw_structs.h"
40 #include "brw_defines.h"
41 #include "brw_reg.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 static inline struct brw_instruction *current_insn( struct brw_compile *p)
95 {
96    return &p->store[p->nr_insn];
97 }
98
99 void brw_pop_insn_state( struct brw_compile *p );
100 void brw_push_insn_state( struct brw_compile *p );
101 void brw_set_mask_control( struct brw_compile *p, unsigned value );
102 void brw_set_saturate( struct brw_compile *p, bool enable );
103 void brw_set_access_mode( struct brw_compile *p, unsigned access_mode );
104 void brw_set_compression_control(struct brw_compile *p, enum brw_compression c);
105 void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value );
106 void brw_set_predicate_control( struct brw_compile *p, unsigned pc );
107 void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
108 void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional );
109 void brw_set_flag_reg(struct brw_compile *p, int reg, int subreg);
110 void brw_set_acc_write_control(struct brw_compile *p, unsigned value);
111
112 void brw_init_compile(struct brw_context *, struct brw_compile *p,
113                       void *mem_ctx);
114 void brw_dump_compile(struct brw_compile *p, FILE *out, int start, int end);
115 const unsigned *brw_get_program( struct brw_compile *p, unsigned *sz );
116
117 struct brw_instruction *brw_next_insn(struct brw_compile *p, unsigned opcode);
118 void brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
119                   struct brw_reg dest);
120 void brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
121                   struct brw_reg reg);
122
123 void gen6_resolve_implied_move(struct brw_compile *p,
124                                struct brw_reg *src,
125                                unsigned msg_reg_nr);
126
127 /* Helpers for regular instructions:
128  */
129 #define ALU1(OP)                                        \
130 struct brw_instruction *brw_##OP(struct brw_compile *p, \
131               struct brw_reg dest,                      \
132               struct brw_reg src0);
133
134 #define ALU2(OP)                                        \
135 struct brw_instruction *brw_##OP(struct brw_compile *p, \
136               struct brw_reg dest,                      \
137               struct brw_reg src0,                      \
138               struct brw_reg src1);
139
140 #define ALU3(OP)                                        \
141 struct brw_instruction *brw_##OP(struct brw_compile *p, \
142               struct brw_reg dest,                      \
143               struct brw_reg src0,                      \
144               struct brw_reg src1,                      \
145               struct brw_reg src2);
146
147 #define ROUND(OP) \
148 void brw_##OP(struct brw_compile *p, struct brw_reg dest, struct brw_reg src0);
149
150 ALU1(MOV)
151 ALU2(SEL)
152 ALU1(NOT)
153 ALU2(AND)
154 ALU2(OR)
155 ALU2(XOR)
156 ALU2(SHR)
157 ALU2(SHL)
158 ALU2(RSR)
159 ALU2(RSL)
160 ALU2(ASR)
161 ALU2(JMPI)
162 ALU2(ADD)
163 ALU2(AVG)
164 ALU2(MUL)
165 ALU1(FRC)
166 ALU1(RNDD)
167 ALU2(MAC)
168 ALU2(MACH)
169 ALU1(LZD)
170 ALU2(DP4)
171 ALU2(DPH)
172 ALU2(DP3)
173 ALU2(DP2)
174 ALU2(LINE)
175 ALU2(PLN)
176 ALU3(MAD)
177
178 ROUND(RNDZ)
179 ROUND(RNDE)
180
181 #undef ALU1
182 #undef ALU2
183 #undef ALU3
184 #undef ROUND
185
186
187 /* Helpers for SEND instruction:
188  */
189 void brw_set_sampler_message(struct brw_compile *p,
190                              struct brw_instruction *insn,
191                              unsigned binding_table_index,
192                              unsigned sampler,
193                              unsigned msg_type,
194                              unsigned response_length,
195                              unsigned msg_length,
196                              unsigned header_present,
197                              unsigned simd_mode,
198                              unsigned return_format);
199
200 void brw_set_dp_read_message(struct brw_compile *p,
201                              struct brw_instruction *insn,
202                              unsigned binding_table_index,
203                              unsigned msg_control,
204                              unsigned msg_type,
205                              unsigned target_cache,
206                              unsigned msg_length,
207                              bool header_present,
208                              unsigned response_length);
209
210 void brw_set_dp_write_message(struct brw_compile *p,
211                               struct brw_instruction *insn,
212                               unsigned binding_table_index,
213                               unsigned msg_control,
214                               unsigned msg_type,
215                               unsigned msg_length,
216                               bool header_present,
217                               unsigned last_render_target,
218                               unsigned response_length,
219                               unsigned end_of_thread,
220                               unsigned send_commit_msg);
221
222 void brw_urb_WRITE(struct brw_compile *p,
223                    struct brw_reg dest,
224                    unsigned msg_reg_nr,
225                    struct brw_reg src0,
226                    bool allocate,
227                    bool used,
228                    unsigned msg_length,
229                    unsigned response_length,
230                    bool eot,
231                    bool writes_complete,
232                    unsigned offset,
233                    unsigned swizzle);
234
235 void brw_ff_sync(struct brw_compile *p,
236                    struct brw_reg dest,
237                    unsigned msg_reg_nr,
238                    struct brw_reg src0,
239                    bool allocate,
240                    unsigned response_length,
241                    bool eot);
242
243 void brw_svb_write(struct brw_compile *p,
244                    struct brw_reg dest,
245                    unsigned msg_reg_nr,
246                    struct brw_reg src0,
247                    unsigned binding_table_index,
248                    bool   send_commit_msg);
249
250 void brw_fb_WRITE(struct brw_compile *p,
251                   int dispatch_width,
252                    unsigned msg_reg_nr,
253                    struct brw_reg src0,
254                    unsigned msg_control,
255                    unsigned binding_table_index,
256                    unsigned msg_length,
257                    unsigned response_length,
258                    bool eot,
259                    bool header_present);
260
261 void brw_SAMPLE(struct brw_compile *p,
262                 struct brw_reg dest,
263                 unsigned msg_reg_nr,
264                 struct brw_reg src0,
265                 unsigned binding_table_index,
266                 unsigned sampler,
267                 unsigned writemask,
268                 unsigned msg_type,
269                 unsigned response_length,
270                 unsigned msg_length,
271                 unsigned header_present,
272                 unsigned simd_mode,
273                 unsigned return_format);
274
275 void brw_math( struct brw_compile *p,
276                struct brw_reg dest,
277                unsigned function,
278                unsigned msg_reg_nr,
279                struct brw_reg src,
280                unsigned data_type,
281                unsigned precision );
282
283 void brw_math2(struct brw_compile *p,
284                struct brw_reg dest,
285                unsigned function,
286                struct brw_reg src0,
287                struct brw_reg src1);
288
289 void brw_oword_block_read(struct brw_compile *p,
290                           struct brw_reg dest,
291                           struct brw_reg mrf,
292                           uint32_t offset,
293                           uint32_t bind_table_index);
294
295 void brw_oword_block_read_scratch(struct brw_compile *p,
296                                   struct brw_reg dest,
297                                   struct brw_reg mrf,
298                                   int num_regs,
299                                   unsigned offset);
300
301 void brw_oword_block_write_scratch(struct brw_compile *p,
302                                    struct brw_reg mrf,
303                                    int num_regs,
304                                    unsigned offset);
305
306 void brw_shader_time_add(struct brw_compile *p,
307                          int mrf,
308                          uint32_t surf_index);
309
310 /* If/else/endif.  Works by manipulating the execution flags on each
311  * channel.
312  */
313 struct brw_instruction *brw_IF(struct brw_compile *p,
314                                unsigned execute_size);
315 struct brw_instruction *gen6_IF(struct brw_compile *p, uint32_t conditional,
316                                 struct brw_reg src0, struct brw_reg src1);
317
318 void brw_ELSE(struct brw_compile *p);
319 void brw_ENDIF(struct brw_compile *p);
320
321 /* DO/WHILE loops:
322  */
323 struct brw_instruction *brw_DO(struct brw_compile *p,
324                                unsigned execute_size);
325
326 struct brw_instruction *brw_WHILE(struct brw_compile *p);
327
328 struct brw_instruction *brw_BREAK(struct brw_compile *p);
329 struct brw_instruction *brw_CONT(struct brw_compile *p);
330 struct brw_instruction *gen6_CONT(struct brw_compile *p);
331 struct brw_instruction *gen6_HALT(struct brw_compile *p);
332 /* Forward jumps:
333  */
334 void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx);
335
336
337
338 void brw_NOP(struct brw_compile *p);
339
340 void brw_WAIT(struct brw_compile *p);
341
342 /* Special case: there is never a destination, execution size will be
343  * taken from src0:
344  */
345 void brw_CMP(struct brw_compile *p,
346              struct brw_reg dest,
347              unsigned conditional,
348              struct brw_reg src0,
349              struct brw_reg src1);
350
351 /***********************************************************************
352  * brw_eu_util.c:
353  */
354
355 void brw_copy_indirect_to_indirect(struct brw_compile *p,
356                                    struct brw_indirect dst_ptr,
357                                    struct brw_indirect src_ptr,
358                                    unsigned count);
359
360 void brw_copy_from_indirect(struct brw_compile *p,
361                             struct brw_reg dst,
362                             struct brw_indirect ptr,
363                             unsigned count);
364
365 void brw_copy4(struct brw_compile *p,
366                struct brw_reg dst,
367                struct brw_reg src,
368                unsigned count);
369
370 void brw_copy8(struct brw_compile *p,
371                struct brw_reg dst,
372                struct brw_reg src,
373                unsigned count);
374
375 void brw_math_invert( struct brw_compile *p,
376                       struct brw_reg dst,
377                       struct brw_reg src);
378
379 void brw_set_src1(struct brw_compile *p,
380                   struct brw_instruction *insn,
381                   struct brw_reg reg);
382
383 void brw_set_uip_jip(struct brw_compile *p);
384
385 uint32_t brw_swap_cmod(uint32_t cmod);
386
387 void
388 brw_set_3src_dest(struct brw_compile *p,
389                   struct brw_instruction *insn,
390                   struct brw_reg dest);
391 void
392 brw_set_3src_src0(struct brw_compile *p,
393                   struct brw_instruction *insn,
394                   struct brw_reg src0);
395 void
396 brw_set_3src_src1(struct brw_compile *p,
397                   struct brw_instruction *insn,
398                   struct brw_reg src1);
399 void
400 brw_set_3src_src2(struct brw_compile *p,
401                   struct brw_instruction *insn,
402                   struct brw_reg src2);
403
404 /* brw_eu_compact.c */
405 void brw_init_compaction_tables(struct intel_context *intel);
406 void brw_compact_instructions(struct brw_compile *p);
407 void brw_uncompact_instruction(struct intel_context *intel,
408                                struct brw_instruction *dst,
409                                struct brw_compact_instruction *src);
410 bool brw_try_compact_instruction(struct brw_compile *p,
411                                  struct brw_compact_instruction *dst,
412                                  struct brw_instruction *src);
413
414 void brw_debug_compact_uncompact(struct intel_context *intel,
415                                  struct brw_instruction *orig,
416                                  struct brw_instruction *uncompacted);
417
418 /* brw_optimize.c */
419 void brw_optimize(struct brw_compile *p);
420 void brw_remove_duplicate_mrf_moves(struct brw_compile *p);
421 void brw_remove_grf_to_mrf_moves(struct brw_compile *p);
422
423 #ifdef __cplusplus
424 }
425 #endif
426
427 #endif