4ed95c473cd9fe2d6a6d76736729f686ed05059e
[mesa.git] / src / mesa / drivers / dri / i965 / brw_inst.h
1 /*
2 * Copyright © 2014 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file brw_inst.h
26 *
27 * A representation of i965 EU assembly instructions, with helper methods to
28 * get and set various fields. This is the actual hardware format.
29 */
30
31 #ifndef BRW_INST_H
32 #define BRW_INST_H
33
34 #include <stdint.h>
35
36 #include "brw_context.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /** Maximum SEND message length */
43 #define BRW_MAX_MSG_LENGTH 15
44
45 /** First MRF register used by pull loads */
46 #define FIRST_SPILL_MRF(gen) ((gen) == 6 ? 21 : 13)
47
48 /** First MRF register used by spills */
49 #define FIRST_PULL_LOAD_MRF(gen) ((gen) == 6 ? 16 : 13)
50
51 /* brw_context.h has a forward declaration of brw_inst, so name the struct. */
52 typedef struct brw_inst {
53 uint64_t data[2];
54 } brw_inst;
55
56 static inline uint64_t brw_inst_bits(const brw_inst *inst,
57 unsigned high, unsigned low);
58 static inline void brw_inst_set_bits(brw_inst *inst,
59 unsigned high, unsigned low,
60 uint64_t value);
61
62 #define FC(name, high, low, assertions) \
63 static inline void \
64 brw_inst_set_##name(const struct brw_device_info *devinfo, \
65 brw_inst *inst, uint64_t v) \
66 { \
67 assert(assertions); \
68 (void) devinfo; \
69 brw_inst_set_bits(inst, high, low, v); \
70 } \
71 static inline uint64_t \
72 brw_inst_##name(const struct brw_device_info *devinfo, \
73 const brw_inst *inst) \
74 { \
75 assert(assertions); \
76 (void) devinfo; \
77 return brw_inst_bits(inst, high, low); \
78 }
79
80 /* A simple macro for fields which stay in the same place on all generations. */
81 #define F(name, high, low) FC(name, high, low, true)
82
83 #define BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
84 unsigned high, low; \
85 if (devinfo->gen >= 8) { \
86 high = hi8; low = lo8; \
87 } else if (devinfo->gen >= 7) { \
88 high = hi7; low = lo7; \
89 } else if (devinfo->gen >= 6) { \
90 high = hi6; low = lo6; \
91 } else if (devinfo->gen >= 5) { \
92 high = hi5; low = lo5; \
93 } else if (devinfo->is_g4x) { \
94 high = hi45; low = lo45; \
95 } else { \
96 high = hi4; low = lo4; \
97 } \
98 assert(((int) high) != -1 && ((int) low) != -1); \
99
100 /* A general macro for cases where the field has moved to several different
101 * bit locations across generations. GCC appears to combine cases where the
102 * bits are identical, removing some of the inefficiency.
103 */
104 #define FF(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8)\
105 static inline void \
106 brw_inst_set_##name(const struct brw_device_info *devinfo, \
107 brw_inst *inst, uint64_t value) \
108 { \
109 BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
110 brw_inst_set_bits(inst, high, low, value); \
111 } \
112 static inline uint64_t \
113 brw_inst_##name(const struct brw_device_info *devinfo, const brw_inst *inst) \
114 { \
115 BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6, hi7, lo7, hi8, lo8) \
116 return brw_inst_bits(inst, high, low); \
117 }
118
119 /* A macro for fields which moved as of Gen8+. */
120 #define F8(name, gen4_high, gen4_low, gen8_high, gen8_low) \
121 FF(name, \
122 /* 4: */ gen4_high, gen4_low, \
123 /* 4.5: */ gen4_high, gen4_low, \
124 /* 5: */ gen4_high, gen4_low, \
125 /* 6: */ gen4_high, gen4_low, \
126 /* 7: */ gen4_high, gen4_low, \
127 /* 8: */ gen8_high, gen8_low);
128
129 F(src1_vstride, 120, 117)
130 F(src1_width, 116, 114)
131 F(src1_da16_swiz_w, 115, 114)
132 F(src1_da16_swiz_z, 113, 112)
133 F(src1_hstride, 113, 112)
134 F(src1_address_mode, 111, 111)
135 /** Src1.SrcMod @{ */
136 F(src1_negate, 110, 110)
137 F(src1_abs, 109, 109)
138 /** @} */
139 F8(src1_ia_subreg_nr, /* 4+ */ 108, 106, /* 8+ */ 108, 105)
140 F(src1_da_reg_nr, 108, 101)
141 F(src1_da16_subreg_nr, 100, 100)
142 F(src1_da1_subreg_nr, 100, 96)
143 F(src1_da16_swiz_y, 99, 98)
144 F(src1_da16_swiz_x, 97, 96)
145 F8(src1_reg_type, /* 4+ */ 46, 44, /* 8+ */ 94, 91)
146 F8(src1_reg_file, /* 4+ */ 43, 42, /* 8+ */ 90, 89)
147 F(src0_vstride, 88, 85)
148 F(src0_width, 84, 82)
149 F(src0_da16_swiz_w, 83, 82)
150 F(src0_da16_swiz_z, 81, 80)
151 F(src0_hstride, 81, 80)
152 F(src0_address_mode, 79, 79)
153 /** Src0.SrcMod @{ */
154 F(src0_negate, 78, 78)
155 F(src0_abs, 77, 77)
156 /** @} */
157 F8(src0_ia_subreg_nr, /* 4+ */ 76, 74, /* 8+ */ 76, 73)
158 F(src0_da_reg_nr, 76, 69)
159 F(src0_da16_subreg_nr, 68, 68)
160 F(src0_da1_subreg_nr, 68, 64)
161 F(src0_da16_swiz_y, 67, 66)
162 F(src0_da16_swiz_x, 65, 64)
163 F(dst_address_mode, 63, 63)
164 F(dst_hstride, 62, 61)
165 F8(dst_ia_subreg_nr, /* 4+ */ 60, 58, /* 8+ */ 60, 57)
166 F(dst_da_reg_nr, 60, 53)
167 F(dst_da16_subreg_nr, 52, 52)
168 F(dst_da1_subreg_nr, 52, 48)
169 F(da16_writemask, 51, 48) /* Dst.ChanEn */
170 F8(src0_reg_type, /* 4+ */ 41, 39, /* 8+ */ 46, 43)
171 F8(src0_reg_file, /* 4+ */ 38, 37, /* 8+ */ 42, 41)
172 F8(dst_reg_type, /* 4+ */ 36, 34, /* 8+ */ 40, 37)
173 F8(dst_reg_file, /* 4+ */ 33, 32, /* 8+ */ 36, 35)
174 F8(mask_control, /* 4+ */ 9, 9, /* 8+ */ 34, 34)
175 FF(flag_reg_nr,
176 /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
177 /* 7: */ 90, 90,
178 /* 8: */ 33, 33)
179 F8(flag_subreg_nr, /* 4+ */ 89, 89, /* 8+ */ 32, 32)
180 F(saturate, 31, 31)
181 F(debug_control, 30, 30)
182 F(cmpt_control, 29, 29)
183 FC(branch_control, 28, 28, devinfo->gen >= 8)
184 FC(acc_wr_control, 28, 28, devinfo->gen >= 6)
185 FC(mask_control_ex, 28, 28, devinfo->is_g4x || devinfo->gen == 5)
186 F(cond_modifier, 27, 24)
187 FC(math_function, 27, 24, devinfo->gen >= 6)
188 F(exec_size, 23, 21)
189 F(pred_inv, 20, 20)
190 F(pred_control, 19, 16)
191 F(thread_control, 15, 14)
192 F(qtr_control, 13, 12)
193 FF(nib_control,
194 /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
195 /* 7: */ 47, 47,
196 /* 8: */ 11, 11)
197 F8(no_dd_check, /* 4+ */ 11, 11, /* 8+ */ 10, 10)
198 F8(no_dd_clear, /* 4+ */ 10, 10, /* 8+ */ 9, 9)
199 F(access_mode, 8, 8)
200 /* Bit 7 is Reserved (for future Opcode expansion) */
201 F(opcode, 6, 0)
202
203 /**
204 * Three-source instructions:
205 * @{
206 */
207 F(3src_src2_reg_nr, 125, 118)
208 F(3src_src2_subreg_nr, 117, 115) /* Extra discontiguous bit on CHV? */
209 F(3src_src2_swizzle, 114, 107)
210 F(3src_src2_rep_ctrl, 106, 106)
211 F(3src_src1_reg_nr, 104, 97)
212 F(3src_src1_subreg_nr, 96, 94) /* Extra discontiguous bit on CHV? */
213 F(3src_src1_swizzle, 93, 86)
214 F(3src_src1_rep_ctrl, 85, 85)
215 F(3src_src0_reg_nr, 83, 76)
216 F(3src_src0_subreg_nr, 75, 73) /* Extra discontiguous bit on CHV? */
217 F(3src_src0_swizzle, 72, 65)
218 F(3src_src0_rep_ctrl, 64, 64)
219 F(3src_dst_reg_nr, 63, 56)
220 F(3src_dst_subreg_nr, 55, 53)
221 F(3src_dst_writemask, 52, 49)
222 F8(3src_nib_ctrl, 47, 47, 11, 11) /* only exists on IVB+ */
223 F8(3src_dst_type, 45, 44, 48, 46) /* only exists on IVB+ */
224 F8(3src_src_type, 43, 42, 45, 43)
225 F8(3src_src2_negate, 41, 41, 42, 42)
226 F8(3src_src2_abs, 40, 40, 41, 41)
227 F8(3src_src1_negate, 39, 39, 40, 40)
228 F8(3src_src1_abs, 38, 38, 39, 39)
229 F8(3src_src0_negate, 37, 37, 38, 38)
230 F8(3src_src0_abs, 36, 36, 37, 37)
231 F8(3src_flag_reg_nr, 34, 34, 33, 33)
232 F8(3src_flag_subreg_nr, 33, 33, 32, 32)
233 FF(3src_dst_reg_file,
234 /* 4-5: doesn't exist - no 3-source instructions */ -1, -1, -1, -1, -1, -1,
235 /* 6: */ 32, 32,
236 /* 7-8: doesn't exist - no MRFs */ -1, -1, -1, -1)
237 F(3src_saturate, 31, 31)
238 F(3src_debug_control, 30, 30)
239 F(3src_cmpt_control, 29, 29)
240 F(3src_acc_wr_control, 28, 28)
241 F(3src_cond_modifier, 27, 24)
242 F(3src_exec_size, 23, 21)
243 F(3src_pred_inv, 20, 20)
244 F(3src_pred_control, 19, 16)
245 F(3src_thread_control, 15, 14)
246 F(3src_qtr_control, 13, 12)
247 F8(3src_no_dd_check, 11, 11, 10, 10)
248 F8(3src_no_dd_clear, 10, 10, 9, 9)
249 F8(3src_mask_control, 9, 9, 34, 34)
250 F(3src_access_mode, 8, 8)
251 /* Bit 7 is Reserved (for future Opcode expansion) */
252 F(3src_opcode, 6, 0)
253 /** @} */
254
255 /**
256 * Flow control instruction bits:
257 * @{
258 */
259 static inline void
260 brw_inst_set_uip(const struct brw_device_info *devinfo,
261 brw_inst *inst, int32_t value)
262 {
263 assert(devinfo->gen >= 6);
264
265 if (devinfo->gen >= 8) {
266 brw_inst_set_bits(inst, 95, 64, (uint32_t)value);
267 } else {
268 assert(value <= (1 << 16) - 1);
269 assert(value > -(1 << 16));
270 brw_inst_set_bits(inst, 127, 112, (uint16_t)value);
271 }
272 }
273
274 static inline int32_t
275 brw_inst_uip(const struct brw_device_info *devinfo, const brw_inst *inst)
276 {
277 assert(devinfo->gen >= 6);
278
279 if (devinfo->gen >= 8) {
280 return brw_inst_bits(inst, 95, 64);
281 } else {
282 return (int16_t)brw_inst_bits(inst, 127, 112);
283 }
284 }
285
286 static inline void
287 brw_inst_set_jip(const struct brw_device_info *devinfo,
288 brw_inst *inst, int32_t value)
289 {
290 assert(devinfo->gen >= 6);
291
292 if (devinfo->gen >= 8) {
293 brw_inst_set_bits(inst, 127, 96, (uint32_t)value);
294 } else {
295 assert(value <= (1 << 16) - 1);
296 assert(value > -(1 << 16));
297 brw_inst_set_bits(inst, 111, 96, (uint16_t)value);
298 }
299 }
300
301 static inline int32_t
302 brw_inst_jip(const struct brw_device_info *devinfo, const brw_inst *inst)
303 {
304 assert(devinfo->gen >= 6);
305
306 if (devinfo->gen >= 8) {
307 return brw_inst_bits(inst, 127, 96);
308 } else {
309 return (int16_t)brw_inst_bits(inst, 111, 96);
310 }
311 }
312
313 /** Like FC, but using int16_t to handle negative jump targets. */
314 #define FJ(name, high, low, assertions) \
315 static inline void \
316 brw_inst_set_##name(const struct brw_device_info *devinfo, brw_inst *inst, int16_t v) \
317 { \
318 assert(assertions); \
319 (void) devinfo; \
320 brw_inst_set_bits(inst, high, low, (uint16_t) v); \
321 } \
322 static inline int16_t \
323 brw_inst_##name(const struct brw_device_info *devinfo, const brw_inst *inst) \
324 { \
325 assert(assertions); \
326 (void) devinfo; \
327 return brw_inst_bits(inst, high, low); \
328 }
329
330 FJ(gen6_jump_count, 63, 48, devinfo->gen == 6)
331 FJ(gen4_jump_count, 111, 96, devinfo->gen < 6)
332 FC(gen4_pop_count, 115, 112, devinfo->gen < 6)
333 /** @} */
334
335 /* Message descriptor bits */
336 #define MD(x) ((x) + 96)
337
338 /**
339 * Fields for SEND messages:
340 * @{
341 */
342 F(eot, 127, 127)
343 FF(mlen,
344 /* 4: */ 119, 116,
345 /* 4.5: */ 119, 116,
346 /* 5: */ 124, 121,
347 /* 6: */ 124, 121,
348 /* 7: */ 124, 121,
349 /* 8: */ 124, 121);
350 FF(rlen,
351 /* 4: */ 115, 112,
352 /* 4.5: */ 115, 112,
353 /* 5: */ 120, 116,
354 /* 6: */ 120, 116,
355 /* 7: */ 120, 116,
356 /* 8: */ 120, 116);
357 FF(header_present,
358 /* 4: doesn't exist */ -1, -1, -1, -1,
359 /* 5: */ 115, 115,
360 /* 6: */ 115, 115,
361 /* 7: */ 115, 115,
362 /* 8: */ 115, 115)
363 F(gateway_notify, MD(16), MD(15))
364 FF(function_control,
365 /* 4: */ 111, 96,
366 /* 4.5: */ 111, 96,
367 /* 5: */ 114, 96,
368 /* 6: */ 114, 96,
369 /* 7: */ 114, 96,
370 /* 8: */ 114, 96)
371 FF(gateway_subfuncid,
372 /* 4: */ MD(1), MD(0),
373 /* 4.5: */ MD(1), MD(0),
374 /* 5: */ MD(1), MD(0), /* 2:0, but bit 2 is reserved MBZ */
375 /* 6: */ MD(2), MD(0),
376 /* 7: */ MD(2), MD(0),
377 /* 8: */ MD(2), MD(0))
378 FF(sfid,
379 /* 4: */ 123, 120, /* called msg_target */
380 /* 4.5 */ 123, 120,
381 /* 5: */ 95, 92,
382 /* 6: */ 27, 24,
383 /* 7: */ 27, 24,
384 /* 8: */ 27, 24)
385 FC(base_mrf, 27, 24, devinfo->gen < 6);
386 /** @} */
387
388 /**
389 * URB message function control bits:
390 * @{
391 */
392 FF(urb_per_slot_offset,
393 /* 4-6: */ -1, -1, -1, -1, -1, -1, -1, -1,
394 /* 7: */ MD(16), MD(16),
395 /* 8: */ MD(17), MD(17))
396 FC(urb_channel_mask_present, MD(15), MD(15), devinfo->gen >= 8)
397 FC(urb_complete, MD(15), MD(15), devinfo->gen < 8)
398 FC(urb_used, MD(14), MD(14), devinfo->gen < 7)
399 FC(urb_allocate, MD(13), MD(13), devinfo->gen < 7)
400 FF(urb_swizzle_control,
401 /* 4: */ MD(11), MD(10),
402 /* 4.5: */ MD(11), MD(10),
403 /* 5: */ MD(11), MD(10),
404 /* 6: */ MD(11), MD(10),
405 /* 7: */ MD(14), MD(14),
406 /* 8: */ MD(15), MD(15))
407 FF(urb_global_offset,
408 /* 4: */ MD( 9), MD(4),
409 /* 4.5: */ MD( 9), MD(4),
410 /* 5: */ MD( 9), MD(4),
411 /* 6: */ MD( 9), MD(4),
412 /* 7: */ MD(13), MD(3),
413 /* 8: */ MD(14), MD(4))
414 FF(urb_opcode,
415 /* 4: */ MD( 3), MD(0),
416 /* 4.5: */ MD( 3), MD(0),
417 /* 5: */ MD( 3), MD(0),
418 /* 6: */ MD( 3), MD(0),
419 /* 7: */ MD( 2), MD(0),
420 /* 8: */ MD( 3), MD(0))
421 /** @} */
422
423 /**
424 * Gen4-5 math messages:
425 * @{
426 */
427 FC(math_msg_data_type, MD(7), MD(7), devinfo->gen < 6)
428 FC(math_msg_saturate, MD(6), MD(6), devinfo->gen < 6)
429 FC(math_msg_precision, MD(5), MD(5), devinfo->gen < 6)
430 FC(math_msg_signed_int, MD(4), MD(4), devinfo->gen < 6)
431 FC(math_msg_function, MD(3), MD(0), devinfo->gen < 6)
432 /** @} */
433
434 /**
435 * Sampler message function control bits:
436 * @{
437 */
438 FF(sampler_simd_mode,
439 /* 4: doesn't exist */ -1, -1, -1, -1,
440 /* 5: */ MD(17), MD(16),
441 /* 6: */ MD(17), MD(16),
442 /* 7: */ MD(18), MD(17),
443 /* 8: */ MD(18), MD(17))
444 FF(sampler_msg_type,
445 /* 4: */ MD(15), MD(14),
446 /* 4.5: */ MD(15), MD(12),
447 /* 5: */ MD(15), MD(12),
448 /* 6: */ MD(15), MD(12),
449 /* 7: */ MD(16), MD(12),
450 /* 8: */ MD(16), MD(12))
451 FC(sampler_return_format, MD(13), MD(12), devinfo->gen == 4 && !devinfo->is_g4x)
452 F(sampler, MD(11), MD(8))
453 F(binding_table_index, MD( 7), MD(0)) /* also used by other messages */
454 /** @} */
455
456 /**
457 * Data port message function control bits:
458 * @{
459 */
460 FC(dp_category, MD(18), MD(18), devinfo->gen >= 7)
461
462 /* Gen4-5 store fields in different bits for read/write messages. */
463 FF(dp_read_msg_type,
464 /* 4: */ MD(13), MD(12),
465 /* 4.5: */ MD(13), MD(11),
466 /* 5: */ MD(13), MD(11),
467 /* 6: */ MD(16), MD(13),
468 /* 7: */ MD(17), MD(14),
469 /* 8: */ MD(17), MD(14))
470 FF(dp_write_msg_type,
471 /* 4: */ MD(14), MD(12),
472 /* 4.5: */ MD(14), MD(12),
473 /* 5: */ MD(14), MD(12),
474 /* 6: */ MD(16), MD(13),
475 /* 7: */ MD(17), MD(14),
476 /* 8: */ MD(17), MD(14))
477 FF(dp_read_msg_control,
478 /* 4: */ MD(11), MD( 8),
479 /* 4.5: */ MD(10), MD( 8),
480 /* 5: */ MD(10), MD( 8),
481 /* 6: */ MD(12), MD( 8),
482 /* 7: */ MD(13), MD( 8),
483 /* 8: */ MD(13), MD( 8))
484 FF(dp_write_msg_control,
485 /* 4: */ MD(11), MD( 8),
486 /* 4.5: */ MD(11), MD( 8),
487 /* 5: */ MD(11), MD( 8),
488 /* 6: */ MD(12), MD( 8),
489 /* 7: */ MD(13), MD( 8),
490 /* 8: */ MD(13), MD( 8))
491 FC(dp_read_target_cache, MD(15), MD(14), devinfo->gen < 6);
492
493 FF(dp_write_commit,
494 /* 4: */ MD(15), MD(15),
495 /* 4.5: */ MD(15), MD(15),
496 /* 5: */ MD(15), MD(15),
497 /* 6: */ MD(17), MD(17),
498 /* 7+: does not exist */ -1, -1, -1, -1)
499
500 /* Gen6+ use the same bit locations for everything. */
501 FF(dp_msg_type,
502 /* 4-5: use dp_read_msg_type or dp_write_msg_type instead */
503 -1, -1, -1, -1, -1, -1,
504 /* 6: */ MD(16), MD(13),
505 /* 7: */ MD(17), MD(14),
506 /* 8: */ MD(17), MD(14))
507 FF(dp_msg_control,
508 /* 4: */ MD(11), MD( 8),
509 /* 4.5-5: use dp_read_msg_control or dp_write_msg_control */ -1, -1, -1, -1,
510 /* 6: */ MD(12), MD( 8),
511 /* 7: */ MD(13), MD( 8),
512 /* 8: */ MD(13), MD( 8))
513 /** @} */
514
515 /**
516 * Scratch message bits (Gen7+):
517 * @{
518 */
519 FC(scratch_read_write, MD(17), MD(17), devinfo->gen >= 7) /* 0 = read, 1 = write */
520 FC(scratch_type, MD(16), MD(16), devinfo->gen >= 7) /* 0 = OWord, 1 = DWord */
521 FC(scratch_invalidate_after_read, MD(15), MD(15), devinfo->gen >= 7)
522 FC(scratch_block_size, MD(13), MD(12), devinfo->gen >= 7)
523 FC(scratch_addr_offset, MD(11), MD( 0), devinfo->gen >= 7)
524 /** @} */
525
526 /**
527 * Render Target message function control bits:
528 * @{
529 */
530 FF(rt_last,
531 /* 4: */ MD(11), MD(11),
532 /* 4.5: */ MD(11), MD(11),
533 /* 5: */ MD(11), MD(11),
534 /* 6: */ MD(12), MD(12),
535 /* 7: */ MD(12), MD(12),
536 /* 8: */ MD(12), MD(12))
537 FC(rt_slot_group, MD(11), MD(11), devinfo->gen >= 6)
538 F(rt_message_type, MD(10), MD( 8))
539 /** @} */
540
541 /**
542 * Thread Spawn message function control bits:
543 * @{
544 */
545 F(ts_resource_select, MD( 4), MD( 4))
546 F(ts_request_type, MD( 1), MD( 1))
547 F(ts_opcode, MD( 0), MD( 0))
548 /** @} */
549
550 /**
551 * Pixel Interpolator message function control bits:
552 * @{
553 */
554 F(pi_simd_mode, MD(16), MD(16))
555 F(pi_nopersp, MD(14), MD(14))
556 F(pi_message_type, MD(13), MD(12))
557 F(pi_slot_group, MD(11), MD(11))
558 F(pi_message_data, MD(7), MD(0))
559 /** @} */
560
561 /**
562 * Immediates:
563 * @{
564 */
565 static inline int
566 brw_inst_imm_d(const struct brw_device_info *devinfo, const brw_inst *insn)
567 {
568 (void) devinfo;
569 return brw_inst_bits(insn, 127, 96);
570 }
571
572 static inline unsigned
573 brw_inst_imm_ud(const struct brw_device_info *devinfo, const brw_inst *insn)
574 {
575 (void) devinfo;
576 return brw_inst_bits(insn, 127, 96);
577 }
578
579 static inline float
580 brw_inst_imm_f(const struct brw_device_info *devinfo, const brw_inst *insn)
581 {
582 fi_type ft;
583 (void) devinfo;
584 ft.u = brw_inst_bits(insn, 127, 96);
585 return ft.f;
586 }
587
588 static inline void
589 brw_inst_set_imm_d(const struct brw_device_info *devinfo,
590 brw_inst *insn, int value)
591 {
592 (void) devinfo;
593 return brw_inst_set_bits(insn, 127, 96, value);
594 }
595
596 static inline void
597 brw_inst_set_imm_ud(const struct brw_device_info *devinfo,
598 brw_inst *insn, unsigned value)
599 {
600 (void) devinfo;
601 return brw_inst_set_bits(insn, 127, 96, value);
602 }
603
604 static inline void
605 brw_inst_set_imm_f(const struct brw_device_info *devinfo,
606 brw_inst *insn, float value)
607 {
608 fi_type ft;
609 (void) devinfo;
610 ft.f = value;
611 brw_inst_set_bits(insn, 127, 96, ft.u);
612 }
613
614 /** @} */
615
616 /* The AddrImm fields are split into two discontiguous sections on Gen8+ */
617 #define BRW_IA1_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low) \
618 static inline void \
619 brw_inst_set_##reg##_ia1_addr_imm(const struct brw_device_info *devinfo, \
620 brw_inst *inst, \
621 unsigned value) \
622 { \
623 assert((value & ~0x3ff) == 0); \
624 if (devinfo->gen >= 8) { \
625 brw_inst_set_bits(inst, g8_high, g8_low, value & 0x1ff); \
626 brw_inst_set_bits(inst, g8_nine, g8_nine, value >> 9); \
627 } else { \
628 brw_inst_set_bits(inst, g4_high, g4_low, value); \
629 } \
630 } \
631 static inline unsigned \
632 brw_inst_##reg##_ia1_addr_imm(const struct brw_device_info *devinfo, \
633 const brw_inst *inst) \
634 { \
635 if (devinfo->gen >= 8) { \
636 return brw_inst_bits(inst, g8_high, g8_low) | \
637 (brw_inst_bits(inst, g8_nine, g8_nine) << 9); \
638 } else { \
639 return brw_inst_bits(inst, g4_high, g4_low); \
640 } \
641 }
642
643 /* AddrImm[9:0] for Align1 Indirect Addressing */
644 /* -Gen 4- ----Gen8---- */
645 BRW_IA1_ADDR_IMM(src1, 105, 96, 121, 104, 96)
646 BRW_IA1_ADDR_IMM(src0, 73, 64, 95, 72, 64)
647 BRW_IA1_ADDR_IMM(dst, 57, 48, 47, 56, 48)
648
649 #define BRW_IA16_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low) \
650 static inline void \
651 brw_inst_set_##reg##_ia16_addr_imm(const struct brw_device_info *devinfo, \
652 brw_inst *inst, unsigned value) \
653 { \
654 assert((value & ~0x3ff) == 0); \
655 if (devinfo->gen >= 8) { \
656 brw_inst_set_bits(inst, g8_high, g8_low, value & 0x1ff); \
657 brw_inst_set_bits(inst, g8_nine, g8_nine, value >> 9); \
658 } else { \
659 brw_inst_set_bits(inst, g4_high, g4_low, value >> 9); \
660 } \
661 } \
662 static inline unsigned \
663 brw_inst_##reg##_ia16_addr_imm(const struct brw_device_info *devinfo, \
664 const brw_inst *inst) \
665 { \
666 if (devinfo->gen >= 8) { \
667 return brw_inst_bits(inst, g8_high, g8_low) | \
668 (brw_inst_bits(inst, g8_nine, g8_nine) << 9); \
669 } else { \
670 return brw_inst_bits(inst, g4_high, g4_low); \
671 } \
672 }
673
674 /* AddrImm[9:0] for Align16 Indirect Addressing:
675 * Compared to Align1, these are missing the low 4 bits.
676 * -Gen 4- ----Gen8----
677 */
678 BRW_IA16_ADDR_IMM(src1, 105, 96, 121, 104, 100)
679 BRW_IA16_ADDR_IMM(src0, 73, 64, 95, 72, 68)
680 BRW_IA16_ADDR_IMM(dst, 57, 52, 47, 56, 52)
681
682 /**
683 * Fetch a set of contiguous bits from the instruction.
684 *
685 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
686 */
687 static inline uint64_t
688 brw_inst_bits(const brw_inst *inst, unsigned high, unsigned low)
689 {
690 /* We assume the field doesn't cross 64-bit boundaries. */
691 const unsigned word = high / 64;
692 assert(word == low / 64);
693
694 high %= 64;
695 low %= 64;
696
697 const uint64_t mask = (1ull << (high - low + 1)) - 1;
698
699 return (inst->data[word] >> low) & mask;
700 }
701
702 /**
703 * Set bits in the instruction, with proper shifting and masking.
704 *
705 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
706 */
707 static inline void
708 brw_inst_set_bits(brw_inst *inst, unsigned high, unsigned low, uint64_t value)
709 {
710 const unsigned word = high / 64;
711 assert(word == low / 64);
712
713 high %= 64;
714 low %= 64;
715
716 const uint64_t mask = ((1ull << (high - low + 1)) - 1) << low;
717
718 /* Make sure the supplied value actually fits in the given bitfield. */
719 assert((value & (mask >> low)) == value);
720
721 inst->data[word] = (inst->data[word] & ~mask) | (value << low);
722 }
723
724 #undef BRW_IA16_ADDR_IMM
725 #undef BRW_IA1_ADDR_IMM
726 #undef MD
727 #undef F8
728 #undef FF
729 #undef BOUNDS
730 #undef F
731 #undef FC
732
733 typedef struct {
734 uint64_t data;
735 } brw_compact_inst;
736
737 /**
738 * Fetch a set of contiguous bits from the compacted instruction.
739 *
740 * Bits indices range from 0..63.
741 */
742 static inline unsigned
743 brw_compact_inst_bits(const brw_compact_inst *inst, unsigned high, unsigned low)
744 {
745 const uint64_t mask = (1ull << (high - low + 1)) - 1;
746
747 return (inst->data >> low) & mask;
748 }
749
750 /**
751 * Set bits in the compacted instruction.
752 *
753 * Bits indices range from 0..63.
754 */
755 static inline void
756 brw_compact_inst_set_bits(brw_compact_inst *inst, unsigned high, unsigned low,
757 uint64_t value)
758 {
759 const uint64_t mask = ((1ull << (high - low + 1)) - 1) << low;
760
761 /* Make sure the supplied value actually fits in the given bitfield. */
762 assert((value & (mask >> low)) == value);
763
764 inst->data = (inst->data & ~mask) | (value << low);
765 }
766
767 #define FC(name, high, low, assertions) \
768 static inline void \
769 brw_compact_inst_set_##name(const struct brw_device_info *devinfo, \
770 brw_compact_inst *inst, unsigned v) \
771 { \
772 assert(assertions); \
773 (void) devinfo; \
774 brw_compact_inst_set_bits(inst, high, low, v); \
775 } \
776 static inline unsigned \
777 brw_compact_inst_##name(const struct brw_device_info *devinfo, \
778 const brw_compact_inst *inst) \
779 { \
780 assert(assertions); \
781 (void) devinfo; \
782 return brw_compact_inst_bits(inst, high, low); \
783 }
784
785 /* A simple macro for fields which stay in the same place on all generations. */
786 #define F(name, high, low) FC(name, high, low, true)
787
788 F(src1_reg_nr, 63, 56)
789 F(src0_reg_nr, 55, 48)
790 F(dst_reg_nr, 47, 40)
791 F(src1_index, 39, 35)
792 F(src0_index, 34, 30)
793 F(cmpt_control, 29, 29) /* Same location as brw_inst */
794 FC(flag_subreg_nr, 28, 28, devinfo->gen <= 6)
795 F(cond_modifier, 27, 24) /* Same location as brw_inst */
796 FC(acc_wr_control, 23, 23, devinfo->gen >= 6)
797 FC(mask_control_ex, 23, 23, devinfo->is_g4x || devinfo->gen == 5)
798 F(subreg_index, 22, 18)
799 F(datatype_index, 17, 13)
800 F(control_index, 12, 8)
801 F(debug_control, 7, 7)
802 F(opcode, 6, 0) /* Same location as brw_inst */
803
804 /**
805 * (Gen8+) Compacted three-source instructions:
806 * @{
807 */
808 FC(3src_src2_reg_nr, 63, 57, devinfo->gen >= 8)
809 FC(3src_src1_reg_nr, 56, 50, devinfo->gen >= 8)
810 FC(3src_src0_reg_nr, 49, 43, devinfo->gen >= 8)
811 FC(3src_src2_subreg_nr, 42, 40, devinfo->gen >= 8)
812 FC(3src_src1_subreg_nr, 39, 37, devinfo->gen >= 8)
813 FC(3src_src0_subreg_nr, 36, 34, devinfo->gen >= 8)
814 FC(3src_src2_rep_ctrl, 33, 33, devinfo->gen >= 8)
815 FC(3src_src1_rep_ctrl, 32, 32, devinfo->gen >= 8)
816 FC(3src_saturate, 31, 31, devinfo->gen >= 8)
817 FC(3src_debug_control, 30, 30, devinfo->gen >= 8)
818 FC(3src_cmpt_control, 29, 29, devinfo->gen >= 8)
819 FC(3src_src0_rep_ctrl, 28, 28, devinfo->gen >= 8)
820 /* Reserved */
821 FC(3src_dst_reg_nr, 18, 12, devinfo->gen >= 8)
822 FC(3src_source_index, 11, 10, devinfo->gen >= 8)
823 FC(3src_control_index, 9, 8, devinfo->gen >= 8)
824 /* Bit 7 is Reserved (for future Opcode expansion) */
825 FC(3src_opcode, 6, 0, devinfo->gen >= 8)
826 /** @} */
827
828 #undef F
829
830 #ifdef __cplusplus
831 }
832 #endif
833
834 #endif