• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
38 #include "brw_inst.h"
39 #include "brw_compiler.h"
40 #include "brw_eu_defines.h"
41 #include "brw_reg.h"
42 #include "brw_disasm_info.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #define BRW_EU_MAX_INSN_STACK 5
49 
50 struct brw_insn_state {
51    /* One of BRW_EXECUTE_* */
52    unsigned exec_size:3;
53 
54    /* Group in units of channels */
55    unsigned group:5;
56 
57    /* Compression control on gen4-5 */
58    bool compressed:1;
59 
60    /* One of BRW_MASK_* */
61    unsigned mask_control:1;
62 
63    /* Scheduling info for Gen12+ */
64    struct tgl_swsb swsb;
65 
66    bool saturate:1;
67 
68    /* One of BRW_ALIGN_* */
69    unsigned access_mode:1;
70 
71    /* One of BRW_PREDICATE_* */
72    enum brw_predicate predicate:4;
73 
74    bool pred_inv:1;
75 
76    /* Flag subreg.  Bottom bit is subreg, top bit is reg */
77    unsigned flag_subreg:2;
78 
79    bool acc_wr_control:1;
80 };
81 
82 
83 /* A helper for accessing the last instruction emitted.  This makes it easy
84  * to set various bits on an instruction without having to create temporary
85  * variable and assign the emitted instruction to those.
86  */
87 #define brw_last_inst (&p->store[p->nr_insn - 1])
88 
89 struct brw_codegen {
90    brw_inst *store;
91    int store_size;
92    unsigned nr_insn;
93    unsigned int next_insn_offset;
94 
95    void *mem_ctx;
96 
97    /* Allow clients to push/pop instruction state:
98     */
99    struct brw_insn_state stack[BRW_EU_MAX_INSN_STACK];
100    struct brw_insn_state *current;
101 
102    /** Whether or not the user wants automatic exec sizes
103     *
104     * If true, codegen will try to automatically infer the exec size of an
105     * instruction from the width of the destination register.  If false, it
106     * will take whatever is set by brw_set_default_exec_size verbatim.
107     *
108     * This is set to true by default in brw_init_codegen.
109     */
110    bool automatic_exec_sizes;
111 
112    bool single_program_flow;
113    const struct gen_device_info *devinfo;
114 
115    /* Control flow stacks:
116     * - if_stack contains IF and ELSE instructions which must be patched
117     *   (and popped) once the matching ENDIF instruction is encountered.
118     *
119     *   Just store the instruction pointer(an index).
120     */
121    int *if_stack;
122    int if_stack_depth;
123    int if_stack_array_size;
124 
125    /**
126     * loop_stack contains the instruction pointers of the starts of loops which
127     * must be patched (and popped) once the matching WHILE instruction is
128     * encountered.
129     */
130    int *loop_stack;
131    /**
132     * pre-gen6, the BREAK and CONT instructions had to tell how many IF/ENDIF
133     * blocks they were popping out of, to fix up the mask stack.  This tracks
134     * the IF/ENDIF nesting in each current nested loop level.
135     */
136    int *if_depth_in_loop;
137    int loop_stack_depth;
138    int loop_stack_array_size;
139 
140    struct brw_shader_reloc *relocs;
141    int num_relocs;
142    int reloc_array_size;
143 };
144 
145 struct brw_label {
146    int offset;
147    int number;
148    struct brw_label *next;
149 };
150 
151 void brw_pop_insn_state( struct brw_codegen *p );
152 void brw_push_insn_state( struct brw_codegen *p );
153 unsigned brw_get_default_exec_size(struct brw_codegen *p);
154 unsigned brw_get_default_group(struct brw_codegen *p);
155 unsigned brw_get_default_access_mode(struct brw_codegen *p);
156 struct tgl_swsb brw_get_default_swsb(struct brw_codegen *p);
157 void brw_set_default_exec_size(struct brw_codegen *p, unsigned value);
158 void brw_set_default_mask_control( struct brw_codegen *p, unsigned value );
159 void brw_set_default_saturate( struct brw_codegen *p, bool enable );
160 void brw_set_default_access_mode( struct brw_codegen *p, unsigned access_mode );
161 void brw_inst_set_compression(const struct gen_device_info *devinfo,
162                               brw_inst *inst, bool on);
163 void brw_set_default_compression(struct brw_codegen *p, bool on);
164 void brw_inst_set_group(const struct gen_device_info *devinfo,
165                         brw_inst *inst, unsigned group);
166 void brw_set_default_group(struct brw_codegen *p, unsigned group);
167 void brw_set_default_compression_control(struct brw_codegen *p, enum brw_compression c);
168 void brw_set_default_predicate_control(struct brw_codegen *p, enum brw_predicate pc);
169 void brw_set_default_predicate_inverse(struct brw_codegen *p, bool predicate_inverse);
170 void brw_set_default_flag_reg(struct brw_codegen *p, int reg, int subreg);
171 void brw_set_default_acc_write_control(struct brw_codegen *p, unsigned value);
172 void brw_set_default_swsb(struct brw_codegen *p, struct tgl_swsb value);
173 
174 void brw_init_codegen(const struct gen_device_info *, struct brw_codegen *p,
175 		      void *mem_ctx);
176 bool brw_has_jip(const struct gen_device_info *devinfo, enum opcode opcode);
177 bool brw_has_uip(const struct gen_device_info *devinfo, enum opcode opcode);
178 const struct brw_label *brw_find_label(const struct brw_label *root, int offset);
179 void brw_create_label(struct brw_label **labels, int offset, void *mem_ctx);
180 int brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
181                          const struct brw_inst *inst, bool is_compacted,
182                          int offset, const struct brw_label *root_label);
183 const struct brw_label *brw_label_assembly(const struct gen_device_info *devinfo,
184                                            const void *assembly, int start, int end,
185                                            void *mem_ctx);
186 void brw_disassemble_with_labels(const struct gen_device_info *devinfo,
187                                  const void *assembly, int start, int end, FILE *out);
188 void brw_disassemble(const struct gen_device_info *devinfo,
189                      const void *assembly, int start, int end,
190                      const struct brw_label *root_label, FILE *out);
191 const struct brw_shader_reloc *brw_get_shader_relocs(struct brw_codegen *p,
192                                                      unsigned *num_relocs);
193 const unsigned *brw_get_program( struct brw_codegen *p, unsigned *sz );
194 
195 bool brw_try_override_assembly(struct brw_codegen *p, int start_offset,
196                                const char *identifier);
197 
198 void brw_realign(struct brw_codegen *p, unsigned align);
199 int brw_append_data(struct brw_codegen *p, void *data,
200                     unsigned size, unsigned align);
201 brw_inst *brw_next_insn(struct brw_codegen *p, unsigned opcode);
202 void brw_set_dest(struct brw_codegen *p, brw_inst *insn, struct brw_reg dest);
203 void brw_set_src0(struct brw_codegen *p, brw_inst *insn, struct brw_reg reg);
204 
205 void gen6_resolve_implied_move(struct brw_codegen *p,
206 			       struct brw_reg *src,
207 			       unsigned msg_reg_nr);
208 
209 /* Helpers for regular instructions:
210  */
211 #define ALU1(OP)				\
212 brw_inst *brw_##OP(struct brw_codegen *p,	\
213 	      struct brw_reg dest,		\
214 	      struct brw_reg src0);
215 
216 #define ALU2(OP)				\
217 brw_inst *brw_##OP(struct brw_codegen *p,	\
218 	      struct brw_reg dest,		\
219 	      struct brw_reg src0,		\
220 	      struct brw_reg src1);
221 
222 #define ALU3(OP)				\
223 brw_inst *brw_##OP(struct brw_codegen *p,	\
224 	      struct brw_reg dest,		\
225 	      struct brw_reg src0,		\
226 	      struct brw_reg src1,		\
227 	      struct brw_reg src2);
228 
229 ALU1(MOV)
ALU2(SEL)230 ALU2(SEL)
231 ALU1(NOT)
232 ALU2(AND)
233 ALU2(OR)
234 ALU2(XOR)
235 ALU2(SHR)
236 ALU2(SHL)
237 ALU1(DIM)
238 ALU2(ASR)
239 ALU2(ROL)
240 ALU2(ROR)
241 ALU3(CSEL)
242 ALU1(F32TO16)
243 ALU1(F16TO32)
244 ALU2(ADD)
245 ALU2(AVG)
246 ALU2(MUL)
247 ALU1(FRC)
248 ALU1(RNDD)
249 ALU1(RNDE)
250 ALU1(RNDU)
251 ALU1(RNDZ)
252 ALU2(MAC)
253 ALU2(MACH)
254 ALU1(LZD)
255 ALU2(DP4)
256 ALU2(DPH)
257 ALU2(DP3)
258 ALU2(DP2)
259 ALU2(LINE)
260 ALU2(PLN)
261 ALU3(MAD)
262 ALU3(LRP)
263 ALU1(BFREV)
264 ALU3(BFE)
265 ALU2(BFI1)
266 ALU3(BFI2)
267 ALU1(FBH)
268 ALU1(FBL)
269 ALU1(CBIT)
270 ALU2(ADDC)
271 ALU2(SUBB)
272 ALU2(MAC)
273 
274 #undef ALU1
275 #undef ALU2
276 #undef ALU3
277 
278 
279 /* Helpers for SEND instruction:
280  */
281 
282 /**
283  * Construct a message descriptor immediate with the specified common
284  * descriptor controls.
285  */
286 static inline uint32_t
287 brw_message_desc(const struct gen_device_info *devinfo,
288                  unsigned msg_length,
289                  unsigned response_length,
290                  bool header_present)
291 {
292    if (devinfo->gen >= 5) {
293       return (SET_BITS(msg_length, 28, 25) |
294               SET_BITS(response_length, 24, 20) |
295               SET_BITS(header_present, 19, 19));
296    } else {
297       return (SET_BITS(msg_length, 23, 20) |
298               SET_BITS(response_length, 19, 16));
299    }
300 }
301 
302 static inline unsigned
brw_message_desc_mlen(const struct gen_device_info * devinfo,uint32_t desc)303 brw_message_desc_mlen(const struct gen_device_info *devinfo, uint32_t desc)
304 {
305    if (devinfo->gen >= 5)
306       return GET_BITS(desc, 28, 25);
307    else
308       return GET_BITS(desc, 23, 20);
309 }
310 
311 static inline unsigned
brw_message_desc_rlen(const struct gen_device_info * devinfo,uint32_t desc)312 brw_message_desc_rlen(const struct gen_device_info *devinfo, uint32_t desc)
313 {
314    if (devinfo->gen >= 5)
315       return GET_BITS(desc, 24, 20);
316    else
317       return GET_BITS(desc, 19, 16);
318 }
319 
320 static inline bool
brw_message_desc_header_present(ASSERTED const struct gen_device_info * devinfo,uint32_t desc)321 brw_message_desc_header_present(ASSERTED const struct gen_device_info *devinfo,
322                                 uint32_t desc)
323 {
324    assert(devinfo->gen >= 5);
325    return GET_BITS(desc, 19, 19);
326 }
327 
328 static inline unsigned
brw_message_ex_desc(UNUSED const struct gen_device_info * devinfo,unsigned ex_msg_length)329 brw_message_ex_desc(UNUSED const struct gen_device_info *devinfo,
330                     unsigned ex_msg_length)
331 {
332    return SET_BITS(ex_msg_length, 9, 6);
333 }
334 
335 static inline unsigned
brw_message_ex_desc_ex_mlen(UNUSED const struct gen_device_info * devinfo,uint32_t ex_desc)336 brw_message_ex_desc_ex_mlen(UNUSED const struct gen_device_info *devinfo,
337                             uint32_t ex_desc)
338 {
339    return GET_BITS(ex_desc, 9, 6);
340 }
341 
342 static inline uint32_t
brw_urb_desc(const struct gen_device_info * devinfo,unsigned msg_type,bool per_slot_offset_present,bool channel_mask_present,unsigned global_offset)343 brw_urb_desc(const struct gen_device_info *devinfo,
344              unsigned msg_type,
345              bool per_slot_offset_present,
346              bool channel_mask_present,
347              unsigned global_offset)
348 {
349    if (devinfo->gen >= 8) {
350       return (SET_BITS(per_slot_offset_present, 17, 17) |
351               SET_BITS(channel_mask_present, 15, 15) |
352               SET_BITS(global_offset, 14, 4) |
353               SET_BITS(msg_type, 3, 0));
354    } else if (devinfo->gen >= 7) {
355       assert(!channel_mask_present);
356       return (SET_BITS(per_slot_offset_present, 16, 16) |
357               SET_BITS(global_offset, 13, 3) |
358               SET_BITS(msg_type, 3, 0));
359    } else {
360       unreachable("unhandled URB write generation");
361    }
362 }
363 
364 static inline uint32_t
brw_urb_desc_msg_type(ASSERTED const struct gen_device_info * devinfo,uint32_t desc)365 brw_urb_desc_msg_type(ASSERTED const struct gen_device_info *devinfo,
366                       uint32_t desc)
367 {
368    assert(devinfo->gen >= 7);
369    return GET_BITS(desc, 3, 0);
370 }
371 
372 /**
373  * Construct a message descriptor immediate with the specified sampler
374  * function controls.
375  */
376 static inline uint32_t
brw_sampler_desc(const struct gen_device_info * devinfo,unsigned binding_table_index,unsigned sampler,unsigned msg_type,unsigned simd_mode,unsigned return_format)377 brw_sampler_desc(const struct gen_device_info *devinfo,
378                  unsigned binding_table_index,
379                  unsigned sampler,
380                  unsigned msg_type,
381                  unsigned simd_mode,
382                  unsigned return_format)
383 {
384    const unsigned desc = (SET_BITS(binding_table_index, 7, 0) |
385                           SET_BITS(sampler, 11, 8));
386    if (devinfo->gen >= 7)
387       return (desc | SET_BITS(msg_type, 16, 12) |
388               SET_BITS(simd_mode, 18, 17));
389    else if (devinfo->gen >= 5)
390       return (desc | SET_BITS(msg_type, 15, 12) |
391               SET_BITS(simd_mode, 17, 16));
392    else if (devinfo->is_g4x)
393       return desc | SET_BITS(msg_type, 15, 12);
394    else
395       return (desc | SET_BITS(return_format, 13, 12) |
396               SET_BITS(msg_type, 15, 14));
397 }
398 
399 static inline unsigned
brw_sampler_desc_binding_table_index(UNUSED const struct gen_device_info * devinfo,uint32_t desc)400 brw_sampler_desc_binding_table_index(UNUSED const struct gen_device_info *devinfo,
401                                      uint32_t desc)
402 {
403    return GET_BITS(desc, 7, 0);
404 }
405 
406 static inline unsigned
brw_sampler_desc_sampler(UNUSED const struct gen_device_info * devinfo,uint32_t desc)407 brw_sampler_desc_sampler(UNUSED const struct gen_device_info *devinfo, uint32_t desc)
408 {
409    return GET_BITS(desc, 11, 8);
410 }
411 
412 static inline unsigned
brw_sampler_desc_msg_type(const struct gen_device_info * devinfo,uint32_t desc)413 brw_sampler_desc_msg_type(const struct gen_device_info *devinfo, uint32_t desc)
414 {
415    if (devinfo->gen >= 7)
416       return GET_BITS(desc, 16, 12);
417    else if (devinfo->gen >= 5 || devinfo->is_g4x)
418       return GET_BITS(desc, 15, 12);
419    else
420       return GET_BITS(desc, 15, 14);
421 }
422 
423 static inline unsigned
brw_sampler_desc_simd_mode(const struct gen_device_info * devinfo,uint32_t desc)424 brw_sampler_desc_simd_mode(const struct gen_device_info *devinfo, uint32_t desc)
425 {
426    assert(devinfo->gen >= 5);
427    if (devinfo->gen >= 7)
428       return GET_BITS(desc, 18, 17);
429    else
430       return GET_BITS(desc, 17, 16);
431 }
432 
433 static  inline unsigned
brw_sampler_desc_return_format(ASSERTED const struct gen_device_info * devinfo,uint32_t desc)434 brw_sampler_desc_return_format(ASSERTED const struct gen_device_info *devinfo,
435                                uint32_t desc)
436 {
437    assert(devinfo->gen == 4 && !devinfo->is_g4x);
438    return GET_BITS(desc, 13, 12);
439 }
440 
441 /**
442  * Construct a message descriptor for the dataport
443  */
444 static inline uint32_t
brw_dp_desc(const struct gen_device_info * devinfo,unsigned binding_table_index,unsigned msg_type,unsigned msg_control)445 brw_dp_desc(const struct gen_device_info *devinfo,
446             unsigned binding_table_index,
447             unsigned msg_type,
448             unsigned msg_control)
449 {
450    /* Prior to gen6, things are too inconsistent; use the dp_read/write_desc
451     * helpers instead.
452     */
453    assert(devinfo->gen >= 6);
454    const unsigned desc = SET_BITS(binding_table_index, 7, 0);
455    if (devinfo->gen >= 8) {
456       return (desc | SET_BITS(msg_control, 13, 8) |
457               SET_BITS(msg_type, 18, 14));
458    } else if (devinfo->gen >= 7) {
459       return (desc | SET_BITS(msg_control, 13, 8) |
460               SET_BITS(msg_type, 17, 14));
461    } else {
462       return (desc | SET_BITS(msg_control, 12, 8) |
463               SET_BITS(msg_type, 16, 13));
464    }
465 }
466 
467 static inline unsigned
brw_dp_desc_binding_table_index(UNUSED const struct gen_device_info * devinfo,uint32_t desc)468 brw_dp_desc_binding_table_index(UNUSED const struct gen_device_info *devinfo,
469                                 uint32_t desc)
470 {
471    return GET_BITS(desc, 7, 0);
472 }
473 
474 static inline unsigned
brw_dp_desc_msg_type(const struct gen_device_info * devinfo,uint32_t desc)475 brw_dp_desc_msg_type(const struct gen_device_info *devinfo, uint32_t desc)
476 {
477    assert(devinfo->gen >= 6);
478    if (devinfo->gen >= 8)
479       return GET_BITS(desc, 18, 14);
480    else if (devinfo->gen >= 7)
481       return GET_BITS(desc, 17, 14);
482    else
483       return GET_BITS(desc, 16, 13);
484 }
485 
486 static inline unsigned
brw_dp_desc_msg_control(const struct gen_device_info * devinfo,uint32_t desc)487 brw_dp_desc_msg_control(const struct gen_device_info *devinfo, uint32_t desc)
488 {
489    assert(devinfo->gen >= 6);
490    if (devinfo->gen >= 7)
491       return GET_BITS(desc, 13, 8);
492    else
493       return GET_BITS(desc, 12, 8);
494 }
495 
496 /**
497  * Construct a message descriptor immediate with the specified dataport read
498  * function controls.
499  */
500 static inline uint32_t
brw_dp_read_desc(const struct gen_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,unsigned msg_type,unsigned target_cache)501 brw_dp_read_desc(const struct gen_device_info *devinfo,
502                  unsigned binding_table_index,
503                  unsigned msg_control,
504                  unsigned msg_type,
505                  unsigned target_cache)
506 {
507    if (devinfo->gen >= 6)
508       return brw_dp_desc(devinfo, binding_table_index, msg_type, msg_control);
509    else if (devinfo->gen >= 5 || devinfo->is_g4x)
510       return (SET_BITS(binding_table_index, 7, 0) |
511               SET_BITS(msg_control, 10, 8) |
512               SET_BITS(msg_type, 13, 11) |
513               SET_BITS(target_cache, 15, 14));
514    else
515       return (SET_BITS(binding_table_index, 7, 0) |
516               SET_BITS(msg_control, 11, 8) |
517               SET_BITS(msg_type, 13, 12) |
518               SET_BITS(target_cache, 15, 14));
519 }
520 
521 static inline unsigned
brw_dp_read_desc_msg_type(const struct gen_device_info * devinfo,uint32_t desc)522 brw_dp_read_desc_msg_type(const struct gen_device_info *devinfo, uint32_t desc)
523 {
524    if (devinfo->gen >= 6)
525       return brw_dp_desc_msg_type(devinfo, desc);
526    else if (devinfo->gen >= 5 || devinfo->is_g4x)
527       return GET_BITS(desc, 13, 11);
528    else
529       return GET_BITS(desc, 13, 12);
530 }
531 
532 static inline unsigned
brw_dp_read_desc_msg_control(const struct gen_device_info * devinfo,uint32_t desc)533 brw_dp_read_desc_msg_control(const struct gen_device_info *devinfo,
534                              uint32_t desc)
535 {
536    if (devinfo->gen >= 6)
537       return brw_dp_desc_msg_control(devinfo, desc);
538    else if (devinfo->gen >= 5 || devinfo->is_g4x)
539       return GET_BITS(desc, 10, 8);
540    else
541       return GET_BITS(desc, 11, 8);
542 }
543 
544 /**
545  * Construct a message descriptor immediate with the specified dataport write
546  * function controls.
547  */
548 static inline uint32_t
brw_dp_write_desc(const struct gen_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,unsigned msg_type,unsigned last_render_target,unsigned send_commit_msg)549 brw_dp_write_desc(const struct gen_device_info *devinfo,
550                   unsigned binding_table_index,
551                   unsigned msg_control,
552                   unsigned msg_type,
553                   unsigned last_render_target,
554                   unsigned send_commit_msg)
555 {
556    assert(devinfo->gen <= 6 || !send_commit_msg);
557    if (devinfo->gen >= 6)
558       return brw_dp_desc(devinfo, binding_table_index, msg_type, msg_control) |
559              SET_BITS(last_render_target, 12, 12) |
560              SET_BITS(send_commit_msg, 17, 17);
561    else
562       return (SET_BITS(binding_table_index, 7, 0) |
563               SET_BITS(msg_control, 11, 8) |
564               SET_BITS(last_render_target, 11, 11) |
565               SET_BITS(msg_type, 14, 12) |
566               SET_BITS(send_commit_msg, 15, 15));
567 }
568 
569 static inline unsigned
brw_dp_write_desc_msg_type(const struct gen_device_info * devinfo,uint32_t desc)570 brw_dp_write_desc_msg_type(const struct gen_device_info *devinfo,
571                            uint32_t desc)
572 {
573    if (devinfo->gen >= 6)
574       return brw_dp_desc_msg_type(devinfo, desc);
575    else
576       return GET_BITS(desc, 14, 12);
577 }
578 
579 static inline unsigned
brw_dp_write_desc_msg_control(const struct gen_device_info * devinfo,uint32_t desc)580 brw_dp_write_desc_msg_control(const struct gen_device_info *devinfo,
581                               uint32_t desc)
582 {
583    if (devinfo->gen >= 6)
584       return brw_dp_desc_msg_control(devinfo, desc);
585    else
586       return GET_BITS(desc, 11, 8);
587 }
588 
589 static inline bool
brw_dp_write_desc_last_render_target(const struct gen_device_info * devinfo,uint32_t desc)590 brw_dp_write_desc_last_render_target(const struct gen_device_info *devinfo,
591                                      uint32_t desc)
592 {
593    if (devinfo->gen >= 6)
594       return GET_BITS(desc, 12, 12);
595    else
596       return GET_BITS(desc, 11, 11);
597 }
598 
599 static inline bool
brw_dp_write_desc_write_commit(const struct gen_device_info * devinfo,uint32_t desc)600 brw_dp_write_desc_write_commit(const struct gen_device_info *devinfo,
601                                uint32_t desc)
602 {
603    assert(devinfo->gen <= 6);
604    if (devinfo->gen >= 6)
605       return GET_BITS(desc, 17, 17);
606    else
607       return GET_BITS(desc, 15, 15);
608 }
609 
610 /**
611  * Construct a message descriptor immediate with the specified dataport
612  * surface function controls.
613  */
614 static inline uint32_t
brw_dp_surface_desc(const struct gen_device_info * devinfo,unsigned msg_type,unsigned msg_control)615 brw_dp_surface_desc(const struct gen_device_info *devinfo,
616                     unsigned msg_type,
617                     unsigned msg_control)
618 {
619    assert(devinfo->gen >= 7);
620    /* We'll OR in the binding table index later */
621    return brw_dp_desc(devinfo, 0, msg_type, msg_control);
622 }
623 
624 static inline uint32_t
brw_dp_untyped_atomic_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned atomic_op,bool response_expected)625 brw_dp_untyped_atomic_desc(const struct gen_device_info *devinfo,
626                            unsigned exec_size, /**< 0 for SIMD4x2 */
627                            unsigned atomic_op,
628                            bool response_expected)
629 {
630    assert(exec_size <= 8 || exec_size == 16);
631 
632    unsigned msg_type;
633    if (devinfo->gen >= 8 || devinfo->is_haswell) {
634       if (exec_size > 0) {
635          msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP;
636       } else {
637          msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2;
638       }
639    } else {
640       msg_type = GEN7_DATAPORT_DC_UNTYPED_ATOMIC_OP;
641    }
642 
643    const unsigned msg_control =
644       SET_BITS(atomic_op, 3, 0) |
645       SET_BITS(0 < exec_size && exec_size <= 8, 4, 4) |
646       SET_BITS(response_expected, 5, 5);
647 
648    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
649 }
650 
651 static inline uint32_t
brw_dp_untyped_atomic_float_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned atomic_op,bool response_expected)652 brw_dp_untyped_atomic_float_desc(const struct gen_device_info *devinfo,
653                                  unsigned exec_size,
654                                  unsigned atomic_op,
655                                  bool response_expected)
656 {
657    assert(exec_size <= 8 || exec_size == 16);
658    assert(devinfo->gen >= 9);
659 
660    assert(exec_size > 0);
661    const unsigned msg_type = GEN9_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_FLOAT_OP;
662 
663    const unsigned msg_control =
664       SET_BITS(atomic_op, 1, 0) |
665       SET_BITS(exec_size <= 8, 4, 4) |
666       SET_BITS(response_expected, 5, 5);
667 
668    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
669 }
670 
671 static inline unsigned
brw_mdc_cmask(unsigned num_channels)672 brw_mdc_cmask(unsigned num_channels)
673 {
674    /* See also MDC_CMASK in the SKL PRM Vol 2d. */
675    return 0xf & (0xf << num_channels);
676 }
677 
678 static inline uint32_t
brw_dp_untyped_surface_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned num_channels,bool write)679 brw_dp_untyped_surface_rw_desc(const struct gen_device_info *devinfo,
680                                unsigned exec_size, /**< 0 for SIMD4x2 */
681                                unsigned num_channels,
682                                bool write)
683 {
684    assert(exec_size <= 8 || exec_size == 16);
685 
686    unsigned msg_type;
687    if (write) {
688       if (devinfo->gen >= 8 || devinfo->is_haswell) {
689          msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE;
690       } else {
691          msg_type = GEN7_DATAPORT_DC_UNTYPED_SURFACE_WRITE;
692       }
693    } else {
694       /* Read */
695       if (devinfo->gen >= 8 || devinfo->is_haswell) {
696          msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ;
697       } else {
698          msg_type = GEN7_DATAPORT_DC_UNTYPED_SURFACE_READ;
699       }
700    }
701 
702    /* SIMD4x2 is only valid for read messages on IVB; use SIMD8 instead */
703    if (write && devinfo->gen == 7 && !devinfo->is_haswell && exec_size == 0)
704       exec_size = 8;
705 
706    /* See also MDC_SM3 in the SKL PRM Vol 2d. */
707    const unsigned simd_mode = exec_size == 0 ? 0 : /* SIMD4x2 */
708                               exec_size <= 8 ? 2 : 1;
709 
710    const unsigned msg_control =
711       SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
712       SET_BITS(simd_mode, 5, 4);
713 
714    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
715 }
716 
717 static inline unsigned
brw_mdc_ds(unsigned bit_size)718 brw_mdc_ds(unsigned bit_size)
719 {
720    switch (bit_size) {
721    case 8:
722       return GEN7_BYTE_SCATTERED_DATA_ELEMENT_BYTE;
723    case 16:
724       return GEN7_BYTE_SCATTERED_DATA_ELEMENT_WORD;
725    case 32:
726       return GEN7_BYTE_SCATTERED_DATA_ELEMENT_DWORD;
727    default:
728       unreachable("Unsupported bit_size for byte scattered messages");
729    }
730 }
731 
732 static inline uint32_t
brw_dp_byte_scattered_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned bit_size,bool write)733 brw_dp_byte_scattered_rw_desc(const struct gen_device_info *devinfo,
734                               unsigned exec_size,
735                               unsigned bit_size,
736                               bool write)
737 {
738    assert(exec_size <= 8 || exec_size == 16);
739 
740    assert(devinfo->gen > 7 || devinfo->is_haswell);
741    const unsigned msg_type =
742       write ? HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_WRITE :
743               HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_READ;
744 
745    assert(exec_size > 0);
746    const unsigned msg_control =
747       SET_BITS(exec_size == 16, 0, 0) |
748       SET_BITS(brw_mdc_ds(bit_size), 3, 2);
749 
750    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
751 }
752 
753 static inline uint32_t
brw_dp_dword_scattered_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,bool write)754 brw_dp_dword_scattered_rw_desc(const struct gen_device_info *devinfo,
755                                unsigned exec_size,
756                                bool write)
757 {
758    assert(exec_size == 8 || exec_size == 16);
759 
760    unsigned msg_type;
761    if (write) {
762       if (devinfo->gen >= 6) {
763          msg_type = GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE;
764       } else {
765          msg_type = BRW_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE;
766       }
767    } else {
768       if (devinfo->gen >= 7) {
769          msg_type = GEN7_DATAPORT_DC_DWORD_SCATTERED_READ;
770       } else if (devinfo->gen > 4 || devinfo->is_g4x) {
771          msg_type = G45_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ;
772       } else {
773          msg_type = BRW_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ;
774       }
775    }
776 
777    const unsigned msg_control =
778       SET_BITS(1, 1, 1) | /* Legacy SIMD Mode */
779       SET_BITS(exec_size == 16, 0, 0);
780 
781    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
782 }
783 
784 static inline uint32_t
brw_dp_oword_block_rw_desc(const struct gen_device_info * devinfo,bool align_16B,unsigned num_dwords,bool write)785 brw_dp_oword_block_rw_desc(const struct gen_device_info *devinfo,
786                            bool align_16B,
787                            unsigned num_dwords,
788                            bool write)
789 {
790    /* Writes can only have addresses aligned by OWORDs (16 Bytes). */
791    assert(!write || align_16B);
792 
793    const unsigned msg_type =
794       write ?     GEN7_DATAPORT_DC_OWORD_BLOCK_WRITE :
795       align_16B ? GEN7_DATAPORT_DC_OWORD_BLOCK_READ :
796                   GEN7_DATAPORT_DC_UNALIGNED_OWORD_BLOCK_READ;
797 
798    const unsigned msg_control =
799       SET_BITS(BRW_DATAPORT_OWORD_BLOCK_DWORDS(num_dwords), 2, 0);
800 
801    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
802 }
803 
804 static inline uint32_t
brw_dp_a64_untyped_surface_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned num_channels,bool write)805 brw_dp_a64_untyped_surface_rw_desc(const struct gen_device_info *devinfo,
806                                    unsigned exec_size, /**< 0 for SIMD4x2 */
807                                    unsigned num_channels,
808                                    bool write)
809 {
810    assert(exec_size <= 8 || exec_size == 16);
811    assert(devinfo->gen >= 8);
812 
813    unsigned msg_type =
814       write ? GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE :
815               GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ;
816 
817    /* See also MDC_SM3 in the SKL PRM Vol 2d. */
818    const unsigned simd_mode = exec_size == 0 ? 0 : /* SIMD4x2 */
819                               exec_size <= 8 ? 2 : 1;
820 
821    const unsigned msg_control =
822       SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
823       SET_BITS(simd_mode, 5, 4);
824 
825    return brw_dp_desc(devinfo, GEN8_BTI_STATELESS_NON_COHERENT,
826                       msg_type, msg_control);
827 }
828 
829 static inline uint32_t
brw_dp_a64_oword_block_rw_desc(const struct gen_device_info * devinfo,bool align_16B,unsigned num_dwords,bool write)830 brw_dp_a64_oword_block_rw_desc(const struct gen_device_info *devinfo,
831                                bool align_16B,
832                                unsigned num_dwords,
833                                bool write)
834 {
835    /* Writes can only have addresses aligned by OWORDs (16 Bytes). */
836    assert(!write || align_16B);
837 
838    unsigned msg_type =
839       write ? GEN9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_WRITE :
840               GEN9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_READ;
841 
842    unsigned msg_control =
843       SET_BITS(!align_16B, 4, 3) |
844       SET_BITS(BRW_DATAPORT_OWORD_BLOCK_DWORDS(num_dwords), 2, 0);
845 
846    return brw_dp_desc(devinfo, GEN8_BTI_STATELESS_NON_COHERENT,
847                       msg_type, msg_control);
848 }
849 
850 /**
851  * Calculate the data size (see MDC_A64_DS in the "Structures" volume of the
852  * Skylake PRM).
853  */
854 static inline uint32_t
brw_mdc_a64_ds(unsigned elems)855 brw_mdc_a64_ds(unsigned elems)
856 {
857    switch (elems) {
858    case 1:  return 0;
859    case 2:  return 1;
860    case 4:  return 2;
861    case 8:  return 3;
862    default:
863       unreachable("Unsupported elmeent count for A64 scattered message");
864    }
865 }
866 
867 static inline uint32_t
brw_dp_a64_byte_scattered_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned bit_size,bool write)868 brw_dp_a64_byte_scattered_rw_desc(const struct gen_device_info *devinfo,
869                                   unsigned exec_size, /**< 0 for SIMD4x2 */
870                                   unsigned bit_size,
871                                   bool write)
872 {
873    assert(exec_size <= 8 || exec_size == 16);
874    assert(devinfo->gen >= 8);
875 
876    unsigned msg_type =
877       write ? GEN8_DATAPORT_DC_PORT1_A64_SCATTERED_WRITE :
878               GEN9_DATAPORT_DC_PORT1_A64_SCATTERED_READ;
879 
880    const unsigned msg_control =
881       SET_BITS(GEN8_A64_SCATTERED_SUBTYPE_BYTE, 1, 0) |
882       SET_BITS(brw_mdc_a64_ds(bit_size / 8), 3, 2) |
883       SET_BITS(exec_size == 16, 4, 4);
884 
885    return brw_dp_desc(devinfo, GEN8_BTI_STATELESS_NON_COHERENT,
886                       msg_type, msg_control);
887 }
888 
889 static inline uint32_t
brw_dp_a64_untyped_atomic_desc(const struct gen_device_info * devinfo,ASSERTED unsigned exec_size,unsigned bit_size,unsigned atomic_op,bool response_expected)890 brw_dp_a64_untyped_atomic_desc(const struct gen_device_info *devinfo,
891                                ASSERTED unsigned exec_size, /**< 0 for SIMD4x2 */
892                                unsigned bit_size,
893                                unsigned atomic_op,
894                                bool response_expected)
895 {
896    assert(exec_size == 8);
897    assert(devinfo->gen >= 8);
898    assert(bit_size == 32 || bit_size == 64);
899 
900    const unsigned msg_type = GEN8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP;
901 
902    const unsigned msg_control =
903       SET_BITS(atomic_op, 3, 0) |
904       SET_BITS(bit_size == 64, 4, 4) |
905       SET_BITS(response_expected, 5, 5);
906 
907    return brw_dp_desc(devinfo, GEN8_BTI_STATELESS_NON_COHERENT,
908                       msg_type, msg_control);
909 }
910 
911 static inline uint32_t
brw_dp_a64_untyped_atomic_float_desc(const struct gen_device_info * devinfo,ASSERTED unsigned exec_size,unsigned atomic_op,bool response_expected)912 brw_dp_a64_untyped_atomic_float_desc(const struct gen_device_info *devinfo,
913                                      ASSERTED unsigned exec_size,
914                                      unsigned atomic_op,
915                                      bool response_expected)
916 {
917    assert(exec_size == 8);
918    assert(devinfo->gen >= 9);
919 
920    assert(exec_size > 0);
921    const unsigned msg_type = GEN9_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_FLOAT_OP;
922 
923    const unsigned msg_control =
924       SET_BITS(atomic_op, 1, 0) |
925       SET_BITS(response_expected, 5, 5);
926 
927    return brw_dp_desc(devinfo, GEN8_BTI_STATELESS_NON_COHERENT,
928                       msg_type, msg_control);
929 }
930 
931 static inline uint32_t
brw_dp_typed_atomic_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned exec_group,unsigned atomic_op,bool response_expected)932 brw_dp_typed_atomic_desc(const struct gen_device_info *devinfo,
933                          unsigned exec_size,
934                          unsigned exec_group,
935                          unsigned atomic_op,
936                          bool response_expected)
937 {
938    assert(exec_size > 0 || exec_group == 0);
939    assert(exec_group % 8 == 0);
940 
941    unsigned msg_type;
942    if (devinfo->gen >= 8 || devinfo->is_haswell) {
943       if (exec_size == 0) {
944          msg_type = HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2;
945       } else {
946          msg_type = HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP;
947       }
948    } else {
949       /* SIMD4x2 typed surface R/W messages only exist on HSW+ */
950       assert(exec_size > 0);
951       msg_type = GEN7_DATAPORT_RC_TYPED_ATOMIC_OP;
952    }
953 
954    const bool high_sample_mask = (exec_group / 8) % 2 == 1;
955 
956    const unsigned msg_control =
957       SET_BITS(atomic_op, 3, 0) |
958       SET_BITS(high_sample_mask, 4, 4) |
959       SET_BITS(response_expected, 5, 5);
960 
961    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
962 }
963 
964 static inline uint32_t
brw_dp_typed_surface_rw_desc(const struct gen_device_info * devinfo,unsigned exec_size,unsigned exec_group,unsigned num_channels,bool write)965 brw_dp_typed_surface_rw_desc(const struct gen_device_info *devinfo,
966                              unsigned exec_size,
967                              unsigned exec_group,
968                              unsigned num_channels,
969                              bool write)
970 {
971    assert(exec_size > 0 || exec_group == 0);
972    assert(exec_group % 8 == 0);
973 
974    /* Typed surface reads and writes don't support SIMD16 */
975    assert(exec_size <= 8);
976 
977    unsigned msg_type;
978    if (write) {
979       if (devinfo->gen >= 8 || devinfo->is_haswell) {
980          msg_type = HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE;
981       } else {
982          msg_type = GEN7_DATAPORT_RC_TYPED_SURFACE_WRITE;
983       }
984    } else {
985       if (devinfo->gen >= 8 || devinfo->is_haswell) {
986          msg_type = HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ;
987       } else {
988          msg_type = GEN7_DATAPORT_RC_TYPED_SURFACE_READ;
989       }
990    }
991 
992    /* See also MDC_SG3 in the SKL PRM Vol 2d. */
993    unsigned msg_control;
994    if (devinfo->gen >= 8 || devinfo->is_haswell) {
995       /* See also MDC_SG3 in the SKL PRM Vol 2d. */
996       const unsigned slot_group = exec_size == 0 ? 0 : /* SIMD4x2 */
997                                   1 + ((exec_group / 8) % 2);
998 
999       msg_control =
1000          SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
1001          SET_BITS(slot_group, 5, 4);
1002    } else {
1003       /* SIMD4x2 typed surface R/W messages only exist on HSW+ */
1004       assert(exec_size > 0);
1005       const unsigned slot_group = ((exec_group / 8) % 2);
1006 
1007       msg_control =
1008          SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
1009          SET_BITS(slot_group, 5, 5);
1010    }
1011 
1012    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
1013 }
1014 
1015 /**
1016  * Construct a message descriptor immediate with the specified pixel
1017  * interpolator function controls.
1018  */
1019 static inline uint32_t
brw_pixel_interp_desc(UNUSED const struct gen_device_info * devinfo,unsigned msg_type,bool noperspective,unsigned simd_mode,unsigned slot_group)1020 brw_pixel_interp_desc(UNUSED const struct gen_device_info *devinfo,
1021                       unsigned msg_type,
1022                       bool noperspective,
1023                       unsigned simd_mode,
1024                       unsigned slot_group)
1025 {
1026    return (SET_BITS(slot_group, 11, 11) |
1027            SET_BITS(msg_type, 13, 12) |
1028            SET_BITS(!!noperspective, 14, 14) |
1029            SET_BITS(simd_mode, 16, 16));
1030 }
1031 
1032 void brw_urb_WRITE(struct brw_codegen *p,
1033 		   struct brw_reg dest,
1034 		   unsigned msg_reg_nr,
1035 		   struct brw_reg src0,
1036                    enum brw_urb_write_flags flags,
1037 		   unsigned msg_length,
1038 		   unsigned response_length,
1039 		   unsigned offset,
1040 		   unsigned swizzle);
1041 
1042 /**
1043  * Send message to shared unit \p sfid with a possibly indirect descriptor \p
1044  * desc.  If \p desc is not an immediate it will be transparently loaded to an
1045  * address register using an OR instruction.
1046  */
1047 void
1048 brw_send_indirect_message(struct brw_codegen *p,
1049                           unsigned sfid,
1050                           struct brw_reg dst,
1051                           struct brw_reg payload,
1052                           struct brw_reg desc,
1053                           unsigned desc_imm,
1054                           bool eot);
1055 
1056 void
1057 brw_send_indirect_split_message(struct brw_codegen *p,
1058                                 unsigned sfid,
1059                                 struct brw_reg dst,
1060                                 struct brw_reg payload0,
1061                                 struct brw_reg payload1,
1062                                 struct brw_reg desc,
1063                                 unsigned desc_imm,
1064                                 struct brw_reg ex_desc,
1065                                 unsigned ex_desc_imm,
1066                                 bool eot);
1067 
1068 void brw_ff_sync(struct brw_codegen *p,
1069 		   struct brw_reg dest,
1070 		   unsigned msg_reg_nr,
1071 		   struct brw_reg src0,
1072 		   bool allocate,
1073 		   unsigned response_length,
1074 		   bool eot);
1075 
1076 void brw_svb_write(struct brw_codegen *p,
1077                    struct brw_reg dest,
1078                    unsigned msg_reg_nr,
1079                    struct brw_reg src0,
1080                    unsigned binding_table_index,
1081                    bool   send_commit_msg);
1082 
1083 brw_inst *brw_fb_WRITE(struct brw_codegen *p,
1084                        struct brw_reg payload,
1085                        struct brw_reg implied_header,
1086                        unsigned msg_control,
1087                        unsigned binding_table_index,
1088                        unsigned msg_length,
1089                        unsigned response_length,
1090                        bool eot,
1091                        bool last_render_target,
1092                        bool header_present);
1093 
1094 brw_inst *gen9_fb_READ(struct brw_codegen *p,
1095                        struct brw_reg dst,
1096                        struct brw_reg payload,
1097                        unsigned binding_table_index,
1098                        unsigned msg_length,
1099                        unsigned response_length,
1100                        bool per_sample);
1101 
1102 void brw_SAMPLE(struct brw_codegen *p,
1103 		struct brw_reg dest,
1104 		unsigned msg_reg_nr,
1105 		struct brw_reg src0,
1106 		unsigned binding_table_index,
1107 		unsigned sampler,
1108 		unsigned msg_type,
1109 		unsigned response_length,
1110 		unsigned msg_length,
1111 		unsigned header_present,
1112 		unsigned simd_mode,
1113 		unsigned return_format);
1114 
1115 void brw_adjust_sampler_state_pointer(struct brw_codegen *p,
1116                                       struct brw_reg header,
1117                                       struct brw_reg sampler_index);
1118 
1119 void gen4_math(struct brw_codegen *p,
1120 	       struct brw_reg dest,
1121 	       unsigned function,
1122 	       unsigned msg_reg_nr,
1123 	       struct brw_reg src,
1124 	       unsigned precision );
1125 
1126 void gen6_math(struct brw_codegen *p,
1127 	       struct brw_reg dest,
1128 	       unsigned function,
1129 	       struct brw_reg src0,
1130 	       struct brw_reg src1);
1131 
1132 void brw_oword_block_read(struct brw_codegen *p,
1133 			  struct brw_reg dest,
1134 			  struct brw_reg mrf,
1135 			  uint32_t offset,
1136 			  uint32_t bind_table_index);
1137 
1138 unsigned brw_scratch_surface_idx(const struct brw_codegen *p);
1139 
1140 void brw_oword_block_read_scratch(struct brw_codegen *p,
1141 				  struct brw_reg dest,
1142 				  struct brw_reg mrf,
1143 				  int num_regs,
1144 				  unsigned offset);
1145 
1146 void brw_oword_block_write_scratch(struct brw_codegen *p,
1147 				   struct brw_reg mrf,
1148 				   int num_regs,
1149 				   unsigned offset);
1150 
1151 void gen7_block_read_scratch(struct brw_codegen *p,
1152                              struct brw_reg dest,
1153                              int num_regs,
1154                              unsigned offset);
1155 
1156 void brw_shader_time_add(struct brw_codegen *p,
1157                          struct brw_reg payload,
1158                          uint32_t surf_index);
1159 
1160 /**
1161  * Return the generation-specific jump distance scaling factor.
1162  *
1163  * Given the number of instructions to jump, we need to scale by
1164  * some number to obtain the actual jump distance to program in an
1165  * instruction.
1166  */
1167 static inline unsigned
brw_jump_scale(const struct gen_device_info * devinfo)1168 brw_jump_scale(const struct gen_device_info *devinfo)
1169 {
1170    /* Broadwell measures jump targets in bytes. */
1171    if (devinfo->gen >= 8)
1172       return 16;
1173 
1174    /* Ironlake and later measure jump targets in 64-bit data chunks (in order
1175     * (to support compaction), so each 128-bit instruction requires 2 chunks.
1176     */
1177    if (devinfo->gen >= 5)
1178       return 2;
1179 
1180    /* Gen4 simply uses the number of 128-bit instructions. */
1181    return 1;
1182 }
1183 
1184 void brw_barrier(struct brw_codegen *p, struct brw_reg src);
1185 
1186 /* If/else/endif.  Works by manipulating the execution flags on each
1187  * channel.
1188  */
1189 brw_inst *brw_IF(struct brw_codegen *p, unsigned execute_size);
1190 brw_inst *gen6_IF(struct brw_codegen *p, enum brw_conditional_mod conditional,
1191                   struct brw_reg src0, struct brw_reg src1);
1192 
1193 void brw_ELSE(struct brw_codegen *p);
1194 void brw_ENDIF(struct brw_codegen *p);
1195 
1196 /* DO/WHILE loops:
1197  */
1198 brw_inst *brw_DO(struct brw_codegen *p, unsigned execute_size);
1199 
1200 brw_inst *brw_WHILE(struct brw_codegen *p);
1201 
1202 brw_inst *brw_BREAK(struct brw_codegen *p);
1203 brw_inst *brw_CONT(struct brw_codegen *p);
1204 brw_inst *brw_HALT(struct brw_codegen *p);
1205 
1206 /* Forward jumps:
1207  */
1208 void brw_land_fwd_jump(struct brw_codegen *p, int jmp_insn_idx);
1209 
1210 brw_inst *brw_JMPI(struct brw_codegen *p, struct brw_reg index,
1211                    unsigned predicate_control);
1212 
1213 void brw_NOP(struct brw_codegen *p);
1214 
1215 void brw_WAIT(struct brw_codegen *p);
1216 
1217 void brw_SYNC(struct brw_codegen *p, enum tgl_sync_function func);
1218 
1219 /* Special case: there is never a destination, execution size will be
1220  * taken from src0:
1221  */
1222 void brw_CMP(struct brw_codegen *p,
1223 	     struct brw_reg dest,
1224 	     unsigned conditional,
1225 	     struct brw_reg src0,
1226 	     struct brw_reg src1);
1227 
1228 void
1229 brw_untyped_atomic(struct brw_codegen *p,
1230                    struct brw_reg dst,
1231                    struct brw_reg payload,
1232                    struct brw_reg surface,
1233                    unsigned atomic_op,
1234                    unsigned msg_length,
1235                    bool response_expected,
1236                    bool header_present);
1237 
1238 void
1239 brw_untyped_surface_read(struct brw_codegen *p,
1240                          struct brw_reg dst,
1241                          struct brw_reg payload,
1242                          struct brw_reg surface,
1243                          unsigned msg_length,
1244                          unsigned num_channels);
1245 
1246 void
1247 brw_untyped_surface_write(struct brw_codegen *p,
1248                           struct brw_reg payload,
1249                           struct brw_reg surface,
1250                           unsigned msg_length,
1251                           unsigned num_channels,
1252                           bool header_present);
1253 
1254 void
1255 brw_memory_fence(struct brw_codegen *p,
1256                  struct brw_reg dst,
1257                  struct brw_reg src,
1258                  enum opcode send_op,
1259                  enum brw_message_target sfid,
1260                  bool commit_enable,
1261                  unsigned bti);
1262 
1263 void
1264 brw_pixel_interpolator_query(struct brw_codegen *p,
1265                              struct brw_reg dest,
1266                              struct brw_reg mrf,
1267                              bool noperspective,
1268                              unsigned mode,
1269                              struct brw_reg data,
1270                              unsigned msg_length,
1271                              unsigned response_length);
1272 
1273 void
1274 brw_find_live_channel(struct brw_codegen *p,
1275                       struct brw_reg dst,
1276                       struct brw_reg mask);
1277 
1278 void
1279 brw_broadcast(struct brw_codegen *p,
1280               struct brw_reg dst,
1281               struct brw_reg src,
1282               struct brw_reg idx);
1283 
1284 void
1285 brw_float_controls_mode(struct brw_codegen *p,
1286                         unsigned mode, unsigned mask);
1287 
1288 void
1289 brw_update_reloc_imm(const struct gen_device_info *devinfo,
1290                      brw_inst *inst,
1291                      uint32_t value);
1292 
1293 void
1294 brw_MOV_reloc_imm(struct brw_codegen *p,
1295                   struct brw_reg dst,
1296                   enum brw_reg_type src_type,
1297                   uint32_t id);
1298 
1299 /***********************************************************************
1300  * brw_eu_util.c:
1301  */
1302 
1303 void brw_copy_indirect_to_indirect(struct brw_codegen *p,
1304 				   struct brw_indirect dst_ptr,
1305 				   struct brw_indirect src_ptr,
1306 				   unsigned count);
1307 
1308 void brw_copy_from_indirect(struct brw_codegen *p,
1309 			    struct brw_reg dst,
1310 			    struct brw_indirect ptr,
1311 			    unsigned count);
1312 
1313 void brw_copy4(struct brw_codegen *p,
1314 	       struct brw_reg dst,
1315 	       struct brw_reg src,
1316 	       unsigned count);
1317 
1318 void brw_copy8(struct brw_codegen *p,
1319 	       struct brw_reg dst,
1320 	       struct brw_reg src,
1321 	       unsigned count);
1322 
1323 void brw_math_invert( struct brw_codegen *p,
1324 		      struct brw_reg dst,
1325 		      struct brw_reg src);
1326 
1327 void brw_set_src1(struct brw_codegen *p, brw_inst *insn, struct brw_reg reg);
1328 
1329 void brw_set_desc_ex(struct brw_codegen *p, brw_inst *insn,
1330                      unsigned desc, unsigned ex_desc);
1331 
1332 static inline void
brw_set_desc(struct brw_codegen * p,brw_inst * insn,unsigned desc)1333 brw_set_desc(struct brw_codegen *p, brw_inst *insn, unsigned desc)
1334 {
1335    brw_set_desc_ex(p, insn, desc, 0);
1336 }
1337 
1338 void brw_set_uip_jip(struct brw_codegen *p, int start_offset);
1339 
1340 enum brw_conditional_mod brw_negate_cmod(enum brw_conditional_mod cmod);
1341 enum brw_conditional_mod brw_swap_cmod(enum brw_conditional_mod cmod);
1342 
1343 /* brw_eu_compact.c */
1344 void brw_compact_instructions(struct brw_codegen *p, int start_offset,
1345                               struct disasm_info *disasm);
1346 void brw_uncompact_instruction(const struct gen_device_info *devinfo,
1347                                brw_inst *dst, brw_compact_inst *src);
1348 bool brw_try_compact_instruction(const struct gen_device_info *devinfo,
1349                                  brw_compact_inst *dst, const brw_inst *src);
1350 
1351 void brw_debug_compact_uncompact(const struct gen_device_info *devinfo,
1352                                  brw_inst *orig, brw_inst *uncompacted);
1353 
1354 /* brw_eu_validate.c */
1355 bool brw_validate_instruction(const struct gen_device_info *devinfo,
1356                               const brw_inst *inst, int offset,
1357                               struct disasm_info *disasm);
1358 bool brw_validate_instructions(const struct gen_device_info *devinfo,
1359                                const void *assembly, int start_offset, int end_offset,
1360                                struct disasm_info *disasm);
1361 
1362 static inline int
next_offset(const struct gen_device_info * devinfo,void * store,int offset)1363 next_offset(const struct gen_device_info *devinfo, void *store, int offset)
1364 {
1365    brw_inst *insn = (brw_inst *)((char *)store + offset);
1366 
1367    if (brw_inst_cmpt_control(devinfo, insn))
1368       return offset + 8;
1369    else
1370       return offset + 16;
1371 }
1372 
1373 struct opcode_desc {
1374    unsigned ir;
1375    unsigned hw;
1376    const char *name;
1377    int nsrc;
1378    int ndst;
1379    int gens;
1380 };
1381 
1382 const struct opcode_desc *
1383 brw_opcode_desc(const struct gen_device_info *devinfo, enum opcode opcode);
1384 
1385 const struct opcode_desc *
1386 brw_opcode_desc_from_hw(const struct gen_device_info *devinfo, unsigned hw);
1387 
1388 static inline unsigned
brw_opcode_encode(const struct gen_device_info * devinfo,enum opcode opcode)1389 brw_opcode_encode(const struct gen_device_info *devinfo, enum opcode opcode)
1390 {
1391    return brw_opcode_desc(devinfo, opcode)->hw;
1392 }
1393 
1394 static inline enum opcode
brw_opcode_decode(const struct gen_device_info * devinfo,unsigned hw)1395 brw_opcode_decode(const struct gen_device_info *devinfo, unsigned hw)
1396 {
1397    const struct opcode_desc *desc = brw_opcode_desc_from_hw(devinfo, hw);
1398    return desc ? (enum opcode)desc->ir : BRW_OPCODE_ILLEGAL;
1399 }
1400 
1401 static inline void
brw_inst_set_opcode(const struct gen_device_info * devinfo,brw_inst * inst,enum opcode opcode)1402 brw_inst_set_opcode(const struct gen_device_info *devinfo,
1403                     brw_inst *inst, enum opcode opcode)
1404 {
1405    brw_inst_set_hw_opcode(devinfo, inst, brw_opcode_encode(devinfo, opcode));
1406 }
1407 
1408 static inline enum opcode
brw_inst_opcode(const struct gen_device_info * devinfo,const brw_inst * inst)1409 brw_inst_opcode(const struct gen_device_info *devinfo, const brw_inst *inst)
1410 {
1411    return brw_opcode_decode(devinfo, brw_inst_hw_opcode(devinfo, inst));
1412 }
1413 
1414 static inline bool
is_3src(const struct gen_device_info * devinfo,enum opcode opcode)1415 is_3src(const struct gen_device_info *devinfo, enum opcode opcode)
1416 {
1417    const struct opcode_desc *desc = brw_opcode_desc(devinfo, opcode);
1418    return desc && desc->nsrc == 3;
1419 }
1420 
1421 /** Maximum SEND message length */
1422 #define BRW_MAX_MSG_LENGTH 15
1423 
1424 /** First MRF register used by pull loads */
1425 #define FIRST_SPILL_MRF(gen) ((gen) == 6 ? 21 : 13)
1426 
1427 /** First MRF register used by spills */
1428 #define FIRST_PULL_LOAD_MRF(gen) ((gen) == 6 ? 16 : 13)
1429 
1430 #ifdef __cplusplus
1431 }
1432 #endif
1433 
1434 #endif
1435