2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * A representation of i965 EU assembly instructions, with helper methods to
28 * get and set various fields. This is the actual hardware format.
37 #include "brw_eu_defines.h"
38 #include "brw_reg_type.h"
39 #include "common/gen_device_info.h"
45 /* brw_context.h has a forward declaration of brw_inst, so name the struct. */
46 typedef struct brw_inst
{
50 static inline uint64_t brw_inst_bits(const brw_inst
*inst
,
51 unsigned high
, unsigned low
);
52 static inline void brw_inst_set_bits(brw_inst
*inst
,
53 unsigned high
, unsigned low
,
56 #define FC(name, high, low, assertions) \
58 brw_inst_set_##name(const struct gen_device_info *devinfo, \
59 brw_inst *inst, uint64_t v) \
63 brw_inst_set_bits(inst, high, low, v); \
65 static inline uint64_t \
66 brw_inst_##name(const struct gen_device_info *devinfo, \
67 const brw_inst *inst) \
71 return brw_inst_bits(inst, high, low); \
74 /* A simple macro for fields which stay in the same place on all generations. */
75 #define F(name, high, low) FC(name, high, low, true)
77 #define BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
79 if (devinfo->gen >= 8) { \
80 high = hi8; low = lo8; \
81 } else if (devinfo->gen >= 7) { \
82 high = hi7; low = lo7; \
83 } else if (devinfo->gen >= 6) { \
84 high = hi6; low = lo6; \
85 } else if (devinfo->gen >= 5) { \
86 high = hi5; low = lo5; \
87 } else if (devinfo->is_g4x) { \
88 high = hi45; low = lo45; \
90 high = hi4; low = lo4; \
92 assert(((int) high) != -1 && ((int) low) != -1);
94 /* A general macro for cases where the field has moved to several different
95 * bit locations across generations. GCC appears to combine cases where the
96 * bits are identical, removing some of the inefficiency.
98 #define FF(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8)\
100 brw_inst_set_##name(const struct gen_device_info *devinfo, \
101 brw_inst *inst, uint64_t value) \
103 BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
104 brw_inst_set_bits(inst, high, low, value); \
106 static inline uint64_t \
107 brw_inst_##name(const struct gen_device_info *devinfo, const brw_inst *inst) \
109 BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
110 return brw_inst_bits(inst, high, low); \
113 /* A macro for fields which moved as of Gen8+. */
114 #define F8(name, gen4_high, gen4_low, gen8_high, gen8_low) \
116 /* 4: */ gen4_high, gen4_low, \
117 /* 4.5: */ gen4_high, gen4_low, \
118 /* 5: */ gen4_high, gen4_low, \
119 /* 6: */ gen4_high, gen4_low, \
120 /* 7: */ gen4_high, gen4_low, \
121 /* 8: */ gen8_high, gen8_low);
123 F(src1_vstride
, 120, 117)
124 F(src1_width
, 116, 114)
125 F(src1_da16_swiz_w
, 115, 114)
126 F(src1_da16_swiz_z
, 113, 112)
127 F(src1_hstride
, 113, 112)
128 F(src1_address_mode
, 111, 111)
129 /** Src1.SrcMod @{ */
130 F(src1_negate
, 110, 110)
131 F(src1_abs
, 109, 109)
133 F8(src1_ia_subreg_nr
, /* 4+ */ 108, 106, /* 8+ */ 108, 105)
134 F(src1_da_reg_nr
, 108, 101)
135 F(src1_da16_subreg_nr
, 100, 100)
136 F(src1_da1_subreg_nr
, 100, 96)
137 F(src1_da16_swiz_y
, 99, 98)
138 F(src1_da16_swiz_x
, 97, 96)
139 F8(src1_reg_hw_type
, /* 4+ */ 46, 44, /* 8+ */ 94, 91)
140 F8(src1_reg_file
, /* 4+ */ 43, 42, /* 8+ */ 90, 89)
141 F(src0_vstride
, 88, 85)
142 F(src0_width
, 84, 82)
143 F(src0_da16_swiz_w
, 83, 82)
144 F(src0_da16_swiz_z
, 81, 80)
145 F(src0_hstride
, 81, 80)
146 F(src0_address_mode
, 79, 79)
147 /** Src0.SrcMod @{ */
148 F(src0_negate
, 78, 78)
151 F8(src0_ia_subreg_nr
, /* 4+ */ 76, 74, /* 8+ */ 76, 73)
152 F(src0_da_reg_nr
, 76, 69)
153 F(src0_da16_subreg_nr
, 68, 68)
154 F(src0_da1_subreg_nr
, 68, 64)
155 F(src0_da16_swiz_y
, 67, 66)
156 F(src0_da16_swiz_x
, 65, 64)
157 F(dst_address_mode
, 63, 63)
158 F(dst_hstride
, 62, 61)
159 F8(dst_ia_subreg_nr
, /* 4+ */ 60, 58, /* 8+ */ 60, 57)
160 F(dst_da_reg_nr
, 60, 53)
161 F(dst_da16_subreg_nr
, 52, 52)
162 F(dst_da1_subreg_nr
, 52, 48)
163 F(da16_writemask
, 51, 48) /* Dst.ChanEn */
164 F8(src0_reg_hw_type
, /* 4+ */ 41, 39, /* 8+ */ 46, 43)
165 F8(src0_reg_file
, /* 4+ */ 38, 37, /* 8+ */ 42, 41)
166 F8(dst_reg_hw_type
, /* 4+ */ 36, 34, /* 8+ */ 40, 37)
167 F8(dst_reg_file
, /* 4+ */ 33, 32, /* 8+ */ 36, 35)
168 F8(mask_control
, /* 4+ */ 9, 9, /* 8+ */ 34, 34)
170 /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
173 F8(flag_subreg_nr
, /* 4+ */ 89, 89, /* 8+ */ 32, 32)
175 F(debug_control
, 30, 30)
176 F(cmpt_control
, 29, 29)
177 FC(branch_control
, 28, 28, devinfo
->gen
>= 8)
178 FC(acc_wr_control
, 28, 28, devinfo
->gen
>= 6)
179 FC(mask_control_ex
, 28, 28, devinfo
->is_g4x
|| devinfo
->gen
== 5)
180 F(cond_modifier
, 27, 24)
181 FC(math_function
, 27, 24, devinfo
->gen
>= 6)
184 F(pred_control
, 19, 16)
185 F(thread_control
, 15, 14)
186 F(qtr_control
, 13, 12)
188 /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
191 F8(no_dd_check
, /* 4+ */ 11, 11, /* 8+ */ 10, 10)
192 F8(no_dd_clear
, /* 4+ */ 10, 10, /* 8+ */ 9, 9)
194 /* Bit 7 is Reserved (for future Opcode expansion) */
198 * Three-source instructions:
201 F(3src_src2_reg_nr
, 125, 118)
202 F(3src_src2_subreg_nr
, 117, 115) /* Extra discontiguous bit on CHV? */
203 F(3src_src2_swizzle
, 114, 107)
204 F(3src_src2_rep_ctrl
, 106, 106)
205 F(3src_src1_reg_nr
, 104, 97)
206 F(3src_src1_subreg_nr
, 96, 94) /* Extra discontiguous bit on CHV? */
207 F(3src_src1_swizzle
, 93, 86)
208 F(3src_src1_rep_ctrl
, 85, 85)
209 F(3src_src0_reg_nr
, 83, 76)
210 F(3src_src0_subreg_nr
, 75, 73) /* Extra discontiguous bit on CHV? */
211 F(3src_src0_swizzle
, 72, 65)
212 F(3src_src0_rep_ctrl
, 64, 64)
213 F(3src_dst_reg_nr
, 63, 56)
214 F(3src_dst_subreg_nr
, 55, 53)
215 F(3src_dst_writemask
, 52, 49)
216 F8(3src_nib_ctrl
, 47, 47, 11, 11) /* only exists on IVB+ */
217 F8(3src_dst_type
, 45, 44, 48, 46) /* only exists on IVB+ */
218 F8(3src_src_type
, 43, 42, 45, 43)
219 F8(3src_src2_negate
, 41, 41, 42, 42)
220 F8(3src_src2_abs
, 40, 40, 41, 41)
221 F8(3src_src1_negate
, 39, 39, 40, 40)
222 F8(3src_src1_abs
, 38, 38, 39, 39)
223 F8(3src_src0_negate
, 37, 37, 38, 38)
224 F8(3src_src0_abs
, 36, 36, 37, 37)
225 F8(3src_flag_reg_nr
, 34, 34, 33, 33)
226 F8(3src_flag_subreg_nr
, 33, 33, 32, 32)
227 FF(3src_dst_reg_file
,
228 /* 4-5: doesn't exist - no 3-source instructions */ -1, -1, -1, -1, -1, -1,
230 /* 7-8: doesn't exist - no MRFs */ -1, -1, -1, -1)
231 F(3src_saturate
, 31, 31)
232 F(3src_debug_control
, 30, 30)
233 F(3src_cmpt_control
, 29, 29)
234 F(3src_acc_wr_control
, 28, 28)
235 F(3src_cond_modifier
, 27, 24)
236 F(3src_exec_size
, 23, 21)
237 F(3src_pred_inv
, 20, 20)
238 F(3src_pred_control
, 19, 16)
239 F(3src_thread_control
, 15, 14)
240 F(3src_qtr_control
, 13, 12)
241 F8(3src_no_dd_check
, 11, 11, 10, 10)
242 F8(3src_no_dd_clear
, 10, 10, 9, 9)
243 F8(3src_mask_control
, 9, 9, 34, 34)
244 F(3src_access_mode
, 8, 8)
245 /* Bit 7 is Reserved (for future Opcode expansion) */
250 * Flow control instruction bits:
254 brw_inst_set_uip(const struct gen_device_info
*devinfo
,
255 brw_inst
*inst
, int32_t value
)
257 assert(devinfo
->gen
>= 6);
259 if (devinfo
->gen
>= 8) {
260 brw_inst_set_bits(inst
, 95, 64, (uint32_t)value
);
262 assert(value
<= (1 << 16) - 1);
263 assert(value
> -(1 << 16));
264 brw_inst_set_bits(inst
, 127, 112, (uint16_t)value
);
268 static inline int32_t
269 brw_inst_uip(const struct gen_device_info
*devinfo
, const brw_inst
*inst
)
271 assert(devinfo
->gen
>= 6);
273 if (devinfo
->gen
>= 8) {
274 return brw_inst_bits(inst
, 95, 64);
276 return (int16_t)brw_inst_bits(inst
, 127, 112);
281 brw_inst_set_jip(const struct gen_device_info
*devinfo
,
282 brw_inst
*inst
, int32_t value
)
284 assert(devinfo
->gen
>= 6);
286 if (devinfo
->gen
>= 8) {
287 brw_inst_set_bits(inst
, 127, 96, (uint32_t)value
);
289 assert(value
<= (1 << 15) - 1);
290 assert(value
>= -(1 << 15));
291 brw_inst_set_bits(inst
, 111, 96, (uint16_t)value
);
295 static inline int32_t
296 brw_inst_jip(const struct gen_device_info
*devinfo
, const brw_inst
*inst
)
298 assert(devinfo
->gen
>= 6);
300 if (devinfo
->gen
>= 8) {
301 return brw_inst_bits(inst
, 127, 96);
303 return (int16_t)brw_inst_bits(inst
, 111, 96);
307 /** Like FC, but using int16_t to handle negative jump targets. */
308 #define FJ(name, high, low, assertions) \
310 brw_inst_set_##name(const struct gen_device_info *devinfo, brw_inst *inst, int16_t v) \
312 assert(assertions); \
314 brw_inst_set_bits(inst, high, low, (uint16_t) v); \
316 static inline int16_t \
317 brw_inst_##name(const struct gen_device_info *devinfo, const brw_inst *inst) \
319 assert(assertions); \
321 return brw_inst_bits(inst, high, low); \
324 FJ(gen6_jump_count
, 63, 48, devinfo
->gen
== 6)
325 FJ(gen4_jump_count
, 111, 96, devinfo
->gen
< 6)
326 FC(gen4_pop_count
, 115, 112, devinfo
->gen
< 6)
329 /* Message descriptor bits */
330 #define MD(x) ((x) + 96)
333 * Fields for SEND messages:
352 /* 4: doesn't exist */ -1, -1, -1, -1,
357 F(gateway_notify
, MD(16), MD(15))
365 FF(gateway_subfuncid
,
366 /* 4: */ MD(1), MD(0),
367 /* 4.5: */ MD(1), MD(0),
368 /* 5: */ MD(1), MD(0), /* 2:0, but bit 2 is reserved MBZ */
369 /* 6: */ MD(2), MD(0),
370 /* 7: */ MD(2), MD(0),
371 /* 8: */ MD(2), MD(0))
373 /* 4: */ 123, 120, /* called msg_target */
379 FC(base_mrf
, 27, 24, devinfo
->gen
< 6);
383 * URB message function control bits:
386 FF(urb_per_slot_offset
,
387 /* 4-6: */ -1, -1, -1, -1, -1, -1, -1, -1,
388 /* 7: */ MD(16), MD(16),
389 /* 8: */ MD(17), MD(17))
390 FC(urb_channel_mask_present
, MD(15), MD(15), devinfo
->gen
>= 8)
391 FC(urb_complete
, MD(15), MD(15), devinfo
->gen
< 8)
392 FC(urb_used
, MD(14), MD(14), devinfo
->gen
< 7)
393 FC(urb_allocate
, MD(13), MD(13), devinfo
->gen
< 7)
394 FF(urb_swizzle_control
,
395 /* 4: */ MD(11), MD(10),
396 /* 4.5: */ MD(11), MD(10),
397 /* 5: */ MD(11), MD(10),
398 /* 6: */ MD(11), MD(10),
399 /* 7: */ MD(14), MD(14),
400 /* 8: */ MD(15), MD(15))
401 FF(urb_global_offset
,
402 /* 4: */ MD( 9), MD(4),
403 /* 4.5: */ MD( 9), MD(4),
404 /* 5: */ MD( 9), MD(4),
405 /* 6: */ MD( 9), MD(4),
406 /* 7: */ MD(13), MD(3),
407 /* 8: */ MD(14), MD(4))
409 /* 4: */ MD( 3), MD(0),
410 /* 4.5: */ MD( 3), MD(0),
411 /* 5: */ MD( 3), MD(0),
412 /* 6: */ MD( 3), MD(0),
413 /* 7: */ MD( 2), MD(0),
414 /* 8: */ MD( 3), MD(0))
418 * Gen4-5 math messages:
421 FC(math_msg_data_type
, MD(7), MD(7), devinfo
->gen
< 6)
422 FC(math_msg_saturate
, MD(6), MD(6), devinfo
->gen
< 6)
423 FC(math_msg_precision
, MD(5), MD(5), devinfo
->gen
< 6)
424 FC(math_msg_signed_int
, MD(4), MD(4), devinfo
->gen
< 6)
425 FC(math_msg_function
, MD(3), MD(0), devinfo
->gen
< 6)
429 * Sampler message function control bits:
432 FF(sampler_simd_mode
,
433 /* 4: doesn't exist */ -1, -1, -1, -1,
434 /* 5: */ MD(17), MD(16),
435 /* 6: */ MD(17), MD(16),
436 /* 7: */ MD(18), MD(17),
437 /* 8: */ MD(18), MD(17))
439 /* 4: */ MD(15), MD(14),
440 /* 4.5: */ MD(15), MD(12),
441 /* 5: */ MD(15), MD(12),
442 /* 6: */ MD(15), MD(12),
443 /* 7: */ MD(16), MD(12),
444 /* 8: */ MD(16), MD(12))
445 FC(sampler_return_format
, MD(13), MD(12), devinfo
->gen
== 4 && !devinfo
->is_g4x
)
446 F(sampler
, MD(11), MD(8))
447 F(binding_table_index
, MD( 7), MD(0)) /* also used by other messages */
451 * Data port message function control bits:
454 FC(dp_category
, MD(18), MD(18), devinfo
->gen
>= 7)
456 /* Gen4-5 store fields in different bits for read/write messages. */
458 /* 4: */ MD(13), MD(12),
459 /* 4.5: */ MD(13), MD(11),
460 /* 5: */ MD(13), MD(11),
461 /* 6: */ MD(16), MD(13),
462 /* 7: */ MD(17), MD(14),
463 /* 8: */ MD(17), MD(14))
464 FF(dp_write_msg_type
,
465 /* 4: */ MD(14), MD(12),
466 /* 4.5: */ MD(14), MD(12),
467 /* 5: */ MD(14), MD(12),
468 /* 6: */ MD(16), MD(13),
469 /* 7: */ MD(17), MD(14),
470 /* 8: */ MD(17), MD(14))
471 FF(dp_read_msg_control
,
472 /* 4: */ MD(11), MD( 8),
473 /* 4.5: */ MD(10), MD( 8),
474 /* 5: */ MD(10), MD( 8),
475 /* 6: */ MD(12), MD( 8),
476 /* 7: */ MD(13), MD( 8),
477 /* 8: */ MD(13), MD( 8))
478 FF(dp_write_msg_control
,
479 /* 4: */ MD(11), MD( 8),
480 /* 4.5: */ MD(11), MD( 8),
481 /* 5: */ MD(11), MD( 8),
482 /* 6: */ MD(12), MD( 8),
483 /* 7: */ MD(13), MD( 8),
484 /* 8: */ MD(13), MD( 8))
485 FC(dp_read_target_cache
, MD(15), MD(14), devinfo
->gen
< 6);
488 /* 4: */ MD(15), MD(15),
489 /* 4.5: */ MD(15), MD(15),
490 /* 5: */ MD(15), MD(15),
491 /* 6: */ MD(17), MD(17),
492 /* 7+: does not exist */ -1, -1, -1, -1)
494 /* Gen6+ use the same bit locations for everything. */
496 /* 4-5: use dp_read_msg_type or dp_write_msg_type instead */
497 -1, -1, -1, -1, -1, -1,
498 /* 6: */ MD(16), MD(13),
499 /* 7: */ MD(17), MD(14),
500 /* 8: */ MD(17), MD(14))
502 /* 4: */ MD(11), MD( 8),
503 /* 4.5-5: use dp_read_msg_control or dp_write_msg_control */ -1, -1, -1, -1,
504 /* 6: */ MD(12), MD( 8),
505 /* 7: */ MD(13), MD( 8),
506 /* 8: */ MD(13), MD( 8))
510 * Scratch message bits (Gen7+):
513 FC(scratch_read_write
, MD(17), MD(17), devinfo
->gen
>= 7) /* 0 = read, 1 = write */
514 FC(scratch_type
, MD(16), MD(16), devinfo
->gen
>= 7) /* 0 = OWord, 1 = DWord */
515 FC(scratch_invalidate_after_read
, MD(15), MD(15), devinfo
->gen
>= 7)
516 FC(scratch_block_size
, MD(13), MD(12), devinfo
->gen
>= 7)
517 FC(scratch_addr_offset
, MD(11), MD( 0), devinfo
->gen
>= 7)
521 * Render Target message function control bits:
525 /* 4: */ MD(11), MD(11),
526 /* 4.5: */ MD(11), MD(11),
527 /* 5: */ MD(11), MD(11),
528 /* 6: */ MD(12), MD(12),
529 /* 7: */ MD(12), MD(12),
530 /* 8: */ MD(12), MD(12))
531 FC(rt_slot_group
, MD(11), MD(11), devinfo
->gen
>= 6)
532 F(rt_message_type
, MD(10), MD( 8))
536 * Thread Spawn message function control bits:
539 F(ts_resource_select
, MD( 4), MD( 4))
540 F(ts_request_type
, MD( 1), MD( 1))
541 F(ts_opcode
, MD( 0), MD( 0))
545 * Pixel Interpolator message function control bits:
548 F(pi_simd_mode
, MD(16), MD(16))
549 F(pi_nopersp
, MD(14), MD(14))
550 F(pi_message_type
, MD(13), MD(12))
551 F(pi_slot_group
, MD(11), MD(11))
552 F(pi_message_data
, MD(7), MD(0))
560 brw_inst_imm_d(const struct gen_device_info
*devinfo
, const brw_inst
*insn
)
563 return brw_inst_bits(insn
, 127, 96);
566 static inline unsigned
567 brw_inst_imm_ud(const struct gen_device_info
*devinfo
, const brw_inst
*insn
)
570 return brw_inst_bits(insn
, 127, 96);
573 static inline uint64_t
574 brw_inst_imm_uq(const struct gen_device_info
*devinfo
, const brw_inst
*insn
)
576 assert(devinfo
->gen
>= 8);
577 return brw_inst_bits(insn
, 127, 64);
581 brw_inst_imm_f(const struct gen_device_info
*devinfo
, const brw_inst
*insn
)
588 ft
.u
= brw_inst_bits(insn
, 127, 96);
593 brw_inst_imm_df(const struct gen_device_info
*devinfo
, const brw_inst
*insn
)
600 dt
.u
= brw_inst_bits(insn
, 127, 64);
605 brw_inst_set_imm_d(const struct gen_device_info
*devinfo
,
606 brw_inst
*insn
, int value
)
609 return brw_inst_set_bits(insn
, 127, 96, value
);
613 brw_inst_set_imm_ud(const struct gen_device_info
*devinfo
,
614 brw_inst
*insn
, unsigned value
)
617 return brw_inst_set_bits(insn
, 127, 96, value
);
621 brw_inst_set_imm_f(const struct gen_device_info
*devinfo
,
622 brw_inst
*insn
, float value
)
630 brw_inst_set_bits(insn
, 127, 96, ft
.u
);
634 brw_inst_set_imm_df(const struct gen_device_info
*devinfo
,
635 brw_inst
*insn
, double value
)
643 brw_inst_set_bits(insn
, 127, 64, dt
.u
);
647 brw_inst_set_imm_uq(const struct gen_device_info
*devinfo
,
648 brw_inst
*insn
, uint64_t value
)
651 brw_inst_set_bits(insn
, 127, 64, value
);
656 #define REG_TYPE(reg) \
658 brw_inst_set_##reg##_file_type(const struct gen_device_info *devinfo, \
659 brw_inst *inst, enum brw_reg_file file, \
660 enum brw_reg_type type) \
662 assert(file <= BRW_IMMEDIATE_VALUE); \
663 unsigned hw_type = brw_reg_type_to_hw_type(devinfo, file, type); \
664 brw_inst_set_##reg##_reg_file(devinfo, inst, file); \
665 brw_inst_set_##reg##_reg_hw_type(devinfo, inst, hw_type); \
668 static inline enum brw_reg_type \
669 brw_inst_##reg##_type(const struct gen_device_info *devinfo, \
670 const brw_inst *inst) \
672 unsigned file = brw_inst_##reg##_reg_file(devinfo, inst); \
673 unsigned hw_type = brw_inst_##reg##_reg_hw_type(devinfo, inst); \
674 return brw_hw_type_to_reg_type(devinfo, (enum brw_reg_file)file, hw_type); \
683 /* The AddrImm fields are split into two discontiguous sections on Gen8+ */
684 #define BRW_IA1_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low) \
686 brw_inst_set_##reg##_ia1_addr_imm(const struct gen_device_info *devinfo, \
690 assert((value & ~0x3ff) == 0); \
691 if (devinfo->gen >= 8) { \
692 brw_inst_set_bits(inst, g8_high, g8_low, value & 0x1ff); \
693 brw_inst_set_bits(inst, g8_nine, g8_nine, value >> 9); \
695 brw_inst_set_bits(inst, g4_high, g4_low, value); \
698 static inline unsigned \
699 brw_inst_##reg##_ia1_addr_imm(const struct gen_device_info *devinfo, \
700 const brw_inst *inst) \
702 if (devinfo->gen >= 8) { \
703 return brw_inst_bits(inst, g8_high, g8_low) | \
704 (brw_inst_bits(inst, g8_nine, g8_nine) << 9); \
706 return brw_inst_bits(inst, g4_high, g4_low); \
710 /* AddrImm[9:0] for Align1 Indirect Addressing */
711 /* -Gen 4- ----Gen8---- */
712 BRW_IA1_ADDR_IMM(src1
, 105, 96, 121, 104, 96)
713 BRW_IA1_ADDR_IMM(src0
, 73, 64, 95, 72, 64)
714 BRW_IA1_ADDR_IMM(dst
, 57, 48, 47, 56, 48)
716 #define BRW_IA16_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low) \
718 brw_inst_set_##reg##_ia16_addr_imm(const struct gen_device_info *devinfo, \
719 brw_inst *inst, unsigned value) \
721 assert((value & ~0x3ff) == 0); \
722 if (devinfo->gen >= 8) { \
723 brw_inst_set_bits(inst, g8_high, g8_low, value & 0x1ff); \
724 brw_inst_set_bits(inst, g8_nine, g8_nine, value >> 9); \
726 brw_inst_set_bits(inst, g4_high, g4_low, value >> 9); \
729 static inline unsigned \
730 brw_inst_##reg##_ia16_addr_imm(const struct gen_device_info *devinfo, \
731 const brw_inst *inst) \
733 if (devinfo->gen >= 8) { \
734 return brw_inst_bits(inst, g8_high, g8_low) | \
735 (brw_inst_bits(inst, g8_nine, g8_nine) << 9); \
737 return brw_inst_bits(inst, g4_high, g4_low); \
741 /* AddrImm[9:0] for Align16 Indirect Addressing:
742 * Compared to Align1, these are missing the low 4 bits.
743 * -Gen 4- ----Gen8----
745 BRW_IA16_ADDR_IMM(src1
, 105, 96, 121, 104, 100)
746 BRW_IA16_ADDR_IMM(src0
, 73, 64, 95, 72, 68)
747 BRW_IA16_ADDR_IMM(dst
, 57, 52, 47, 56, 52)
750 * Fetch a set of contiguous bits from the instruction.
752 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
754 static inline uint64_t
755 brw_inst_bits(const brw_inst
*inst
, unsigned high
, unsigned low
)
757 /* We assume the field doesn't cross 64-bit boundaries. */
758 const unsigned word
= high
/ 64;
759 assert(word
== low
/ 64);
764 const uint64_t mask
= (~0ull >> (64 - (high
- low
+ 1)));
766 return (inst
->data
[word
] >> low
) & mask
;
770 * Set bits in the instruction, with proper shifting and masking.
772 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
775 brw_inst_set_bits(brw_inst
*inst
, unsigned high
, unsigned low
, uint64_t value
)
777 const unsigned word
= high
/ 64;
778 assert(word
== low
/ 64);
783 const uint64_t mask
= (~0ull >> (64 - (high
- low
+ 1))) << low
;
785 /* Make sure the supplied value actually fits in the given bitfield. */
786 assert((value
& (mask
>> low
)) == value
);
788 inst
->data
[word
] = (inst
->data
[word
] & ~mask
) | (value
<< low
);
791 #undef BRW_IA16_ADDR_IMM
792 #undef BRW_IA1_ADDR_IMM
805 * Fetch a set of contiguous bits from the compacted instruction.
807 * Bits indices range from 0..63.
809 static inline unsigned
810 brw_compact_inst_bits(const brw_compact_inst
*inst
, unsigned high
, unsigned low
)
812 const uint64_t mask
= (1ull << (high
- low
+ 1)) - 1;
814 return (inst
->data
>> low
) & mask
;
818 * Set bits in the compacted instruction.
820 * Bits indices range from 0..63.
823 brw_compact_inst_set_bits(brw_compact_inst
*inst
, unsigned high
, unsigned low
,
826 const uint64_t mask
= ((1ull << (high
- low
+ 1)) - 1) << low
;
828 /* Make sure the supplied value actually fits in the given bitfield. */
829 assert((value
& (mask
>> low
)) == value
);
831 inst
->data
= (inst
->data
& ~mask
) | (value
<< low
);
834 #define FC(name, high, low, assertions) \
836 brw_compact_inst_set_##name(const struct gen_device_info *devinfo, \
837 brw_compact_inst *inst, unsigned v) \
839 assert(assertions); \
841 brw_compact_inst_set_bits(inst, high, low, v); \
843 static inline unsigned \
844 brw_compact_inst_##name(const struct gen_device_info *devinfo, \
845 const brw_compact_inst *inst) \
847 assert(assertions); \
849 return brw_compact_inst_bits(inst, high, low); \
852 /* A simple macro for fields which stay in the same place on all generations. */
853 #define F(name, high, low) FC(name, high, low, true)
855 F(src1_reg_nr
, 63, 56)
856 F(src0_reg_nr
, 55, 48)
857 F(dst_reg_nr
, 47, 40)
858 F(src1_index
, 39, 35)
859 F(src0_index
, 34, 30)
860 F(cmpt_control
, 29, 29) /* Same location as brw_inst */
861 FC(flag_subreg_nr
, 28, 28, devinfo
->gen
<= 6)
862 F(cond_modifier
, 27, 24) /* Same location as brw_inst */
863 FC(acc_wr_control
, 23, 23, devinfo
->gen
>= 6)
864 FC(mask_control_ex
, 23, 23, devinfo
->is_g4x
|| devinfo
->gen
== 5)
865 F(subreg_index
, 22, 18)
866 F(datatype_index
, 17, 13)
867 F(control_index
, 12, 8)
868 F(debug_control
, 7, 7)
869 F(opcode
, 6, 0) /* Same location as brw_inst */
872 * (Gen8+) Compacted three-source instructions:
875 FC(3src_src2_reg_nr
, 63, 57, devinfo
->gen
>= 8)
876 FC(3src_src1_reg_nr
, 56, 50, devinfo
->gen
>= 8)
877 FC(3src_src0_reg_nr
, 49, 43, devinfo
->gen
>= 8)
878 FC(3src_src2_subreg_nr
, 42, 40, devinfo
->gen
>= 8)
879 FC(3src_src1_subreg_nr
, 39, 37, devinfo
->gen
>= 8)
880 FC(3src_src0_subreg_nr
, 36, 34, devinfo
->gen
>= 8)
881 FC(3src_src2_rep_ctrl
, 33, 33, devinfo
->gen
>= 8)
882 FC(3src_src1_rep_ctrl
, 32, 32, devinfo
->gen
>= 8)
883 FC(3src_saturate
, 31, 31, devinfo
->gen
>= 8)
884 FC(3src_debug_control
, 30, 30, devinfo
->gen
>= 8)
885 FC(3src_cmpt_control
, 29, 29, devinfo
->gen
>= 8)
886 FC(3src_src0_rep_ctrl
, 28, 28, devinfo
->gen
>= 8)
888 FC(3src_dst_reg_nr
, 18, 12, devinfo
->gen
>= 8)
889 FC(3src_source_index
, 11, 10, devinfo
->gen
>= 8)
890 FC(3src_control_index
, 9, 8, devinfo
->gen
>= 8)
891 /* Bit 7 is Reserved (for future Opcode expansion) */
892 FC(3src_opcode
, 6, 0, devinfo
->gen
>= 8)