• 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_isa_info.h"
42 #include "brw_reg.h"
43 
44 #include "util/bitset.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 struct disasm_info;
51 
52 #define BRW_EU_MAX_INSN_STACK 5
53 
54 struct brw_insn_state {
55    /* One of BRW_EXECUTE_* */
56    unsigned exec_size:3;
57 
58    /* Group in units of channels */
59    unsigned group:5;
60 
61    /* One of BRW_MASK_* */
62    unsigned mask_control:1;
63 
64    /* Scheduling info for Gfx12+ */
65    struct tgl_swsb swsb;
66 
67    bool saturate:1;
68 
69    /* One of BRW_ALIGN_* */
70    unsigned access_mode:1;
71 
72    /* One of BRW_PREDICATE_* */
73    enum brw_predicate predicate:4;
74 
75    bool pred_inv:1;
76 
77    /* Flag subreg.  Bottom bit is subreg, top bit is reg */
78    unsigned flag_subreg:2;
79 
80    bool acc_wr_control:1;
81 };
82 
83 
84 /* A helper for accessing the last instruction emitted.  This makes it easy
85  * to set various bits on an instruction without having to create temporary
86  * variable and assign the emitted instruction to those.
87  */
88 #define brw_last_inst (&p->store[p->nr_insn - 1])
89 
90 struct brw_codegen {
91    brw_inst *store;
92    int store_size;
93    unsigned nr_insn;
94    unsigned int next_insn_offset;
95 
96    void *mem_ctx;
97 
98    /* Allow clients to push/pop instruction state:
99     */
100    struct brw_insn_state stack[BRW_EU_MAX_INSN_STACK];
101    struct brw_insn_state *current;
102 
103    const struct brw_isa_info *isa;
104    const struct intel_device_info *devinfo;
105 
106    /* Control flow stacks:
107     * - if_stack contains IF and ELSE instructions which must be patched
108     *   (and popped) once the matching ENDIF instruction is encountered.
109     *
110     *   Just store the instruction pointer(an index).
111     */
112    int *if_stack;
113    int if_stack_depth;
114    int if_stack_array_size;
115 
116    /**
117     * loop_stack contains the instruction pointers of the starts of loops which
118     * must be patched (and popped) once the matching WHILE instruction is
119     * encountered.
120     */
121    int *loop_stack;
122    /**
123     * pre-gfx6, the BREAK and CONT instructions had to tell how many IF/ENDIF
124     * blocks they were popping out of, to fix up the mask stack.  This tracks
125     * the IF/ENDIF nesting in each current nested loop level.
126     */
127    int *if_depth_in_loop;
128    int loop_stack_depth;
129    int loop_stack_array_size;
130 
131    struct brw_shader_reloc *relocs;
132    int num_relocs;
133    int reloc_array_size;
134 };
135 
136 struct brw_label {
137    int offset;
138    int number;
139    struct brw_label *next;
140 };
141 
142 void brw_pop_insn_state( struct brw_codegen *p );
143 void brw_push_insn_state( struct brw_codegen *p );
144 unsigned brw_get_default_exec_size(struct brw_codegen *p);
145 unsigned brw_get_default_group(struct brw_codegen *p);
146 unsigned brw_get_default_access_mode(struct brw_codegen *p);
147 struct tgl_swsb brw_get_default_swsb(struct brw_codegen *p);
148 void brw_set_default_exec_size(struct brw_codegen *p, unsigned value);
149 void brw_set_default_mask_control( struct brw_codegen *p, unsigned value );
150 void brw_set_default_saturate( struct brw_codegen *p, bool enable );
151 void brw_set_default_access_mode( struct brw_codegen *p, unsigned access_mode );
152 void brw_inst_set_group(const struct intel_device_info *devinfo,
153                         brw_inst *inst, unsigned group);
154 void brw_set_default_group(struct brw_codegen *p, unsigned group);
155 void brw_set_default_compression_control(struct brw_codegen *p, enum brw_compression c);
156 void brw_set_default_predicate_control(struct brw_codegen *p, enum brw_predicate pc);
157 void brw_set_default_predicate_inverse(struct brw_codegen *p, bool predicate_inverse);
158 void brw_set_default_flag_reg(struct brw_codegen *p, int reg, int subreg);
159 void brw_set_default_acc_write_control(struct brw_codegen *p, unsigned value);
160 void brw_set_default_swsb(struct brw_codegen *p, struct tgl_swsb value);
161 
162 void brw_init_codegen(const struct brw_isa_info *isa,
163                       struct brw_codegen *p, void *mem_ctx);
164 bool brw_has_jip(const struct intel_device_info *devinfo, enum opcode opcode);
165 bool brw_has_uip(const struct intel_device_info *devinfo, enum opcode opcode);
166 const struct brw_shader_reloc *brw_get_shader_relocs(struct brw_codegen *p,
167                                                      unsigned *num_relocs);
168 const unsigned *brw_get_program( struct brw_codegen *p, unsigned *sz );
169 
170 bool brw_should_dump_shader_bin(void);
171 void brw_dump_shader_bin(void *assembly, int start_offset, int end_offset,
172                          const char *identifier);
173 
174 bool brw_try_override_assembly(struct brw_codegen *p, int start_offset,
175                                const char *identifier);
176 
177 void brw_realign(struct brw_codegen *p, unsigned alignment);
178 int brw_append_data(struct brw_codegen *p, void *data,
179                     unsigned size, unsigned alignment);
180 brw_inst *brw_next_insn(struct brw_codegen *p, unsigned opcode);
181 void brw_add_reloc(struct brw_codegen *p, uint32_t id,
182                    enum brw_shader_reloc_type type,
183                    uint32_t offset, uint32_t delta);
184 void brw_set_dest(struct brw_codegen *p, brw_inst *insn, struct brw_reg dest);
185 void brw_set_src0(struct brw_codegen *p, brw_inst *insn, struct brw_reg reg);
186 
187 /* Helpers for regular instructions:
188  */
189 #define ALU1(OP)				\
190 brw_inst *brw_##OP(struct brw_codegen *p,	\
191 	      struct brw_reg dest,		\
192 	      struct brw_reg src0);
193 
194 #define ALU2(OP)				\
195 brw_inst *brw_##OP(struct brw_codegen *p,	\
196 	      struct brw_reg dest,		\
197 	      struct brw_reg src0,		\
198 	      struct brw_reg src1);
199 
200 #define ALU3(OP)				\
201 brw_inst *brw_##OP(struct brw_codegen *p,	\
202 	      struct brw_reg dest,		\
203 	      struct brw_reg src0,		\
204 	      struct brw_reg src1,		\
205 	      struct brw_reg src2);
206 
207 ALU1(MOV)
ALU2(SEL)208 ALU2(SEL)
209 ALU1(NOT)
210 ALU2(AND)
211 ALU2(OR)
212 ALU2(XOR)
213 ALU2(SHR)
214 ALU2(SHL)
215 ALU1(DIM)
216 ALU2(ASR)
217 ALU2(ROL)
218 ALU2(ROR)
219 ALU3(CSEL)
220 ALU1(F32TO16)
221 ALU1(F16TO32)
222 ALU2(ADD)
223 ALU3(ADD3)
224 ALU2(AVG)
225 ALU2(MUL)
226 ALU1(FRC)
227 ALU1(RNDD)
228 ALU1(RNDE)
229 ALU1(RNDU)
230 ALU1(RNDZ)
231 ALU2(MAC)
232 ALU2(MACH)
233 ALU1(LZD)
234 ALU2(DP4)
235 ALU2(DPH)
236 ALU2(DP3)
237 ALU2(DP2)
238 ALU3(DP4A)
239 ALU2(LINE)
240 ALU2(PLN)
241 ALU3(MAD)
242 ALU3(LRP)
243 ALU1(BFREV)
244 ALU3(BFE)
245 ALU2(BFI1)
246 ALU3(BFI2)
247 ALU1(FBH)
248 ALU1(FBL)
249 ALU1(CBIT)
250 ALU2(ADDC)
251 ALU2(SUBB)
252 
253 #undef ALU1
254 #undef ALU2
255 #undef ALU3
256 
257 static inline unsigned
258 reg_unit(const struct intel_device_info *devinfo)
259 {
260    return devinfo->ver >= 20 ? 2 : 1;
261 }
262 
263 
264 /* Helpers for SEND instruction:
265  */
266 
267 /**
268  * Construct a message descriptor immediate with the specified common
269  * descriptor controls.
270  */
271 static inline uint32_t
brw_message_desc(const struct intel_device_info * devinfo,unsigned msg_length,unsigned response_length,bool header_present)272 brw_message_desc(const struct intel_device_info *devinfo,
273                  unsigned msg_length,
274                  unsigned response_length,
275                  bool header_present)
276 {
277    assert(msg_length % reg_unit(devinfo) == 0);
278    assert(response_length % reg_unit(devinfo) == 0);
279    return (SET_BITS(msg_length / reg_unit(devinfo), 28, 25) |
280            SET_BITS(response_length / reg_unit(devinfo), 24, 20) |
281            SET_BITS(header_present, 19, 19));
282 }
283 
284 static inline unsigned
brw_message_desc_mlen(const struct intel_device_info * devinfo,uint32_t desc)285 brw_message_desc_mlen(const struct intel_device_info *devinfo, uint32_t desc)
286 {
287    return GET_BITS(desc, 28, 25) * reg_unit(devinfo);
288 }
289 
290 static inline unsigned
brw_message_desc_rlen(const struct intel_device_info * devinfo,uint32_t desc)291 brw_message_desc_rlen(const struct intel_device_info *devinfo, uint32_t desc)
292 {
293    return GET_BITS(desc, 24, 20) * reg_unit(devinfo);
294 }
295 
296 static inline bool
brw_message_desc_header_present(ASSERTED const struct intel_device_info * devinfo,uint32_t desc)297 brw_message_desc_header_present(ASSERTED
298                                 const struct intel_device_info *devinfo,
299                                 uint32_t desc)
300 {
301    return GET_BITS(desc, 19, 19);
302 }
303 
304 static inline unsigned
brw_message_ex_desc(const struct intel_device_info * devinfo,unsigned ex_msg_length)305 brw_message_ex_desc(const struct intel_device_info *devinfo,
306                     unsigned ex_msg_length)
307 {
308    assert(ex_msg_length % reg_unit(devinfo) == 0);
309    return SET_BITS(ex_msg_length / reg_unit(devinfo), 9, 6);
310 }
311 
312 static inline unsigned
brw_message_ex_desc_ex_mlen(const struct intel_device_info * devinfo,uint32_t ex_desc)313 brw_message_ex_desc_ex_mlen(const struct intel_device_info *devinfo,
314                             uint32_t ex_desc)
315 {
316    return GET_BITS(ex_desc, 9, 6) * reg_unit(devinfo);
317 }
318 
319 static inline uint32_t
brw_urb_desc(const struct intel_device_info * devinfo,unsigned msg_type,bool per_slot_offset_present,bool channel_mask_present,unsigned global_offset)320 brw_urb_desc(const struct intel_device_info *devinfo,
321              unsigned msg_type,
322              bool per_slot_offset_present,
323              bool channel_mask_present,
324              unsigned global_offset)
325 {
326    return (SET_BITS(per_slot_offset_present, 17, 17) |
327            SET_BITS(channel_mask_present, 15, 15) |
328            SET_BITS(global_offset, 14, 4) |
329            SET_BITS(msg_type, 3, 0));
330 }
331 
332 static inline uint32_t
brw_urb_desc_msg_type(ASSERTED const struct intel_device_info * devinfo,uint32_t desc)333 brw_urb_desc_msg_type(ASSERTED const struct intel_device_info *devinfo,
334                       uint32_t desc)
335 {
336    return GET_BITS(desc, 3, 0);
337 }
338 
339 static inline uint32_t
brw_urb_fence_desc(const struct intel_device_info * devinfo)340 brw_urb_fence_desc(const struct intel_device_info *devinfo)
341 {
342    assert(devinfo->has_lsc);
343    return brw_urb_desc(devinfo, GFX125_URB_OPCODE_FENCE, false, false, 0);
344 }
345 
346 /**
347  * Construct a message descriptor immediate with the specified sampler
348  * function controls.
349  */
350 static inline uint32_t
brw_sampler_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned sampler,unsigned msg_type,unsigned simd_mode,unsigned return_format)351 brw_sampler_desc(const struct intel_device_info *devinfo,
352                  unsigned binding_table_index,
353                  unsigned sampler,
354                  unsigned msg_type,
355                  unsigned simd_mode,
356                  unsigned return_format)
357 {
358    const unsigned desc = (SET_BITS(binding_table_index, 7, 0) |
359                           SET_BITS(sampler, 11, 8));
360 
361    /* From GFX20 Bspec: Shared Functions - Message Descriptor -
362     * Sampling Engine:
363     *
364     *    Message Type[5]  31  This bit represents the upper bit of message type
365     *                         6-bit encoding (c.f. [16:12]). This bit is set
366     *                         for messages with programmable offsets.
367     */
368    if (devinfo->ver >= 20)
369       return desc | SET_BITS(msg_type & 0x1F, 16, 12) |
370              SET_BITS(simd_mode & 0x3, 18, 17) |
371              SET_BITS(simd_mode >> 2, 29, 29) |
372              SET_BITS(return_format, 30, 30) |
373              SET_BITS(msg_type >> 5, 31, 31);
374 
375    /* From the CHV Bspec: Shared Functions - Message Descriptor -
376     * Sampling Engine:
377     *
378     *   SIMD Mode[2]  29    This field is the upper bit of the 3-bit
379     *                       SIMD Mode field.
380     */
381    return desc | SET_BITS(msg_type, 16, 12) |
382           SET_BITS(simd_mode & 0x3, 18, 17) |
383           SET_BITS(simd_mode >> 2, 29, 29) |
384           SET_BITS(return_format, 30, 30);
385 }
386 
387 static inline unsigned
brw_sampler_desc_binding_table_index(UNUSED const struct intel_device_info * devinfo,uint32_t desc)388 brw_sampler_desc_binding_table_index(UNUSED
389                                      const struct intel_device_info *devinfo,
390                                      uint32_t desc)
391 {
392    return GET_BITS(desc, 7, 0);
393 }
394 
395 static inline unsigned
brw_sampler_desc_sampler(UNUSED const struct intel_device_info * devinfo,uint32_t desc)396 brw_sampler_desc_sampler(UNUSED const struct intel_device_info *devinfo,
397                          uint32_t desc)
398 {
399    return GET_BITS(desc, 11, 8);
400 }
401 
402 static inline unsigned
brw_sampler_desc_msg_type(const struct intel_device_info * devinfo,uint32_t desc)403 brw_sampler_desc_msg_type(const struct intel_device_info *devinfo, uint32_t desc)
404 {
405    if (devinfo->ver >= 20)
406       return GET_BITS(desc, 31, 31) << 5 | GET_BITS(desc, 16, 12);
407    else
408       return GET_BITS(desc, 16, 12);
409 }
410 
411 static inline unsigned
brw_sampler_desc_simd_mode(const struct intel_device_info * devinfo,uint32_t desc)412 brw_sampler_desc_simd_mode(const struct intel_device_info *devinfo,
413                            uint32_t desc)
414 {
415    return GET_BITS(desc, 18, 17) | GET_BITS(desc, 29, 29) << 2;
416 }
417 
418 static inline unsigned
brw_sampler_desc_return_format(ASSERTED const struct intel_device_info * devinfo,uint32_t desc)419 brw_sampler_desc_return_format(ASSERTED const struct intel_device_info *devinfo,
420                                uint32_t desc)
421 {
422    return GET_BITS(desc, 30, 30);
423 }
424 
425 /**
426  * Construct a message descriptor for the dataport
427  */
428 static inline uint32_t
brw_dp_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_type,unsigned msg_control)429 brw_dp_desc(const struct intel_device_info *devinfo,
430             unsigned binding_table_index,
431             unsigned msg_type,
432             unsigned msg_control)
433 {
434    return SET_BITS(binding_table_index, 7, 0) |
435           SET_BITS(msg_control, 13, 8) |
436           SET_BITS(msg_type, 18, 14);
437 }
438 
439 static inline unsigned
brw_dp_desc_binding_table_index(UNUSED const struct intel_device_info * devinfo,uint32_t desc)440 brw_dp_desc_binding_table_index(UNUSED const struct intel_device_info *devinfo,
441                                 uint32_t desc)
442 {
443    return GET_BITS(desc, 7, 0);
444 }
445 
446 static inline unsigned
brw_dp_desc_msg_type(const struct intel_device_info * devinfo,uint32_t desc)447 brw_dp_desc_msg_type(const struct intel_device_info *devinfo, uint32_t desc)
448 {
449    return GET_BITS(desc, 18, 14);
450 }
451 
452 static inline unsigned
brw_dp_desc_msg_control(const struct intel_device_info * devinfo,uint32_t desc)453 brw_dp_desc_msg_control(const struct intel_device_info *devinfo, uint32_t desc)
454 {
455    return GET_BITS(desc, 13, 8);
456 }
457 
458 /**
459  * Construct a message descriptor immediate with the specified dataport read
460  * function controls.
461  */
462 static inline uint32_t
brw_dp_read_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,unsigned msg_type,unsigned target_cache)463 brw_dp_read_desc(const struct intel_device_info *devinfo,
464                  unsigned binding_table_index,
465                  unsigned msg_control,
466                  unsigned msg_type,
467                  unsigned target_cache)
468 {
469    return brw_dp_desc(devinfo, binding_table_index, msg_type, msg_control);
470 }
471 
472 static inline unsigned
brw_dp_read_desc_msg_type(const struct intel_device_info * devinfo,uint32_t desc)473 brw_dp_read_desc_msg_type(const struct intel_device_info *devinfo,
474                           uint32_t desc)
475 {
476    return brw_dp_desc_msg_type(devinfo, desc);
477 }
478 
479 static inline unsigned
brw_dp_read_desc_msg_control(const struct intel_device_info * devinfo,uint32_t desc)480 brw_dp_read_desc_msg_control(const struct intel_device_info *devinfo,
481                              uint32_t desc)
482 {
483    return brw_dp_desc_msg_control(devinfo, desc);
484 }
485 
486 /**
487  * Construct a message descriptor immediate with the specified dataport write
488  * function controls.
489  */
490 static inline uint32_t
brw_dp_write_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,unsigned msg_type,unsigned send_commit_msg)491 brw_dp_write_desc(const struct intel_device_info *devinfo,
492                   unsigned binding_table_index,
493                   unsigned msg_control,
494                   unsigned msg_type,
495                   unsigned send_commit_msg)
496 {
497    assert(!send_commit_msg);
498    return brw_dp_desc(devinfo, binding_table_index, msg_type, msg_control) |
499           SET_BITS(send_commit_msg, 17, 17);
500 }
501 
502 static inline unsigned
brw_dp_write_desc_msg_type(const struct intel_device_info * devinfo,uint32_t desc)503 brw_dp_write_desc_msg_type(const struct intel_device_info *devinfo,
504                            uint32_t desc)
505 {
506    return brw_dp_desc_msg_type(devinfo, desc);
507 }
508 
509 static inline unsigned
brw_dp_write_desc_msg_control(const struct intel_device_info * devinfo,uint32_t desc)510 brw_dp_write_desc_msg_control(const struct intel_device_info *devinfo,
511                               uint32_t desc)
512 {
513    return brw_dp_desc_msg_control(devinfo, desc);
514 }
515 
516 /**
517  * Construct a message descriptor immediate with the specified dataport
518  * surface function controls.
519  */
520 static inline uint32_t
brw_dp_surface_desc(const struct intel_device_info * devinfo,unsigned msg_type,unsigned msg_control)521 brw_dp_surface_desc(const struct intel_device_info *devinfo,
522                     unsigned msg_type,
523                     unsigned msg_control)
524 {
525    /* We'll OR in the binding table index later */
526    return brw_dp_desc(devinfo, 0, msg_type, msg_control);
527 }
528 
529 static inline uint32_t
brw_dp_untyped_atomic_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned atomic_op,bool response_expected)530 brw_dp_untyped_atomic_desc(const struct intel_device_info *devinfo,
531                            unsigned exec_size, /**< 0 for SIMD4x2 */
532                            unsigned atomic_op,
533                            bool response_expected)
534 {
535    assert(exec_size <= 8 || exec_size == 16);
536 
537    unsigned msg_type;
538    if (exec_size > 0) {
539       msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP;
540    } else {
541       msg_type = HSW_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_OP_SIMD4X2;
542    }
543 
544    const unsigned msg_control =
545       SET_BITS(atomic_op, 3, 0) |
546       SET_BITS(0 < exec_size && exec_size <= 8, 4, 4) |
547       SET_BITS(response_expected, 5, 5);
548 
549    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
550 }
551 
552 static inline uint32_t
brw_dp_untyped_atomic_float_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned atomic_op,bool response_expected)553 brw_dp_untyped_atomic_float_desc(const struct intel_device_info *devinfo,
554                                  unsigned exec_size,
555                                  unsigned atomic_op,
556                                  bool response_expected)
557 {
558    assert(exec_size <= 8 || exec_size == 16);
559 
560    assert(exec_size > 0);
561    const unsigned msg_type = GFX9_DATAPORT_DC_PORT1_UNTYPED_ATOMIC_FLOAT_OP;
562 
563    const unsigned msg_control =
564       SET_BITS(atomic_op, 1, 0) |
565       SET_BITS(exec_size <= 8, 4, 4) |
566       SET_BITS(response_expected, 5, 5);
567 
568    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
569 }
570 
571 static inline unsigned
brw_mdc_cmask(unsigned num_channels)572 brw_mdc_cmask(unsigned num_channels)
573 {
574    /* See also MDC_CMASK in the SKL PRM Vol 2d. */
575    return 0xf & (0xf << num_channels);
576 }
577 
578 static inline unsigned
lsc_cmask(unsigned num_channels)579 lsc_cmask(unsigned num_channels)
580 {
581    assert(num_channels > 0 && num_channels <= 4);
582    return BITSET_MASK(num_channels);
583 }
584 
585 static inline uint32_t
brw_dp_untyped_surface_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned num_channels,bool write)586 brw_dp_untyped_surface_rw_desc(const struct intel_device_info *devinfo,
587                                unsigned exec_size, /**< 0 for SIMD4x2 */
588                                unsigned num_channels,
589                                bool write)
590 {
591    assert(exec_size <= 8 || exec_size == 16);
592 
593    const unsigned msg_type =
594       write ? HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_WRITE :
595               HSW_DATAPORT_DC_PORT1_UNTYPED_SURFACE_READ;
596 
597    /* See also MDC_SM3 in the SKL PRM Vol 2d. */
598    const unsigned simd_mode = exec_size == 0 ? 0 : /* SIMD4x2 */
599                               exec_size <= 8 ? 2 : 1;
600 
601    const unsigned msg_control =
602       SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
603       SET_BITS(simd_mode, 5, 4);
604 
605    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
606 }
607 
608 static inline unsigned
brw_mdc_ds(unsigned bit_size)609 brw_mdc_ds(unsigned bit_size)
610 {
611    switch (bit_size) {
612    case 8:
613       return GFX7_BYTE_SCATTERED_DATA_ELEMENT_BYTE;
614    case 16:
615       return GFX7_BYTE_SCATTERED_DATA_ELEMENT_WORD;
616    case 32:
617       return GFX7_BYTE_SCATTERED_DATA_ELEMENT_DWORD;
618    default:
619       unreachable("Unsupported bit_size for byte scattered messages");
620    }
621 }
622 
623 static inline uint32_t
brw_dp_byte_scattered_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned bit_size,bool write)624 brw_dp_byte_scattered_rw_desc(const struct intel_device_info *devinfo,
625                               unsigned exec_size,
626                               unsigned bit_size,
627                               bool write)
628 {
629    assert(exec_size <= 8 || exec_size == 16);
630 
631    const unsigned msg_type =
632       write ? HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_WRITE :
633               HSW_DATAPORT_DC_PORT0_BYTE_SCATTERED_READ;
634 
635    assert(exec_size > 0);
636    const unsigned msg_control =
637       SET_BITS(exec_size == 16, 0, 0) |
638       SET_BITS(brw_mdc_ds(bit_size), 3, 2);
639 
640    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
641 }
642 
643 static inline uint32_t
brw_dp_dword_scattered_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,bool write)644 brw_dp_dword_scattered_rw_desc(const struct intel_device_info *devinfo,
645                                unsigned exec_size,
646                                bool write)
647 {
648    assert(exec_size == 8 || exec_size == 16);
649 
650    const unsigned msg_type =
651       write ? GFX6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE :
652               GFX7_DATAPORT_DC_DWORD_SCATTERED_READ;
653 
654    const unsigned msg_control =
655       SET_BITS(1, 1, 1) | /* Legacy SIMD Mode */
656       SET_BITS(exec_size == 16, 0, 0);
657 
658    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
659 }
660 
661 static inline uint32_t
brw_dp_oword_block_rw_desc(const struct intel_device_info * devinfo,bool align_16B,unsigned num_dwords,bool write)662 brw_dp_oword_block_rw_desc(const struct intel_device_info *devinfo,
663                            bool align_16B,
664                            unsigned num_dwords,
665                            bool write)
666 {
667    /* Writes can only have addresses aligned by OWORDs (16 Bytes). */
668    assert(!write || align_16B);
669 
670    const unsigned msg_type =
671       write ?     GFX7_DATAPORT_DC_OWORD_BLOCK_WRITE :
672       align_16B ? GFX7_DATAPORT_DC_OWORD_BLOCK_READ :
673                   GFX7_DATAPORT_DC_UNALIGNED_OWORD_BLOCK_READ;
674 
675    const unsigned msg_control =
676       SET_BITS(BRW_DATAPORT_OWORD_BLOCK_DWORDS(num_dwords), 2, 0);
677 
678    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
679 }
680 
681 static inline uint32_t
brw_dp_a64_untyped_surface_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned num_channels,bool write)682 brw_dp_a64_untyped_surface_rw_desc(const struct intel_device_info *devinfo,
683                                    unsigned exec_size, /**< 0 for SIMD4x2 */
684                                    unsigned num_channels,
685                                    bool write)
686 {
687    assert(exec_size <= 8 || exec_size == 16);
688 
689    unsigned msg_type =
690       write ? GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_WRITE :
691               GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_SURFACE_READ;
692 
693    /* See also MDC_SM3 in the SKL PRM Vol 2d. */
694    const unsigned simd_mode = exec_size == 0 ? 0 : /* SIMD4x2 */
695                               exec_size <= 8 ? 2 : 1;
696 
697    const unsigned msg_control =
698       SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
699       SET_BITS(simd_mode, 5, 4);
700 
701    return brw_dp_desc(devinfo, GFX8_BTI_STATELESS_NON_COHERENT,
702                       msg_type, msg_control);
703 }
704 
705 static inline uint32_t
brw_dp_a64_oword_block_rw_desc(const struct intel_device_info * devinfo,bool align_16B,unsigned num_dwords,bool write)706 brw_dp_a64_oword_block_rw_desc(const struct intel_device_info *devinfo,
707                                bool align_16B,
708                                unsigned num_dwords,
709                                bool write)
710 {
711    /* Writes can only have addresses aligned by OWORDs (16 Bytes). */
712    assert(!write || align_16B);
713 
714    unsigned msg_type =
715       write ? GFX9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_WRITE :
716               GFX9_DATAPORT_DC_PORT1_A64_OWORD_BLOCK_READ;
717 
718    unsigned msg_control =
719       SET_BITS(!align_16B, 4, 3) |
720       SET_BITS(BRW_DATAPORT_OWORD_BLOCK_DWORDS(num_dwords), 2, 0);
721 
722    return brw_dp_desc(devinfo, GFX8_BTI_STATELESS_NON_COHERENT,
723                       msg_type, msg_control);
724 }
725 
726 /**
727  * Calculate the data size (see MDC_A64_DS in the "Structures" volume of the
728  * Skylake PRM).
729  */
730 static inline uint32_t
brw_mdc_a64_ds(unsigned elems)731 brw_mdc_a64_ds(unsigned elems)
732 {
733    switch (elems) {
734    case 1:  return 0;
735    case 2:  return 1;
736    case 4:  return 2;
737    case 8:  return 3;
738    default:
739       unreachable("Unsupported elmeent count for A64 scattered message");
740    }
741 }
742 
743 static inline uint32_t
brw_dp_a64_byte_scattered_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned bit_size,bool write)744 brw_dp_a64_byte_scattered_rw_desc(const struct intel_device_info *devinfo,
745                                   unsigned exec_size, /**< 0 for SIMD4x2 */
746                                   unsigned bit_size,
747                                   bool write)
748 {
749    assert(exec_size <= 8 || exec_size == 16);
750 
751    unsigned msg_type =
752       write ? GFX8_DATAPORT_DC_PORT1_A64_SCATTERED_WRITE :
753               GFX9_DATAPORT_DC_PORT1_A64_SCATTERED_READ;
754 
755    const unsigned msg_control =
756       SET_BITS(GFX8_A64_SCATTERED_SUBTYPE_BYTE, 1, 0) |
757       SET_BITS(brw_mdc_a64_ds(bit_size / 8), 3, 2) |
758       SET_BITS(exec_size == 16, 4, 4);
759 
760    return brw_dp_desc(devinfo, GFX8_BTI_STATELESS_NON_COHERENT,
761                       msg_type, msg_control);
762 }
763 
764 static inline uint32_t
brw_dp_a64_untyped_atomic_desc(const struct intel_device_info * devinfo,ASSERTED unsigned exec_size,unsigned bit_size,unsigned atomic_op,bool response_expected)765 brw_dp_a64_untyped_atomic_desc(const struct intel_device_info *devinfo,
766                                ASSERTED unsigned exec_size, /**< 0 for SIMD4x2 */
767                                unsigned bit_size,
768                                unsigned atomic_op,
769                                bool response_expected)
770 {
771    assert(exec_size == 8);
772    assert(bit_size == 16 || bit_size == 32 || bit_size == 64);
773    assert(devinfo->ver >= 12 || bit_size >= 32);
774 
775    const unsigned msg_type = bit_size == 16 ?
776       GFX12_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_HALF_INT_OP :
777       GFX8_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_OP;
778 
779    const unsigned msg_control =
780       SET_BITS(atomic_op, 3, 0) |
781       SET_BITS(bit_size == 64, 4, 4) |
782       SET_BITS(response_expected, 5, 5);
783 
784    return brw_dp_desc(devinfo, GFX8_BTI_STATELESS_NON_COHERENT,
785                       msg_type, msg_control);
786 }
787 
788 static inline uint32_t
brw_dp_a64_untyped_atomic_float_desc(const struct intel_device_info * devinfo,ASSERTED unsigned exec_size,unsigned bit_size,unsigned atomic_op,bool response_expected)789 brw_dp_a64_untyped_atomic_float_desc(const struct intel_device_info *devinfo,
790                                      ASSERTED unsigned exec_size,
791                                      unsigned bit_size,
792                                      unsigned atomic_op,
793                                      bool response_expected)
794 {
795    assert(exec_size == 8);
796    assert(bit_size == 16 || bit_size == 32);
797    assert(devinfo->ver >= 12 || bit_size == 32);
798 
799    assert(exec_size > 0);
800    const unsigned msg_type = bit_size == 32 ?
801       GFX9_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_FLOAT_OP :
802       GFX12_DATAPORT_DC_PORT1_A64_UNTYPED_ATOMIC_HALF_FLOAT_OP;
803 
804    const unsigned msg_control =
805       SET_BITS(atomic_op, 1, 0) |
806       SET_BITS(response_expected, 5, 5);
807 
808    return brw_dp_desc(devinfo, GFX8_BTI_STATELESS_NON_COHERENT,
809                       msg_type, msg_control);
810 }
811 
812 static inline uint32_t
brw_dp_typed_atomic_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned exec_group,unsigned atomic_op,bool response_expected)813 brw_dp_typed_atomic_desc(const struct intel_device_info *devinfo,
814                          unsigned exec_size,
815                          unsigned exec_group,
816                          unsigned atomic_op,
817                          bool response_expected)
818 {
819    assert(exec_size > 0 || exec_group == 0);
820    assert(exec_group % 8 == 0);
821 
822    const unsigned msg_type =
823       exec_size == 0 ? HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP_SIMD4X2 :
824                        HSW_DATAPORT_DC_PORT1_TYPED_ATOMIC_OP;
825 
826    const bool high_sample_mask = (exec_group / 8) % 2 == 1;
827 
828    const unsigned msg_control =
829       SET_BITS(atomic_op, 3, 0) |
830       SET_BITS(high_sample_mask, 4, 4) |
831       SET_BITS(response_expected, 5, 5);
832 
833    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
834 }
835 
836 static inline uint32_t
brw_dp_typed_surface_rw_desc(const struct intel_device_info * devinfo,unsigned exec_size,unsigned exec_group,unsigned num_channels,bool write)837 brw_dp_typed_surface_rw_desc(const struct intel_device_info *devinfo,
838                              unsigned exec_size,
839                              unsigned exec_group,
840                              unsigned num_channels,
841                              bool write)
842 {
843    assert(exec_size > 0 || exec_group == 0);
844    assert(exec_group % 8 == 0);
845 
846    /* Typed surface reads and writes don't support SIMD16 */
847    assert(exec_size <= 8);
848 
849    const unsigned msg_type =
850       write ? HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_WRITE :
851               HSW_DATAPORT_DC_PORT1_TYPED_SURFACE_READ;
852 
853    /* See also MDC_SG3 in the SKL PRM Vol 2d. */
854    const unsigned slot_group = exec_size == 0 ? 0 : /* SIMD4x2 */
855                                1 + ((exec_group / 8) % 2);
856 
857    const unsigned msg_control =
858       SET_BITS(brw_mdc_cmask(num_channels), 3, 0) |
859       SET_BITS(slot_group, 5, 4);
860 
861    return brw_dp_surface_desc(devinfo, msg_type, msg_control);
862 }
863 
864 static inline uint32_t
brw_fb_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_type,unsigned msg_control)865 brw_fb_desc(const struct intel_device_info *devinfo,
866             unsigned binding_table_index,
867             unsigned msg_type,
868             unsigned msg_control)
869 {
870    return SET_BITS(binding_table_index, 7, 0) |
871           SET_BITS(msg_control, 13, 8) |
872           SET_BITS(msg_type, 17, 14);
873 }
874 
875 static inline unsigned
brw_fb_desc_binding_table_index(UNUSED const struct intel_device_info * devinfo,uint32_t desc)876 brw_fb_desc_binding_table_index(UNUSED const struct intel_device_info *devinfo,
877                                 uint32_t desc)
878 {
879    return GET_BITS(desc, 7, 0);
880 }
881 
882 static inline uint32_t
brw_fb_desc_msg_control(const struct intel_device_info * devinfo,uint32_t desc)883 brw_fb_desc_msg_control(const struct intel_device_info *devinfo, uint32_t desc)
884 {
885    return GET_BITS(desc, 13, 8);
886 }
887 
888 static inline unsigned
brw_fb_desc_msg_type(const struct intel_device_info * devinfo,uint32_t desc)889 brw_fb_desc_msg_type(const struct intel_device_info *devinfo, uint32_t desc)
890 {
891    return GET_BITS(desc, 17, 14);
892 }
893 
894 static inline uint32_t
brw_fb_read_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,unsigned exec_size,bool per_sample)895 brw_fb_read_desc(const struct intel_device_info *devinfo,
896                  unsigned binding_table_index,
897                  unsigned msg_control,
898                  unsigned exec_size,
899                  bool per_sample)
900 {
901    assert(exec_size == 8 || exec_size == 16);
902 
903    return brw_fb_desc(devinfo, binding_table_index,
904                       GFX9_DATAPORT_RC_RENDER_TARGET_READ, msg_control) |
905           SET_BITS(per_sample, 13, 13) |
906           SET_BITS(exec_size == 8, 8, 8) /* Render Target Message Subtype */;
907 }
908 
909 static inline uint32_t
brw_fb_write_desc(const struct intel_device_info * devinfo,unsigned binding_table_index,unsigned msg_control,bool last_render_target,bool coarse_write)910 brw_fb_write_desc(const struct intel_device_info *devinfo,
911                   unsigned binding_table_index,
912                   unsigned msg_control,
913                   bool last_render_target,
914                   bool coarse_write)
915 {
916    const unsigned msg_type = GFX6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE;
917 
918    assert(devinfo->ver >= 10 || !coarse_write);
919 
920    return brw_fb_desc(devinfo, binding_table_index, msg_type, msg_control) |
921           SET_BITS(last_render_target, 12, 12) |
922           SET_BITS(coarse_write, 18, 18);
923 }
924 
925 static inline bool
brw_fb_write_desc_last_render_target(const struct intel_device_info * devinfo,uint32_t desc)926 brw_fb_write_desc_last_render_target(const struct intel_device_info *devinfo,
927                                      uint32_t desc)
928 {
929    return GET_BITS(desc, 12, 12);
930 }
931 
932 static inline bool
brw_fb_write_desc_coarse_write(const struct intel_device_info * devinfo,uint32_t desc)933 brw_fb_write_desc_coarse_write(const struct intel_device_info *devinfo,
934                                uint32_t desc)
935 {
936    assert(devinfo->ver >= 10);
937    return GET_BITS(desc, 18, 18);
938 }
939 
940 static inline bool
lsc_opcode_has_cmask(enum lsc_opcode opcode)941 lsc_opcode_has_cmask(enum lsc_opcode opcode)
942 {
943    return opcode == LSC_OP_LOAD_CMASK || opcode == LSC_OP_STORE_CMASK;
944 }
945 
946 static inline bool
lsc_opcode_has_transpose(enum lsc_opcode opcode)947 lsc_opcode_has_transpose(enum lsc_opcode opcode)
948 {
949    return opcode == LSC_OP_LOAD || opcode == LSC_OP_STORE;
950 }
951 
952 static inline bool
lsc_opcode_is_store(enum lsc_opcode opcode)953 lsc_opcode_is_store(enum lsc_opcode opcode)
954 {
955    return opcode == LSC_OP_STORE ||
956           opcode == LSC_OP_STORE_CMASK;
957 }
958 
959 static inline bool
lsc_opcode_is_atomic(enum lsc_opcode opcode)960 lsc_opcode_is_atomic(enum lsc_opcode opcode)
961 {
962    switch (opcode) {
963    case LSC_OP_ATOMIC_INC:
964    case LSC_OP_ATOMIC_DEC:
965    case LSC_OP_ATOMIC_LOAD:
966    case LSC_OP_ATOMIC_STORE:
967    case LSC_OP_ATOMIC_ADD:
968    case LSC_OP_ATOMIC_SUB:
969    case LSC_OP_ATOMIC_MIN:
970    case LSC_OP_ATOMIC_MAX:
971    case LSC_OP_ATOMIC_UMIN:
972    case LSC_OP_ATOMIC_UMAX:
973    case LSC_OP_ATOMIC_CMPXCHG:
974    case LSC_OP_ATOMIC_FADD:
975    case LSC_OP_ATOMIC_FSUB:
976    case LSC_OP_ATOMIC_FMIN:
977    case LSC_OP_ATOMIC_FMAX:
978    case LSC_OP_ATOMIC_FCMPXCHG:
979    case LSC_OP_ATOMIC_AND:
980    case LSC_OP_ATOMIC_OR:
981    case LSC_OP_ATOMIC_XOR:
982       return true;
983 
984    default:
985       return false;
986    }
987 }
988 
989 static inline bool
lsc_opcode_is_atomic_float(enum lsc_opcode opcode)990 lsc_opcode_is_atomic_float(enum lsc_opcode opcode)
991 {
992    switch (opcode) {
993    case LSC_OP_ATOMIC_FADD:
994    case LSC_OP_ATOMIC_FSUB:
995    case LSC_OP_ATOMIC_FMIN:
996    case LSC_OP_ATOMIC_FMAX:
997    case LSC_OP_ATOMIC_FCMPXCHG:
998       return true;
999 
1000    default:
1001       return false;
1002    }
1003 }
1004 
1005 static inline unsigned
lsc_op_num_data_values(unsigned _op)1006 lsc_op_num_data_values(unsigned _op)
1007 {
1008    enum lsc_opcode op = (enum lsc_opcode) _op;
1009 
1010    switch (op) {
1011    case LSC_OP_ATOMIC_CMPXCHG:
1012    case LSC_OP_ATOMIC_FCMPXCHG:
1013       return 2;
1014    case LSC_OP_ATOMIC_INC:
1015    case LSC_OP_ATOMIC_DEC:
1016    case LSC_OP_LOAD:
1017    case LSC_OP_LOAD_CMASK:
1018    case LSC_OP_FENCE:
1019       /* XXX: actually check docs */
1020       return 0;
1021    default:
1022       return 1;
1023    }
1024 }
1025 
1026 static inline unsigned
lsc_op_to_legacy_atomic(unsigned _op)1027 lsc_op_to_legacy_atomic(unsigned _op)
1028 {
1029    enum lsc_opcode op = (enum lsc_opcode) _op;
1030 
1031    switch (op) {
1032    case LSC_OP_ATOMIC_INC:
1033       return BRW_AOP_INC;
1034    case LSC_OP_ATOMIC_DEC:
1035       return BRW_AOP_DEC;
1036    case LSC_OP_ATOMIC_STORE:
1037       return BRW_AOP_MOV;
1038    case LSC_OP_ATOMIC_ADD:
1039       return BRW_AOP_ADD;
1040    case LSC_OP_ATOMIC_SUB:
1041       return BRW_AOP_SUB;
1042    case LSC_OP_ATOMIC_MIN:
1043       return BRW_AOP_IMIN;
1044    case LSC_OP_ATOMIC_MAX:
1045       return BRW_AOP_IMAX;
1046    case LSC_OP_ATOMIC_UMIN:
1047       return BRW_AOP_UMIN;
1048    case LSC_OP_ATOMIC_UMAX:
1049       return BRW_AOP_UMAX;
1050    case LSC_OP_ATOMIC_CMPXCHG:
1051       return BRW_AOP_CMPWR;
1052    case LSC_OP_ATOMIC_FADD:
1053       return BRW_AOP_FADD;
1054    case LSC_OP_ATOMIC_FMIN:
1055       return BRW_AOP_FMIN;
1056    case LSC_OP_ATOMIC_FMAX:
1057       return BRW_AOP_FMAX;
1058    case LSC_OP_ATOMIC_FCMPXCHG:
1059       return BRW_AOP_FCMPWR;
1060    case LSC_OP_ATOMIC_AND:
1061       return BRW_AOP_AND;
1062    case LSC_OP_ATOMIC_OR:
1063       return BRW_AOP_OR;
1064    case LSC_OP_ATOMIC_XOR:
1065       return BRW_AOP_XOR;
1066    /* No LSC op maps to BRW_AOP_PREDEC */
1067    case LSC_OP_ATOMIC_LOAD:
1068    case LSC_OP_ATOMIC_FSUB:
1069       unreachable("no corresponding legacy atomic operation");
1070    case LSC_OP_LOAD:
1071    case LSC_OP_LOAD_CMASK:
1072    case LSC_OP_STORE:
1073    case LSC_OP_STORE_CMASK:
1074    case LSC_OP_FENCE:
1075       unreachable("not an atomic op");
1076    }
1077 
1078    unreachable("invalid LSC op");
1079 }
1080 
1081 static inline uint32_t
lsc_data_size_bytes(enum lsc_data_size data_size)1082 lsc_data_size_bytes(enum lsc_data_size data_size)
1083 {
1084    switch (data_size) {
1085    case LSC_DATA_SIZE_D8:
1086       return 1;
1087    case LSC_DATA_SIZE_D16:
1088       return 2;
1089    case LSC_DATA_SIZE_D32:
1090    case LSC_DATA_SIZE_D8U32:
1091    case LSC_DATA_SIZE_D16U32:
1092    case LSC_DATA_SIZE_D16BF32:
1093       return 4;
1094    case LSC_DATA_SIZE_D64:
1095       return 8;
1096    default:
1097       unreachable("Unsupported data payload size.");
1098    }
1099 }
1100 
1101 static inline uint32_t
lsc_addr_size_bytes(enum lsc_addr_size addr_size)1102 lsc_addr_size_bytes(enum lsc_addr_size addr_size)
1103 {
1104    switch (addr_size) {
1105    case LSC_ADDR_SIZE_A16: return 2;
1106    case LSC_ADDR_SIZE_A32: return 4;
1107    case LSC_ADDR_SIZE_A64: return 8;
1108    default:
1109       unreachable("Unsupported address size.");
1110    }
1111 }
1112 
1113 static inline uint32_t
lsc_vector_length(enum lsc_vect_size vect_size)1114 lsc_vector_length(enum lsc_vect_size vect_size)
1115 {
1116    switch (vect_size) {
1117    case LSC_VECT_SIZE_V1: return 1;
1118    case LSC_VECT_SIZE_V2: return 2;
1119    case LSC_VECT_SIZE_V3: return 3;
1120    case LSC_VECT_SIZE_V4: return 4;
1121    case LSC_VECT_SIZE_V8: return 8;
1122    case LSC_VECT_SIZE_V16: return 16;
1123    case LSC_VECT_SIZE_V32: return 32;
1124    case LSC_VECT_SIZE_V64: return 64;
1125    default:
1126       unreachable("Unsupported size of vector");
1127    }
1128 }
1129 
1130 static inline enum lsc_vect_size
lsc_vect_size(unsigned vect_size)1131 lsc_vect_size(unsigned vect_size)
1132 {
1133    switch(vect_size) {
1134    case 1:  return LSC_VECT_SIZE_V1;
1135    case 2:  return LSC_VECT_SIZE_V2;
1136    case 3:  return LSC_VECT_SIZE_V3;
1137    case 4:  return LSC_VECT_SIZE_V4;
1138    case 8:  return LSC_VECT_SIZE_V8;
1139    case 16: return LSC_VECT_SIZE_V16;
1140    case 32: return LSC_VECT_SIZE_V32;
1141    case 64: return LSC_VECT_SIZE_V64;
1142    default:
1143       unreachable("Unsupported vector size for dataport");
1144    }
1145 }
1146 
1147 static inline uint32_t
lsc_msg_desc_wcmask(UNUSED const struct intel_device_info * devinfo,enum lsc_opcode opcode,unsigned simd_size,enum lsc_addr_surface_type addr_type,enum lsc_addr_size addr_sz,unsigned num_coordinates,enum lsc_data_size data_sz,unsigned num_channels,bool transpose,unsigned cache_ctrl,bool has_dest,unsigned cmask)1148 lsc_msg_desc_wcmask(UNUSED const struct intel_device_info *devinfo,
1149              enum lsc_opcode opcode, unsigned simd_size,
1150              enum lsc_addr_surface_type addr_type,
1151              enum lsc_addr_size addr_sz, unsigned num_coordinates,
1152              enum lsc_data_size data_sz, unsigned num_channels,
1153              bool transpose, unsigned cache_ctrl, bool has_dest, unsigned cmask)
1154 {
1155    assert(devinfo->has_lsc);
1156 
1157    unsigned dest_length = !has_dest ? 0 :
1158       DIV_ROUND_UP(lsc_data_size_bytes(data_sz) * num_channels * simd_size,
1159                    reg_unit(devinfo) * REG_SIZE);
1160 
1161    unsigned src0_length =
1162       DIV_ROUND_UP(lsc_addr_size_bytes(addr_sz) * num_coordinates * simd_size,
1163                    reg_unit(devinfo) * REG_SIZE);
1164 
1165    assert(!transpose || lsc_opcode_has_transpose(opcode));
1166 
1167    unsigned msg_desc =
1168       SET_BITS(opcode, 5, 0) |
1169       SET_BITS(addr_sz, 8, 7) |
1170       SET_BITS(data_sz, 11, 9) |
1171       SET_BITS(transpose, 15, 15) |
1172       SET_BITS(cache_ctrl, 19, 17) |
1173       SET_BITS(dest_length, 24, 20) |
1174       SET_BITS(src0_length, 28, 25) |
1175       SET_BITS(addr_type, 30, 29);
1176 
1177    if (lsc_opcode_has_cmask(opcode))
1178       msg_desc |= SET_BITS(cmask ? cmask : lsc_cmask(num_channels), 15, 12);
1179    else
1180       msg_desc |= SET_BITS(lsc_vect_size(num_channels), 14, 12);
1181 
1182    return msg_desc;
1183 }
1184 
1185 static inline uint32_t
lsc_msg_desc(UNUSED const struct intel_device_info * devinfo,enum lsc_opcode opcode,unsigned simd_size,enum lsc_addr_surface_type addr_type,enum lsc_addr_size addr_sz,unsigned num_coordinates,enum lsc_data_size data_sz,unsigned num_channels,bool transpose,unsigned cache_ctrl,bool has_dest)1186 lsc_msg_desc(UNUSED const struct intel_device_info *devinfo,
1187              enum lsc_opcode opcode, unsigned simd_size,
1188              enum lsc_addr_surface_type addr_type,
1189              enum lsc_addr_size addr_sz, unsigned num_coordinates,
1190              enum lsc_data_size data_sz, unsigned num_channels,
1191              bool transpose, unsigned cache_ctrl, bool has_dest)
1192 {
1193    return lsc_msg_desc_wcmask(devinfo, opcode, simd_size, addr_type, addr_sz,
1194          num_coordinates, data_sz, num_channels, transpose, cache_ctrl,
1195          has_dest, 0);
1196 }
1197 
1198 static inline enum lsc_opcode
lsc_msg_desc_opcode(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1199 lsc_msg_desc_opcode(UNUSED const struct intel_device_info *devinfo,
1200                     uint32_t desc)
1201 {
1202    assert(devinfo->has_lsc);
1203    return (enum lsc_opcode) GET_BITS(desc, 5, 0);
1204 }
1205 
1206 static inline enum lsc_addr_size
lsc_msg_desc_addr_size(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1207 lsc_msg_desc_addr_size(UNUSED const struct intel_device_info *devinfo,
1208                        uint32_t desc)
1209 {
1210    assert(devinfo->has_lsc);
1211    return (enum lsc_addr_size) GET_BITS(desc, 8, 7);
1212 }
1213 
1214 static inline enum lsc_data_size
lsc_msg_desc_data_size(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1215 lsc_msg_desc_data_size(UNUSED const struct intel_device_info *devinfo,
1216                        uint32_t desc)
1217 {
1218    assert(devinfo->has_lsc);
1219    return (enum lsc_data_size) GET_BITS(desc, 11, 9);
1220 }
1221 
1222 static inline enum lsc_vect_size
lsc_msg_desc_vect_size(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1223 lsc_msg_desc_vect_size(UNUSED const struct intel_device_info *devinfo,
1224                        uint32_t desc)
1225 {
1226    assert(devinfo->has_lsc);
1227    assert(!lsc_opcode_has_cmask(lsc_msg_desc_opcode(devinfo, desc)));
1228    return (enum lsc_vect_size) GET_BITS(desc, 14, 12);
1229 }
1230 
1231 static inline enum lsc_cmask
lsc_msg_desc_cmask(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1232 lsc_msg_desc_cmask(UNUSED const struct intel_device_info *devinfo,
1233                    uint32_t desc)
1234 {
1235    assert(devinfo->has_lsc);
1236    assert(lsc_opcode_has_cmask(lsc_msg_desc_opcode(devinfo, desc)));
1237    return (enum lsc_cmask) GET_BITS(desc, 15, 12);
1238 }
1239 
1240 static inline bool
lsc_msg_desc_transpose(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1241 lsc_msg_desc_transpose(UNUSED const struct intel_device_info *devinfo,
1242                        uint32_t desc)
1243 {
1244    assert(devinfo->has_lsc);
1245    return GET_BITS(desc, 15, 15);
1246 }
1247 
1248 static inline unsigned
lsc_msg_desc_cache_ctrl(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1249 lsc_msg_desc_cache_ctrl(UNUSED const struct intel_device_info *devinfo,
1250                         uint32_t desc)
1251 {
1252    assert(devinfo->has_lsc);
1253    return GET_BITS(desc, 19, 17);
1254 }
1255 
1256 static inline unsigned
lsc_msg_desc_dest_len(const struct intel_device_info * devinfo,uint32_t desc)1257 lsc_msg_desc_dest_len(const struct intel_device_info *devinfo,
1258                       uint32_t desc)
1259 {
1260    assert(devinfo->has_lsc);
1261    return GET_BITS(desc, 24, 20) * reg_unit(devinfo);
1262 }
1263 
1264 static inline unsigned
lsc_msg_desc_src0_len(const struct intel_device_info * devinfo,uint32_t desc)1265 lsc_msg_desc_src0_len(const struct intel_device_info *devinfo,
1266                       uint32_t desc)
1267 {
1268    assert(devinfo->has_lsc);
1269    return GET_BITS(desc, 28, 25) * reg_unit(devinfo);
1270 }
1271 
1272 static inline enum lsc_addr_surface_type
lsc_msg_desc_addr_type(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1273 lsc_msg_desc_addr_type(UNUSED const struct intel_device_info *devinfo,
1274                        uint32_t desc)
1275 {
1276    assert(devinfo->has_lsc);
1277    return (enum lsc_addr_surface_type) GET_BITS(desc, 30, 29);
1278 }
1279 
1280 static inline uint32_t
lsc_fence_msg_desc(UNUSED const struct intel_device_info * devinfo,enum lsc_fence_scope scope,enum lsc_flush_type flush_type,bool route_to_lsc)1281 lsc_fence_msg_desc(UNUSED const struct intel_device_info *devinfo,
1282                    enum lsc_fence_scope scope,
1283                    enum lsc_flush_type flush_type,
1284                    bool route_to_lsc)
1285 {
1286    assert(devinfo->has_lsc);
1287    return SET_BITS(LSC_OP_FENCE, 5, 0) |
1288           SET_BITS(LSC_ADDR_SIZE_A32, 8, 7) |
1289           SET_BITS(scope, 11, 9) |
1290           SET_BITS(flush_type, 14, 12) |
1291           SET_BITS(route_to_lsc, 18, 18) |
1292           SET_BITS(LSC_ADDR_SURFTYPE_FLAT, 30, 29);
1293 }
1294 
1295 static inline enum lsc_fence_scope
lsc_fence_msg_desc_scope(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1296 lsc_fence_msg_desc_scope(UNUSED const struct intel_device_info *devinfo,
1297                          uint32_t desc)
1298 {
1299    assert(devinfo->has_lsc);
1300    return (enum lsc_fence_scope) GET_BITS(desc, 11, 9);
1301 }
1302 
1303 static inline enum lsc_flush_type
lsc_fence_msg_desc_flush_type(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1304 lsc_fence_msg_desc_flush_type(UNUSED const struct intel_device_info *devinfo,
1305                               uint32_t desc)
1306 {
1307    assert(devinfo->has_lsc);
1308    return (enum lsc_flush_type) GET_BITS(desc, 14, 12);
1309 }
1310 
1311 static inline enum lsc_backup_fence_routing
lsc_fence_msg_desc_backup_routing(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1312 lsc_fence_msg_desc_backup_routing(UNUSED const struct intel_device_info *devinfo,
1313                                   uint32_t desc)
1314 {
1315    assert(devinfo->has_lsc);
1316    return (enum lsc_backup_fence_routing) GET_BITS(desc, 18, 18);
1317 }
1318 
1319 static inline uint32_t
lsc_bti_ex_desc(const struct intel_device_info * devinfo,unsigned bti)1320 lsc_bti_ex_desc(const struct intel_device_info *devinfo, unsigned bti)
1321 {
1322    assert(devinfo->has_lsc);
1323    return SET_BITS(bti, 31, 24) |
1324           SET_BITS(0, 23, 12);  /* base offset */
1325 }
1326 
1327 static inline unsigned
lsc_bti_ex_desc_base_offset(const struct intel_device_info * devinfo,uint32_t ex_desc)1328 lsc_bti_ex_desc_base_offset(const struct intel_device_info *devinfo,
1329                             uint32_t ex_desc)
1330 {
1331    assert(devinfo->has_lsc);
1332    return GET_BITS(ex_desc, 23, 12);
1333 }
1334 
1335 static inline unsigned
lsc_bti_ex_desc_index(const struct intel_device_info * devinfo,uint32_t ex_desc)1336 lsc_bti_ex_desc_index(const struct intel_device_info *devinfo,
1337                       uint32_t ex_desc)
1338 {
1339    assert(devinfo->has_lsc);
1340    return GET_BITS(ex_desc, 31, 24);
1341 }
1342 
1343 static inline unsigned
lsc_flat_ex_desc_base_offset(const struct intel_device_info * devinfo,uint32_t ex_desc)1344 lsc_flat_ex_desc_base_offset(const struct intel_device_info *devinfo,
1345                              uint32_t ex_desc)
1346 {
1347    assert(devinfo->has_lsc);
1348    return GET_BITS(ex_desc, 31, 12);
1349 }
1350 
1351 static inline uint32_t
lsc_bss_ex_desc(const struct intel_device_info * devinfo,unsigned surface_state_index)1352 lsc_bss_ex_desc(const struct intel_device_info *devinfo,
1353                 unsigned surface_state_index)
1354 {
1355    assert(devinfo->has_lsc);
1356    return SET_BITS(surface_state_index, 31, 6);
1357 }
1358 
1359 static inline unsigned
lsc_bss_ex_desc_index(const struct intel_device_info * devinfo,uint32_t ex_desc)1360 lsc_bss_ex_desc_index(const struct intel_device_info *devinfo,
1361                       uint32_t ex_desc)
1362 {
1363    assert(devinfo->has_lsc);
1364    return GET_BITS(ex_desc, 31, 6);
1365 }
1366 
1367 static inline uint32_t
brw_mdc_sm2(unsigned exec_size)1368 brw_mdc_sm2(unsigned exec_size)
1369 {
1370    assert(exec_size == 8 || exec_size == 16);
1371    return exec_size > 8;
1372 }
1373 
1374 static inline uint32_t
brw_mdc_sm2_exec_size(uint32_t sm2)1375 brw_mdc_sm2_exec_size(uint32_t sm2)
1376 {
1377    assert(sm2 <= 1);
1378    return 8 << sm2;
1379 }
1380 
1381 static inline uint32_t
brw_btd_spawn_desc(ASSERTED const struct intel_device_info * devinfo,unsigned exec_size,unsigned msg_type)1382 brw_btd_spawn_desc(ASSERTED const struct intel_device_info *devinfo,
1383                    unsigned exec_size, unsigned msg_type)
1384 {
1385    assert(devinfo->has_ray_tracing);
1386    assert(devinfo->ver < 20 || exec_size == 16);
1387 
1388    return SET_BITS(0, 19, 19) | /* No header */
1389           SET_BITS(msg_type, 17, 14) |
1390           SET_BITS(brw_mdc_sm2(exec_size), 8, 8);
1391 }
1392 
1393 static inline uint32_t
brw_btd_spawn_msg_type(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1394 brw_btd_spawn_msg_type(UNUSED const struct intel_device_info *devinfo,
1395                        uint32_t desc)
1396 {
1397    return GET_BITS(desc, 17, 14);
1398 }
1399 
1400 static inline uint32_t
brw_btd_spawn_exec_size(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1401 brw_btd_spawn_exec_size(UNUSED const struct intel_device_info *devinfo,
1402                         uint32_t desc)
1403 {
1404    return brw_mdc_sm2_exec_size(GET_BITS(desc, 8, 8));
1405 }
1406 
1407 static inline uint32_t
brw_rt_trace_ray_desc(ASSERTED const struct intel_device_info * devinfo,unsigned exec_size)1408 brw_rt_trace_ray_desc(ASSERTED const struct intel_device_info *devinfo,
1409                       unsigned exec_size)
1410 {
1411    assert(devinfo->has_ray_tracing);
1412    assert(devinfo->ver < 20 || exec_size == 16);
1413 
1414    return SET_BITS(0, 19, 19) | /* No header */
1415           SET_BITS(0, 17, 14) | /* Message type */
1416           SET_BITS(brw_mdc_sm2(exec_size), 8, 8);
1417 }
1418 
1419 static inline uint32_t
brw_rt_trace_ray_desc_exec_size(UNUSED const struct intel_device_info * devinfo,uint32_t desc)1420 brw_rt_trace_ray_desc_exec_size(UNUSED const struct intel_device_info *devinfo,
1421                                 uint32_t desc)
1422 {
1423    return brw_mdc_sm2_exec_size(GET_BITS(desc, 8, 8));
1424 }
1425 
1426 /**
1427  * Construct a message descriptor immediate with the specified pixel
1428  * interpolator function controls.
1429  */
1430 static inline uint32_t
brw_pixel_interp_desc(UNUSED const struct intel_device_info * devinfo,unsigned msg_type,bool noperspective,bool coarse_pixel_rate,unsigned exec_size,unsigned group)1431 brw_pixel_interp_desc(UNUSED const struct intel_device_info *devinfo,
1432                       unsigned msg_type,
1433                       bool noperspective,
1434                       bool coarse_pixel_rate,
1435                       unsigned exec_size,
1436                       unsigned group)
1437 {
1438    assert(exec_size == 8 || exec_size == 16);
1439    const bool simd_mode = exec_size == 16;
1440    const bool slot_group = group >= 16;
1441 
1442    assert(devinfo->ver >= 10 || !coarse_pixel_rate);
1443    return (SET_BITS(slot_group, 11, 11) |
1444            SET_BITS(msg_type, 13, 12) |
1445            SET_BITS(!!noperspective, 14, 14) |
1446            SET_BITS(coarse_pixel_rate, 15, 15) |
1447            SET_BITS(simd_mode, 16, 16));
1448 }
1449 
1450 /**
1451  * Send message to shared unit \p sfid with a possibly indirect descriptor \p
1452  * desc.  If \p desc is not an immediate it will be transparently loaded to an
1453  * address register using an OR instruction.
1454  */
1455 void
1456 brw_send_indirect_message(struct brw_codegen *p,
1457                           unsigned sfid,
1458                           struct brw_reg dst,
1459                           struct brw_reg payload,
1460                           struct brw_reg desc,
1461                           unsigned desc_imm,
1462                           bool eot);
1463 
1464 void
1465 brw_send_indirect_split_message(struct brw_codegen *p,
1466                                 unsigned sfid,
1467                                 struct brw_reg dst,
1468                                 struct brw_reg payload0,
1469                                 struct brw_reg payload1,
1470                                 struct brw_reg desc,
1471                                 unsigned desc_imm,
1472                                 struct brw_reg ex_desc,
1473                                 unsigned ex_desc_imm,
1474                                 bool ex_desc_scratch,
1475                                 bool ex_bso,
1476                                 bool eot);
1477 
1478 void brw_svb_write(struct brw_codegen *p,
1479                    struct brw_reg dest,
1480                    unsigned msg_reg_nr,
1481                    struct brw_reg src0,
1482                    unsigned binding_table_index,
1483                    bool   send_commit_msg);
1484 
1485 brw_inst *gfx9_fb_READ(struct brw_codegen *p,
1486                        struct brw_reg dst,
1487                        struct brw_reg payload,
1488                        unsigned binding_table_index,
1489                        unsigned msg_length,
1490                        unsigned response_length,
1491                        bool per_sample);
1492 
1493 void brw_adjust_sampler_state_pointer(struct brw_codegen *p,
1494                                       struct brw_reg header,
1495                                       struct brw_reg sampler_index);
1496 
1497 void gfx6_math(struct brw_codegen *p,
1498 	       struct brw_reg dest,
1499 	       unsigned function,
1500 	       struct brw_reg src0,
1501 	       struct brw_reg src1);
1502 
1503 unsigned brw_scratch_surface_idx(const struct brw_codegen *p);
1504 
1505 void gfx7_block_read_scratch(struct brw_codegen *p,
1506                              struct brw_reg dest,
1507                              int num_regs,
1508                              unsigned offset);
1509 
1510 /**
1511  * Return the generation-specific jump distance scaling factor.
1512  *
1513  * Given the number of instructions to jump, we need to scale by
1514  * some number to obtain the actual jump distance to program in an
1515  * instruction.
1516  */
1517 static inline unsigned
brw_jump_scale(const struct intel_device_info * devinfo)1518 brw_jump_scale(const struct intel_device_info *devinfo)
1519 {
1520    /* Broadwell measures jump targets in bytes. */
1521    return 16;
1522 }
1523 
1524 void brw_barrier(struct brw_codegen *p, struct brw_reg src);
1525 
1526 /* If/else/endif.  Works by manipulating the execution flags on each
1527  * channel.
1528  */
1529 brw_inst *brw_IF(struct brw_codegen *p, unsigned execute_size);
1530 
1531 void brw_ELSE(struct brw_codegen *p);
1532 void brw_ENDIF(struct brw_codegen *p);
1533 
1534 /* DO/WHILE loops:
1535  */
1536 brw_inst *brw_DO(struct brw_codegen *p, unsigned execute_size);
1537 
1538 brw_inst *brw_WHILE(struct brw_codegen *p);
1539 
1540 brw_inst *brw_BREAK(struct brw_codegen *p);
1541 brw_inst *brw_CONT(struct brw_codegen *p);
1542 brw_inst *brw_HALT(struct brw_codegen *p);
1543 
1544 /* Forward jumps:
1545  */
1546 brw_inst *brw_JMPI(struct brw_codegen *p, struct brw_reg index,
1547                    unsigned predicate_control);
1548 
1549 void brw_NOP(struct brw_codegen *p);
1550 
1551 void brw_WAIT(struct brw_codegen *p);
1552 
1553 void brw_SYNC(struct brw_codegen *p, enum tgl_sync_function func);
1554 
1555 /* Special case: there is never a destination, execution size will be
1556  * taken from src0:
1557  */
1558 void brw_CMP(struct brw_codegen *p,
1559 	     struct brw_reg dest,
1560 	     unsigned conditional,
1561 	     struct brw_reg src0,
1562 	     struct brw_reg src1);
1563 
1564 void brw_CMPN(struct brw_codegen *p,
1565               struct brw_reg dest,
1566               unsigned conditional,
1567               struct brw_reg src0,
1568               struct brw_reg src1);
1569 
1570 brw_inst *brw_DPAS(struct brw_codegen *p, enum gfx12_systolic_depth sdepth,
1571                    unsigned rcount, struct brw_reg dest, struct brw_reg src0,
1572                    struct brw_reg src1, struct brw_reg src2);
1573 
1574 void
1575 brw_untyped_atomic(struct brw_codegen *p,
1576                    struct brw_reg dst,
1577                    struct brw_reg payload,
1578                    struct brw_reg surface,
1579                    unsigned atomic_op,
1580                    unsigned msg_length,
1581                    bool response_expected,
1582                    bool header_present);
1583 
1584 void
1585 brw_untyped_surface_read(struct brw_codegen *p,
1586                          struct brw_reg dst,
1587                          struct brw_reg payload,
1588                          struct brw_reg surface,
1589                          unsigned msg_length,
1590                          unsigned num_channels);
1591 
1592 void
1593 brw_untyped_surface_write(struct brw_codegen *p,
1594                           struct brw_reg payload,
1595                           struct brw_reg surface,
1596                           unsigned msg_length,
1597                           unsigned num_channels,
1598                           bool header_present);
1599 
1600 void
1601 brw_memory_fence(struct brw_codegen *p,
1602                  struct brw_reg dst,
1603                  struct brw_reg src,
1604                  enum opcode send_op,
1605                  enum brw_message_target sfid,
1606                  uint32_t desc,
1607                  bool commit_enable,
1608                  unsigned bti);
1609 
1610 void
1611 brw_broadcast(struct brw_codegen *p,
1612               struct brw_reg dst,
1613               struct brw_reg src,
1614               struct brw_reg idx);
1615 
1616 void
1617 brw_float_controls_mode(struct brw_codegen *p,
1618                         unsigned mode, unsigned mask);
1619 
1620 void
1621 brw_update_reloc_imm(const struct brw_isa_info *isa,
1622                      brw_inst *inst,
1623                      uint32_t value);
1624 
1625 void
1626 brw_MOV_reloc_imm(struct brw_codegen *p,
1627                   struct brw_reg dst,
1628                   enum brw_reg_type src_type,
1629                   uint32_t id);
1630 
1631 unsigned
1632 brw_num_sources_from_inst(const struct brw_isa_info *isa,
1633                           const brw_inst *inst);
1634 
1635 /***********************************************************************
1636  * brw_eu_util.c:
1637  */
1638 
1639 void brw_copy_indirect_to_indirect(struct brw_codegen *p,
1640 				   struct brw_indirect dst_ptr,
1641 				   struct brw_indirect src_ptr,
1642 				   unsigned count);
1643 
1644 void brw_copy_from_indirect(struct brw_codegen *p,
1645 			    struct brw_reg dst,
1646 			    struct brw_indirect ptr,
1647 			    unsigned count);
1648 
1649 void brw_copy4(struct brw_codegen *p,
1650 	       struct brw_reg dst,
1651 	       struct brw_reg src,
1652 	       unsigned count);
1653 
1654 void brw_copy8(struct brw_codegen *p,
1655 	       struct brw_reg dst,
1656 	       struct brw_reg src,
1657 	       unsigned count);
1658 
1659 void brw_math_invert( struct brw_codegen *p,
1660 		      struct brw_reg dst,
1661 		      struct brw_reg src);
1662 
1663 void brw_set_src1(struct brw_codegen *p, brw_inst *insn, struct brw_reg reg);
1664 
1665 void brw_set_desc_ex(struct brw_codegen *p, brw_inst *insn,
1666                      unsigned desc, unsigned ex_desc);
1667 
1668 static inline void
brw_set_desc(struct brw_codegen * p,brw_inst * insn,unsigned desc)1669 brw_set_desc(struct brw_codegen *p, brw_inst *insn, unsigned desc)
1670 {
1671    brw_set_desc_ex(p, insn, desc, 0);
1672 }
1673 
1674 void brw_set_uip_jip(struct brw_codegen *p, int start_offset);
1675 
1676 enum brw_conditional_mod brw_negate_cmod(enum brw_conditional_mod cmod);
1677 enum brw_conditional_mod brw_swap_cmod(enum brw_conditional_mod cmod);
1678 
1679 /* brw_eu_compact.c */
1680 void brw_compact_instructions(struct brw_codegen *p, int start_offset,
1681                               struct disasm_info *disasm);
1682 void brw_uncompact_instruction(const struct brw_isa_info *isa,
1683                                brw_inst *dst, brw_compact_inst *src);
1684 bool brw_try_compact_instruction(const struct brw_isa_info *isa,
1685                                  brw_compact_inst *dst, const brw_inst *src);
1686 
1687 void brw_debug_compact_uncompact(const struct brw_isa_info *isa,
1688                                  brw_inst *orig, brw_inst *uncompacted);
1689 
1690 /* brw_eu_validate.c */
1691 bool brw_validate_instruction(const struct brw_isa_info *isa,
1692                               const brw_inst *inst, int offset,
1693                               unsigned inst_size,
1694                               struct disasm_info *disasm);
1695 bool brw_validate_instructions(const struct brw_isa_info *isa,
1696                                const void *assembly, int start_offset, int end_offset,
1697                                struct disasm_info *disasm);
1698 
1699 static inline int
next_offset(const struct intel_device_info * devinfo,void * store,int offset)1700 next_offset(const struct intel_device_info *devinfo, void *store, int offset)
1701 {
1702    brw_inst *insn = (brw_inst *)((char *)store + offset);
1703 
1704    if (brw_inst_cmpt_control(devinfo, insn))
1705       return offset + 8;
1706    else
1707       return offset + 16;
1708 }
1709 
1710 /** Maximum SEND message length */
1711 #define BRW_MAX_MSG_LENGTH 15
1712 
1713 #ifdef __cplusplus
1714 }
1715 #endif
1716 
1717 #endif
1718