~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/intel/compiler/brw_inst.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <assert.h>
35
 
#include <stdint.h>
36
 
 
37
 
#include "brw_eu_defines.h"
38
 
#include "brw_reg_type.h"
39
 
#include "dev/intel_device_info.h"
40
 
 
41
 
#ifdef __cplusplus
42
 
extern "C" {
43
 
#endif
44
 
 
45
 
/* brw_context.h has a forward declaration of brw_inst, so name the struct. */
46
 
typedef struct brw_inst {
47
 
   uint64_t data[2];
48
 
} brw_inst;
49
 
 
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,
54
 
                                     uint64_t value);
55
 
 
56
 
#define FC(name, hi4, lo4, hi12, lo12, assertions)            \
57
 
static inline void                                            \
58
 
brw_inst_set_##name(const struct intel_device_info *devinfo,  \
59
 
                    brw_inst *inst, uint64_t v)               \
60
 
{                                                             \
61
 
   assert(assertions);                                        \
62
 
   if (devinfo->ver >= 12)                                    \
63
 
      brw_inst_set_bits(inst, hi12, lo12, v);                 \
64
 
   else                                                       \
65
 
      brw_inst_set_bits(inst, hi4, lo4, v);                   \
66
 
}                                                             \
67
 
static inline uint64_t                                        \
68
 
brw_inst_##name(const struct intel_device_info *devinfo,      \
69
 
                const brw_inst *inst)                         \
70
 
{                                                             \
71
 
   assert(assertions);                                        \
72
 
   if (devinfo->ver >= 12)                                    \
73
 
      return brw_inst_bits(inst, hi12, lo12);                 \
74
 
   else                                                       \
75
 
      return brw_inst_bits(inst, hi4, lo4);                   \
76
 
}
77
 
 
78
 
/* A simple macro for fields which stay in the same place on all generations,
79
 
 * except for Gfx12!
80
 
 */
81
 
#define F(name, hi4, lo4, hi12, lo12) FC(name, hi4, lo4, hi12, lo12, true)
82
 
 
83
 
#define BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                     \
84
 
               hi7, lo7, hi8, lo8, hi12, lo12)                               \
85
 
   unsigned high, low;                                                       \
86
 
   if (devinfo->ver >= 12) {                                                 \
87
 
      high = hi12; low = lo12;                                               \
88
 
   } else if (devinfo->ver >= 8) {                                           \
89
 
      high = hi8;  low = lo8;                                                \
90
 
   } else if (devinfo->ver >= 7) {                                           \
91
 
      high = hi7;  low = lo7;                                                \
92
 
   } else if (devinfo->ver >= 6) {                                           \
93
 
      high = hi6;  low = lo6;                                                \
94
 
   } else if (devinfo->ver >= 5) {                                           \
95
 
      high = hi5;  low = lo5;                                                \
96
 
   } else if (devinfo->verx10 >= 45) {                                       \
97
 
      high = hi45; low = lo45;                                               \
98
 
   } else {                                                                  \
99
 
      high = hi4;  low = lo4;                                                \
100
 
   }                                                                         \
101
 
   assert(((int) high) != -1 && ((int) low) != -1);
102
 
 
103
 
/* A general macro for cases where the field has moved to several different
104
 
 * bit locations across generations.  GCC appears to combine cases where the
105
 
 * bits are identical, removing some of the inefficiency.
106
 
 */
107
 
#define FF(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                    \
108
 
           hi7, lo7, hi8, lo8, hi12, lo12)                                    \
109
 
static inline void                                                            \
110
 
brw_inst_set_##name(const struct intel_device_info *devinfo,                  \
111
 
                    brw_inst *inst, uint64_t value)                           \
112
 
{                                                                             \
113
 
   BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                           \
114
 
          hi7, lo7, hi8, lo8, hi12, lo12)                                     \
115
 
   brw_inst_set_bits(inst, high, low, value);                                 \
116
 
}                                                                             \
117
 
static inline uint64_t                                                        \
118
 
brw_inst_##name(const struct intel_device_info *devinfo, const brw_inst *inst)\
119
 
{                                                                             \
120
 
   BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                           \
121
 
          hi7, lo7, hi8, lo8, hi12, lo12)                                     \
122
 
   return brw_inst_bits(inst, high, low);                                     \
123
 
}
124
 
 
125
 
/* A macro for fields which moved as of Gfx8+. */
126
 
#define F8(name, gfx4_high, gfx4_low, gfx8_high, gfx8_low, \
127
 
           gfx12_high, gfx12_low)                          \
128
 
FF(name,                                                   \
129
 
   /* 4:   */ gfx4_high, gfx4_low,                         \
130
 
   /* 4.5: */ gfx4_high, gfx4_low,                         \
131
 
   /* 5:   */ gfx4_high, gfx4_low,                         \
132
 
   /* 6:   */ gfx4_high, gfx4_low,                         \
133
 
   /* 7:   */ gfx4_high, gfx4_low,                         \
134
 
   /* 8:   */ gfx8_high, gfx8_low,                         \
135
 
   /* 12:  */ gfx12_high, gfx12_low);
136
 
 
137
 
/* Macro for fields that gained extra discontiguous MSBs in Gfx12 (specified
138
 
 * by hi12ex-lo12ex).
139
 
 */
140
 
#define FFDC(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                  \
141
 
             hi7, lo7, hi8, lo8, hi12ex, lo12ex, hi12, lo12, assertions)      \
142
 
static inline void                                                            \
143
 
brw_inst_set_##name(const struct intel_device_info *devinfo,                  \
144
 
                    brw_inst *inst, uint64_t value)                           \
145
 
{                                                                             \
146
 
   assert(assertions);                                                        \
147
 
   if (devinfo->ver >= 12) {                                                  \
148
 
      const unsigned k = hi12 - lo12 + 1;                                     \
149
 
      if (hi12ex != -1 && lo12ex != -1)                                       \
150
 
         brw_inst_set_bits(inst, hi12ex, lo12ex, value >> k);                 \
151
 
      brw_inst_set_bits(inst, hi12, lo12, value & ((1ull << k) - 1));         \
152
 
   } else {                                                                   \
153
 
      BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                        \
154
 
             hi7, lo7, hi8, lo8, -1, -1);                                     \
155
 
      brw_inst_set_bits(inst, high, low, value);                              \
156
 
   }                                                                          \
157
 
}                                                                             \
158
 
static inline uint64_t                                                        \
159
 
brw_inst_##name(const struct intel_device_info *devinfo, const brw_inst *inst)\
160
 
{                                                                             \
161
 
   assert(assertions);                                                        \
162
 
   if (devinfo->ver >= 12) {                                                  \
163
 
      const unsigned k = hi12 - lo12 + 1;                                     \
164
 
      return (hi12ex == -1 || lo12ex == -1 ? 0 :                              \
165
 
              brw_inst_bits(inst, hi12ex, lo12ex) << k) |                     \
166
 
             brw_inst_bits(inst, hi12, lo12);                                 \
167
 
   } else {                                                                   \
168
 
      BOUNDS(hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,                        \
169
 
             hi7, lo7, hi8, lo8, -1, -1);                                     \
170
 
      return brw_inst_bits(inst, high, low);                                  \
171
 
   }                                                                          \
172
 
}
173
 
 
174
 
#define FD(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,        \
175
 
           hi7, lo7, hi8, lo8, hi12ex, lo12ex, hi12, lo12)        \
176
 
   FFDC(name, hi4, lo4, hi45, lo45, hi5, lo5, hi6, lo6,           \
177
 
        hi7, lo7, hi8, lo8, hi12ex, lo12ex, hi12, lo12, true)
178
 
 
179
 
/* Macro for fields that didn't move across generations until Gfx12, and then
180
 
 * gained extra discontiguous bits.
181
 
 */
182
 
#define FDC(name, hi4, lo4, hi12ex, lo12ex, hi12, lo12, assertions)     \
183
 
   FFDC(name, hi4, lo4, hi4, lo4, hi4, lo4, hi4, lo4,                   \
184
 
        hi4, lo4, hi4, lo4, hi12ex, lo12ex, hi12, lo12, assertions)
185
 
 
186
 
 
187
 
/* Macro for the 2-bit register file field, which on Gfx12+ is stored as the
188
 
 * variable length combination of an IsImm (hi12) bit and an additional file
189
 
 * (lo12) bit.
190
 
 */
191
 
#define FI(name, hi4, lo4, hi8, lo8, hi12, lo12)                              \
192
 
static inline void                                                            \
193
 
brw_inst_set_##name(const struct intel_device_info *devinfo,                  \
194
 
                    brw_inst *inst, uint64_t value)                           \
195
 
{                                                                             \
196
 
   if (devinfo->ver >= 12) {                                                  \
197
 
      brw_inst_set_bits(inst, hi12, hi12, value >> 1);                        \
198
 
      if ((value >> 1) == 0)                                                  \
199
 
         brw_inst_set_bits(inst, lo12, lo12, value & 1);                      \
200
 
   } else {                                                                   \
201
 
      BOUNDS(hi4, lo4, hi4, lo4, hi4, lo4, hi4, lo4,                          \
202
 
             hi4, lo4, hi8, lo8, -1, -1);                                     \
203
 
      brw_inst_set_bits(inst, high, low, value);                              \
204
 
   }                                                                          \
205
 
}                                                                             \
206
 
static inline uint64_t                                                        \
207
 
brw_inst_##name(const struct intel_device_info *devinfo, const brw_inst *inst)\
208
 
{                                                                             \
209
 
   if (devinfo->ver >= 12) {                                                  \
210
 
      return (brw_inst_bits(inst, hi12, hi12) << 1) |                         \
211
 
             (brw_inst_bits(inst, hi12, hi12) == 0 ?                          \
212
 
              brw_inst_bits(inst, lo12, lo12) : 1);                           \
213
 
   } else {                                                                   \
214
 
      BOUNDS(hi4, lo4, hi4, lo4, hi4, lo4, hi4, lo4,                          \
215
 
             hi4, lo4, hi8, lo8, -1, -1);                                     \
216
 
      return brw_inst_bits(inst, high, low);                                  \
217
 
   }                                                                          \
218
 
}
219
 
 
220
 
/* Macro for fields that become a constant in Gfx12+ not actually represented
221
 
 * in the instruction.
222
 
 */
223
 
#define FK(name, hi4, lo4, const12)                           \
224
 
static inline void                                            \
225
 
brw_inst_set_##name(const struct intel_device_info *devinfo,  \
226
 
                    brw_inst *inst, uint64_t v)               \
227
 
{                                                             \
228
 
   if (devinfo->ver >= 12)                                    \
229
 
      assert(v == (const12));                                 \
230
 
   else                                                       \
231
 
      brw_inst_set_bits(inst, hi4, lo4, v);                   \
232
 
}                                                             \
233
 
static inline uint64_t                                        \
234
 
brw_inst_##name(const struct intel_device_info *devinfo,      \
235
 
                const brw_inst *inst)                         \
236
 
{                                                             \
237
 
   if (devinfo->ver >= 12)                                    \
238
 
      return (const12);                                       \
239
 
   else                                                       \
240
 
      return brw_inst_bits(inst, hi4, lo4);                   \
241
 
}
242
 
 
243
 
F(src1_vstride,        /* 4+ */ 120, 117, /* 12+ */ 119, 116)
244
 
F(src1_width,          /* 4+ */ 116, 114, /* 12+ */ 115, 113)
245
 
F(src1_da16_swiz_w,    /* 4+ */ 115, 114, /* 12+ */ -1, -1)
246
 
F(src1_da16_swiz_z,    /* 4+ */ 113, 112, /* 12+ */ -1, -1)
247
 
F(src1_hstride,        /* 4+ */ 113, 112, /* 12+ */ 97, 96)
248
 
F(src1_address_mode,   /* 4+ */ 111, 111, /* 12+ */ 112, 112)
249
 
/** Src1.SrcMod @{ */
250
 
F(src1_negate,         /* 4+ */ 110, 110, /* 12+ */ 121, 121)
251
 
F(src1_abs,            /* 4+ */ 109, 109, /* 12+ */ 120, 120)
252
 
/** @} */
253
 
F8(src1_ia_subreg_nr,  /* 4+ */ 108, 106, /* 8+ */  108, 105, /* 12+ */ 111, 108)
254
 
F(src1_da_reg_nr,      /* 4+ */ 108, 101, /* 12+ */ 111, 104)
255
 
F(src1_da16_subreg_nr, /* 4+ */ 100, 100, /* 12+ */ -1, -1)
256
 
F(src1_da1_subreg_nr,  /* 4+ */ 100,  96, /* 12+ */ 103, 99)
257
 
F(src1_da16_swiz_y,    /* 4+ */ 99,  98,  /* 12+ */ -1, -1)
258
 
F(src1_da16_swiz_x,    /* 4+ */ 97,  96,  /* 12+ */ -1, -1)
259
 
F8(src1_reg_hw_type,   /* 4+ */ 46,  44,  /* 8+ */  94,  91, /* 12+ */ 91, 88)
260
 
FI(src1_reg_file,      /* 4+ */ 43,  42,  /* 8+ */  90,  89, /* 12+ */ 47, 98)
261
 
F(src1_is_imm,         /* 4+ */ -1,  -1,  /* 12+ */ 47, 47)
262
 
F(src0_vstride,        /* 4+ */ 88,  85,  /* 12+ */ 87, 84)
263
 
F(src0_width,          /* 4+ */ 84,  82,  /* 12+ */ 83, 81)
264
 
F(src0_da16_swiz_w,    /* 4+ */ 83,  82,  /* 12+ */ -1, -1)
265
 
F(src0_da16_swiz_z,    /* 4+ */ 81,  80,  /* 12+ */ -1, -1)
266
 
F(src0_hstride,        /* 4+ */ 81,  80,  /* 12+ */ 65, 64)
267
 
F(src0_address_mode,   /* 4+ */ 79,  79,  /* 12+ */ 80, 80)
268
 
/** Src0.SrcMod @{ */
269
 
F(src0_negate,         /* 4+ */ 78,  78,  /* 12+ */ 45, 45)
270
 
F(src0_abs,            /* 4+ */ 77,  77,  /* 12+ */ 44, 44)
271
 
/** @} */
272
 
F8(src0_ia_subreg_nr,  /* 4+ */ 76,  74,  /* 8+ */  76,  73, /* 12+ */ 79, 76)
273
 
F(src0_da_reg_nr,      /* 4+ */ 76,  69,  /* 12+ */ 79, 72)
274
 
F(src0_da16_subreg_nr, /* 4+ */ 68,  68,  /* 12+ */ -1, -1)
275
 
F(src0_da1_subreg_nr,  /* 4+ */ 68,  64,  /* 12+ */ 71, 67)
276
 
F(src0_da16_swiz_y,    /* 4+ */ 67,  66,  /* 12+ */ -1, -1)
277
 
F(src0_da16_swiz_x,    /* 4+ */ 65,  64,  /* 12+ */ -1, -1)
278
 
F(dst_address_mode,    /* 4+ */ 63,  63,  /* 12+ */ 35, 35)
279
 
F(dst_hstride,         /* 4+ */ 62,  61,  /* 12+ */ 49, 48)
280
 
F8(dst_ia_subreg_nr,   /* 4+ */ 60,  58,  /* 8+ */  60,  57, /* 12+ */ 63, 60)
281
 
F(dst_da_reg_nr,       /* 4+ */ 60,  53,  /* 12+ */ 63, 56)
282
 
F(dst_da16_subreg_nr,  /* 4+ */ 52,  52,  /* 12+ */ -1, -1)
283
 
F(dst_da1_subreg_nr,   /* 4+ */ 52,  48,  /* 12+ */ 55, 51)
284
 
F(da16_writemask,      /* 4+ */ 51,  48,  /* 12+ */ -1, -1) /* Dst.ChanEn */
285
 
F8(src0_reg_hw_type,   /* 4+ */ 41,  39,  /* 8+ */  46,  43, /* 12+ */ 43, 40)
286
 
FI(src0_reg_file,      /* 4+ */ 38,  37,  /* 8+ */  42,  41, /* 12+ */ 46, 66)
287
 
F(src0_is_imm,         /* 4+ */ -1,  -1,  /* 12+ */ 46, 46)
288
 
F8(dst_reg_hw_type,    /* 4+ */ 36,  34,  /* 8+ */  40,  37, /* 12+ */ 39, 36)
289
 
F8(dst_reg_file,       /* 4+ */ 33,  32,  /* 8+ */  36,  35, /* 12+ */ 50, 50)
290
 
F8(mask_control,       /* 4+ */  9,   9,  /* 8+ */  34,  34, /* 12+ */ 31, 31)
291
 
FF(flag_reg_nr,
292
 
   /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
293
 
   /* 7: */ 90, 90,
294
 
   /* 8: */ 33, 33,
295
 
   /* 12: */ 23, 23)
296
 
F8(flag_subreg_nr,     /* 4+ */ 89,  89,  /* 8+ */ 32, 32,   /* 12+ */ 22, 22)
297
 
F(saturate,            /* 4+ */ 31,  31,  /* 12+ */ 34, 34)
298
 
F(debug_control,       /* 4+ */ 30,  30,  /* 12+ */ 30, 30)
299
 
F(cmpt_control,        /* 4+ */ 29,  29,  /* 12+ */ 29, 29)
300
 
FC(branch_control,     /* 4+ */ 28,  28,  /* 12+ */ 33, 33, devinfo->ver >= 8)
301
 
FC(acc_wr_control,     /* 4+ */ 28,  28,  /* 12+ */ 33, 33, devinfo->ver >= 6)
302
 
FC(mask_control_ex,    /* 4+ */ 28,  28,  /* 12+ */ -1, -1, devinfo->verx10 == 45 ||
303
 
                                                            devinfo->ver == 5)
304
 
F(cond_modifier,       /* 4+ */ 27,  24,  /* 12+ */ 95, 92)
305
 
FC(math_function,      /* 4+ */ 27,  24,  /* 12+ */ 95, 92, devinfo->ver >= 6)
306
 
F(exec_size,           /* 4+ */ 23,  21,  /* 12+ */ 18, 16)
307
 
F(pred_inv,            /* 4+ */ 20,  20,  /* 12+ */ 28, 28)
308
 
F(pred_control,        /* 4+ */ 19,  16,  /* 12+ */ 27, 24)
309
 
F(thread_control,      /* 4+ */ 15,  14,  /* 12+ */ -1, -1)
310
 
F(atomic_control,      /* 4+ */ -1,  -1,  /* 12+ */ 32, 32)
311
 
F(qtr_control,         /* 4+ */ 13,  12,  /* 12+ */ 21, 20)
312
 
FF(nib_control,
313
 
   /* 4-6: doesn't exist */ -1, -1, -1, -1, -1, -1, -1, -1,
314
 
   /* 7: */ 47, 47,
315
 
   /* 8: */ 11, 11,
316
 
   /* 12: */ 19, 19)
317
 
F8(no_dd_check,        /* 4+ */  11, 11,  /* 8+ */  10,  10, /* 12+ */ -1, -1)
318
 
F8(no_dd_clear,        /* 4+ */  10, 10,  /* 8+ */   9,   9, /* 12+ */ -1, -1)
319
 
F(swsb,                /* 4+ */  -1, -1,  /* 12+ */ 15,  8)
320
 
FK(access_mode,        /* 4+ */   8,  8,  /* 12+ */ BRW_ALIGN_1)
321
 
/* Bit 7 is Reserved (for future Opcode expansion) */
322
 
F(hw_opcode,           /* 4+ */   6,  0,  /* 12+ */ 6,  0)
323
 
 
324
 
/**
325
 
 * Three-source instructions:
326
 
 *  @{
327
 
 */
328
 
F(3src_src2_reg_nr,         /* 4+ */ 125, 118, /* 12+ */ 127, 120) /* same in align1 */
329
 
F(3src_a16_src2_subreg_nr,  /* 4+ */ 117, 115, /* 12+ */ -1, -1) /* Extra discontiguous bit on CHV? */
330
 
F(3src_a16_src2_swizzle,    /* 4+ */ 114, 107, /* 12+ */ -1, -1)
331
 
F(3src_a16_src2_rep_ctrl,   /* 4+ */ 106, 106, /* 12+ */ -1, -1)
332
 
F(3src_src1_reg_nr,         /* 4+ */ 104,  97, /* 12+ */ 111, 104) /* same in align1 */
333
 
F(3src_a16_src1_subreg_nr,  /* 4+ */ 96,  94,  /* 12+ */ -1, -1) /* Extra discontiguous bit on CHV? */
334
 
F(3src_a16_src1_swizzle,    /* 4+ */ 93,  86,  /* 12+ */ -1, -1)
335
 
F(3src_a16_src1_rep_ctrl,   /* 4+ */ 85,  85,  /* 12+ */ -1, -1)
336
 
F(3src_src0_reg_nr,         /* 4+ */ 83,  76,  /* 12+ */ 79, 72) /* same in align1 */
337
 
F(3src_a16_src0_subreg_nr,  /* 4+ */ 75,  73,  /* 12+ */ -1, -1) /* Extra discontiguous bit on CHV? */
338
 
F(3src_a16_src0_swizzle,    /* 4+ */ 72,  65,  /* 12+ */ -1, -1)
339
 
F(3src_a16_src0_rep_ctrl,   /* 4+ */ 64,  64,  /* 12+ */ -1, -1)
340
 
F(3src_dst_reg_nr,          /* 4+ */ 63,  56,  /* 12+ */ 63, 56) /* same in align1 */
341
 
F(3src_a16_dst_subreg_nr,   /* 4+ */ 55,  53,  /* 12+ */ -1, -1)
342
 
F(3src_a16_dst_writemask,   /* 4+ */ 52,  49,  /* 12+ */ -1, -1)
343
 
F8(3src_a16_nib_ctrl,       /* 4+ */ 47, 47,   /* 8+ */  11, 11, /* 12+ */ -1, -1) /* only exists on IVB+ */
344
 
F8(3src_a16_dst_hw_type,    /* 4+ */ 45, 44,   /* 8+ */  48, 46, /* 12+ */ -1, -1) /* only exists on IVB+ */
345
 
F8(3src_a16_src_hw_type,    /* 4+ */ 43, 42,   /* 8+ */  45, 43, /* 12+ */ -1, -1)
346
 
F8(3src_src2_negate,        /* 4+ */ 41, 41,   /* 8+ */  42, 42, /* 12+ */ 85, 85)
347
 
F8(3src_src2_abs,           /* 4+ */ 40, 40,   /* 8+ */  41, 41, /* 12+ */ 84, 84)
348
 
F8(3src_src1_negate,        /* 4+ */ 39, 39,   /* 8+ */  40, 40, /* 12+ */ 87, 87)
349
 
F8(3src_src1_abs,           /* 4+ */ 38, 38,   /* 8+ */  39, 39, /* 12+ */ 86, 86)
350
 
F8(3src_src0_negate,        /* 4+ */ 37, 37,   /* 8+ */  38, 38, /* 12+ */ 45, 45)
351
 
F8(3src_src0_abs,           /* 4+ */ 36, 36,   /* 8+ */  37, 37, /* 12+ */ 44, 44)
352
 
F8(3src_a16_src1_type,      /* 4+ */ -1, -1,   /* 8+ */  36, 36, /* 12+ */ -1, -1)
353
 
F8(3src_a16_src2_type,      /* 4+ */ -1, -1,   /* 8+ */  35, 35, /* 12+ */ -1, -1)
354
 
F8(3src_a16_flag_reg_nr,    /* 4+ */ 34, 34,   /* 8+ */  33, 33, /* 12+ */ -1, -1)
355
 
F8(3src_a16_flag_subreg_nr, /* 4+ */ 33, 33,   /* 8+ */  32, 32, /* 12+ */ -1, -1)
356
 
FF(3src_a16_dst_reg_file,
357
 
   /* 4-5: doesn't exist - no 3-source instructions */ -1, -1, -1, -1, -1, -1,
358
 
   /* 6: */ 32, 32,
359
 
   /* 7-8: doesn't exist - no MRFs */ -1, -1, -1, -1,
360
 
   /* 12: */ -1, -1)
361
 
F(3src_saturate,            /* 4+ */ 31, 31,   /* 12+ */ 34, 34)
362
 
F(3src_debug_control,       /* 4+ */ 30, 30,   /* 12+ */ 30, 30)
363
 
F(3src_cmpt_control,        /* 4+ */ 29, 29,   /* 12+ */ 29, 29)
364
 
F(3src_acc_wr_control,      /* 4+ */ 28, 28,   /* 12+ */ 33, 33)
365
 
F(3src_cond_modifier,       /* 4+ */ 27, 24,   /* 12+ */ 95, 92)
366
 
F(3src_exec_size,           /* 4+ */ 23, 21,   /* 12+ */ 18, 16)
367
 
F(3src_pred_inv,            /* 4+ */ 20, 20,   /* 12+ */ 28, 28)
368
 
F(3src_pred_control,        /* 4+ */ 19, 16,   /* 12+ */ 27, 24)
369
 
F(3src_thread_control,      /* 4+ */ 15, 14,   /* 12+ */ -1, -1)
370
 
F(3src_atomic_control,      /* 4+ */ -1, -1,   /* 12+ */ 32, 32)
371
 
F(3src_qtr_control,         /* 4+ */ 13, 12,   /* 12+ */ 21, 20)
372
 
F8(3src_no_dd_check,        /* 4+ */ 11, 11,   /* 8+ */  10, 10, /* 12+ */ -1, -1)
373
 
F8(3src_no_dd_clear,        /* 4+ */ 10, 10,   /* 8+ */   9,  9, /* 12+ */ -1, -1)
374
 
F8(3src_mask_control,       /* 4+ */ 9,  9,    /* 8+ */  34, 34, /* 12+ */ 31, 31)
375
 
FK(3src_access_mode,        /* 4+ */ 8,  8,    /* 12+ */ BRW_ALIGN_1)
376
 
F(3src_swsb,                /* 4+ */ -1, -1,   /* 12+ */ 15,  8)
377
 
/* Bit 7 is Reserved (for future Opcode expansion) */
378
 
F(3src_hw_opcode,           /* 4+ */ 6,  0,    /* 12+ */ 6, 0)
379
 
/** @} */
380
 
 
381
 
#define REG_TYPE(reg)                                                         \
382
 
static inline void                                                            \
383
 
brw_inst_set_3src_a16_##reg##_type(const struct intel_device_info *devinfo,   \
384
 
                                   brw_inst *inst, enum brw_reg_type type)    \
385
 
{                                                                             \
386
 
   unsigned hw_type = brw_reg_type_to_a16_hw_3src_type(devinfo, type);        \
387
 
   brw_inst_set_3src_a16_##reg##_hw_type(devinfo, inst, hw_type);             \
388
 
}                                                                             \
389
 
                                                                              \
390
 
static inline enum brw_reg_type                                               \
391
 
brw_inst_3src_a16_##reg##_type(const struct intel_device_info *devinfo,       \
392
 
                               const brw_inst *inst)                          \
393
 
{                                                                             \
394
 
   unsigned hw_type = brw_inst_3src_a16_##reg##_hw_type(devinfo, inst);       \
395
 
   return brw_a16_hw_3src_type_to_reg_type(devinfo, hw_type);                 \
396
 
}
397
 
 
398
 
REG_TYPE(dst)
399
 
REG_TYPE(src)
400
 
#undef REG_TYPE
401
 
 
402
 
/**
403
 
 * Three-source align1 instructions:
404
 
 *  @{
405
 
 */
406
 
/* Reserved 127:126 */
407
 
/* src2_reg_nr same in align16 */
408
 
FC(3src_a1_src2_subreg_nr,  /* 4+ */   117, 113, /* 12+ */ 119, 115, devinfo->ver >= 10)
409
 
FC(3src_a1_src2_hstride,    /* 4+ */   112, 111, /* 12+ */ 113, 112, devinfo->ver >= 10)
410
 
/* Reserved 110:109. src2 vstride is an implied parameter */
411
 
FC(3src_a1_src2_hw_type,    /* 4+ */   108, 106, /* 12+ */ 82, 80, devinfo->ver >= 10)
412
 
/* Reserved 105 */
413
 
/* src1_reg_nr same in align16 */
414
 
FC(3src_a1_src1_subreg_nr,  /* 4+ */   96,  92,  /* 12+ */ 103, 99, devinfo->ver >= 10)
415
 
FC(3src_a1_src1_hstride,    /* 4+ */   91,  90,  /* 12+ */ 97, 96, devinfo->ver >= 10)
416
 
FDC(3src_a1_src1_vstride,  /* 4+ */   89,  88,  /* 12+ */ 91, 91, 83, 83, devinfo->ver >= 10)
417
 
FC(3src_a1_src1_hw_type,    /* 4+ */   87,  85,  /* 12+ */ 90, 88, devinfo->ver >= 10)
418
 
/* Reserved 84 */
419
 
/* src0_reg_nr same in align16 */
420
 
FC(3src_a1_src0_subreg_nr,  /* 4+ */   75,  71,  /* 12+ */ 71, 67, devinfo->ver >= 10)
421
 
FC(3src_a1_src0_hstride,    /* 4+ */   70,  69,  /* 12+ */ 65, 64, devinfo->ver >= 10)
422
 
FDC(3src_a1_src0_vstride,  /* 4+ */   68,  67,  /* 12+ */ 43, 43, 35, 35, devinfo->ver >= 10)
423
 
FC(3src_a1_src0_hw_type,    /* 4+ */   66,  64,  /* 12+ */ 42, 40, devinfo->ver >= 10)
424
 
/* dst_reg_nr same in align16 */
425
 
FC(3src_a1_dst_subreg_nr,   /* 4+ */   55,  54,  /* 12+ */ 55, 54, devinfo->ver >= 10)
426
 
FC(3src_a1_special_acc,     /* 4+ */   55,  52,  /* 12+ */ 54, 51, devinfo->ver >= 10) /* aliases dst_subreg_nr */
427
 
/* Reserved 51:50 */
428
 
FC(3src_a1_dst_hstride,     /* 4+ */   49,  49,  /* 12+ */ 48, 48, devinfo->ver >= 10)
429
 
FC(3src_a1_dst_hw_type,     /* 4+ */   48,  46,  /* 12+ */ 38, 36, devinfo->ver >= 10)
430
 
FI(3src_a1_src2_reg_file,   /* 4+ */   -1,  -1,  /* 8+ */  45, 45,  /* 12+ */ 47, 114)
431
 
FC(3src_a1_src1_reg_file,   /* 4+ */   44,  44,  /* 12+ */ 98, 98, devinfo->ver >= 10)
432
 
FI(3src_a1_src0_reg_file,   /* 4+ */   -1,  -1,  /* 8+ */  43, 43,  /* 12+ */ 46, 66)
433
 
 
434
 
F(3src_a1_src2_is_imm,      /* 4+ */   -1,  -1,  /* 12+ */ 47, 47)
435
 
F(3src_a1_src0_is_imm,      /* 4+ */   -1,  -1,  /* 12+ */ 46, 46)
436
 
 
437
 
/* Source Modifier fields same in align16 */
438
 
FC(3src_a1_dst_reg_file,    /* 4+ */    36,  36, /* 12+ */ 50, 50, devinfo->ver >= 10)
439
 
FC(3src_a1_exec_type,       /* 4+ */    35,  35, /* 12+ */ 39, 39, devinfo->ver >= 10)
440
 
/* Fields below this same in align16 */
441
 
/** @} */
442
 
 
443
 
#define REG_TYPE(reg)                                                         \
444
 
static inline void                                                            \
445
 
brw_inst_set_3src_a1_##reg##_type(const struct intel_device_info *devinfo,    \
446
 
                                  brw_inst *inst, enum brw_reg_type type)     \
447
 
{                                                                             \
448
 
   UNUSED enum gfx10_align1_3src_exec_type exec_type =                        \
449
 
      (enum gfx10_align1_3src_exec_type) brw_inst_3src_a1_exec_type(devinfo,  \
450
 
                                                                    inst);    \
451
 
   if (brw_reg_type_is_floating_point(type)) {                                \
452
 
      assert(exec_type == BRW_ALIGN1_3SRC_EXEC_TYPE_FLOAT);                   \
453
 
   } else {                                                                   \
454
 
      assert(exec_type == BRW_ALIGN1_3SRC_EXEC_TYPE_INT);                     \
455
 
   }                                                                          \
456
 
   unsigned hw_type = brw_reg_type_to_a1_hw_3src_type(devinfo, type);         \
457
 
   brw_inst_set_3src_a1_##reg##_hw_type(devinfo, inst, hw_type);              \
458
 
}                                                                             \
459
 
                                                                              \
460
 
static inline enum brw_reg_type                                               \
461
 
brw_inst_3src_a1_##reg##_type(const struct intel_device_info *devinfo,        \
462
 
                              const brw_inst *inst)                           \
463
 
{                                                                             \
464
 
   enum gfx10_align1_3src_exec_type exec_type =                               \
465
 
      (enum gfx10_align1_3src_exec_type) brw_inst_3src_a1_exec_type(devinfo,  \
466
 
                                                                    inst);    \
467
 
   unsigned hw_type = brw_inst_3src_a1_##reg##_hw_type(devinfo, inst);        \
468
 
   return brw_a1_hw_3src_type_to_reg_type(devinfo, hw_type, exec_type);       \
469
 
}
470
 
 
471
 
REG_TYPE(dst)
472
 
REG_TYPE(src0)
473
 
REG_TYPE(src1)
474
 
REG_TYPE(src2)
475
 
#undef REG_TYPE
476
 
 
477
 
/**
478
 
 * Three-source align1 instruction immediates:
479
 
 *  @{
480
 
 */
481
 
static inline uint16_t
482
 
brw_inst_3src_a1_src0_imm(ASSERTED const struct intel_device_info *devinfo,
483
 
                          const brw_inst *insn)
484
 
{
485
 
   assert(devinfo->ver >= 10);
486
 
   if (devinfo->ver >= 12)
487
 
      return brw_inst_bits(insn, 79, 64);
488
 
   else
489
 
      return brw_inst_bits(insn, 82, 67);
490
 
}
491
 
 
492
 
static inline uint16_t
493
 
brw_inst_3src_a1_src2_imm(ASSERTED const struct intel_device_info *devinfo,
494
 
                          const brw_inst *insn)
495
 
{
496
 
   assert(devinfo->ver >= 10);
497
 
   if (devinfo->ver >= 12)
498
 
      return brw_inst_bits(insn, 127, 112);
499
 
   else
500
 
      return brw_inst_bits(insn, 124, 109);
501
 
}
502
 
 
503
 
static inline void
504
 
brw_inst_set_3src_a1_src0_imm(ASSERTED const struct intel_device_info *devinfo,
505
 
                              brw_inst *insn, uint16_t value)
506
 
{
507
 
   assert(devinfo->ver >= 10);
508
 
   if (devinfo->ver >= 12)
509
 
      brw_inst_set_bits(insn, 79, 64, value);
510
 
   else
511
 
      brw_inst_set_bits(insn, 82, 67, value);
512
 
}
513
 
 
514
 
static inline void
515
 
brw_inst_set_3src_a1_src2_imm(ASSERTED const struct intel_device_info *devinfo,
516
 
                              brw_inst *insn, uint16_t value)
517
 
{
518
 
   assert(devinfo->ver >= 10);
519
 
   if (devinfo->ver >= 12)
520
 
      brw_inst_set_bits(insn, 127, 112, value);
521
 
   else
522
 
      brw_inst_set_bits(insn, 124, 109, value);
523
 
}
524
 
/** @} */
525
 
 
526
 
/**
527
 
 * Flow control instruction bits:
528
 
 *  @{
529
 
 */
530
 
static inline void
531
 
brw_inst_set_uip(const struct intel_device_info *devinfo,
532
 
                 brw_inst *inst, int32_t value)
533
 
{
534
 
   assert(devinfo->ver >= 6);
535
 
 
536
 
   if (devinfo->ver >= 12)
537
 
      brw_inst_set_src1_is_imm(devinfo, inst, 1);
538
 
 
539
 
   if (devinfo->ver >= 8) {
540
 
      brw_inst_set_bits(inst, 95, 64, (uint32_t)value);
541
 
   } else {
542
 
      assert(value <= (1 << 16) - 1);
543
 
      assert(value > -(1 << 16));
544
 
      brw_inst_set_bits(inst, 127, 112, (uint16_t)value);
545
 
   }
546
 
}
547
 
 
548
 
static inline int32_t
549
 
brw_inst_uip(const struct intel_device_info *devinfo, const brw_inst *inst)
550
 
{
551
 
   assert(devinfo->ver >= 6);
552
 
 
553
 
   if (devinfo->ver >= 8) {
554
 
      return brw_inst_bits(inst, 95, 64);
555
 
   } else {
556
 
      return (int16_t)brw_inst_bits(inst, 127, 112);
557
 
   }
558
 
}
559
 
 
560
 
static inline void
561
 
brw_inst_set_jip(const struct intel_device_info *devinfo,
562
 
                 brw_inst *inst, int32_t value)
563
 
{
564
 
   assert(devinfo->ver >= 6);
565
 
 
566
 
   if (devinfo->ver >= 12)
567
 
      brw_inst_set_src0_is_imm(devinfo, inst, 1);
568
 
 
569
 
   if (devinfo->ver >= 8) {
570
 
      brw_inst_set_bits(inst, 127, 96, (uint32_t)value);
571
 
   } else {
572
 
      assert(value <= (1 << 15) - 1);
573
 
      assert(value >= -(1 << 15));
574
 
      brw_inst_set_bits(inst, 111, 96, (uint16_t)value);
575
 
   }
576
 
}
577
 
 
578
 
static inline int32_t
579
 
brw_inst_jip(const struct intel_device_info *devinfo, const brw_inst *inst)
580
 
{
581
 
   assert(devinfo->ver >= 6);
582
 
 
583
 
   if (devinfo->ver >= 8) {
584
 
      return brw_inst_bits(inst, 127, 96);
585
 
   } else {
586
 
      return (int16_t)brw_inst_bits(inst, 111, 96);
587
 
   }
588
 
}
589
 
 
590
 
/** Like FC, but using int16_t to handle negative jump targets. */
591
 
#define FJ(name, high, low, assertions)                                       \
592
 
static inline void                                                            \
593
 
brw_inst_set_##name(const struct intel_device_info *devinfo, brw_inst *inst, int16_t v) \
594
 
{                                                                             \
595
 
   assert(assertions);                                                        \
596
 
   (void) devinfo;                                                            \
597
 
   brw_inst_set_bits(inst, high, low, (uint16_t) v);                          \
598
 
}                                                                             \
599
 
static inline int16_t                                                         \
600
 
brw_inst_##name(const struct intel_device_info *devinfo, const brw_inst *inst)\
601
 
{                                                                             \
602
 
   assert(assertions);                                                        \
603
 
   (void) devinfo;                                                            \
604
 
   return brw_inst_bits(inst, high, low);                                     \
605
 
}
606
 
 
607
 
FJ(gfx6_jump_count,  63,  48, devinfo->ver == 6)
608
 
FJ(gfx4_jump_count, 111,  96, devinfo->ver < 6)
609
 
FC(gfx4_pop_count,  /* 4+ */ 115, 112, /* 12+ */ -1, -1, devinfo->ver < 6)
610
 
/** @} */
611
 
 
612
 
/**
613
 
 * SEND instructions:
614
 
 *  @{
615
 
 */
616
 
FC(send_ex_desc_ia_subreg_nr, /* 4+ */ 82, 80, /* 12+ */  42,  40, devinfo->ver >= 9)
617
 
FC(send_src0_address_mode,    /* 4+ */ 79, 79, /* 12+ */  -1,  -1, devinfo->ver >= 9)
618
 
FC(send_sel_reg32_desc,       /* 4+ */ 77, 77, /* 12+ */  48,  48, devinfo->ver >= 9)
619
 
FC(send_sel_reg32_ex_desc,    /* 4+ */ 61, 61, /* 12+ */  49,  49, devinfo->ver >= 9)
620
 
F8(send_src0_reg_file,        /* 4+ */ 38, 37, /* 8+ */   42,  41, /* 12+ */ 66, 66)
621
 
FC(send_src1_reg_nr,          /* 4+ */ 51, 44, /* 12+ */ 111, 104, devinfo->ver >= 9)
622
 
FC(send_src1_reg_file,        /* 4+ */ 36, 36, /* 12+ */  98,  98, devinfo->ver >= 9)
623
 
FC(send_dst_reg_file,         /* 4+ */ 35, 35, /* 12+ */  50,  50, devinfo->ver >= 9)
624
 
/** @} */
625
 
 
626
 
/* Message descriptor bits */
627
 
#define MD(x) ((x) + 96)
628
 
#define MD12(x) ((x) >= 30 ? (x) - 30 + 122 :        \
629
 
                 (x) >= 25 ? (x) - 25 + 67 :         \
630
 
                 (x) >= 20 ? (x) - 20 + 51 :         \
631
 
                 (x) >= 11 ? (x) - 11 + 113 :        \
632
 
                 (x) - 0 + 81)
633
 
 
634
 
/**
635
 
 * Set the SEND(C) message descriptor immediate.
636
 
 *
637
 
 * This doesn't include the SFID nor the EOT field that were considered to be
638
 
 * part of the message descriptor by ancient versions of the BSpec, because
639
 
 * they are present in the instruction even if the message descriptor is
640
 
 * provided indirectly in the address register, so we want to specify them
641
 
 * separately.
642
 
 */
643
 
static inline void
644
 
brw_inst_set_send_desc(const struct intel_device_info *devinfo,
645
 
                       brw_inst *inst, uint32_t value)
646
 
{
647
 
   if (devinfo->ver >= 12) {
648
 
      brw_inst_set_bits(inst, 123, 122, GET_BITS(value, 31, 30));
649
 
      brw_inst_set_bits(inst, 71, 67, GET_BITS(value, 29, 25));
650
 
      brw_inst_set_bits(inst, 55, 51, GET_BITS(value, 24, 20));
651
 
      brw_inst_set_bits(inst, 121, 113, GET_BITS(value, 19, 11));
652
 
      brw_inst_set_bits(inst, 91, 81, GET_BITS(value, 10, 0));
653
 
   } else if (devinfo->ver >= 9) {
654
 
      brw_inst_set_bits(inst, 126, 96, value);
655
 
      assert(value >> 31 == 0);
656
 
   } else if (devinfo->ver >= 5) {
657
 
      brw_inst_set_bits(inst, 124, 96, value);
658
 
      assert(value >> 29 == 0);
659
 
   } else {
660
 
      brw_inst_set_bits(inst, 119, 96, value);
661
 
      assert(value >> 24 == 0);
662
 
   }
663
 
}
664
 
 
665
 
/**
666
 
 * Get the SEND(C) message descriptor immediate.
667
 
 *
668
 
 * \sa brw_inst_set_send_desc().
669
 
 */
670
 
static inline uint32_t
671
 
brw_inst_send_desc(const struct intel_device_info *devinfo,
672
 
                   const brw_inst *inst)
673
 
{
674
 
   if (devinfo->ver >= 12) {
675
 
      return (brw_inst_bits(inst, 123, 122) << 30 |
676
 
              brw_inst_bits(inst, 71, 67) << 25 |
677
 
              brw_inst_bits(inst, 55, 51) << 20 |
678
 
              brw_inst_bits(inst, 121, 113) << 11 |
679
 
              brw_inst_bits(inst, 91, 81));
680
 
   } else if (devinfo->ver >= 9) {
681
 
      return brw_inst_bits(inst, 126, 96);
682
 
   } else if (devinfo->ver >= 5) {
683
 
      return brw_inst_bits(inst, 124, 96);
684
 
   } else {
685
 
      return brw_inst_bits(inst, 119, 96);
686
 
   }
687
 
}
688
 
 
689
 
/**
690
 
 * Set the SEND(C) message extended descriptor immediate.
691
 
 *
692
 
 * This doesn't include the SFID nor the EOT field that were considered to be
693
 
 * part of the extended message descriptor by some versions of the BSpec,
694
 
 * because they are present in the instruction even if the extended message
695
 
 * descriptor is provided indirectly in a register, so we want to specify them
696
 
 * separately.
697
 
 */
698
 
static inline void
699
 
brw_inst_set_send_ex_desc(const struct intel_device_info *devinfo,
700
 
                          brw_inst *inst, uint32_t value)
701
 
{
702
 
   if (devinfo->ver >= 12) {
703
 
      brw_inst_set_bits(inst, 127, 124, GET_BITS(value, 31, 28));
704
 
      brw_inst_set_bits(inst, 97, 96, GET_BITS(value, 27, 26));
705
 
      brw_inst_set_bits(inst, 65, 64, GET_BITS(value, 25, 24));
706
 
      brw_inst_set_bits(inst, 47, 35, GET_BITS(value, 23, 11));
707
 
      brw_inst_set_bits(inst, 103, 99, GET_BITS(value, 10, 6));
708
 
      assert(GET_BITS(value, 5, 0) == 0);
709
 
   } else {
710
 
      assert(devinfo->ver >= 9);
711
 
      brw_inst_set_bits(inst, 94, 91, GET_BITS(value, 31, 28));
712
 
      brw_inst_set_bits(inst, 88, 85, GET_BITS(value, 27, 24));
713
 
      brw_inst_set_bits(inst, 83, 80, GET_BITS(value, 23, 20));
714
 
      brw_inst_set_bits(inst, 67, 64, GET_BITS(value, 19, 16));
715
 
      assert(GET_BITS(value, 15, 0) == 0);
716
 
   }
717
 
}
718
 
 
719
 
/**
720
 
 * Set the SENDS(C) message extended descriptor immediate.
721
 
 *
722
 
 * This doesn't include the SFID nor the EOT field that were considered to be
723
 
 * part of the extended message descriptor by some versions of the BSpec,
724
 
 * because they are present in the instruction even if the extended message
725
 
 * descriptor is provided indirectly in a register, so we want to specify them
726
 
 * separately.
727
 
 */
728
 
static inline void
729
 
brw_inst_set_sends_ex_desc(const struct intel_device_info *devinfo,
730
 
                           brw_inst *inst, uint32_t value)
731
 
{
732
 
   if (devinfo->ver >= 12) {
733
 
      brw_inst_set_send_ex_desc(devinfo, inst, value);
734
 
   } else {
735
 
      brw_inst_set_bits(inst, 95, 80, GET_BITS(value, 31, 16));
736
 
      assert(GET_BITS(value, 15, 10) == 0);
737
 
      brw_inst_set_bits(inst, 67, 64, GET_BITS(value, 9, 6));
738
 
      assert(GET_BITS(value, 5, 0) == 0);
739
 
   }
740
 
}
741
 
 
742
 
/**
743
 
 * Get the SEND(C) message extended descriptor immediate.
744
 
 *
745
 
 * \sa brw_inst_set_send_ex_desc().
746
 
 */
747
 
static inline uint32_t
748
 
brw_inst_send_ex_desc(const struct intel_device_info *devinfo,
749
 
                      const brw_inst *inst)
750
 
{
751
 
   if (devinfo->ver >= 12) {
752
 
      return (brw_inst_bits(inst, 127, 124) << 28 |
753
 
              brw_inst_bits(inst, 97, 96) << 26 |
754
 
              brw_inst_bits(inst, 65, 64) << 24 |
755
 
              brw_inst_bits(inst, 47, 35) << 11 |
756
 
              brw_inst_bits(inst, 103, 99) << 6);
757
 
   } else {
758
 
      assert(devinfo->ver >= 9);
759
 
      return (brw_inst_bits(inst, 94, 91) << 28 |
760
 
              brw_inst_bits(inst, 88, 85) << 24 |
761
 
              brw_inst_bits(inst, 83, 80) << 20 |
762
 
              brw_inst_bits(inst, 67, 64) << 16);
763
 
   }
764
 
}
765
 
 
766
 
/**
767
 
 * Get the SENDS(C) message extended descriptor immediate.
768
 
 *
769
 
 * \sa brw_inst_set_send_ex_desc().
770
 
 */
771
 
static inline uint32_t
772
 
brw_inst_sends_ex_desc(const struct intel_device_info *devinfo,
773
 
                       const brw_inst *inst)
774
 
{
775
 
   if (devinfo->ver >= 12) {
776
 
      return brw_inst_send_ex_desc(devinfo, inst);
777
 
   } else {
778
 
      return (brw_inst_bits(inst, 95, 80) << 16 |
779
 
              brw_inst_bits(inst, 67, 64) << 6);
780
 
   }
781
 
}
782
 
 
783
 
/**
784
 
 * Fields for SEND messages:
785
 
 *  @{
786
 
 */
787
 
F(eot,                 /* 4+ */ 127, 127, /* 12+ */ 34, 34)
788
 
FF(mlen,
789
 
   /* 4:   */ 119, 116,
790
 
   /* 4.5: */ 119, 116,
791
 
   /* 5:   */ 124, 121,
792
 
   /* 6:   */ 124, 121,
793
 
   /* 7:   */ 124, 121,
794
 
   /* 8:   */ 124, 121,
795
 
   /* 12:  */ MD12(28), MD12(25));
796
 
FF(rlen,
797
 
   /* 4:   */ 115, 112,
798
 
   /* 4.5: */ 115, 112,
799
 
   /* 5:   */ 120, 116,
800
 
   /* 6:   */ 120, 116,
801
 
   /* 7:   */ 120, 116,
802
 
   /* 8:   */ 120, 116,
803
 
   /* 12:  */ MD12(24), MD12(20));
804
 
FF(header_present,
805
 
   /* 4: doesn't exist */ -1, -1, -1, -1,
806
 
   /* 5:   */ 115, 115,
807
 
   /* 6:   */ 115, 115,
808
 
   /* 7:   */ 115, 115,
809
 
   /* 8:   */ 115, 115,
810
 
   /* 12:  */ MD12(19), MD12(19))
811
 
F(gateway_notify, /* 4+ */ MD(16), MD(15), /* 12+ */ -1, -1)
812
 
FD(function_control,
813
 
   /* 4:   */ 111,  96,
814
 
   /* 4.5: */ 111,  96,
815
 
   /* 5:   */ 114,  96,
816
 
   /* 6:   */ 114,  96,
817
 
   /* 7:   */ 114,  96,
818
 
   /* 8:   */ 114,  96,
819
 
   /* 12:  */ MD12(18), MD12(11), MD12(10), MD12(0))
820
 
FF(gateway_subfuncid,
821
 
   /* 4:   */ MD(1), MD(0),
822
 
   /* 4.5: */ MD(1), MD(0),
823
 
   /* 5:   */ MD(1), MD(0), /* 2:0, but bit 2 is reserved MBZ */
824
 
   /* 6:   */ MD(2), MD(0),
825
 
   /* 7:   */ MD(2), MD(0),
826
 
   /* 8:   */ MD(2), MD(0),
827
 
   /* 12:  */ MD12(2), MD12(0))
828
 
FF(sfid,
829
 
   /* 4:   */ 123, 120, /* called msg_target */
830
 
   /* 4.5  */ 123, 120,
831
 
   /* 5:   */  95,  92,
832
 
   /* 6:   */  27,  24,
833
 
   /* 7:   */  27,  24,
834
 
   /* 8:   */  27,  24,
835
 
   /* 12:  */  95,  92)
836
 
FF(null_rt,
837
 
   /* 4-7: */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
838
 
   /* 8:   */ 80, 80,
839
 
   /* 12:  */ 44, 44) /* actually only Gfx11+ */
840
 
FC(base_mrf,   /* 4+ */ 27,  24, /* 12+ */ -1, -1, devinfo->ver < 6);
841
 
FF(send_rta_index,
842
 
   /* 4:   */  -1,  -1,
843
 
   /* 4.5  */  -1,  -1,
844
 
   /* 5:   */  -1,  -1,
845
 
   /* 6:   */  -1,  -1,
846
 
   /* 7:   */  -1,  -1,
847
 
   /* 8:   */  -1,  -1,
848
 
   /* 12:  */  38,  36)
849
 
/** @} */
850
 
 
851
 
/**
852
 
 * URB message function control bits:
853
 
 *  @{
854
 
 */
855
 
FF(urb_per_slot_offset,
856
 
   /* 4-6: */ -1, -1, -1, -1, -1, -1, -1, -1,
857
 
   /* 7:   */ MD(16), MD(16),
858
 
   /* 8:   */ MD(17), MD(17),
859
 
   /* 12:  */ MD12(17), MD12(17))
860
 
FC(urb_channel_mask_present, /* 4+ */ MD(15), MD(15), /* 12+ */ MD12(15), MD12(15), devinfo->ver >= 8)
861
 
FC(urb_complete, /* 4+ */ MD(15), MD(15), /* 12+ */ -1, -1, devinfo->ver < 8)
862
 
FC(urb_used,     /* 4+ */ MD(14), MD(14), /* 12+ */ -1, -1, devinfo->ver < 7)
863
 
FC(urb_allocate, /* 4+ */ MD(13), MD(13), /* 12+ */ -1, -1, devinfo->ver < 7)
864
 
FF(urb_swizzle_control,
865
 
   /* 4:   */ MD(11), MD(10),
866
 
   /* 4.5: */ MD(11), MD(10),
867
 
   /* 5:   */ MD(11), MD(10),
868
 
   /* 6:   */ MD(11), MD(10),
869
 
   /* 7:   */ MD(14), MD(14),
870
 
   /* 8:   */ MD(15), MD(15),
871
 
   /* 12:  */ -1, -1)
872
 
FD(urb_global_offset,
873
 
   /* 4:   */ MD( 9), MD(4),
874
 
   /* 4.5: */ MD( 9), MD(4),
875
 
   /* 5:   */ MD( 9), MD(4),
876
 
   /* 6:   */ MD( 9), MD(4),
877
 
   /* 7:   */ MD(13), MD(3),
878
 
   /* 8:   */ MD(14), MD(4),
879
 
   /* 12:  */ MD12(14), MD12(11), MD12(10), MD12(4))
880
 
FF(urb_opcode,
881
 
   /* 4:   */ MD( 3), MD(0),
882
 
   /* 4.5: */ MD( 3), MD(0),
883
 
   /* 5:   */ MD( 3), MD(0),
884
 
   /* 6:   */ MD( 3), MD(0),
885
 
   /* 7:   */ MD( 2), MD(0),
886
 
   /* 8:   */ MD( 3), MD(0),
887
 
   /* 12:  */ MD12(3), MD12(0))
888
 
/** @} */
889
 
 
890
 
/**
891
 
 * Gfx4-5 math messages:
892
 
 *  @{
893
 
 */
894
 
FC(math_msg_data_type,  /* 4+ */ MD(7), MD(7), /* 12+ */ -1, -1, devinfo->ver < 6)
895
 
FC(math_msg_saturate,   /* 4+ */ MD(6), MD(6), /* 12+ */ -1, -1, devinfo->ver < 6)
896
 
FC(math_msg_precision,  /* 4+ */ MD(5), MD(5), /* 12+ */ -1, -1, devinfo->ver < 6)
897
 
FC(math_msg_signed_int, /* 4+ */ MD(4), MD(4), /* 12+ */ -1, -1, devinfo->ver < 6)
898
 
FC(math_msg_function,   /* 4+ */ MD(3), MD(0), /* 12+ */ -1, -1, devinfo->ver < 6)
899
 
/** @} */
900
 
 
901
 
/**
902
 
 * Sampler message function control bits:
903
 
 *  @{
904
 
 */
905
 
FF(sampler_simd_mode,
906
 
   /* 4: doesn't exist */ -1, -1, -1, -1,
907
 
   /* 5:   */ MD(17), MD(16),
908
 
   /* 6:   */ MD(17), MD(16),
909
 
   /* 7:   */ MD(18), MD(17),
910
 
   /* 8:   */ MD(18), MD(17),
911
 
   /* 12:  */ MD12(18), MD12(17))
912
 
FF(sampler_msg_type,
913
 
   /* 4:   */ MD(15), MD(14),
914
 
   /* 4.5: */ MD(15), MD(12),
915
 
   /* 5:   */ MD(15), MD(12),
916
 
   /* 6:   */ MD(15), MD(12),
917
 
   /* 7:   */ MD(16), MD(12),
918
 
   /* 8:   */ MD(16), MD(12),
919
 
   /* 12:  */ MD12(16), MD12(12))
920
 
FC(sampler_return_format, /* 4+ */ MD(13), MD(12), /* 12+ */ -1, -1, devinfo->verx10 == 40)
921
 
FD(sampler,
922
 
   /* 4:   */ MD(11), MD(8),
923
 
   /* 4.5: */ MD(11), MD(8),
924
 
   /* 5:   */ MD(11), MD(8),
925
 
   /* 6:   */ MD(11), MD(8),
926
 
   /* 7:   */ MD(11), MD(8),
927
 
   /* 8:   */ MD(11), MD(8),
928
 
   /* 12:   */ MD12(11), MD12(11), MD12(10), MD12(8))
929
 
F(binding_table_index,    /* 4+ */ MD(7), MD(0),  /* 12+ */ MD12(7), MD12(0)) /* also used by other messages */
930
 
/** @} */
931
 
 
932
 
/**
933
 
 * Data port message function control bits:
934
 
 *  @{
935
 
 */
936
 
FC(dp_category,           /* 4+ */ MD(18), MD(18), /* 12+ */ MD12(18), MD12(18), devinfo->ver >= 7)
937
 
 
938
 
/* Gfx4-5 store fields in different bits for read/write messages. */
939
 
FF(dp_read_msg_type,
940
 
   /* 4:   */ MD(13), MD(12),
941
 
   /* 4.5: */ MD(13), MD(11),
942
 
   /* 5:   */ MD(13), MD(11),
943
 
   /* 6:   */ MD(16), MD(13),
944
 
   /* 7:   */ MD(17), MD(14),
945
 
   /* 8:   */ MD(17), MD(14),
946
 
   /* 12:  */ MD12(17), MD12(14))
947
 
FF(dp_write_msg_type,
948
 
   /* 4:   */ MD(14), MD(12),
949
 
   /* 4.5: */ MD(14), MD(12),
950
 
   /* 5:   */ MD(14), MD(12),
951
 
   /* 6:   */ MD(16), MD(13),
952
 
   /* 7:   */ MD(17), MD(14),
953
 
   /* 8:   */ MD(17), MD(14),
954
 
   /* 12:  */ MD12(17), MD12(14))
955
 
FD(dp_read_msg_control,
956
 
   /* 4:   */ MD(11), MD( 8),
957
 
   /* 4.5: */ MD(10), MD( 8),
958
 
   /* 5:   */ MD(10), MD( 8),
959
 
   /* 6:   */ MD(12), MD( 8),
960
 
   /* 7:   */ MD(13), MD( 8),
961
 
   /* 8:   */ MD(13), MD( 8),
962
 
   /* 12:  */ MD12(13), MD12(11), MD12(10), MD12(8))
963
 
FD(dp_write_msg_control,
964
 
   /* 4:   */ MD(11), MD( 8),
965
 
   /* 4.5: */ MD(11), MD( 8),
966
 
   /* 5:   */ MD(11), MD( 8),
967
 
   /* 6:   */ MD(12), MD( 8),
968
 
   /* 7:   */ MD(13), MD( 8),
969
 
   /* 8:   */ MD(13), MD( 8),
970
 
   /* 12:  */ MD12(13), MD12(11), MD12(10), MD12(8))
971
 
FC(dp_read_target_cache, /* 4+ */ MD(15), MD(14), /* 12+ */ -1, -1, devinfo->ver < 6);
972
 
 
973
 
FF(dp_write_commit,
974
 
   /* 4:   */ MD(15),  MD(15),
975
 
   /* 4.5: */ MD(15),  MD(15),
976
 
   /* 5:   */ MD(15),  MD(15),
977
 
   /* 6:   */ MD(17),  MD(17),
978
 
   /* 7+: does not exist */ -1, -1, -1, -1,
979
 
   /* 12:  */ -1, -1)
980
 
 
981
 
/* Gfx6+ use the same bit locations for everything. */
982
 
FF(dp_msg_type,
983
 
   /* 4-5: use dp_read_msg_type or dp_write_msg_type instead */
984
 
   -1, -1, -1, -1, -1, -1,
985
 
   /* 6:   */ MD(16), MD(13),
986
 
   /* 7:   */ MD(17), MD(14),
987
 
   /* 8:   */ MD(18), MD(14),
988
 
   /* 12:  */ MD12(18), MD12(14))
989
 
FD(dp_msg_control,
990
 
   /* 4:   */ MD(11), MD( 8),
991
 
   /* 4.5-5: use dp_read_msg_control or dp_write_msg_control */ -1, -1, -1, -1,
992
 
   /* 6:   */ MD(12), MD( 8),
993
 
   /* 7:   */ MD(13), MD( 8),
994
 
   /* 8:   */ MD(13), MD( 8),
995
 
   /* 12:  */ MD12(13), MD12(11), MD12(10), MD12(8))
996
 
/** @} */
997
 
 
998
 
/**
999
 
 * Scratch message bits (Gfx7+):
1000
 
 *  @{
1001
 
 */
1002
 
FC(scratch_read_write, /* 4+ */ MD(17), MD(17), /* 12+ */ MD12(17), MD12(17), devinfo->ver >= 7) /* 0 = read,  1 = write */
1003
 
FC(scratch_type,       /* 4+ */ MD(16), MD(16), /* 12+ */ -1, -1, devinfo->ver >= 7) /* 0 = OWord, 1 = DWord */
1004
 
FC(scratch_invalidate_after_read, /* 4+ */ MD(15), MD(15), /* 12+ */ MD12(15), MD12(15), devinfo->ver >= 7)
1005
 
FC(scratch_block_size, /* 4+ */ MD(13), MD(12), /* 12+ */ MD12(13), MD12(12), devinfo->ver >= 7)
1006
 
FD(scratch_addr_offset,
1007
 
   /* 4:   */ -1, -1,
1008
 
   /* 4.5: */ -1, -1,
1009
 
   /* 5:   */ -1, -1,
1010
 
   /* 6:   */ -1, -1,
1011
 
   /* 7:   */ MD(11), MD(0),
1012
 
   /* 8:   */ MD(11), MD(0),
1013
 
   /* 12:  */ MD12(11), MD12(11), MD12(10), MD12(0))
1014
 
/** @} */
1015
 
 
1016
 
/**
1017
 
 * Render Target message function control bits:
1018
 
 *  @{
1019
 
 */
1020
 
FF(rt_last,
1021
 
   /* 4:   */ MD(11), MD(11),
1022
 
   /* 4.5: */ MD(11), MD(11),
1023
 
   /* 5:   */ MD(11), MD(11),
1024
 
   /* 6:   */ MD(12), MD(12),
1025
 
   /* 7:   */ MD(12), MD(12),
1026
 
   /* 8:   */ MD(12), MD(12),
1027
 
   /* 12:  */ MD12(12), MD12(12))
1028
 
FC(rt_slot_group,      /* 4+ */ MD(11),  MD(11), /* 12+ */ MD12(11), MD12(11), devinfo->ver >= 6)
1029
 
F(rt_message_type,     /* 4+ */ MD(10),  MD( 8), /* 12+ */ MD12(10), MD12(8))
1030
 
/** @} */
1031
 
 
1032
 
/**
1033
 
 * Thread Spawn message function control bits:
1034
 
 *  @{
1035
 
 */
1036
 
FC(ts_resource_select,  /* 4+ */ MD( 4),  MD( 4), /* 12+ */ -1, -1, devinfo->ver < 11)
1037
 
FC(ts_request_type,     /* 4+ */ MD( 1),  MD( 1), /* 12+ */ -1, -1, devinfo->ver < 11)
1038
 
F(ts_opcode,           /* 4+ */ MD( 0),  MD( 0), /* 12+ */ MD12(0), MD12(0))
1039
 
/** @} */
1040
 
 
1041
 
/**
1042
 
 * Pixel Interpolator message function control bits:
1043
 
 *  @{
1044
 
 */
1045
 
F(pi_simd_mode,        /* 4+ */ MD(16),  MD(16), /* 12+ */ MD12(16), MD12(16))
1046
 
F(pi_nopersp,          /* 4+ */ MD(14),  MD(14), /* 12+ */ MD12(14), MD12(14))
1047
 
F(pi_message_type,     /* 4+ */ MD(13),  MD(12), /* 12+ */ MD12(13), MD12(12))
1048
 
F(pi_slot_group,       /* 4+ */ MD(11),  MD(11), /* 12+ */ MD12(11), MD12(11))
1049
 
F(pi_message_data,     /* 4+ */ MD(7),   MD(0),  /* 12+ */  MD12(7), MD12(0))
1050
 
/** @} */
1051
 
 
1052
 
/**
1053
 
 * Immediates:
1054
 
 *  @{
1055
 
 */
1056
 
static inline int
1057
 
brw_inst_imm_d(const struct intel_device_info *devinfo, const brw_inst *insn)
1058
 
{
1059
 
   (void) devinfo;
1060
 
   return brw_inst_bits(insn, 127, 96);
1061
 
}
1062
 
 
1063
 
static inline unsigned
1064
 
brw_inst_imm_ud(const struct intel_device_info *devinfo, const brw_inst *insn)
1065
 
{
1066
 
   (void) devinfo;
1067
 
   return brw_inst_bits(insn, 127, 96);
1068
 
}
1069
 
 
1070
 
static inline uint64_t
1071
 
brw_inst_imm_uq(ASSERTED const struct intel_device_info *devinfo,
1072
 
                const brw_inst *insn)
1073
 
{
1074
 
   assert(devinfo->ver >= 8);
1075
 
   return brw_inst_bits(insn, 127, 64);
1076
 
}
1077
 
 
1078
 
static inline float
1079
 
brw_inst_imm_f(const struct intel_device_info *devinfo, const brw_inst *insn)
1080
 
{
1081
 
   union {
1082
 
      float f;
1083
 
      uint32_t u;
1084
 
   } ft;
1085
 
   (void) devinfo;
1086
 
   ft.u = brw_inst_bits(insn, 127, 96);
1087
 
   return ft.f;
1088
 
}
1089
 
 
1090
 
static inline double
1091
 
brw_inst_imm_df(const struct intel_device_info *devinfo, const brw_inst *insn)
1092
 
{
1093
 
   union {
1094
 
      double d;
1095
 
      uint64_t u;
1096
 
   } dt;
1097
 
   (void) devinfo;
1098
 
   dt.u = brw_inst_bits(insn, 127, 64);
1099
 
   return dt.d;
1100
 
}
1101
 
 
1102
 
static inline void
1103
 
brw_inst_set_imm_d(const struct intel_device_info *devinfo,
1104
 
                   brw_inst *insn, int value)
1105
 
{
1106
 
   (void) devinfo;
1107
 
   return brw_inst_set_bits(insn, 127, 96, value);
1108
 
}
1109
 
 
1110
 
static inline void
1111
 
brw_inst_set_imm_ud(const struct intel_device_info *devinfo,
1112
 
                    brw_inst *insn, unsigned value)
1113
 
{
1114
 
   (void) devinfo;
1115
 
   return brw_inst_set_bits(insn, 127, 96, value);
1116
 
}
1117
 
 
1118
 
static inline void
1119
 
brw_inst_set_imm_f(const struct intel_device_info *devinfo,
1120
 
                   brw_inst *insn, float value)
1121
 
{
1122
 
   union {
1123
 
      float f;
1124
 
      uint32_t u;
1125
 
   } ft;
1126
 
   (void) devinfo;
1127
 
   ft.f = value;
1128
 
   brw_inst_set_bits(insn, 127, 96, ft.u);
1129
 
}
1130
 
 
1131
 
static inline void
1132
 
brw_inst_set_imm_df(const struct intel_device_info *devinfo,
1133
 
                    brw_inst *insn, double value)
1134
 
{
1135
 
   union {
1136
 
      double d;
1137
 
      uint64_t u;
1138
 
   } dt;
1139
 
   (void) devinfo;
1140
 
   dt.d = value;
1141
 
 
1142
 
   if (devinfo->ver >= 12) {
1143
 
      brw_inst_set_bits(insn, 95, 64, dt.u >> 32);
1144
 
      brw_inst_set_bits(insn, 127, 96, dt.u & 0xFFFFFFFF);
1145
 
   } else {
1146
 
      brw_inst_set_bits(insn, 127, 64, dt.u);
1147
 
   }
1148
 
}
1149
 
 
1150
 
static inline void
1151
 
brw_inst_set_imm_uq(const struct intel_device_info *devinfo,
1152
 
                    brw_inst *insn, uint64_t value)
1153
 
{
1154
 
   (void) devinfo;
1155
 
   if (devinfo->ver >= 12) {
1156
 
      brw_inst_set_bits(insn, 95, 64, value >> 32);
1157
 
      brw_inst_set_bits(insn, 127, 96, value & 0xFFFFFFFF);
1158
 
   } else {
1159
 
      brw_inst_set_bits(insn, 127, 64, value);
1160
 
   }
1161
 
}
1162
 
 
1163
 
/** @} */
1164
 
 
1165
 
#define REG_TYPE(reg)                                                         \
1166
 
static inline void                                                            \
1167
 
brw_inst_set_##reg##_file_type(const struct intel_device_info *devinfo,       \
1168
 
                               brw_inst *inst, enum brw_reg_file file,        \
1169
 
                               enum brw_reg_type type)                        \
1170
 
{                                                                             \
1171
 
   assert(file <= BRW_IMMEDIATE_VALUE);                                       \
1172
 
   unsigned hw_type = brw_reg_type_to_hw_type(devinfo, file, type);           \
1173
 
   brw_inst_set_##reg##_reg_file(devinfo, inst, file);                        \
1174
 
   brw_inst_set_##reg##_reg_hw_type(devinfo, inst, hw_type);                  \
1175
 
}                                                                             \
1176
 
                                                                              \
1177
 
static inline enum brw_reg_type                                               \
1178
 
brw_inst_##reg##_type(const struct intel_device_info *devinfo,                \
1179
 
                      const brw_inst *inst)                                   \
1180
 
{                                                                             \
1181
 
   unsigned file = __builtin_strcmp("dst", #reg) == 0 ?                       \
1182
 
                   (unsigned) BRW_GENERAL_REGISTER_FILE :                     \
1183
 
                   brw_inst_##reg##_reg_file(devinfo, inst);                  \
1184
 
   unsigned hw_type = brw_inst_##reg##_reg_hw_type(devinfo, inst);            \
1185
 
   return brw_hw_type_to_reg_type(devinfo, (enum brw_reg_file)file, hw_type); \
1186
 
}
1187
 
 
1188
 
REG_TYPE(dst)
1189
 
REG_TYPE(src0)
1190
 
REG_TYPE(src1)
1191
 
#undef REG_TYPE
1192
 
 
1193
 
 
1194
 
/* The AddrImm fields are split into two discontiguous sections on Gfx8+ */
1195
 
#define BRW_IA1_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low, \
1196
 
                         g12_high, g12_low)                              \
1197
 
static inline void                                                       \
1198
 
brw_inst_set_##reg##_ia1_addr_imm(const struct                           \
1199
 
                                  intel_device_info *devinfo,            \
1200
 
                                  brw_inst *inst,                        \
1201
 
                                  unsigned value)                        \
1202
 
{                                                                        \
1203
 
   assert((value & ~0x3ff) == 0);                                        \
1204
 
   if (devinfo->ver >= 12) {                                             \
1205
 
      brw_inst_set_bits(inst, g12_high, g12_low, value);                 \
1206
 
   } else if (devinfo->ver >= 8) {                                       \
1207
 
      brw_inst_set_bits(inst, g8_high, g8_low, value & 0x1ff);           \
1208
 
      brw_inst_set_bits(inst, g8_nine, g8_nine, value >> 9);             \
1209
 
   } else {                                                              \
1210
 
      brw_inst_set_bits(inst, g4_high, g4_low, value);                   \
1211
 
   }                                                                     \
1212
 
}                                                                        \
1213
 
static inline unsigned                                                   \
1214
 
brw_inst_##reg##_ia1_addr_imm(const struct intel_device_info *devinfo,   \
1215
 
                              const brw_inst *inst)                      \
1216
 
{                                                                        \
1217
 
   if (devinfo->ver >= 12) {                                             \
1218
 
      return brw_inst_bits(inst, g12_high, g12_low);                     \
1219
 
   } else if (devinfo->ver >= 8) {                                       \
1220
 
      return brw_inst_bits(inst, g8_high, g8_low) |                      \
1221
 
             (brw_inst_bits(inst, g8_nine, g8_nine) << 9);               \
1222
 
   } else {                                                              \
1223
 
      return brw_inst_bits(inst, g4_high, g4_low);                       \
1224
 
   }                                                                     \
1225
 
}
1226
 
 
1227
 
/* AddrImm[9:0] for Align1 Indirect Addressing        */
1228
 
/*                     -Gen 4-  ----Gfx8----  -Gfx12- */
1229
 
BRW_IA1_ADDR_IMM(src1, 105, 96, 121, 104, 96, 107, 98)
1230
 
BRW_IA1_ADDR_IMM(src0,  73, 64,  95,  72, 64,  75, 66)
1231
 
BRW_IA1_ADDR_IMM(dst,   57, 48,  47,  56, 48,  59, 50)
1232
 
 
1233
 
#define BRW_IA16_ADDR_IMM(reg, g4_high, g4_low, g8_nine, g8_high, g8_low) \
1234
 
static inline void                                                        \
1235
 
brw_inst_set_##reg##_ia16_addr_imm(const struct                           \
1236
 
                                   intel_device_info *devinfo,            \
1237
 
                                   brw_inst *inst, unsigned value)        \
1238
 
{                                                                         \
1239
 
   assert(devinfo->ver < 12);                                             \
1240
 
   assert((value & ~0x3ff) == 0);                                         \
1241
 
   if (devinfo->ver >= 8) {                                               \
1242
 
      assert(GET_BITS(value, 3, 0) == 0);                                 \
1243
 
      brw_inst_set_bits(inst, g8_high, g8_low, GET_BITS(value, 8, 4));    \
1244
 
      brw_inst_set_bits(inst, g8_nine, g8_nine, GET_BITS(value, 9, 9));   \
1245
 
   } else {                                                               \
1246
 
      brw_inst_set_bits(inst, g4_high, g4_low, value);                    \
1247
 
   }                                                                      \
1248
 
}                                                                         \
1249
 
static inline unsigned                                                    \
1250
 
brw_inst_##reg##_ia16_addr_imm(const struct intel_device_info *devinfo,   \
1251
 
                               const brw_inst *inst)                      \
1252
 
{                                                                         \
1253
 
   assert(devinfo->ver < 12);                                             \
1254
 
   if (devinfo->ver >= 8) {                                               \
1255
 
      return (brw_inst_bits(inst, g8_high, g8_low) << 4) |                \
1256
 
             (brw_inst_bits(inst, g8_nine, g8_nine) << 9);                \
1257
 
   } else {                                                               \
1258
 
      return brw_inst_bits(inst, g4_high, g4_low);                        \
1259
 
   }                                                                      \
1260
 
}
1261
 
 
1262
 
/* AddrImm[9:0] for Align16 Indirect Addressing:
1263
 
 * Compared to Align1, these are missing the low 4 bits.
1264
 
 *                     -Gen 4-  ----Gfx8----
1265
 
 */
1266
 
BRW_IA16_ADDR_IMM(src1,       105, 96, 121, 104, 100)
1267
 
BRW_IA16_ADDR_IMM(src0,        73, 64,  95,  72,  68)
1268
 
BRW_IA16_ADDR_IMM(dst,         57, 52,  47,  56,  52)
1269
 
BRW_IA16_ADDR_IMM(send_src0,   -1, -1,  78,  72,  68)
1270
 
BRW_IA16_ADDR_IMM(send_dst,    -1, -1,  62,  56,  52)
1271
 
 
1272
 
/**
1273
 
 * Fetch a set of contiguous bits from the instruction.
1274
 
 *
1275
 
 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
1276
 
 */
1277
 
static inline uint64_t
1278
 
brw_inst_bits(const brw_inst *inst, unsigned high, unsigned low)
1279
 
{
1280
 
   assume(high < 128);
1281
 
   assume(high >= low);
1282
 
   /* We assume the field doesn't cross 64-bit boundaries. */
1283
 
   const unsigned word = high / 64;
1284
 
   assert(word == low / 64);
1285
 
 
1286
 
   high %= 64;
1287
 
   low %= 64;
1288
 
 
1289
 
   const uint64_t mask = (~0ull >> (64 - (high - low + 1)));
1290
 
 
1291
 
   return (inst->data[word] >> low) & mask;
1292
 
}
1293
 
 
1294
 
/**
1295
 
 * Set bits in the instruction, with proper shifting and masking.
1296
 
 *
1297
 
 * Bits indices range from 0..127; fields may not cross 64-bit boundaries.
1298
 
 */
1299
 
static inline void
1300
 
brw_inst_set_bits(brw_inst *inst, unsigned high, unsigned low, uint64_t value)
1301
 
{
1302
 
   assume(high < 128);
1303
 
   assume(high >= low);
1304
 
   const unsigned word = high / 64;
1305
 
   assert(word == low / 64);
1306
 
 
1307
 
   high %= 64;
1308
 
   low %= 64;
1309
 
 
1310
 
   const uint64_t mask = (~0ull >> (64 - (high - low + 1))) << low;
1311
 
 
1312
 
   /* Make sure the supplied value actually fits in the given bitfield. */
1313
 
   assert((value & (mask >> low)) == value);
1314
 
 
1315
 
   inst->data[word] = (inst->data[word] & ~mask) | (value << low);
1316
 
}
1317
 
 
1318
 
#undef BRW_IA16_ADDR_IMM
1319
 
#undef BRW_IA1_ADDR_IMM
1320
 
#undef MD
1321
 
#undef F8
1322
 
#undef FF
1323
 
#undef BOUNDS
1324
 
#undef F
1325
 
#undef FC
1326
 
 
1327
 
typedef struct {
1328
 
   uint64_t data;
1329
 
} brw_compact_inst;
1330
 
 
1331
 
/**
1332
 
 * Fetch a set of contiguous bits from the compacted instruction.
1333
 
 *
1334
 
 * Bits indices range from 0..63.
1335
 
 */
1336
 
static inline unsigned
1337
 
brw_compact_inst_bits(const brw_compact_inst *inst, unsigned high, unsigned low)
1338
 
{
1339
 
   const uint64_t mask = (1ull << (high - low + 1)) - 1;
1340
 
 
1341
 
   return (inst->data >> low) & mask;
1342
 
}
1343
 
 
1344
 
/**
1345
 
 * Set bits in the compacted instruction.
1346
 
 *
1347
 
 * Bits indices range from 0..63.
1348
 
 */
1349
 
static inline void
1350
 
brw_compact_inst_set_bits(brw_compact_inst *inst, unsigned high, unsigned low,
1351
 
                          uint64_t value)
1352
 
{
1353
 
   const uint64_t mask = ((1ull << (high - low + 1)) - 1) << low;
1354
 
 
1355
 
   /* Make sure the supplied value actually fits in the given bitfield. */
1356
 
   assert((value & (mask >> low)) == value);
1357
 
 
1358
 
   inst->data = (inst->data & ~mask) | (value << low);
1359
 
}
1360
 
 
1361
 
#define FC(name, high, low, gfx12_high, gfx12_low, assertions)     \
1362
 
static inline void                                                 \
1363
 
brw_compact_inst_set_##name(const struct                           \
1364
 
                            intel_device_info *devinfo,            \
1365
 
                            brw_compact_inst *inst, unsigned v)    \
1366
 
{                                                                  \
1367
 
   assert(assertions);                                             \
1368
 
   if (devinfo->ver >= 12)                                         \
1369
 
      brw_compact_inst_set_bits(inst, gfx12_high, gfx12_low, v);   \
1370
 
   else                                                            \
1371
 
      brw_compact_inst_set_bits(inst, high, low, v);               \
1372
 
}                                                                  \
1373
 
static inline unsigned                                             \
1374
 
brw_compact_inst_##name(const struct intel_device_info *devinfo,   \
1375
 
                        const brw_compact_inst *inst)              \
1376
 
{                                                                  \
1377
 
   assert(assertions);                                             \
1378
 
   if (devinfo->ver >= 12)                                         \
1379
 
      return brw_compact_inst_bits(inst, gfx12_high, gfx12_low);   \
1380
 
   else                                                            \
1381
 
      return brw_compact_inst_bits(inst, high, low);               \
1382
 
}
1383
 
 
1384
 
/* A simple macro for fields which stay in the same place on all generations
1385
 
 * except for Gfx12.
1386
 
 */
1387
 
#define F(name, high, low, gfx12_high, gfx12_low)       \
1388
 
   FC(name, high, low, gfx12_high, gfx12_low, true)
1389
 
 
1390
 
F(src1_reg_nr,      /* 4+ */ 63, 56, /* 12+ */ 63, 56)
1391
 
F(src0_reg_nr,      /* 4+ */ 55, 48, /* 12+ */ 47, 40)
1392
 
F(dst_reg_nr,       /* 4+ */ 47, 40, /* 12+ */ 23, 16)
1393
 
F(src1_index,       /* 4+ */ 39, 35, /* 12+ */ 55, 52)
1394
 
F(src0_index,       /* 4+ */ 34, 30, /* 12+ */ 51, 48)
1395
 
F(cmpt_control,     /* 4+ */ 29, 29, /* 12+ */ 29, 29) /* Same location as brw_inst */
1396
 
FC(flag_subreg_nr,  /* 4+ */ 28, 28, /* 12+ */ -1, -1, devinfo->ver <= 6)
1397
 
F(cond_modifier,    /* 4+ */ 27, 24, /* 12+ */ -1, -1) /* Same location as brw_inst */
1398
 
FC(acc_wr_control,  /* 4+ */ 23, 23, /* 12+ */ -1, -1, devinfo->ver >= 6)
1399
 
FC(mask_control_ex, /* 4+ */ 23, 23, /* 12+ */ -1, -1, devinfo->verx10 == 45 || devinfo->ver == 5)
1400
 
F(subreg_index,     /* 4+ */ 22, 18, /* 12+ */ 39, 35)
1401
 
F(datatype_index,   /* 4+ */ 17, 13, /* 12+ */ 34, 30)
1402
 
F(control_index,    /* 4+ */ 12,  8, /* 12+ */ 28, 24)
1403
 
FC(swsb,            /* 4+ */ -1, -1, /* 12+ */ 15,  8, devinfo->ver >= 12)
1404
 
F(debug_control,    /* 4+ */  7,  7, /* 12+ */  7,  7)
1405
 
F(hw_opcode,        /* 4+ */  6,  0, /* 12+ */  6,  0) /* Same location as brw_inst */
1406
 
 
1407
 
static inline unsigned
1408
 
brw_compact_inst_imm(const struct intel_device_info *devinfo,
1409
 
                     const brw_compact_inst *inst)
1410
 
{
1411
 
   if (devinfo->ver >= 12) {
1412
 
      return brw_compact_inst_bits(inst, 63, 52);
1413
 
   } else {
1414
 
      return (brw_compact_inst_bits(inst, 39, 35) << 8) |
1415
 
             (brw_compact_inst_bits(inst, 63, 56));
1416
 
   }
1417
 
}
1418
 
 
1419
 
/**
1420
 
 * (Gfx8+) Compacted three-source instructions:
1421
 
 *  @{
1422
 
 */
1423
 
FC(3src_src2_reg_nr,    /* 4+ */ 63, 57, /* 12+ */ 55, 48, devinfo->ver >= 8)
1424
 
FC(3src_src1_reg_nr,    /* 4+ */ 56, 50, /* 12+ */ 63, 56, devinfo->ver >= 8)
1425
 
FC(3src_src0_reg_nr,    /* 4+ */ 49, 43, /* 12+ */ 47, 40, devinfo->ver >= 8)
1426
 
FC(3src_src2_subreg_nr, /* 4+ */ 42, 40, /* 12+ */ -1, -1, devinfo->ver >= 8)
1427
 
FC(3src_src1_subreg_nr, /* 4+ */ 39, 37, /* 12+ */ -1, -1, devinfo->ver >= 8)
1428
 
FC(3src_src0_subreg_nr, /* 4+ */ 36, 34, /* 12+ */ -1, -1, devinfo->ver >= 8)
1429
 
FC(3src_src2_rep_ctrl,  /* 4+ */ 33, 33, /* 12+ */ -1, -1, devinfo->ver >= 8)
1430
 
FC(3src_src1_rep_ctrl,  /* 4+ */ 32, 32, /* 12+ */ -1, -1, devinfo->ver >= 8)
1431
 
FC(3src_saturate,       /* 4+ */ 31, 31, /* 12+ */ -1, -1, devinfo->ver >= 8)
1432
 
FC(3src_debug_control,  /* 4+ */ 30, 30, /* 12+ */  7,  7, devinfo->ver >= 8)
1433
 
FC(3src_cmpt_control,   /* 4+ */ 29, 29, /* 12+ */ 29, 29, devinfo->ver >= 8)
1434
 
FC(3src_src0_rep_ctrl,  /* 4+ */ 28, 28, /* 12+ */ -1, -1, devinfo->ver >= 8)
1435
 
/* Reserved */
1436
 
FC(3src_dst_reg_nr,     /* 4+ */ 18, 12, /* 12+ */ 23, 16, devinfo->ver >= 8)
1437
 
FC(3src_source_index,   /* 4+ */ 11, 10, /* 12+ */ 34, 30, devinfo->ver >= 8)
1438
 
FC(3src_subreg_index,   /* 4+ */ -1, -1, /* 12+ */ 39, 35, devinfo->ver >= 12)
1439
 
FC(3src_control_index,  /* 4+ */  9,  8, /* 12+ */ 28, 24, devinfo->ver >= 8)
1440
 
FC(3src_swsb,           /* 4+ */ -1, -1, /* 12+ */ 15,  8, devinfo->ver >= 8)
1441
 
/* Bit 7 is Reserved (for future Opcode expansion) */
1442
 
FC(3src_hw_opcode,      /* 4+ */  6,  0, /* 12+ */  6,  0, devinfo->ver >= 8)
1443
 
/** @} */
1444
 
 
1445
 
#undef F
1446
 
 
1447
 
#ifdef __cplusplus
1448
 
}
1449
 
#endif
1450
 
 
1451
 
#endif