assembler: Import brw_eu_compact.c
[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 "gen4asm.h"
39 #include "brw_context.h"
40 #include "brw_structs.h"
41 #include "brw_defines.h"
42 #include "brw_reg.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #define BRW_EU_MAX_INSN_STACK 5
49
50 struct brw_compile {
51    struct brw_instruction *store;
52    int store_size;
53    GLuint nr_insn;
54    unsigned int next_insn_offset;
55
56    void *mem_ctx;
57
58    /* Allow clients to push/pop instruction state:
59     */
60    struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
61    bool compressed_stack[BRW_EU_MAX_INSN_STACK];
62    struct brw_instruction *current;
63
64    GLuint flag_value;
65    bool single_program_flow;
66    bool compressed;
67    struct brw_context *brw;
68
69    /* Control flow stacks:
70     * - if_stack contains IF and ELSE instructions which must be patched
71     *   (and popped) once the matching ENDIF instruction is encountered.
72     *
73     *   Just store the instruction pointer(an index).
74     */
75    int *if_stack;
76    int if_stack_depth;
77    int if_stack_array_size;
78
79    /**
80     * loop_stack contains the instruction pointers of the starts of loops which
81     * must be patched (and popped) once the matching WHILE instruction is
82     * encountered.
83     */
84    int *loop_stack;
85    /**
86     * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
87     * blocks they were popping out of, to fix up the mask stack.  This tracks
88     * the IF/ENDIF nesting in each current nested loop level.
89     */
90    int *if_depth_in_loop;
91    int loop_stack_depth;
92    int loop_stack_array_size;
93 };
94
95 static inline struct brw_instruction *current_insn( struct brw_compile *p)
96 {
97    return &p->store[p->nr_insn];
98 }
99
100 void brw_pop_insn_state( struct brw_compile *p );
101 void brw_push_insn_state( struct brw_compile *p );
102 void brw_set_mask_control( struct brw_compile *p, GLuint value );
103 void brw_set_saturate( struct brw_compile *p, bool enable );
104 void brw_set_access_mode( struct brw_compile *p, GLuint access_mode );
105 void brw_set_compression_control(struct brw_compile *p, enum brw_compression c);
106 void brw_set_predicate_control_flag_value( struct brw_compile *p, GLuint value );
107 void brw_set_predicate_control( struct brw_compile *p, GLuint pc );
108 void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
109 void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional );
110 void brw_set_flag_reg(struct brw_compile *p, int reg, int subreg);
111 void brw_set_acc_write_control(struct brw_compile *p, GLuint value);
112
113 void brw_init_compile(struct brw_context *, struct brw_compile *p,
114                       void *mem_ctx);
115 void brw_dump_compile(struct brw_compile *p, FILE *out, int start, int end);
116 const GLuint *brw_get_program( struct brw_compile *p, GLuint *sz );
117
118 struct brw_instruction *brw_next_insn(struct brw_compile *p, GLuint opcode);
119 void brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
120                   struct brw_reg dest);
121 void brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
122                   struct brw_reg reg);
123
124 void gen6_resolve_implied_move(struct brw_compile *p,
125                                struct brw_reg *src,
126                                GLuint msg_reg_nr);
127
128 /* Helpers for regular instructions:
129  */
130 #define ALU1(OP)                                        \
131 struct brw_instruction *brw_##OP(struct brw_compile *p, \
132               struct brw_reg dest,                      \
133               struct brw_reg src0);
134
135 #define ALU2(OP)                                        \
136 struct brw_instruction *brw_##OP(struct brw_compile *p, \
137               struct brw_reg dest,                      \
138               struct brw_reg src0,                      \
139               struct brw_reg src1);
140
141 #define ALU3(OP)                                        \
142 struct brw_instruction *brw_##OP(struct brw_compile *p, \
143               struct brw_reg dest,                      \
144               struct brw_reg src0,                      \
145               struct brw_reg src1,                      \
146               struct brw_reg src2);
147
148 #define ROUND(OP) \
149 void brw_##OP(struct brw_compile *p, struct brw_reg dest, struct brw_reg src0);
150
151 ALU1(MOV)
152 ALU2(SEL)
153 ALU1(NOT)
154 ALU2(AND)
155 ALU2(OR)
156 ALU2(XOR)
157 ALU2(SHR)
158 ALU2(SHL)
159 ALU2(RSR)
160 ALU2(RSL)
161 ALU2(ASR)
162 ALU2(JMPI)
163 ALU2(ADD)
164 ALU2(AVG)
165 ALU2(MUL)
166 ALU1(FRC)
167 ALU1(RNDD)
168 ALU2(MAC)
169 ALU2(MACH)
170 ALU1(LZD)
171 ALU2(DP4)
172 ALU2(DPH)
173 ALU2(DP3)
174 ALU2(DP2)
175 ALU2(LINE)
176 ALU2(PLN)
177 ALU3(MAD)
178
179 ROUND(RNDZ)
180 ROUND(RNDE)
181
182 #undef ALU1
183 #undef ALU2
184 #undef ALU3
185 #undef ROUND
186
187
188 /* Helpers for SEND instruction:
189  */
190 void brw_set_sampler_message(struct brw_compile *p,
191                              struct brw_instruction *insn,
192                              GLuint binding_table_index,
193                              GLuint sampler,
194                              GLuint msg_type,
195                              GLuint response_length,
196                              GLuint msg_length,
197                              GLuint header_present,
198                              GLuint simd_mode,
199                              GLuint return_format);
200
201 void brw_set_dp_read_message(struct brw_compile *p,
202                              struct brw_instruction *insn,
203                              GLuint binding_table_index,
204                              GLuint msg_control,
205                              GLuint msg_type,
206                              GLuint target_cache,
207                              GLuint msg_length,
208                              bool header_present,
209                              GLuint response_length);
210
211 void brw_set_dp_write_message(struct brw_compile *p,
212                               struct brw_instruction *insn,
213                               GLuint binding_table_index,
214                               GLuint msg_control,
215                               GLuint msg_type,
216                               GLuint msg_length,
217                               bool header_present,
218                               GLuint last_render_target,
219                               GLuint response_length,
220                               GLuint end_of_thread,
221                               GLuint send_commit_msg);
222
223 void brw_urb_WRITE(struct brw_compile *p,
224                    struct brw_reg dest,
225                    GLuint msg_reg_nr,
226                    struct brw_reg src0,
227                    bool allocate,
228                    bool used,
229                    GLuint msg_length,
230                    GLuint response_length,
231                    bool eot,
232                    bool writes_complete,
233                    GLuint offset,
234                    GLuint swizzle);
235
236 void brw_ff_sync(struct brw_compile *p,
237                    struct brw_reg dest,
238                    GLuint msg_reg_nr,
239                    struct brw_reg src0,
240                    bool allocate,
241                    GLuint response_length,
242                    bool eot);
243
244 void brw_svb_write(struct brw_compile *p,
245                    struct brw_reg dest,
246                    GLuint msg_reg_nr,
247                    struct brw_reg src0,
248                    GLuint binding_table_index,
249                    bool   send_commit_msg);
250
251 void brw_fb_WRITE(struct brw_compile *p,
252                   int dispatch_width,
253                    GLuint msg_reg_nr,
254                    struct brw_reg src0,
255                    GLuint msg_control,
256                    GLuint binding_table_index,
257                    GLuint msg_length,
258                    GLuint response_length,
259                    bool eot,
260                    bool header_present);
261
262 void brw_SAMPLE(struct brw_compile *p,
263                 struct brw_reg dest,
264                 GLuint msg_reg_nr,
265                 struct brw_reg src0,
266                 GLuint binding_table_index,
267                 GLuint sampler,
268                 GLuint writemask,
269                 GLuint msg_type,
270                 GLuint response_length,
271                 GLuint msg_length,
272                 GLuint header_present,
273                 GLuint simd_mode,
274                 GLuint return_format);
275
276 void brw_math( struct brw_compile *p,
277                struct brw_reg dest,
278                GLuint function,
279                GLuint msg_reg_nr,
280                struct brw_reg src,
281                GLuint data_type,
282                GLuint precision );
283
284 void brw_math2(struct brw_compile *p,
285                struct brw_reg dest,
286                GLuint function,
287                struct brw_reg src0,
288                struct brw_reg src1);
289
290 void brw_oword_block_read(struct brw_compile *p,
291                           struct brw_reg dest,
292                           struct brw_reg mrf,
293                           uint32_t offset,
294                           uint32_t bind_table_index);
295
296 void brw_oword_block_read_scratch(struct brw_compile *p,
297                                   struct brw_reg dest,
298                                   struct brw_reg mrf,
299                                   int num_regs,
300                                   GLuint offset);
301
302 void brw_oword_block_write_scratch(struct brw_compile *p,
303                                    struct brw_reg mrf,
304                                    int num_regs,
305                                    GLuint offset);
306
307 void brw_shader_time_add(struct brw_compile *p,
308                          int mrf,
309                          uint32_t surf_index);
310
311 /* If/else/endif.  Works by manipulating the execution flags on each
312  * channel.
313  */
314 struct brw_instruction *brw_IF(struct brw_compile *p,
315                                GLuint execute_size);
316 struct brw_instruction *gen6_IF(struct brw_compile *p, uint32_t conditional,
317                                 struct brw_reg src0, struct brw_reg src1);
318
319 void brw_ELSE(struct brw_compile *p);
320 void brw_ENDIF(struct brw_compile *p);
321
322 /* DO/WHILE loops:
323  */
324 struct brw_instruction *brw_DO(struct brw_compile *p,
325                                GLuint execute_size);
326
327 struct brw_instruction *brw_WHILE(struct brw_compile *p);
328
329 struct brw_instruction *brw_BREAK(struct brw_compile *p);
330 struct brw_instruction *brw_CONT(struct brw_compile *p);
331 struct brw_instruction *gen6_CONT(struct brw_compile *p);
332 struct brw_instruction *gen6_HALT(struct brw_compile *p);
333 /* Forward jumps:
334  */
335 void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx);
336
337
338
339 void brw_NOP(struct brw_compile *p);
340
341 void brw_WAIT(struct brw_compile *p);
342
343 /* Special case: there is never a destination, execution size will be
344  * taken from src0:
345  */
346 void brw_CMP(struct brw_compile *p,
347              struct brw_reg dest,
348              GLuint conditional,
349              struct brw_reg src0,
350              struct brw_reg src1);
351
352 /***********************************************************************
353  * brw_eu_util.c:
354  */
355
356 void brw_copy_indirect_to_indirect(struct brw_compile *p,
357                                    struct brw_indirect dst_ptr,
358                                    struct brw_indirect src_ptr,
359                                    GLuint count);
360
361 void brw_copy_from_indirect(struct brw_compile *p,
362                             struct brw_reg dst,
363                             struct brw_indirect ptr,
364                             GLuint count);
365
366 void brw_copy4(struct brw_compile *p,
367                struct brw_reg dst,
368                struct brw_reg src,
369                GLuint count);
370
371 void brw_copy8(struct brw_compile *p,
372                struct brw_reg dst,
373                struct brw_reg src,
374                GLuint count);
375
376 void brw_math_invert( struct brw_compile *p,
377                       struct brw_reg dst,
378                       struct brw_reg src);
379
380 void brw_set_src1(struct brw_compile *p,
381                   struct brw_instruction *insn,
382                   struct brw_reg reg);
383
384 void brw_set_uip_jip(struct brw_compile *p);
385
386 uint32_t brw_swap_cmod(uint32_t cmod);
387
388 /* brw_eu_compact.c */
389 void brw_init_compaction_tables(struct intel_context *intel);
390 void brw_compact_instructions(struct brw_compile *p);
391 void brw_uncompact_instruction(struct intel_context *intel,
392                                struct brw_instruction *dst,
393                                struct brw_compact_instruction *src);
394 bool brw_try_compact_instruction(struct brw_compile *p,
395                                  struct brw_compact_instruction *dst,
396                                  struct brw_instruction *src);
397
398 void brw_debug_compact_uncompact(struct intel_context *intel,
399                                  struct brw_instruction *orig,
400                                  struct brw_instruction *uncompacted);
401
402 /* brw_optimize.c */
403 void brw_optimize(struct brw_compile *p);
404 void brw_remove_duplicate_mrf_moves(struct brw_compile *p);
405 void brw_remove_grf_to_mrf_moves(struct brw_compile *p);
406
407 /* brw_disasm.c */
408 struct opcode_desc {
409     char    *name;
410     int     nsrc;
411     int     ndst;
412 };
413
414 extern const struct opcode_desc opcode_descs[128];
415
416 int brw_disasm (FILE *file, struct brw_instruction *inst, int gen);
417
418 #ifdef __cplusplus
419 }
420 #endif
421
422 #endif