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