1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2012-2018 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci/** @file brw_eu_compact.c
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci * Instruction compaction is a feature of G45 and newer hardware that allows
27bf215546Sopenharmony_ci * for a smaller instruction encoding.
28bf215546Sopenharmony_ci *
29bf215546Sopenharmony_ci * The instruction cache is on the order of 32KB, and many programs generate
30bf215546Sopenharmony_ci * far more instructions than that.  The instruction cache is built to barely
31bf215546Sopenharmony_ci * keep up with instruction dispatch ability in cache hit cases -- L1
32bf215546Sopenharmony_ci * instruction cache misses that still hit in the next level could limit
33bf215546Sopenharmony_ci * throughput by around 50%.
34bf215546Sopenharmony_ci *
35bf215546Sopenharmony_ci * The idea of instruction compaction is that most instructions use a tiny
36bf215546Sopenharmony_ci * subset of the GPU functionality, so we can encode what would be a 16 byte
37bf215546Sopenharmony_ci * instruction in 8 bytes using some lookup tables for various fields.
38bf215546Sopenharmony_ci *
39bf215546Sopenharmony_ci *
40bf215546Sopenharmony_ci * Instruction compaction capabilities vary subtly by generation.
41bf215546Sopenharmony_ci *
42bf215546Sopenharmony_ci * G45's support for instruction compaction is very limited. Jump counts on
43bf215546Sopenharmony_ci * this generation are in units of 16-byte uncompacted instructions. As such,
44bf215546Sopenharmony_ci * all jump targets must be 16-byte aligned. Also, all instructions must be
45bf215546Sopenharmony_ci * naturally aligned, i.e. uncompacted instructions must be 16-byte aligned.
46bf215546Sopenharmony_ci * A G45-only instruction, NENOP, must be used to provide padding to align
47bf215546Sopenharmony_ci * uncompacted instructions.
48bf215546Sopenharmony_ci *
49bf215546Sopenharmony_ci * Gfx5 removes these restrictions and changes jump counts to be in units of
50bf215546Sopenharmony_ci * 8-byte compacted instructions, allowing jump targets to be only 8-byte
51bf215546Sopenharmony_ci * aligned. Uncompacted instructions can also be placed on 8-byte boundaries.
52bf215546Sopenharmony_ci *
53bf215546Sopenharmony_ci * Gfx6 adds the ability to compact instructions with a limited range of
54bf215546Sopenharmony_ci * immediate values. Compactable immediates have 12 unrestricted bits, and a
55bf215546Sopenharmony_ci * 13th bit that's replicated through the high 20 bits, to create the 32-bit
56bf215546Sopenharmony_ci * value of DW3 in the uncompacted instruction word.
57bf215546Sopenharmony_ci *
58bf215546Sopenharmony_ci * On Gfx7 we can compact some control flow instructions with a small positive
59bf215546Sopenharmony_ci * immediate in the low bits of DW3, like ENDIF with the JIP field. Other
60bf215546Sopenharmony_ci * control flow instructions with UIP cannot be compacted, because of the
61bf215546Sopenharmony_ci * replicated 13th bit. No control flow instructions can be compacted on Gfx6
62bf215546Sopenharmony_ci * since the jump count field is not in DW3.
63bf215546Sopenharmony_ci *
64bf215546Sopenharmony_ci *    break    JIP/UIP
65bf215546Sopenharmony_ci *    cont     JIP/UIP
66bf215546Sopenharmony_ci *    halt     JIP/UIP
67bf215546Sopenharmony_ci *    if       JIP/UIP
68bf215546Sopenharmony_ci *    else     JIP (plus UIP on BDW+)
69bf215546Sopenharmony_ci *    endif    JIP
70bf215546Sopenharmony_ci *    while    JIP (must be negative)
71bf215546Sopenharmony_ci *
72bf215546Sopenharmony_ci * Gen 8 adds support for compacting 3-src instructions.
73bf215546Sopenharmony_ci *
74bf215546Sopenharmony_ci * Gfx12 reduces the number of bits that available to compacted immediates from
75bf215546Sopenharmony_ci * 13 to 12, but improves the compaction of floating-point immediates by
76bf215546Sopenharmony_ci * allowing the high bits to be encoded (the sign, 8-bit exponent, and the
77bf215546Sopenharmony_ci * three most significant bits of the mantissa), rather than the lowest bits of
78bf215546Sopenharmony_ci * the mantissa.
79bf215546Sopenharmony_ci */
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci#include "brw_eu.h"
82bf215546Sopenharmony_ci#include "brw_shader.h"
83bf215546Sopenharmony_ci#include "brw_disasm_info.h"
84bf215546Sopenharmony_ci#include "dev/intel_debug.h"
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_cistatic const uint32_t g45_control_index_table[32] = {
87bf215546Sopenharmony_ci   0b00000000000000000,
88bf215546Sopenharmony_ci   0b01000000000000000,
89bf215546Sopenharmony_ci   0b00110000000000000,
90bf215546Sopenharmony_ci   0b00000000000000010,
91bf215546Sopenharmony_ci   0b00100000000000000,
92bf215546Sopenharmony_ci   0b00010000000000000,
93bf215546Sopenharmony_ci   0b01000000000100000,
94bf215546Sopenharmony_ci   0b01000000100000000,
95bf215546Sopenharmony_ci   0b01010000000100000,
96bf215546Sopenharmony_ci   0b00000000100000010,
97bf215546Sopenharmony_ci   0b11000000000000000,
98bf215546Sopenharmony_ci   0b00001000100000010,
99bf215546Sopenharmony_ci   0b01001000100000000,
100bf215546Sopenharmony_ci   0b00000000100000000,
101bf215546Sopenharmony_ci   0b11000000000100000,
102bf215546Sopenharmony_ci   0b00001000100000000,
103bf215546Sopenharmony_ci   0b10110000000000000,
104bf215546Sopenharmony_ci   0b11010000000100000,
105bf215546Sopenharmony_ci   0b00110000100000000,
106bf215546Sopenharmony_ci   0b00100000100000000,
107bf215546Sopenharmony_ci   0b01000000000001000,
108bf215546Sopenharmony_ci   0b01000000000000100,
109bf215546Sopenharmony_ci   0b00111100000000000,
110bf215546Sopenharmony_ci   0b00101011000000000,
111bf215546Sopenharmony_ci   0b00110000000010000,
112bf215546Sopenharmony_ci   0b00010000100000000,
113bf215546Sopenharmony_ci   0b01000000000100100,
114bf215546Sopenharmony_ci   0b01000000000101000,
115bf215546Sopenharmony_ci   0b00110000000000110,
116bf215546Sopenharmony_ci   0b00000000000001010,
117bf215546Sopenharmony_ci   0b01010000000101000,
118bf215546Sopenharmony_ci   0b01010000000100100,
119bf215546Sopenharmony_ci};
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_cistatic const uint32_t g45_datatype_table[32] = {
122bf215546Sopenharmony_ci   0b001000000000100001,
123bf215546Sopenharmony_ci   0b001011010110101101,
124bf215546Sopenharmony_ci   0b001000001000110001,
125bf215546Sopenharmony_ci   0b001111011110111101,
126bf215546Sopenharmony_ci   0b001011010110101100,
127bf215546Sopenharmony_ci   0b001000000110101101,
128bf215546Sopenharmony_ci   0b001000000000100000,
129bf215546Sopenharmony_ci   0b010100010110110001,
130bf215546Sopenharmony_ci   0b001100011000101101,
131bf215546Sopenharmony_ci   0b001000000000100010,
132bf215546Sopenharmony_ci   0b001000001000110110,
133bf215546Sopenharmony_ci   0b010000001000110001,
134bf215546Sopenharmony_ci   0b001000001000110010,
135bf215546Sopenharmony_ci   0b011000001000110010,
136bf215546Sopenharmony_ci   0b001111011110111100,
137bf215546Sopenharmony_ci   0b001000000100101000,
138bf215546Sopenharmony_ci   0b010100011000110001,
139bf215546Sopenharmony_ci   0b001010010100101001,
140bf215546Sopenharmony_ci   0b001000001000101001,
141bf215546Sopenharmony_ci   0b010000001000110110,
142bf215546Sopenharmony_ci   0b101000001000110001,
143bf215546Sopenharmony_ci   0b001011011000101101,
144bf215546Sopenharmony_ci   0b001000000100001001,
145bf215546Sopenharmony_ci   0b001011011000101100,
146bf215546Sopenharmony_ci   0b110100011000110001,
147bf215546Sopenharmony_ci   0b001000001110111101,
148bf215546Sopenharmony_ci   0b110000001000110001,
149bf215546Sopenharmony_ci   0b011000000100101010,
150bf215546Sopenharmony_ci   0b101000001000101001,
151bf215546Sopenharmony_ci   0b001011010110001100,
152bf215546Sopenharmony_ci   0b001000000110100001,
153bf215546Sopenharmony_ci   0b001010010100001000,
154bf215546Sopenharmony_ci};
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_cistatic const uint16_t g45_subreg_table[32] = {
157bf215546Sopenharmony_ci   0b000000000000000,
158bf215546Sopenharmony_ci   0b000000010000000,
159bf215546Sopenharmony_ci   0b000001000000000,
160bf215546Sopenharmony_ci   0b000100000000000,
161bf215546Sopenharmony_ci   0b000000000100000,
162bf215546Sopenharmony_ci   0b100000000000000,
163bf215546Sopenharmony_ci   0b000000000010000,
164bf215546Sopenharmony_ci   0b001100000000000,
165bf215546Sopenharmony_ci   0b001010000000000,
166bf215546Sopenharmony_ci   0b000000100000000,
167bf215546Sopenharmony_ci   0b001000000000000,
168bf215546Sopenharmony_ci   0b000000000001000,
169bf215546Sopenharmony_ci   0b000000001000000,
170bf215546Sopenharmony_ci   0b000000000000001,
171bf215546Sopenharmony_ci   0b000010000000000,
172bf215546Sopenharmony_ci   0b000000010100000,
173bf215546Sopenharmony_ci   0b000000000000111,
174bf215546Sopenharmony_ci   0b000001000100000,
175bf215546Sopenharmony_ci   0b011000000000000,
176bf215546Sopenharmony_ci   0b000000110000000,
177bf215546Sopenharmony_ci   0b000000000000010,
178bf215546Sopenharmony_ci   0b000000000000100,
179bf215546Sopenharmony_ci   0b000000001100000,
180bf215546Sopenharmony_ci   0b000100000000010,
181bf215546Sopenharmony_ci   0b001110011000110,
182bf215546Sopenharmony_ci   0b001110100001000,
183bf215546Sopenharmony_ci   0b000110011000110,
184bf215546Sopenharmony_ci   0b000001000011000,
185bf215546Sopenharmony_ci   0b000110010000100,
186bf215546Sopenharmony_ci   0b001100000000110,
187bf215546Sopenharmony_ci   0b000000010000110,
188bf215546Sopenharmony_ci   0b000001000110000,
189bf215546Sopenharmony_ci};
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_cistatic const uint16_t g45_src_index_table[32] = {
192bf215546Sopenharmony_ci   0b000000000000,
193bf215546Sopenharmony_ci   0b010001101000,
194bf215546Sopenharmony_ci   0b010110001000,
195bf215546Sopenharmony_ci   0b011010010000,
196bf215546Sopenharmony_ci   0b001101001000,
197bf215546Sopenharmony_ci   0b010110001010,
198bf215546Sopenharmony_ci   0b010101110000,
199bf215546Sopenharmony_ci   0b011001111000,
200bf215546Sopenharmony_ci   0b001000101000,
201bf215546Sopenharmony_ci   0b000000101000,
202bf215546Sopenharmony_ci   0b010001010000,
203bf215546Sopenharmony_ci   0b111101101100,
204bf215546Sopenharmony_ci   0b010110001100,
205bf215546Sopenharmony_ci   0b010001101100,
206bf215546Sopenharmony_ci   0b011010010100,
207bf215546Sopenharmony_ci   0b010001001100,
208bf215546Sopenharmony_ci   0b001100101000,
209bf215546Sopenharmony_ci   0b000000000010,
210bf215546Sopenharmony_ci   0b111101001100,
211bf215546Sopenharmony_ci   0b011001101000,
212bf215546Sopenharmony_ci   0b010101001000,
213bf215546Sopenharmony_ci   0b000000000100,
214bf215546Sopenharmony_ci   0b000000101100,
215bf215546Sopenharmony_ci   0b010001101010,
216bf215546Sopenharmony_ci   0b000000111000,
217bf215546Sopenharmony_ci   0b010101011000,
218bf215546Sopenharmony_ci   0b000100100000,
219bf215546Sopenharmony_ci   0b010110000000,
220bf215546Sopenharmony_ci   0b010000000100,
221bf215546Sopenharmony_ci   0b010000111000,
222bf215546Sopenharmony_ci   0b000101100000,
223bf215546Sopenharmony_ci   0b111101110100,
224bf215546Sopenharmony_ci};
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_cistatic const uint32_t gfx6_control_index_table[32] = {
227bf215546Sopenharmony_ci   0b00000000000000000,
228bf215546Sopenharmony_ci   0b01000000000000000,
229bf215546Sopenharmony_ci   0b00110000000000000,
230bf215546Sopenharmony_ci   0b00000000100000000,
231bf215546Sopenharmony_ci   0b00010000000000000,
232bf215546Sopenharmony_ci   0b00001000100000000,
233bf215546Sopenharmony_ci   0b00000000100000010,
234bf215546Sopenharmony_ci   0b00000000000000010,
235bf215546Sopenharmony_ci   0b01000000100000000,
236bf215546Sopenharmony_ci   0b01010000000000000,
237bf215546Sopenharmony_ci   0b10110000000000000,
238bf215546Sopenharmony_ci   0b00100000000000000,
239bf215546Sopenharmony_ci   0b11010000000000000,
240bf215546Sopenharmony_ci   0b11000000000000000,
241bf215546Sopenharmony_ci   0b01001000100000000,
242bf215546Sopenharmony_ci   0b01000000000001000,
243bf215546Sopenharmony_ci   0b01000000000000100,
244bf215546Sopenharmony_ci   0b00000000000001000,
245bf215546Sopenharmony_ci   0b00000000000000100,
246bf215546Sopenharmony_ci   0b00111000100000000,
247bf215546Sopenharmony_ci   0b00001000100000010,
248bf215546Sopenharmony_ci   0b00110000100000000,
249bf215546Sopenharmony_ci   0b00110000000000001,
250bf215546Sopenharmony_ci   0b00100000000000001,
251bf215546Sopenharmony_ci   0b00110000000000010,
252bf215546Sopenharmony_ci   0b00110000000000101,
253bf215546Sopenharmony_ci   0b00110000000001001,
254bf215546Sopenharmony_ci   0b00110000000010000,
255bf215546Sopenharmony_ci   0b00110000000000011,
256bf215546Sopenharmony_ci   0b00110000000000100,
257bf215546Sopenharmony_ci   0b00110000100001000,
258bf215546Sopenharmony_ci   0b00100000000001001,
259bf215546Sopenharmony_ci};
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_cistatic const uint32_t gfx6_datatype_table[32] = {
262bf215546Sopenharmony_ci   0b001001110000000000,
263bf215546Sopenharmony_ci   0b001000110000100000,
264bf215546Sopenharmony_ci   0b001001110000000001,
265bf215546Sopenharmony_ci   0b001000000001100000,
266bf215546Sopenharmony_ci   0b001010110100101001,
267bf215546Sopenharmony_ci   0b001000000110101101,
268bf215546Sopenharmony_ci   0b001100011000101100,
269bf215546Sopenharmony_ci   0b001011110110101101,
270bf215546Sopenharmony_ci   0b001000000111101100,
271bf215546Sopenharmony_ci   0b001000000001100001,
272bf215546Sopenharmony_ci   0b001000110010100101,
273bf215546Sopenharmony_ci   0b001000000001000001,
274bf215546Sopenharmony_ci   0b001000001000110001,
275bf215546Sopenharmony_ci   0b001000001000101001,
276bf215546Sopenharmony_ci   0b001000000000100000,
277bf215546Sopenharmony_ci   0b001000001000110010,
278bf215546Sopenharmony_ci   0b001010010100101001,
279bf215546Sopenharmony_ci   0b001011010010100101,
280bf215546Sopenharmony_ci   0b001000000110100101,
281bf215546Sopenharmony_ci   0b001100011000101001,
282bf215546Sopenharmony_ci   0b001011011000101100,
283bf215546Sopenharmony_ci   0b001011010110100101,
284bf215546Sopenharmony_ci   0b001011110110100101,
285bf215546Sopenharmony_ci   0b001111011110111101,
286bf215546Sopenharmony_ci   0b001111011110111100,
287bf215546Sopenharmony_ci   0b001111011110111101,
288bf215546Sopenharmony_ci   0b001111011110011101,
289bf215546Sopenharmony_ci   0b001111011110111110,
290bf215546Sopenharmony_ci   0b001000000000100001,
291bf215546Sopenharmony_ci   0b001000000000100010,
292bf215546Sopenharmony_ci   0b001001111111011101,
293bf215546Sopenharmony_ci   0b001000001110111110,
294bf215546Sopenharmony_ci};
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_cistatic const uint16_t gfx6_subreg_table[32] = {
297bf215546Sopenharmony_ci   0b000000000000000,
298bf215546Sopenharmony_ci   0b000000000000100,
299bf215546Sopenharmony_ci   0b000000110000000,
300bf215546Sopenharmony_ci   0b111000000000000,
301bf215546Sopenharmony_ci   0b011110000001000,
302bf215546Sopenharmony_ci   0b000010000000000,
303bf215546Sopenharmony_ci   0b000000000010000,
304bf215546Sopenharmony_ci   0b000110000001100,
305bf215546Sopenharmony_ci   0b001000000000000,
306bf215546Sopenharmony_ci   0b000001000000000,
307bf215546Sopenharmony_ci   0b000001010010100,
308bf215546Sopenharmony_ci   0b000000001010110,
309bf215546Sopenharmony_ci   0b010000000000000,
310bf215546Sopenharmony_ci   0b110000000000000,
311bf215546Sopenharmony_ci   0b000100000000000,
312bf215546Sopenharmony_ci   0b000000010000000,
313bf215546Sopenharmony_ci   0b000000000001000,
314bf215546Sopenharmony_ci   0b100000000000000,
315bf215546Sopenharmony_ci   0b000001010000000,
316bf215546Sopenharmony_ci   0b001010000000000,
317bf215546Sopenharmony_ci   0b001100000000000,
318bf215546Sopenharmony_ci   0b000000001010100,
319bf215546Sopenharmony_ci   0b101101010010100,
320bf215546Sopenharmony_ci   0b010100000000000,
321bf215546Sopenharmony_ci   0b000000010001111,
322bf215546Sopenharmony_ci   0b011000000000000,
323bf215546Sopenharmony_ci   0b111110000000000,
324bf215546Sopenharmony_ci   0b101000000000000,
325bf215546Sopenharmony_ci   0b000000000001111,
326bf215546Sopenharmony_ci   0b000100010001111,
327bf215546Sopenharmony_ci   0b001000010001111,
328bf215546Sopenharmony_ci   0b000110000000000,
329bf215546Sopenharmony_ci};
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_cistatic const uint16_t gfx6_src_index_table[32] = {
332bf215546Sopenharmony_ci   0b000000000000,
333bf215546Sopenharmony_ci   0b010110001000,
334bf215546Sopenharmony_ci   0b010001101000,
335bf215546Sopenharmony_ci   0b001000101000,
336bf215546Sopenharmony_ci   0b011010010000,
337bf215546Sopenharmony_ci   0b000100100000,
338bf215546Sopenharmony_ci   0b010001101100,
339bf215546Sopenharmony_ci   0b010101110000,
340bf215546Sopenharmony_ci   0b011001111000,
341bf215546Sopenharmony_ci   0b001100101000,
342bf215546Sopenharmony_ci   0b010110001100,
343bf215546Sopenharmony_ci   0b001000100000,
344bf215546Sopenharmony_ci   0b010110001010,
345bf215546Sopenharmony_ci   0b000000000010,
346bf215546Sopenharmony_ci   0b010101010000,
347bf215546Sopenharmony_ci   0b010101101000,
348bf215546Sopenharmony_ci   0b111101001100,
349bf215546Sopenharmony_ci   0b111100101100,
350bf215546Sopenharmony_ci   0b011001110000,
351bf215546Sopenharmony_ci   0b010110001001,
352bf215546Sopenharmony_ci   0b010101011000,
353bf215546Sopenharmony_ci   0b001101001000,
354bf215546Sopenharmony_ci   0b010000101100,
355bf215546Sopenharmony_ci   0b010000000000,
356bf215546Sopenharmony_ci   0b001101110000,
357bf215546Sopenharmony_ci   0b001100010000,
358bf215546Sopenharmony_ci   0b001100000000,
359bf215546Sopenharmony_ci   0b010001101010,
360bf215546Sopenharmony_ci   0b001101111000,
361bf215546Sopenharmony_ci   0b000001110000,
362bf215546Sopenharmony_ci   0b001100100000,
363bf215546Sopenharmony_ci   0b001101010000,
364bf215546Sopenharmony_ci};
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_cistatic const uint32_t gfx7_control_index_table[32] = {
367bf215546Sopenharmony_ci   0b0000000000000000010,
368bf215546Sopenharmony_ci   0b0000100000000000000,
369bf215546Sopenharmony_ci   0b0000100000000000001,
370bf215546Sopenharmony_ci   0b0000100000000000010,
371bf215546Sopenharmony_ci   0b0000100000000000011,
372bf215546Sopenharmony_ci   0b0000100000000000100,
373bf215546Sopenharmony_ci   0b0000100000000000101,
374bf215546Sopenharmony_ci   0b0000100000000000111,
375bf215546Sopenharmony_ci   0b0000100000000001000,
376bf215546Sopenharmony_ci   0b0000100000000001001,
377bf215546Sopenharmony_ci   0b0000100000000001101,
378bf215546Sopenharmony_ci   0b0000110000000000000,
379bf215546Sopenharmony_ci   0b0000110000000000001,
380bf215546Sopenharmony_ci   0b0000110000000000010,
381bf215546Sopenharmony_ci   0b0000110000000000011,
382bf215546Sopenharmony_ci   0b0000110000000000100,
383bf215546Sopenharmony_ci   0b0000110000000000101,
384bf215546Sopenharmony_ci   0b0000110000000000111,
385bf215546Sopenharmony_ci   0b0000110000000001001,
386bf215546Sopenharmony_ci   0b0000110000000001101,
387bf215546Sopenharmony_ci   0b0000110000000010000,
388bf215546Sopenharmony_ci   0b0000110000100000000,
389bf215546Sopenharmony_ci   0b0001000000000000000,
390bf215546Sopenharmony_ci   0b0001000000000000010,
391bf215546Sopenharmony_ci   0b0001000000000000100,
392bf215546Sopenharmony_ci   0b0001000000100000000,
393bf215546Sopenharmony_ci   0b0010110000000000000,
394bf215546Sopenharmony_ci   0b0010110000000010000,
395bf215546Sopenharmony_ci   0b0011000000000000000,
396bf215546Sopenharmony_ci   0b0011000000100000000,
397bf215546Sopenharmony_ci   0b0101000000000000000,
398bf215546Sopenharmony_ci   0b0101000000100000000,
399bf215546Sopenharmony_ci};
400bf215546Sopenharmony_ci
401bf215546Sopenharmony_cistatic const uint32_t gfx7_datatype_table[32] = {
402bf215546Sopenharmony_ci   0b001000000000000001,
403bf215546Sopenharmony_ci   0b001000000000100000,
404bf215546Sopenharmony_ci   0b001000000000100001,
405bf215546Sopenharmony_ci   0b001000000001100001,
406bf215546Sopenharmony_ci   0b001000000010111101,
407bf215546Sopenharmony_ci   0b001000001011111101,
408bf215546Sopenharmony_ci   0b001000001110100001,
409bf215546Sopenharmony_ci   0b001000001110100101,
410bf215546Sopenharmony_ci   0b001000001110111101,
411bf215546Sopenharmony_ci   0b001000010000100001,
412bf215546Sopenharmony_ci   0b001000110000100000,
413bf215546Sopenharmony_ci   0b001000110000100001,
414bf215546Sopenharmony_ci   0b001001010010100101,
415bf215546Sopenharmony_ci   0b001001110010100100,
416bf215546Sopenharmony_ci   0b001001110010100101,
417bf215546Sopenharmony_ci   0b001111001110111101,
418bf215546Sopenharmony_ci   0b001111011110011101,
419bf215546Sopenharmony_ci   0b001111011110111100,
420bf215546Sopenharmony_ci   0b001111011110111101,
421bf215546Sopenharmony_ci   0b001111111110111100,
422bf215546Sopenharmony_ci   0b000000001000001100,
423bf215546Sopenharmony_ci   0b001000000000111101,
424bf215546Sopenharmony_ci   0b001000000010100101,
425bf215546Sopenharmony_ci   0b001000010000100000,
426bf215546Sopenharmony_ci   0b001001010010100100,
427bf215546Sopenharmony_ci   0b001001110010000100,
428bf215546Sopenharmony_ci   0b001010010100001001,
429bf215546Sopenharmony_ci   0b001101111110111101,
430bf215546Sopenharmony_ci   0b001111111110111101,
431bf215546Sopenharmony_ci   0b001011110110101100,
432bf215546Sopenharmony_ci   0b001010010100101000,
433bf215546Sopenharmony_ci   0b001010110100101000,
434bf215546Sopenharmony_ci};
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_cistatic const uint16_t gfx7_subreg_table[32] = {
437bf215546Sopenharmony_ci   0b000000000000000,
438bf215546Sopenharmony_ci   0b000000000000001,
439bf215546Sopenharmony_ci   0b000000000001000,
440bf215546Sopenharmony_ci   0b000000000001111,
441bf215546Sopenharmony_ci   0b000000000010000,
442bf215546Sopenharmony_ci   0b000000010000000,
443bf215546Sopenharmony_ci   0b000000100000000,
444bf215546Sopenharmony_ci   0b000000110000000,
445bf215546Sopenharmony_ci   0b000001000000000,
446bf215546Sopenharmony_ci   0b000001000010000,
447bf215546Sopenharmony_ci   0b000010100000000,
448bf215546Sopenharmony_ci   0b001000000000000,
449bf215546Sopenharmony_ci   0b001000000000001,
450bf215546Sopenharmony_ci   0b001000010000001,
451bf215546Sopenharmony_ci   0b001000010000010,
452bf215546Sopenharmony_ci   0b001000010000011,
453bf215546Sopenharmony_ci   0b001000010000100,
454bf215546Sopenharmony_ci   0b001000010000111,
455bf215546Sopenharmony_ci   0b001000010001000,
456bf215546Sopenharmony_ci   0b001000010001110,
457bf215546Sopenharmony_ci   0b001000010001111,
458bf215546Sopenharmony_ci   0b001000110000000,
459bf215546Sopenharmony_ci   0b001000111101000,
460bf215546Sopenharmony_ci   0b010000000000000,
461bf215546Sopenharmony_ci   0b010000110000000,
462bf215546Sopenharmony_ci   0b011000000000000,
463bf215546Sopenharmony_ci   0b011110010000111,
464bf215546Sopenharmony_ci   0b100000000000000,
465bf215546Sopenharmony_ci   0b101000000000000,
466bf215546Sopenharmony_ci   0b110000000000000,
467bf215546Sopenharmony_ci   0b111000000000000,
468bf215546Sopenharmony_ci   0b111000000011100,
469bf215546Sopenharmony_ci};
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_cistatic const uint16_t gfx7_src_index_table[32] = {
472bf215546Sopenharmony_ci   0b000000000000,
473bf215546Sopenharmony_ci   0b000000000010,
474bf215546Sopenharmony_ci   0b000000010000,
475bf215546Sopenharmony_ci   0b000000010010,
476bf215546Sopenharmony_ci   0b000000011000,
477bf215546Sopenharmony_ci   0b000000100000,
478bf215546Sopenharmony_ci   0b000000101000,
479bf215546Sopenharmony_ci   0b000001001000,
480bf215546Sopenharmony_ci   0b000001010000,
481bf215546Sopenharmony_ci   0b000001110000,
482bf215546Sopenharmony_ci   0b000001111000,
483bf215546Sopenharmony_ci   0b001100000000,
484bf215546Sopenharmony_ci   0b001100000010,
485bf215546Sopenharmony_ci   0b001100001000,
486bf215546Sopenharmony_ci   0b001100010000,
487bf215546Sopenharmony_ci   0b001100010010,
488bf215546Sopenharmony_ci   0b001100100000,
489bf215546Sopenharmony_ci   0b001100101000,
490bf215546Sopenharmony_ci   0b001100111000,
491bf215546Sopenharmony_ci   0b001101000000,
492bf215546Sopenharmony_ci   0b001101000010,
493bf215546Sopenharmony_ci   0b001101001000,
494bf215546Sopenharmony_ci   0b001101010000,
495bf215546Sopenharmony_ci   0b001101100000,
496bf215546Sopenharmony_ci   0b001101101000,
497bf215546Sopenharmony_ci   0b001101110000,
498bf215546Sopenharmony_ci   0b001101110001,
499bf215546Sopenharmony_ci   0b001101111000,
500bf215546Sopenharmony_ci   0b010001101000,
501bf215546Sopenharmony_ci   0b010001101001,
502bf215546Sopenharmony_ci   0b010001101010,
503bf215546Sopenharmony_ci   0b010110001000,
504bf215546Sopenharmony_ci};
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_cistatic const uint32_t gfx8_control_index_table[32] = {
507bf215546Sopenharmony_ci   0b0000000000000000010,
508bf215546Sopenharmony_ci   0b0000100000000000000,
509bf215546Sopenharmony_ci   0b0000100000000000001,
510bf215546Sopenharmony_ci   0b0000100000000000010,
511bf215546Sopenharmony_ci   0b0000100000000000011,
512bf215546Sopenharmony_ci   0b0000100000000000100,
513bf215546Sopenharmony_ci   0b0000100000000000101,
514bf215546Sopenharmony_ci   0b0000100000000000111,
515bf215546Sopenharmony_ci   0b0000100000000001000,
516bf215546Sopenharmony_ci   0b0000100000000001001,
517bf215546Sopenharmony_ci   0b0000100000000001101,
518bf215546Sopenharmony_ci   0b0000110000000000000,
519bf215546Sopenharmony_ci   0b0000110000000000001,
520bf215546Sopenharmony_ci   0b0000110000000000010,
521bf215546Sopenharmony_ci   0b0000110000000000011,
522bf215546Sopenharmony_ci   0b0000110000000000100,
523bf215546Sopenharmony_ci   0b0000110000000000101,
524bf215546Sopenharmony_ci   0b0000110000000000111,
525bf215546Sopenharmony_ci   0b0000110000000001001,
526bf215546Sopenharmony_ci   0b0000110000000001101,
527bf215546Sopenharmony_ci   0b0000110000000010000,
528bf215546Sopenharmony_ci   0b0000110000100000000,
529bf215546Sopenharmony_ci   0b0001000000000000000,
530bf215546Sopenharmony_ci   0b0001000000000000010,
531bf215546Sopenharmony_ci   0b0001000000000000100,
532bf215546Sopenharmony_ci   0b0001000000100000000,
533bf215546Sopenharmony_ci   0b0010110000000000000,
534bf215546Sopenharmony_ci   0b0010110000000010000,
535bf215546Sopenharmony_ci   0b0011000000000000000,
536bf215546Sopenharmony_ci   0b0011000000100000000,
537bf215546Sopenharmony_ci   0b0101000000000000000,
538bf215546Sopenharmony_ci   0b0101000000100000000,
539bf215546Sopenharmony_ci};
540bf215546Sopenharmony_ci
541bf215546Sopenharmony_cistatic const uint32_t gfx8_datatype_table[32] = {
542bf215546Sopenharmony_ci   0b001000000000000000001,
543bf215546Sopenharmony_ci   0b001000000000001000000,
544bf215546Sopenharmony_ci   0b001000000000001000001,
545bf215546Sopenharmony_ci   0b001000000000011000001,
546bf215546Sopenharmony_ci   0b001000000000101011101,
547bf215546Sopenharmony_ci   0b001000000010111011101,
548bf215546Sopenharmony_ci   0b001000000011101000001,
549bf215546Sopenharmony_ci   0b001000000011101000101,
550bf215546Sopenharmony_ci   0b001000000011101011101,
551bf215546Sopenharmony_ci   0b001000001000001000001,
552bf215546Sopenharmony_ci   0b001000011000001000000,
553bf215546Sopenharmony_ci   0b001000011000001000001,
554bf215546Sopenharmony_ci   0b001000101000101000101,
555bf215546Sopenharmony_ci   0b001000111000101000100,
556bf215546Sopenharmony_ci   0b001000111000101000101,
557bf215546Sopenharmony_ci   0b001011100011101011101,
558bf215546Sopenharmony_ci   0b001011101011100011101,
559bf215546Sopenharmony_ci   0b001011101011101011100,
560bf215546Sopenharmony_ci   0b001011101011101011101,
561bf215546Sopenharmony_ci   0b001011111011101011100,
562bf215546Sopenharmony_ci   0b000000000010000001100,
563bf215546Sopenharmony_ci   0b001000000000001011101,
564bf215546Sopenharmony_ci   0b001000000000101000101,
565bf215546Sopenharmony_ci   0b001000001000001000000,
566bf215546Sopenharmony_ci   0b001000101000101000100,
567bf215546Sopenharmony_ci   0b001000111000100000100,
568bf215546Sopenharmony_ci   0b001001001001000001001,
569bf215546Sopenharmony_ci   0b001010111011101011101,
570bf215546Sopenharmony_ci   0b001011111011101011101,
571bf215546Sopenharmony_ci   0b001001111001101001100,
572bf215546Sopenharmony_ci   0b001001001001001001000,
573bf215546Sopenharmony_ci   0b001001011001001001000,
574bf215546Sopenharmony_ci};
575bf215546Sopenharmony_ci
576bf215546Sopenharmony_cistatic const uint16_t gfx8_subreg_table[32] = {
577bf215546Sopenharmony_ci   0b000000000000000,
578bf215546Sopenharmony_ci   0b000000000000001,
579bf215546Sopenharmony_ci   0b000000000001000,
580bf215546Sopenharmony_ci   0b000000000001111,
581bf215546Sopenharmony_ci   0b000000000010000,
582bf215546Sopenharmony_ci   0b000000010000000,
583bf215546Sopenharmony_ci   0b000000100000000,
584bf215546Sopenharmony_ci   0b000000110000000,
585bf215546Sopenharmony_ci   0b000001000000000,
586bf215546Sopenharmony_ci   0b000001000010000,
587bf215546Sopenharmony_ci   0b000001010000000,
588bf215546Sopenharmony_ci   0b001000000000000,
589bf215546Sopenharmony_ci   0b001000000000001,
590bf215546Sopenharmony_ci   0b001000010000001,
591bf215546Sopenharmony_ci   0b001000010000010,
592bf215546Sopenharmony_ci   0b001000010000011,
593bf215546Sopenharmony_ci   0b001000010000100,
594bf215546Sopenharmony_ci   0b001000010000111,
595bf215546Sopenharmony_ci   0b001000010001000,
596bf215546Sopenharmony_ci   0b001000010001110,
597bf215546Sopenharmony_ci   0b001000010001111,
598bf215546Sopenharmony_ci   0b001000110000000,
599bf215546Sopenharmony_ci   0b001000111101000,
600bf215546Sopenharmony_ci   0b010000000000000,
601bf215546Sopenharmony_ci   0b010000110000000,
602bf215546Sopenharmony_ci   0b011000000000000,
603bf215546Sopenharmony_ci   0b011110010000111,
604bf215546Sopenharmony_ci   0b100000000000000,
605bf215546Sopenharmony_ci   0b101000000000000,
606bf215546Sopenharmony_ci   0b110000000000000,
607bf215546Sopenharmony_ci   0b111000000000000,
608bf215546Sopenharmony_ci   0b111000000011100,
609bf215546Sopenharmony_ci};
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_cistatic const uint16_t gfx8_src_index_table[32] = {
612bf215546Sopenharmony_ci   0b000000000000,
613bf215546Sopenharmony_ci   0b000000000010,
614bf215546Sopenharmony_ci   0b000000010000,
615bf215546Sopenharmony_ci   0b000000010010,
616bf215546Sopenharmony_ci   0b000000011000,
617bf215546Sopenharmony_ci   0b000000100000,
618bf215546Sopenharmony_ci   0b000000101000,
619bf215546Sopenharmony_ci   0b000001001000,
620bf215546Sopenharmony_ci   0b000001010000,
621bf215546Sopenharmony_ci   0b000001110000,
622bf215546Sopenharmony_ci   0b000001111000,
623bf215546Sopenharmony_ci   0b001100000000,
624bf215546Sopenharmony_ci   0b001100000010,
625bf215546Sopenharmony_ci   0b001100001000,
626bf215546Sopenharmony_ci   0b001100010000,
627bf215546Sopenharmony_ci   0b001100010010,
628bf215546Sopenharmony_ci   0b001100100000,
629bf215546Sopenharmony_ci   0b001100101000,
630bf215546Sopenharmony_ci   0b001100111000,
631bf215546Sopenharmony_ci   0b001101000000,
632bf215546Sopenharmony_ci   0b001101000010,
633bf215546Sopenharmony_ci   0b001101001000,
634bf215546Sopenharmony_ci   0b001101010000,
635bf215546Sopenharmony_ci   0b001101100000,
636bf215546Sopenharmony_ci   0b001101101000,
637bf215546Sopenharmony_ci   0b001101110000,
638bf215546Sopenharmony_ci   0b001101110001,
639bf215546Sopenharmony_ci   0b001101111000,
640bf215546Sopenharmony_ci   0b010001101000,
641bf215546Sopenharmony_ci   0b010001101001,
642bf215546Sopenharmony_ci   0b010001101010,
643bf215546Sopenharmony_ci   0b010110001000,
644bf215546Sopenharmony_ci};
645bf215546Sopenharmony_ci
646bf215546Sopenharmony_cistatic const uint32_t gfx11_datatype_table[32] = {
647bf215546Sopenharmony_ci   0b001000000000000000001,
648bf215546Sopenharmony_ci   0b001000000000001000000,
649bf215546Sopenharmony_ci   0b001000000000001000001,
650bf215546Sopenharmony_ci   0b001000000000011000001,
651bf215546Sopenharmony_ci   0b001000000000101100101,
652bf215546Sopenharmony_ci   0b001000000101111100101,
653bf215546Sopenharmony_ci   0b001000000100101000001,
654bf215546Sopenharmony_ci   0b001000000100101000101,
655bf215546Sopenharmony_ci   0b001000000100101100101,
656bf215546Sopenharmony_ci   0b001000001000001000001,
657bf215546Sopenharmony_ci   0b001000011000001000000,
658bf215546Sopenharmony_ci   0b001000011000001000001,
659bf215546Sopenharmony_ci   0b001000101000101000101,
660bf215546Sopenharmony_ci   0b001000111000101000100,
661bf215546Sopenharmony_ci   0b001000111000101000101,
662bf215546Sopenharmony_ci   0b001100100100101100101,
663bf215546Sopenharmony_ci   0b001100101100100100101,
664bf215546Sopenharmony_ci   0b001100101100101100100,
665bf215546Sopenharmony_ci   0b001100101100101100101,
666bf215546Sopenharmony_ci   0b001100111100101100100,
667bf215546Sopenharmony_ci   0b000000000010000001100,
668bf215546Sopenharmony_ci   0b001000000000001100101,
669bf215546Sopenharmony_ci   0b001000000000101000101,
670bf215546Sopenharmony_ci   0b001000001000001000000,
671bf215546Sopenharmony_ci   0b001000101000101000100,
672bf215546Sopenharmony_ci   0b001000111000100000100,
673bf215546Sopenharmony_ci   0b001001001001000001001,
674bf215546Sopenharmony_ci   0b001101111100101100101,
675bf215546Sopenharmony_ci   0b001100111100101100101,
676bf215546Sopenharmony_ci   0b001001111001101001100,
677bf215546Sopenharmony_ci   0b001001001001001001000,
678bf215546Sopenharmony_ci   0b001001011001001001000,
679bf215546Sopenharmony_ci};
680bf215546Sopenharmony_ci
681bf215546Sopenharmony_cistatic const uint32_t gfx12_control_index_table[32] = {
682bf215546Sopenharmony_ci   0b000000000000000000100, /* 	       (16|M0)                            */
683bf215546Sopenharmony_ci   0b000000000000000000011, /* 	       (8|M0)                             */
684bf215546Sopenharmony_ci   0b000000010000000000000, /* 	(W)    (1|M0)                             */
685bf215546Sopenharmony_ci   0b000000010000000000100, /* 	(W)    (16|M0)                            */
686bf215546Sopenharmony_ci   0b000000010000000000011, /* 	(W)    (8|M0)                             */
687bf215546Sopenharmony_ci   0b010000000000000000100, /* 	       (16|M0)  (ge)f0.0                  */
688bf215546Sopenharmony_ci   0b000000000000000100100, /* 	       (16|M16)                           */
689bf215546Sopenharmony_ci   0b010100000000000000100, /* 	       (16|M0)  (lt)f0.0                  */
690bf215546Sopenharmony_ci   0b000000000000000000000, /* 	       (1|M0)                             */
691bf215546Sopenharmony_ci   0b000010000000000000100, /* 	       (16|M0)           (sat)            */
692bf215546Sopenharmony_ci   0b000000000000000010011, /* 	       (8|M8)                             */
693bf215546Sopenharmony_ci   0b001100000000000000100, /* 	       (16|M0)  (gt)f0.0                  */
694bf215546Sopenharmony_ci   0b000100000000000000100, /* 	       (16|M0)  (eq)f0.0                  */
695bf215546Sopenharmony_ci   0b000100010000000000100, /* 	(W)    (16|M0)  (eq)f0.0                  */
696bf215546Sopenharmony_ci   0b001000000000000000100, /* 	       (16|M0)  (ne)f0.0                  */
697bf215546Sopenharmony_ci   0b000000000000100000100, /* 	(f0.0) (16|M0)                            */
698bf215546Sopenharmony_ci   0b010100000000000000011, /* 	       (8|M0)   (lt)f0.0                  */
699bf215546Sopenharmony_ci   0b000000000000110000100, /* 	(f1.0) (16|M0)                            */
700bf215546Sopenharmony_ci   0b000000010000000000001, /* 	(W)    (2|M0)                             */
701bf215546Sopenharmony_ci   0b000000000000101000100, /* 	(f0.1) (16|M0)                            */
702bf215546Sopenharmony_ci   0b000000000000111000100, /* 	(f1.1) (16|M0)                            */
703bf215546Sopenharmony_ci   0b010000010000000000100, /* 	(W)    (16|M0)  (ge)f0.0                  */
704bf215546Sopenharmony_ci   0b000000000000000100011, /* 	       (8|M16)                            */
705bf215546Sopenharmony_ci   0b000000000000000110011, /* 	       (8|M24)                            */
706bf215546Sopenharmony_ci   0b010100010000000000100, /* 	(W)    (16|M0)  (lt)f0.0                  */
707bf215546Sopenharmony_ci   0b010000000000000000011, /* 	       (8|M0)   (ge)f0.0                  */
708bf215546Sopenharmony_ci   0b000100010000000000000, /* 	(W)    (1|M0)   (eq)f0.0                  */
709bf215546Sopenharmony_ci   0b000010000000000000011, /* 	       (8|M0)            (sat)            */
710bf215546Sopenharmony_ci   0b010100000000010000100, /* 	       (16|M0)  (lt)f1.0                  */
711bf215546Sopenharmony_ci   0b000100000000000000011, /* 	       (8|M0)   (eq)f0.0                  */
712bf215546Sopenharmony_ci   0b000001000000000000011, /* 	       (8|M0)                   {AccWrEn} */
713bf215546Sopenharmony_ci   0b000000010000000100100, /* 	(W)    (16|M16)                           */
714bf215546Sopenharmony_ci};
715bf215546Sopenharmony_ci
716bf215546Sopenharmony_cistatic const uint32_t gfx12_datatype_table[32] = {
717bf215546Sopenharmony_ci   0b11010110100101010100, /* grf<1>:f  grf:f  grf:f  */
718bf215546Sopenharmony_ci   0b00000110100101010100, /* grf<1>:f  grf:f  arf:ub */
719bf215546Sopenharmony_ci   0b00000010101101010100, /* grf<1>:f  imm:f  arf:ub */
720bf215546Sopenharmony_ci   0b01010110110101010100, /* grf<1>:f  grf:f  imm:f  */
721bf215546Sopenharmony_ci   0b11010100100101010100, /* arf<1>:f  grf:f  grf:f  */
722bf215546Sopenharmony_ci   0b11010010100101010100, /* grf<1>:f  arf:f  grf:f  */
723bf215546Sopenharmony_ci   0b01010100110101010100, /* arf<1>:f  grf:f  imm:f  */
724bf215546Sopenharmony_ci   0b00000000100000000000, /* arf<1>:ub arf:ub arf:ub */
725bf215546Sopenharmony_ci   0b11010000100101010100, /* arf<1>:f  arf:f  grf:f  */
726bf215546Sopenharmony_ci   0b00101110110011001100, /* grf<1>:d  grf:d  imm:w  */
727bf215546Sopenharmony_ci   0b10110110100011001100, /* grf<1>:d  grf:d  grf:d  */
728bf215546Sopenharmony_ci   0b01010010110101010100, /* grf<1>:f  arf:f  imm:f  */
729bf215546Sopenharmony_ci   0b10010110100001000100, /* grf<1>:ud grf:ud grf:ud */
730bf215546Sopenharmony_ci   0b01010000110101010100, /* arf<1>:f  arf:f  imm:f  */
731bf215546Sopenharmony_ci   0b00110110110011001100, /* grf<1>:d  grf:d  imm:d  */
732bf215546Sopenharmony_ci   0b00010110110001000100, /* grf<1>:ud grf:ud imm:ud */
733bf215546Sopenharmony_ci   0b00000111000101010100, /* grf<2>:f  grf:f  arf:ub */
734bf215546Sopenharmony_ci   0b00101100110011001100, /* arf<1>:d  grf:d  imm:w  */
735bf215546Sopenharmony_ci   0b00000000100000100010, /* arf<1>:uw arf:uw arf:ub */
736bf215546Sopenharmony_ci   0b00000010100001000100, /* grf<1>:ud arf:ud arf:ub */
737bf215546Sopenharmony_ci   0b00100110110000101010, /* grf<1>:w  grf:uw imm:uv */
738bf215546Sopenharmony_ci   0b00001110110000100010, /* grf<1>:uw grf:uw imm:uw */
739bf215546Sopenharmony_ci   0b10010111000001000100, /* grf<2>:ud grf:ud grf:ud */
740bf215546Sopenharmony_ci   0b00000110100101001100, /* grf<1>:d  grf:f  arf:ub */
741bf215546Sopenharmony_ci   0b10001100100011001100, /* arf<1>:d  grf:d  grf:uw */
742bf215546Sopenharmony_ci   0b00000110100001010100, /* grf<1>:f  grf:ud arf:ub */
743bf215546Sopenharmony_ci   0b00101110110001001100, /* grf<1>:d  grf:ud imm:w  */
744bf215546Sopenharmony_ci   0b00000010100000100010, /* grf<1>:uw arf:uw arf:ub */
745bf215546Sopenharmony_ci   0b00000110100000110100, /* grf<1>:f  grf:uw arf:ub */
746bf215546Sopenharmony_ci   0b00000110100000010100, /* grf<1>:f  grf:ub arf:ub */
747bf215546Sopenharmony_ci   0b00000110100011010100, /* grf<1>:f  grf:d  arf:ub */
748bf215546Sopenharmony_ci   0b00000010100101010100, /* grf<1>:f  arf:f  arf:ub */
749bf215546Sopenharmony_ci};
750bf215546Sopenharmony_ci
751bf215546Sopenharmony_cistatic const uint16_t gfx12_subreg_table[32] = {
752bf215546Sopenharmony_ci   0b000000000000000, /* .0  .0  .0  */
753bf215546Sopenharmony_ci   0b100000000000000, /* .0  .0  .16 */
754bf215546Sopenharmony_ci   0b001000000000000, /* .0  .0  .4  */
755bf215546Sopenharmony_ci   0b011000000000000, /* .0  .0  .12 */
756bf215546Sopenharmony_ci   0b000000010000000, /* .0  .4  .0  */
757bf215546Sopenharmony_ci   0b010000000000000, /* .0  .0  .8  */
758bf215546Sopenharmony_ci   0b101000000000000, /* .0  .0  .20 */
759bf215546Sopenharmony_ci   0b000000000001000, /* .8  .0  .0  */
760bf215546Sopenharmony_ci   0b000000100000000, /* .0  .8  .0  */
761bf215546Sopenharmony_ci   0b110000000000000, /* .0  .0  .24 */
762bf215546Sopenharmony_ci   0b111000000000000, /* .0  .0  .28 */
763bf215546Sopenharmony_ci   0b000001000000000, /* .0  .16 .0  */
764bf215546Sopenharmony_ci   0b000000000000100, /* .4  .0  .0  */
765bf215546Sopenharmony_ci   0b000001100000000, /* .0  .24 .0  */
766bf215546Sopenharmony_ci   0b000001010000000, /* .0  .20 .0  */
767bf215546Sopenharmony_ci   0b000000110000000, /* .0  .12 .0  */
768bf215546Sopenharmony_ci   0b000001110000000, /* .0  .28 .0  */
769bf215546Sopenharmony_ci   0b000000000011100, /* .28 .0  .0  */
770bf215546Sopenharmony_ci   0b000000000010000, /* .16 .0  .0  */
771bf215546Sopenharmony_ci   0b000000000001100, /* .12 .0  .0  */
772bf215546Sopenharmony_ci   0b000000000011000, /* .24 .0  .0  */
773bf215546Sopenharmony_ci   0b000000000010100, /* .20 .0  .0  */
774bf215546Sopenharmony_ci   0b000000000000010, /* .2  .0  .0  */
775bf215546Sopenharmony_ci   0b000000101000000, /* .0  .10 .0  */
776bf215546Sopenharmony_ci   0b000000001000000, /* .0  .2  .0  */
777bf215546Sopenharmony_ci   0b000000010000100, /* .4  .4  .0  */
778bf215546Sopenharmony_ci   0b000000001011100, /* .28 .2  .0  */
779bf215546Sopenharmony_ci   0b000000001000010, /* .2  .2  .0  */
780bf215546Sopenharmony_ci   0b000000110001100, /* .12 .12 .0  */
781bf215546Sopenharmony_ci   0b000000000100000, /* .0  .1  .0  */
782bf215546Sopenharmony_ci   0b000000001100000, /* .0  .3  .0  */
783bf215546Sopenharmony_ci   0b110001100000000, /* .0  .24 .24 */
784bf215546Sopenharmony_ci};
785bf215546Sopenharmony_ci
786bf215546Sopenharmony_cistatic const uint16_t gfx12_src0_index_table[16] = {
787bf215546Sopenharmony_ci   0b010001100100, /*       r<8;8,1>  */
788bf215546Sopenharmony_ci   0b000000000000, /*       r<0;1,0>  */
789bf215546Sopenharmony_ci   0b010001100110, /*      -r<8;8,1>  */
790bf215546Sopenharmony_ci   0b010001100101, /*  (abs)r<8;8,1>  */
791bf215546Sopenharmony_ci   0b000000000010, /*      -r<0;1,0>  */
792bf215546Sopenharmony_ci   0b001000000000, /*       r<2;1,0>  */
793bf215546Sopenharmony_ci   0b001001000000, /*       r<2;4,0>  */
794bf215546Sopenharmony_ci   0b001101000000, /*       r<4;4,0>  */
795bf215546Sopenharmony_ci   0b001000100100, /*       r<2;2,1>  */
796bf215546Sopenharmony_ci   0b001100000000, /*       r<4;1,0>  */
797bf215546Sopenharmony_ci   0b001000100110, /*      -r<2;2,1>  */
798bf215546Sopenharmony_ci   0b001101000100, /*       r<4;4,1>  */
799bf215546Sopenharmony_ci   0b010001100111, /* -(abs)r<8;8,1>  */
800bf215546Sopenharmony_ci   0b000100000000, /*       r<1;1,0>  */
801bf215546Sopenharmony_ci   0b000000000001, /*  (abs)r<0;1,0>  */
802bf215546Sopenharmony_ci   0b111100010000, /*       r[a]<1,0> */
803bf215546Sopenharmony_ci};
804bf215546Sopenharmony_ci
805bf215546Sopenharmony_cistatic const uint16_t gfx12_src1_index_table[16] = {
806bf215546Sopenharmony_ci   0b000100011001, /*       r<8;8,1> */
807bf215546Sopenharmony_ci   0b000000000000, /*       r<0;1,0> */
808bf215546Sopenharmony_ci   0b100100011001, /*      -r<8;8,1> */
809bf215546Sopenharmony_ci   0b100000000000, /*      -r<0;1,0> */
810bf215546Sopenharmony_ci   0b010100011001, /*  (abs)r<8;8,1> */
811bf215546Sopenharmony_ci   0b100011010000, /*      -r<4;4,0> */
812bf215546Sopenharmony_ci   0b000010000000, /*       r<2;1,0> */
813bf215546Sopenharmony_ci   0b000010001001, /*       r<2;2,1> */
814bf215546Sopenharmony_ci   0b100010001001, /*      -r<2;2,1> */
815bf215546Sopenharmony_ci   0b000011010000, /*       r<4;4,0> */
816bf215546Sopenharmony_ci   0b000011010001, /*       r<4;4,1> */
817bf215546Sopenharmony_ci   0b000011000000, /*       r<4;1,0> */
818bf215546Sopenharmony_ci   0b110100011001, /* -(abs)r<8;8,1> */
819bf215546Sopenharmony_ci   0b010000000000, /*  (abs)r<0;1,0> */
820bf215546Sopenharmony_ci   0b110000000000, /* -(abs)r<0;1,0> */
821bf215546Sopenharmony_ci   0b100011010001, /*      -r<4;4,1> */
822bf215546Sopenharmony_ci};
823bf215546Sopenharmony_ci
824bf215546Sopenharmony_cistatic const uint16_t xehp_src0_index_table[16] = {
825bf215546Sopenharmony_ci   0b000100000000, /*       r<1;1,0>  */
826bf215546Sopenharmony_ci   0b000000000000, /*       r<0;1,0>  */
827bf215546Sopenharmony_ci   0b000100000010, /*      -r<1;1,0>  */
828bf215546Sopenharmony_ci   0b000100000001, /*  (abs)r<1;1,0>  */
829bf215546Sopenharmony_ci   0b000000000010, /*      -r<0;1,0>  */
830bf215546Sopenharmony_ci   0b001000000000, /*       r<2;1,0>  */
831bf215546Sopenharmony_ci   0b001001000000, /*       r<2;4,0>  */
832bf215546Sopenharmony_ci   0b001101000000, /*       r<4;4,0>  */
833bf215546Sopenharmony_ci   0b001100000000, /*       r<4;1,0>  */
834bf215546Sopenharmony_ci   0b000100000011, /* -(abs)r<1;1,0>  */
835bf215546Sopenharmony_ci   0b000000000001, /*  (abs)r<0;1,0>  */
836bf215546Sopenharmony_ci   0b111100010000, /*       r[a]<1,0> */
837bf215546Sopenharmony_ci   0b010001100000, /*       r<8;8,0>  */
838bf215546Sopenharmony_ci   0b000101000000, /*       r<1;4,0>  */
839bf215546Sopenharmony_ci   0b010001001000, /*       r<8;4,2>  */
840bf215546Sopenharmony_ci   0b001000000010, /*      -r<2;1,0>  */
841bf215546Sopenharmony_ci};
842bf215546Sopenharmony_ci
843bf215546Sopenharmony_cistatic const uint16_t xehp_src1_index_table[16] = {
844bf215546Sopenharmony_ci   0b000001000000, /*       r<1;1,0>    */
845bf215546Sopenharmony_ci   0b000000000000, /*       r<0;1,0>    */
846bf215546Sopenharmony_ci   0b100001000000, /*      -r<1;1,0>    */
847bf215546Sopenharmony_ci   0b100000000000, /*      -r<0;1,0>    */
848bf215546Sopenharmony_ci   0b010001000000, /*  (abs)r<1;1,0>    */
849bf215546Sopenharmony_ci   0b100011010000, /*      -r<4;4,0>    */
850bf215546Sopenharmony_ci   0b000010000000, /*       r<2;1,0>    */
851bf215546Sopenharmony_ci   0b000011010000, /*       r<4;4,0>    */
852bf215546Sopenharmony_ci   0b000011000000, /*       r<4;1,0>    */
853bf215546Sopenharmony_ci   0b110001000000, /* -(abs)r<1;1,0>    */
854bf215546Sopenharmony_ci   0b010000000000, /*  (abs)r<0;1,0>    */
855bf215546Sopenharmony_ci   0b110000000000, /* -(abs)r<0;1,0>    */
856bf215546Sopenharmony_ci   0b000100011000, /*       r<8;8,0>    */
857bf215546Sopenharmony_ci   0b100010000000, /*      -r<2;1,0>    */
858bf215546Sopenharmony_ci   0b100000001001, /*      -r<0;2,1>    */
859bf215546Sopenharmony_ci   0b100001000100, /*      -r[a]<1;1,0> */
860bf215546Sopenharmony_ci};
861bf215546Sopenharmony_ci
862bf215546Sopenharmony_ci/* This is actually the control index table for Cherryview (26 bits), but the
863bf215546Sopenharmony_ci * only difference from Broadwell (24 bits) is that it has two extra 0-bits at
864bf215546Sopenharmony_ci * the start.
865bf215546Sopenharmony_ci *
866bf215546Sopenharmony_ci * The low 24 bits have the same mappings on both hardware.
867bf215546Sopenharmony_ci */
868bf215546Sopenharmony_cistatic const uint32_t gfx8_3src_control_index_table[4] = {
869bf215546Sopenharmony_ci   0b00100000000110000000000001,
870bf215546Sopenharmony_ci   0b00000000000110000000000001,
871bf215546Sopenharmony_ci   0b00000000001000000000000001,
872bf215546Sopenharmony_ci   0b00000000001000000000100001,
873bf215546Sopenharmony_ci};
874bf215546Sopenharmony_ci
875bf215546Sopenharmony_ci/* This is actually the control index table for Cherryview (49 bits), but the
876bf215546Sopenharmony_ci * only difference from Broadwell (46 bits) is that it has three extra 0-bits
877bf215546Sopenharmony_ci * at the start.
878bf215546Sopenharmony_ci *
879bf215546Sopenharmony_ci * The low 44 bits have the same mappings on both hardware, and since the high
880bf215546Sopenharmony_ci * three bits on Broadwell are zero, we can reuse Cherryview's table.
881bf215546Sopenharmony_ci */
882bf215546Sopenharmony_cistatic const uint64_t gfx8_3src_source_index_table[4] = {
883bf215546Sopenharmony_ci   0b0000001110010011100100111001000001111000000000000,
884bf215546Sopenharmony_ci   0b0000001110010011100100111001000001111000000000010,
885bf215546Sopenharmony_ci   0b0000001110010011100100111001000001111000000001000,
886bf215546Sopenharmony_ci   0b0000001110010011100100111001000001111000000100000,
887bf215546Sopenharmony_ci};
888bf215546Sopenharmony_ci
889bf215546Sopenharmony_cistatic const uint64_t gfx12_3src_control_index_table[32] = {
890bf215546Sopenharmony_ci   0b000001001010010101000000000000000100, /*      (16|M0)       grf<1>:f   :f  :f  :f */
891bf215546Sopenharmony_ci   0b000001001010010101000000000000000011, /*      (8|M0)        grf<1>:f   :f  :f  :f */
892bf215546Sopenharmony_ci   0b000001001000010101000000000000000011, /*      (8|M0)        arf<1>:f   :f  :f  :f */
893bf215546Sopenharmony_ci   0b000001001010010101000010000000000011, /* (W)  (8|M0)        grf<1>:f   :f  :f  :f */
894bf215546Sopenharmony_ci   0b000001001000010101000010000000000011, /* (W)  (8|M0)        arf<1>:f   :f  :f  :f */
895bf215546Sopenharmony_ci   0b000001001000010101000000000000010011, /*      (8|M8)        arf<1>:f   :f  :f  :f */
896bf215546Sopenharmony_ci   0b000001001010010101000000000000010011, /*      (8|M8)        grf<1>:f   :f  :f  :f */
897bf215546Sopenharmony_ci   0b000001001000010101000010000000010011, /* (W)  (8|M8)        arf<1>:f   :f  :f  :f */
898bf215546Sopenharmony_ci   0b000001001010010101000010000000010011, /* (W)  (8|M8)        grf<1>:f   :f  :f  :f */
899bf215546Sopenharmony_ci   0b000001001010010101000010000000000100, /* (W)  (16|M0)       grf<1>:f   :f  :f  :f */
900bf215546Sopenharmony_ci   0b000001001000010101000000000000000100, /*      (16|M0)       arf<1>:f   :f  :f  :f */
901bf215546Sopenharmony_ci   0b000001001010010101010000000000000100, /*      (16|M0)  (sat)grf<1>:f   :f  :f  :f */
902bf215546Sopenharmony_ci   0b000001001010010101000000000000100100, /*      (16|M16)      grf<1>:f   :f  :f  :f */
903bf215546Sopenharmony_ci   0b000001001000010101000010000000000100, /* (W)  (16|M0)       arf<1>:f   :f  :f  :f */
904bf215546Sopenharmony_ci   0b000001001010010101000010000000000000, /* (W)  (1|M0)        grf<1>:f   :f  :f  :f */
905bf215546Sopenharmony_ci   0b000001001010010101010000000000000011, /*      (8|M0)   (sat)grf<1>:f   :f  :f  :f */
906bf215546Sopenharmony_ci   0b000001001000010101000010000000110011, /* (W)  (8|M24)       arf<1>:f   :f  :f  :f */
907bf215546Sopenharmony_ci   0b000001001000010101000010000000100011, /* (W)  (8|M16)       arf<1>:f   :f  :f  :f */
908bf215546Sopenharmony_ci   0b000001001010010101000010000000110011, /* (W)  (8|M24)       grf<1>:f   :f  :f  :f */
909bf215546Sopenharmony_ci   0b000001001010010101000010000000100011, /* (W)  (8|M16)       grf<1>:f   :f  :f  :f */
910bf215546Sopenharmony_ci   0b000001001000010101000000000000100011, /*      (8|M16)       arf<1>:f   :f  :f  :f */
911bf215546Sopenharmony_ci   0b000001001000010101000000000000110011, /*      (8|M24)       arf<1>:f   :f  :f  :f */
912bf215546Sopenharmony_ci   0b000001001010010101000000000000100011, /*      (8|M16)       grf<1>:f   :f  :f  :f */
913bf215546Sopenharmony_ci   0b000001001010010101000000000000110011, /*      (8|M24)       grf<1>:f   :f  :f  :f */
914bf215546Sopenharmony_ci   0b000001001000010101010000000000000100, /*      (16|M0)  (sat)arf<1>:f   :f  :f  :f */
915bf215546Sopenharmony_ci   0b000001001010010101010010000000000100, /* (W)  (16|M0)  (sat)grf<1>:f   :f  :f  :f */
916bf215546Sopenharmony_ci   0b000001001010010101000010000000100100, /* (W)  (16|M16)      grf<1>:f   :f  :f  :f */
917bf215546Sopenharmony_ci   0b000001001010010001000010000000000000, /* (W)  (1|M0)        grf<1>:ud :ud :ud :ud */
918bf215546Sopenharmony_ci   0b000001001000010101000000000000100100, /*      (16|M16)      arf<1>:f   :f  :f  :f */
919bf215546Sopenharmony_ci   0b000001001010010101010000000000100100, /*      (16|M16) (sat)grf<1>:f   :f  :f  :f */
920bf215546Sopenharmony_ci   0b000001001010010101000010000000000010, /* (W)  (4|M0)        grf<1>:f   :f  :f  :f */
921bf215546Sopenharmony_ci   0b000001001000010101010000000000000011, /*      (8|M0)   (sat)arf<1>:f   :f  :f  :f */
922bf215546Sopenharmony_ci};
923bf215546Sopenharmony_ci
924bf215546Sopenharmony_cistatic const uint64_t xehp_3src_control_index_table[32] = {
925bf215546Sopenharmony_ci   0b0000010010100010101000000000000000100, /*          (16|M0)       grf<1>:f   :f   :f   :f          */
926bf215546Sopenharmony_ci   0b0000010010100010101000000000000000011, /*          (8|M0)        grf<1>:f   :f   :f   :f          */
927bf215546Sopenharmony_ci   0b0000010010000010101000000000000000011, /*          (8|M0)        arf<1>:f   :f   :f   :f          */
928bf215546Sopenharmony_ci   0b0000010010100010101000010000000000011, /*     (W)  (8|M0)        grf<1>:f   :f   :f   :f          */
929bf215546Sopenharmony_ci   0b0000010010000010101000010000000000011, /*     (W)  (8|M0)        arf<1>:f   :f   :f   :f          */
930bf215546Sopenharmony_ci   0b0000010010000010101000000000000010011, /*          (8|M8)        arf<1>:f   :f   :f   :f          */
931bf215546Sopenharmony_ci   0b0000010010100010101000000000000010011, /*          (8|M8)        grf<1>:f   :f   :f   :f          */
932bf215546Sopenharmony_ci   0b0000010010000010101000010000000010011, /*     (W)  (8|M8)        arf<1>:f   :f   :f   :f          */
933bf215546Sopenharmony_ci   0b0000010010100010101000010000000010011, /*     (W)  (8|M8)        grf<1>:f   :f   :f   :f          */
934bf215546Sopenharmony_ci   0b0000010010100010101000010000000000100, /*     (W)  (16|M0)       grf<1>:f   :f   :f   :f          */
935bf215546Sopenharmony_ci   0b0000010010000010101000000000000000100, /*          (16|M0)       arf<1>:f   :f   :f   :f          */
936bf215546Sopenharmony_ci   0b0000010010100010101010000000000000100, /*          (16|M0)  (sat)grf<1>:f   :f   :f   :f          */
937bf215546Sopenharmony_ci   0b0000010010100010101000000000000100100, /*          (16|M16)      grf<1>:f   :f   :f   :f          */
938bf215546Sopenharmony_ci   0b0000010010000010101000010000000000100, /*     (W)  (16|M0)       arf<1>:f   :f   :f   :f          */
939bf215546Sopenharmony_ci   0b0000010010100010101000010000000000000, /*     (W)  (1|M0)        grf<1>:f   :f   :f   :f          */
940bf215546Sopenharmony_ci   0b0000010010100010101010000000000000011, /*          (8|M0)   (sat)grf<1>:f   :f   :f   :f          */
941bf215546Sopenharmony_ci   0b0000010010000010101000010000000100011, /*     (W)  (8|M16)       arf<1>:f   :f   :f   :f          */
942bf215546Sopenharmony_ci   0b0000010010000010101000010000000110011, /*     (W)  (8|M24)       arf<1>:f   :f   :f   :f          */
943bf215546Sopenharmony_ci   0b0000010010100010101000010000000100011, /*     (W)  (8|M16)       grf<1>:f   :f   :f   :f          */
944bf215546Sopenharmony_ci   0b0000010010100010101000010000000110011, /*     (W)  (8|M24)       grf<1>:f   :f   :f   :f          */
945bf215546Sopenharmony_ci   0b0000010010000010101000000000000110011, /*          (8|M24)       arf<1>:f   :f   :f   :f          */
946bf215546Sopenharmony_ci   0b0000010010000010101000000000000100011, /*          (8|M16)       arf<1>:f   :f   :f   :f          */
947bf215546Sopenharmony_ci   0b0000000100111110011000000000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d  :ub   :b          */
948bf215546Sopenharmony_ci   0b0000000000111110011000100000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d  :ub  :ub {Atomic} */
949bf215546Sopenharmony_ci   0b0000100100111110011000100000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d   :b   :b {Atomic} */
950bf215546Sopenharmony_ci   0b0000100000111110011000100000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d   :b  :ub {Atomic} */
951bf215546Sopenharmony_ci   0b0000100100111110011000000000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d   :b   :b          */
952bf215546Sopenharmony_ci   0b0000000000111110011000000000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d  :ub  :ub          */
953bf215546Sopenharmony_ci   0b0000000100111110011000100000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d  :ub   :b {Atomic} */
954bf215546Sopenharmony_ci   0b0000100000111110011000000000000000011, /* dpas.8x* (8|M0)        grf<1>:d   :d   :b  :ub          */
955bf215546Sopenharmony_ci   0b0000101101111010101000100000000000011, /* dpas.8x* (8|M0)        grf<1>:f   :f  :bf  :bf {Atomic} */
956bf215546Sopenharmony_ci   0b0000101101111010101000000000000000011, /* dpas.8x* (8|M0)        grf<1>:f   :f  :bf  :bf          */
957bf215546Sopenharmony_ci};
958bf215546Sopenharmony_ci
959bf215546Sopenharmony_cistatic const uint32_t gfx12_3src_source_index_table[32] = {
960bf215546Sopenharmony_ci   0b100101100001100000000, /*  grf<0;0>   grf<8;1>  grf<0> */
961bf215546Sopenharmony_ci   0b100101100001001000010, /*  arf<4;1>   grf<8;1>  grf<0> */
962bf215546Sopenharmony_ci   0b101101100001101000011, /*  grf<8;1>   grf<8;1>  grf<1> */
963bf215546Sopenharmony_ci   0b100101100001101000011, /*  grf<8;1>   grf<8;1>  grf<0> */
964bf215546Sopenharmony_ci   0b101100000000101000011, /*  grf<8;1>   grf<0;0>  grf<1> */
965bf215546Sopenharmony_ci   0b101101100001101001011, /* -grf<8;1>   grf<8;1>  grf<1> */
966bf215546Sopenharmony_ci   0b101001100001101000011, /*  grf<8;1>   arf<8;1>  grf<1> */
967bf215546Sopenharmony_ci   0b100001100001100000000, /*  grf<0;0>   arf<8;1>  grf<0> */
968bf215546Sopenharmony_ci   0b101101100001100000000, /*  grf<0;0>   grf<8;1>  grf<1> */
969bf215546Sopenharmony_ci   0b101101100101101000011, /*  grf<8;1>   grf<8;1> -grf<1> */
970bf215546Sopenharmony_ci   0b101101110001101000011, /*  grf<8;1>  -grf<8;1>  grf<1> */
971bf215546Sopenharmony_ci   0b101100000000100000000, /*  grf<0;0>   grf<0;0>  grf<1> */
972bf215546Sopenharmony_ci   0b100001100001101000011, /*  grf<8;1>   arf<8;1>  grf<0> */
973bf215546Sopenharmony_ci   0b100101110001100000000, /*  grf<0;0>  -grf<8;1>  grf<0> */
974bf215546Sopenharmony_ci   0b100101110001101000011, /*  grf<8;1>  -grf<8;1>  grf<0> */
975bf215546Sopenharmony_ci   0b100101100001101001011, /* -grf<8;1>   grf<8;1>  grf<0> */
976bf215546Sopenharmony_ci   0b100100000000101000011, /*  grf<8;1>   grf<0;0>  grf<0> */
977bf215546Sopenharmony_ci   0b100101100001100001000, /* -grf<0;0>   grf<8;1>  grf<0> */
978bf215546Sopenharmony_ci   0b100100000000100000000, /*  grf<0;0>   grf<0;0>  grf<0> */
979bf215546Sopenharmony_ci   0b101101110001100000000, /*  grf<0;0>  -grf<8;1>  grf<1> */
980bf215546Sopenharmony_ci   0b100101100101100000000, /*  grf<0;0>   grf<8;1> -grf<0> */
981bf215546Sopenharmony_ci   0b101001100001100000000, /*  grf<0;0>   arf<8;1>  grf<1> */
982bf215546Sopenharmony_ci   0b100101100101101000011, /*  grf<8;1>   grf<8;1> -grf<0> */
983bf215546Sopenharmony_ci   0b101101100101101001011, /* -grf<8;1>   grf<8;1> -grf<1> */
984bf215546Sopenharmony_ci   0b101001100001101001011, /* -grf<8;1>   arf<8;1>  grf<1> */
985bf215546Sopenharmony_ci   0b101101110001101001011, /* -grf<8;1>  -grf<8;1>  grf<1> */
986bf215546Sopenharmony_ci   0b101100010000101000011, /*  grf<8;1>  -grf<0;0>  grf<1> */
987bf215546Sopenharmony_ci   0b101100000100101000011, /*  grf<8;1>   grf<0;0> -grf<1> */
988bf215546Sopenharmony_ci   0b101101100001100001000, /* -grf<0;0>   grf<8;1>  grf<1> */
989bf215546Sopenharmony_ci   0b101101100101100000000, /*  grf<0;0>   grf<8;1> -grf<1> */
990bf215546Sopenharmony_ci   0b100100000100101000011, /*  grf<8;1>   grf<0;0> -grf<0> */
991bf215546Sopenharmony_ci   0b101001100101101000011, /*  grf<8;1>   arf<8;1> -grf<1> */
992bf215546Sopenharmony_ci};
993bf215546Sopenharmony_ci
994bf215546Sopenharmony_cistatic const uint32_t xehp_3src_source_index_table[32] = {
995bf215546Sopenharmony_ci   0b100100000001100000000, /*           grf<0;0>   grf<1;0>     grf<0>      */
996bf215546Sopenharmony_ci   0b100100000001000000001, /*           arf<1;0>   grf<1;0>     grf<0>      */
997bf215546Sopenharmony_ci   0b101100000001100000001, /*           grf<1;0>   grf<1;0>     grf<1>      */
998bf215546Sopenharmony_ci   0b100100000001100000001, /*           grf<1;0>   grf<1;0>     grf<0>      */
999bf215546Sopenharmony_ci   0b101100000000100000001, /*           grf<1;0>   grf<0;0>     grf<1>      */
1000bf215546Sopenharmony_ci   0b101100000001100001001, /*          -grf<1;0>   grf<1;0>     grf<1>      */
1001bf215546Sopenharmony_ci   0b101000000001100000001, /*           grf<1;0>   arf<1;0>     grf<1>      */
1002bf215546Sopenharmony_ci   0b101100000001100000000, /*           grf<0;0>   grf<1;0>     grf<1>      */
1003bf215546Sopenharmony_ci   0b100000000001100000000, /*           grf<0;0>   arf<1;0>     grf<0>      */
1004bf215546Sopenharmony_ci   0b101100000101100000001, /*           grf<1;0>   grf<1;0>    -grf<1>      */
1005bf215546Sopenharmony_ci   0b101100010001100000001, /*           grf<1;0>  -grf<1;0>     grf<1>      */
1006bf215546Sopenharmony_ci   0b101100000000100000000, /*           grf<0;0>   grf<0;0>     grf<1>      */
1007bf215546Sopenharmony_ci   0b100000000001100000001, /*           grf<1;0>   arf<1;0>     grf<0>      */
1008bf215546Sopenharmony_ci   0b100100010001100000000, /*           grf<0;0>  -grf<1;0>     grf<0>      */
1009bf215546Sopenharmony_ci   0b100100010001100000001, /*           grf<1;0>  -grf<1;0>     grf<0>      */
1010bf215546Sopenharmony_ci   0b100100000001100001001, /*          -grf<1;0>   grf<1;0>     grf<0>      */
1011bf215546Sopenharmony_ci   0b100100000000100000001, /*           grf<1;0>   grf<0;0>     grf<0>      */
1012bf215546Sopenharmony_ci   0b100100000001100001000, /*          -grf<0;0>   grf<1;0>     grf<0>      */
1013bf215546Sopenharmony_ci   0b100100000000100000000, /*           grf<0;0>   grf<0;0>     grf<0>
1014bf215546Sopenharmony_ci                             * dpas.*x1  grf:d      grf:[ub,b]   grf:[ub,b]
1015bf215546Sopenharmony_ci                             * dpas.*x1  grf:f      grf:bf       grf:bf
1016bf215546Sopenharmony_ci                             */
1017bf215546Sopenharmony_ci   0b101100010001100000000, /*           grf<0;0>  -grf<1;0>     grf<1>      */
1018bf215546Sopenharmony_ci   0b100100000101100000000, /*           grf<0;0>   grf<1;0>    -grf<0>      */
1019bf215546Sopenharmony_ci   0b101000000001100000000, /*           grf<0;0>   arf<1;0>     grf<1>      */
1020bf215546Sopenharmony_ci   0b100100000101100000001, /*           grf<1;0>   grf<1;0>    -grf<0>      */
1021bf215546Sopenharmony_ci   0b101100000101100001001, /*          -grf<1;0>   grf<1;0>    -grf<1>      */
1022bf215546Sopenharmony_ci   0b100100010000100000000, /* dpas.*x1  grf:d      grf:[u2,s2]  grf:[ub,b]  */
1023bf215546Sopenharmony_ci   0b100100000100100000000, /* dpas.*x1  grf:d      grf:[ub,b]   grf:[u2,s2] */
1024bf215546Sopenharmony_ci   0b100100010100100000000, /* dpas.*x1  grf:d      grf:[u2,s2]  grf:[u2,s2] */
1025bf215546Sopenharmony_ci   0b100100001000100000000, /* dpas.*x1  grf:d      grf:[u4,s4]  grf:[ub,b]  */
1026bf215546Sopenharmony_ci   0b100100001100100000000, /* dpas.*x1  grf:d      grf:[u4,s4]  grf:[u2,s2] */
1027bf215546Sopenharmony_ci   0b100100000010100000000, /* dpas.*x1  grf:d      grf:[ub,b]   grf:[u4,s4] */
1028bf215546Sopenharmony_ci   0b100100001010100000000, /* dpas.*x1  grf:d      grf:[u4,s4]  grf:[u4,s4] */
1029bf215546Sopenharmony_ci   0b100100010010100000000, /* dpas.*x1  grf:d      grf:[u2,s2]  grf:[u4,s4] */
1030bf215546Sopenharmony_ci};
1031bf215546Sopenharmony_ci
1032bf215546Sopenharmony_cistatic const uint32_t gfx12_3src_subreg_table[32] = {
1033bf215546Sopenharmony_ci   0b00000000000000000000, /* .0  .0  .0  .0  */
1034bf215546Sopenharmony_ci   0b00100000000000000000, /* .0  .0  .0  .4  */
1035bf215546Sopenharmony_ci   0b00000000000110000000, /* .0  .12 .0  .0  */
1036bf215546Sopenharmony_ci   0b10100000000000000000, /* .0  .0  .0  .20 */
1037bf215546Sopenharmony_ci   0b10000000001110000000, /* .0  .28 .0  .16 */
1038bf215546Sopenharmony_ci   0b01100000000000000000, /* .0  .0  .0  .12 */
1039bf215546Sopenharmony_ci   0b01000000000000000000, /* .0  .0  .0  .8  */
1040bf215546Sopenharmony_ci   0b00000010000000000000, /* .0  .0  .8  .0  */
1041bf215546Sopenharmony_ci   0b00000001000000000000, /* .0  .0  .4  .0  */
1042bf215546Sopenharmony_ci   0b11000000000000000000, /* .0  .0  .0  .24 */
1043bf215546Sopenharmony_ci   0b10000000000000000000, /* .0  .0  .0  .16 */
1044bf215546Sopenharmony_ci   0b11100000000000000000, /* .0  .0  .0  .28 */
1045bf215546Sopenharmony_ci   0b00000110000000000000, /* .0  .0  .24 .0  */
1046bf215546Sopenharmony_ci   0b00000000000010000000, /* .0  .4  .0  .0  */
1047bf215546Sopenharmony_ci   0b00000100000000000000, /* .0  .0  .16 .0  */
1048bf215546Sopenharmony_ci   0b00000011000000000000, /* .0  .0  .12 .0  */
1049bf215546Sopenharmony_ci   0b00000101000000000000, /* .0  .0  .20 .0  */
1050bf215546Sopenharmony_ci   0b00000111000000000000, /* .0  .0  .28 .0  */
1051bf215546Sopenharmony_ci   0b00000000000100000000, /* .0  .8  .0  .0  */
1052bf215546Sopenharmony_ci   0b00000000001000000000, /* .0  .16 .0  .0  */
1053bf215546Sopenharmony_ci   0b00000000001100000000, /* .0  .24 .0  .0  */
1054bf215546Sopenharmony_ci   0b00000000001010000000, /* .0  .20 .0  .0  */
1055bf215546Sopenharmony_ci   0b00000000001110000000, /* .0  .28 .0  .0  */
1056bf215546Sopenharmony_ci   0b11000000001110000000, /* .0  .28 .0  .24 */
1057bf215546Sopenharmony_ci   0b00100000000100000000, /* .0  .8  .0  .4  */
1058bf215546Sopenharmony_ci   0b00100000000110000000, /* .0  .12 .0  .4  */
1059bf215546Sopenharmony_ci   0b01000000000110000000, /* .0  .12 .0  .8  */
1060bf215546Sopenharmony_ci   0b10000000001100000000, /* .0  .24 .0  .16 */
1061bf215546Sopenharmony_ci   0b10000000001010000000, /* .0  .20 .0  .16 */
1062bf215546Sopenharmony_ci   0b01100000000010000000, /* .0  .4  .0  .12 */
1063bf215546Sopenharmony_ci   0b10100000001110000000, /* .0  .28 .0  .20 */
1064bf215546Sopenharmony_ci   0b01000000000010000000, /* .0  .4  .0  .8  */
1065bf215546Sopenharmony_ci};
1066bf215546Sopenharmony_ci
1067bf215546Sopenharmony_cistruct compaction_state {
1068bf215546Sopenharmony_ci   const struct brw_isa_info *isa;
1069bf215546Sopenharmony_ci   const uint32_t *control_index_table;
1070bf215546Sopenharmony_ci   const uint32_t *datatype_table;
1071bf215546Sopenharmony_ci   const uint16_t *subreg_table;
1072bf215546Sopenharmony_ci   const uint16_t *src0_index_table;
1073bf215546Sopenharmony_ci   const uint16_t *src1_index_table;
1074bf215546Sopenharmony_ci};
1075bf215546Sopenharmony_ci
1076bf215546Sopenharmony_cistatic void compaction_state_init(struct compaction_state *c,
1077bf215546Sopenharmony_ci                                  const struct brw_isa_info *isa);
1078bf215546Sopenharmony_ci
1079bf215546Sopenharmony_cistatic bool
1080bf215546Sopenharmony_ciset_control_index(const struct compaction_state *c,
1081bf215546Sopenharmony_ci                  brw_compact_inst *dst, const brw_inst *src)
1082bf215546Sopenharmony_ci{
1083bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1084bf215546Sopenharmony_ci   uint32_t uncompacted; /* 17b/G45; 19b/IVB+; 21b/TGL+ */
1085bf215546Sopenharmony_ci
1086bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1087bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 95, 92) << 17) | /*  4b */
1088bf215546Sopenharmony_ci                    (brw_inst_bits(src, 34, 34) << 16) | /*  1b */
1089bf215546Sopenharmony_ci                    (brw_inst_bits(src, 33, 33) << 15) | /*  1b */
1090bf215546Sopenharmony_ci                    (brw_inst_bits(src, 32, 32) << 14) | /*  1b */
1091bf215546Sopenharmony_ci                    (brw_inst_bits(src, 31, 31) << 13) | /*  1b */
1092bf215546Sopenharmony_ci                    (brw_inst_bits(src, 28, 28) << 12) | /*  1b */
1093bf215546Sopenharmony_ci                    (brw_inst_bits(src, 27, 24) <<  8) | /*  4b */
1094bf215546Sopenharmony_ci                    (brw_inst_bits(src, 23, 22) <<  6) | /*  2b */
1095bf215546Sopenharmony_ci                    (brw_inst_bits(src, 21, 19) <<  3) | /*  3b */
1096bf215546Sopenharmony_ci                    (brw_inst_bits(src, 18, 16));        /*  3b */
1097bf215546Sopenharmony_ci   } else if (devinfo->ver >= 8) {
1098bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 33, 31) << 16) | /*  3b */
1099bf215546Sopenharmony_ci                    (brw_inst_bits(src, 23, 12) <<  4) | /* 12b */
1100bf215546Sopenharmony_ci                    (brw_inst_bits(src, 10,  9) <<  2) | /*  2b */
1101bf215546Sopenharmony_ci                    (brw_inst_bits(src, 34, 34) <<  1) | /*  1b */
1102bf215546Sopenharmony_ci                    (brw_inst_bits(src,  8,  8));        /*  1b */
1103bf215546Sopenharmony_ci   } else {
1104bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 31, 31) << 16) | /*  1b */
1105bf215546Sopenharmony_ci                    (brw_inst_bits(src, 23,  8));        /* 16b */
1106bf215546Sopenharmony_ci
1107bf215546Sopenharmony_ci      /* On gfx7, the flag register and subregister numbers are integrated into
1108bf215546Sopenharmony_ci       * the control index.
1109bf215546Sopenharmony_ci       */
1110bf215546Sopenharmony_ci      if (devinfo->ver == 7)
1111bf215546Sopenharmony_ci         uncompacted |= brw_inst_bits(src, 90, 89) << 17; /* 2b */
1112bf215546Sopenharmony_ci   }
1113bf215546Sopenharmony_ci
1114bf215546Sopenharmony_ci   for (int i = 0; i < 32; i++) {
1115bf215546Sopenharmony_ci      if (c->control_index_table[i] == uncompacted) {
1116bf215546Sopenharmony_ci         brw_compact_inst_set_control_index(devinfo, dst, i);
1117bf215546Sopenharmony_ci	 return true;
1118bf215546Sopenharmony_ci      }
1119bf215546Sopenharmony_ci   }
1120bf215546Sopenharmony_ci
1121bf215546Sopenharmony_ci   return false;
1122bf215546Sopenharmony_ci}
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_cistatic bool
1125bf215546Sopenharmony_ciset_datatype_index(const struct compaction_state *c, brw_compact_inst *dst,
1126bf215546Sopenharmony_ci                   const brw_inst *src, bool is_immediate)
1127bf215546Sopenharmony_ci{
1128bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1129bf215546Sopenharmony_ci   uint32_t uncompacted; /* 18b/G45+; 21b/BDW+; 20b/TGL+ */
1130bf215546Sopenharmony_ci
1131bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1132bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 91, 88) << 15) | /*  4b */
1133bf215546Sopenharmony_ci                    (brw_inst_bits(src, 66, 66) << 14) | /*  1b */
1134bf215546Sopenharmony_ci                    (brw_inst_bits(src, 50, 50) << 13) | /*  1b */
1135bf215546Sopenharmony_ci                    (brw_inst_bits(src, 49, 48) << 11) | /*  2b */
1136bf215546Sopenharmony_ci                    (brw_inst_bits(src, 47, 47) << 10) | /*  1b */
1137bf215546Sopenharmony_ci                    (brw_inst_bits(src, 46, 46) <<  9) | /*  1b */
1138bf215546Sopenharmony_ci                    (brw_inst_bits(src, 43, 40) <<  5) | /*  4b */
1139bf215546Sopenharmony_ci                    (brw_inst_bits(src, 39, 36) <<  1) | /*  4b */
1140bf215546Sopenharmony_ci                    (brw_inst_bits(src, 35, 35));        /*  1b */
1141bf215546Sopenharmony_ci
1142bf215546Sopenharmony_ci      /* Src1.RegFile overlaps with the immediate, so ignore it if an immediate
1143bf215546Sopenharmony_ci       * is present
1144bf215546Sopenharmony_ci       */
1145bf215546Sopenharmony_ci      if (!is_immediate) {
1146bf215546Sopenharmony_ci         uncompacted |= brw_inst_bits(src, 98, 98) << 19; /* 1b */
1147bf215546Sopenharmony_ci      }
1148bf215546Sopenharmony_ci   } else if (devinfo->ver >= 8) {
1149bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 63, 61) << 18) | /*  3b */
1150bf215546Sopenharmony_ci                    (brw_inst_bits(src, 94, 89) << 12) | /*  6b */
1151bf215546Sopenharmony_ci                    (brw_inst_bits(src, 46, 35));        /* 12b */
1152bf215546Sopenharmony_ci   } else {
1153bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 63, 61) << 15) | /*  3b */
1154bf215546Sopenharmony_ci                    (brw_inst_bits(src, 46, 32));        /* 15b */
1155bf215546Sopenharmony_ci   }
1156bf215546Sopenharmony_ci
1157bf215546Sopenharmony_ci   for (int i = 0; i < 32; i++) {
1158bf215546Sopenharmony_ci      if (c->datatype_table[i] == uncompacted) {
1159bf215546Sopenharmony_ci         brw_compact_inst_set_datatype_index(devinfo, dst, i);
1160bf215546Sopenharmony_ci	 return true;
1161bf215546Sopenharmony_ci      }
1162bf215546Sopenharmony_ci   }
1163bf215546Sopenharmony_ci
1164bf215546Sopenharmony_ci   return false;
1165bf215546Sopenharmony_ci}
1166bf215546Sopenharmony_ci
1167bf215546Sopenharmony_cistatic bool
1168bf215546Sopenharmony_ciset_subreg_index(const struct compaction_state *c, brw_compact_inst *dst,
1169bf215546Sopenharmony_ci                 const brw_inst *src, bool is_immediate)
1170bf215546Sopenharmony_ci{
1171bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1172bf215546Sopenharmony_ci   uint16_t uncompacted; /* 15b */
1173bf215546Sopenharmony_ci
1174bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1175bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 55, 51) << 0) |    /* 5b */
1176bf215546Sopenharmony_ci                    (brw_inst_bits(src, 71, 67) << 5);     /* 5b */
1177bf215546Sopenharmony_ci
1178bf215546Sopenharmony_ci      if (!is_immediate)
1179bf215546Sopenharmony_ci         uncompacted |= brw_inst_bits(src, 103, 99) << 10; /* 5b */
1180bf215546Sopenharmony_ci   } else {
1181bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 52, 48) << 0) |    /* 5b */
1182bf215546Sopenharmony_ci                    (brw_inst_bits(src, 68, 64) << 5);     /* 5b */
1183bf215546Sopenharmony_ci
1184bf215546Sopenharmony_ci      if (!is_immediate)
1185bf215546Sopenharmony_ci         uncompacted |= brw_inst_bits(src, 100, 96) << 10; /* 5b */
1186bf215546Sopenharmony_ci   }
1187bf215546Sopenharmony_ci
1188bf215546Sopenharmony_ci   for (int i = 0; i < 32; i++) {
1189bf215546Sopenharmony_ci      if (c->subreg_table[i] == uncompacted) {
1190bf215546Sopenharmony_ci         brw_compact_inst_set_subreg_index(devinfo, dst, i);
1191bf215546Sopenharmony_ci	 return true;
1192bf215546Sopenharmony_ci      }
1193bf215546Sopenharmony_ci   }
1194bf215546Sopenharmony_ci
1195bf215546Sopenharmony_ci   return false;
1196bf215546Sopenharmony_ci}
1197bf215546Sopenharmony_ci
1198bf215546Sopenharmony_cistatic bool
1199bf215546Sopenharmony_ciset_src0_index(const struct compaction_state *c, brw_compact_inst *dst,
1200bf215546Sopenharmony_ci               const brw_inst *src)
1201bf215546Sopenharmony_ci{
1202bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1203bf215546Sopenharmony_ci   uint16_t uncompacted; /* 12b */
1204bf215546Sopenharmony_ci   int table_len;
1205bf215546Sopenharmony_ci
1206bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1207bf215546Sopenharmony_ci      table_len = ARRAY_SIZE(gfx12_src0_index_table);
1208bf215546Sopenharmony_ci      uncompacted = (brw_inst_bits(src, 87, 84) << 8) | /*  4b */
1209bf215546Sopenharmony_ci                    (brw_inst_bits(src, 83, 81) << 5) | /*  3b */
1210bf215546Sopenharmony_ci                    (brw_inst_bits(src, 80, 80) << 4) | /*  1b */
1211bf215546Sopenharmony_ci                    (brw_inst_bits(src, 65, 64) << 2) | /*  2b */
1212bf215546Sopenharmony_ci                    (brw_inst_bits(src, 45, 44));       /*  2b */
1213bf215546Sopenharmony_ci   } else {
1214bf215546Sopenharmony_ci      table_len = ARRAY_SIZE(gfx8_src_index_table);
1215bf215546Sopenharmony_ci      uncompacted = brw_inst_bits(src, 88, 77);         /* 12b */
1216bf215546Sopenharmony_ci   }
1217bf215546Sopenharmony_ci
1218bf215546Sopenharmony_ci   for (int i = 0; i < table_len; i++) {
1219bf215546Sopenharmony_ci      if (c->src0_index_table[i] == uncompacted) {
1220bf215546Sopenharmony_ci         brw_compact_inst_set_src0_index(devinfo, dst, i);
1221bf215546Sopenharmony_ci	 return true;
1222bf215546Sopenharmony_ci      }
1223bf215546Sopenharmony_ci   }
1224bf215546Sopenharmony_ci
1225bf215546Sopenharmony_ci   return false;
1226bf215546Sopenharmony_ci}
1227bf215546Sopenharmony_ci
1228bf215546Sopenharmony_cistatic bool
1229bf215546Sopenharmony_ciset_src1_index(const struct compaction_state *c, brw_compact_inst *dst,
1230bf215546Sopenharmony_ci               const brw_inst *src, bool is_immediate, unsigned imm)
1231bf215546Sopenharmony_ci{
1232bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1233bf215546Sopenharmony_ci   if (is_immediate) {
1234bf215546Sopenharmony_ci      if (devinfo->ver >= 12) {
1235bf215546Sopenharmony_ci         /* src1 index takes the low 4 bits of the 12-bit compacted value */
1236bf215546Sopenharmony_ci         brw_compact_inst_set_src1_index(devinfo, dst, imm & 0xf);
1237bf215546Sopenharmony_ci      } else {
1238bf215546Sopenharmony_ci         /* src1 index takes the high 5 bits of the 13-bit compacted value */
1239bf215546Sopenharmony_ci         brw_compact_inst_set_src1_index(devinfo, dst, imm >> 8);
1240bf215546Sopenharmony_ci      }
1241bf215546Sopenharmony_ci      return true;
1242bf215546Sopenharmony_ci   } else {
1243bf215546Sopenharmony_ci      uint16_t uncompacted; /* 12b */
1244bf215546Sopenharmony_ci      int table_len;
1245bf215546Sopenharmony_ci
1246bf215546Sopenharmony_ci      if (devinfo->ver >= 12) {
1247bf215546Sopenharmony_ci         table_len = ARRAY_SIZE(gfx12_src0_index_table);
1248bf215546Sopenharmony_ci         uncompacted = (brw_inst_bits(src, 121, 120) << 10) | /*  2b */
1249bf215546Sopenharmony_ci                       (brw_inst_bits(src, 119, 116) <<  6) | /*  4b */
1250bf215546Sopenharmony_ci                       (brw_inst_bits(src, 115, 113) <<  3) | /*  3b */
1251bf215546Sopenharmony_ci                       (brw_inst_bits(src, 112, 112) <<  2) | /*  1b */
1252bf215546Sopenharmony_ci                       (brw_inst_bits(src,  97,  96));        /*  2b */
1253bf215546Sopenharmony_ci      } else {
1254bf215546Sopenharmony_ci         table_len = ARRAY_SIZE(gfx8_src_index_table);
1255bf215546Sopenharmony_ci         uncompacted = brw_inst_bits(src, 120, 109);          /* 12b */
1256bf215546Sopenharmony_ci      }
1257bf215546Sopenharmony_ci
1258bf215546Sopenharmony_ci      for (int i = 0; i < table_len; i++) {
1259bf215546Sopenharmony_ci         if (c->src1_index_table[i] == uncompacted) {
1260bf215546Sopenharmony_ci            brw_compact_inst_set_src1_index(devinfo, dst, i);
1261bf215546Sopenharmony_ci            return true;
1262bf215546Sopenharmony_ci         }
1263bf215546Sopenharmony_ci      }
1264bf215546Sopenharmony_ci   }
1265bf215546Sopenharmony_ci
1266bf215546Sopenharmony_ci   return false;
1267bf215546Sopenharmony_ci}
1268bf215546Sopenharmony_ci
1269bf215546Sopenharmony_cistatic bool
1270bf215546Sopenharmony_ciset_3src_control_index(const struct intel_device_info *devinfo,
1271bf215546Sopenharmony_ci                       brw_compact_inst *dst, const brw_inst *src)
1272bf215546Sopenharmony_ci{
1273bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
1274bf215546Sopenharmony_ci
1275bf215546Sopenharmony_ci   if (devinfo->verx10 >= 125) {
1276bf215546Sopenharmony_ci      uint64_t uncompacted =             /* 37b/XeHP+ */
1277bf215546Sopenharmony_ci         (brw_inst_bits(src, 95, 92) << 33) | /*  4b */
1278bf215546Sopenharmony_ci         (brw_inst_bits(src, 90, 88) << 30) | /*  3b */
1279bf215546Sopenharmony_ci         (brw_inst_bits(src, 82, 80) << 27) | /*  3b */
1280bf215546Sopenharmony_ci         (brw_inst_bits(src, 50, 50) << 26) | /*  1b */
1281bf215546Sopenharmony_ci         (brw_inst_bits(src, 49, 48) << 24) | /*  2b */
1282bf215546Sopenharmony_ci         (brw_inst_bits(src, 42, 40) << 21) | /*  3b */
1283bf215546Sopenharmony_ci         (brw_inst_bits(src, 39, 39) << 20) | /*  1b */
1284bf215546Sopenharmony_ci         (brw_inst_bits(src, 38, 36) << 17) | /*  3b */
1285bf215546Sopenharmony_ci         (brw_inst_bits(src, 34, 34) << 16) | /*  1b */
1286bf215546Sopenharmony_ci         (brw_inst_bits(src, 33, 33) << 15) | /*  1b */
1287bf215546Sopenharmony_ci         (brw_inst_bits(src, 32, 32) << 14) | /*  1b */
1288bf215546Sopenharmony_ci         (brw_inst_bits(src, 31, 31) << 13) | /*  1b */
1289bf215546Sopenharmony_ci         (brw_inst_bits(src, 28, 28) << 12) | /*  1b */
1290bf215546Sopenharmony_ci         (brw_inst_bits(src, 27, 24) <<  8) | /*  4b */
1291bf215546Sopenharmony_ci         (brw_inst_bits(src, 23, 23) <<  7) | /*  1b */
1292bf215546Sopenharmony_ci         (brw_inst_bits(src, 22, 22) <<  6) | /*  1b */
1293bf215546Sopenharmony_ci         (brw_inst_bits(src, 21, 19) <<  3) | /*  3b */
1294bf215546Sopenharmony_ci         (brw_inst_bits(src, 18, 16));        /*  3b */
1295bf215546Sopenharmony_ci
1296bf215546Sopenharmony_ci      for (unsigned i = 0; i < ARRAY_SIZE(xehp_3src_control_index_table); i++) {
1297bf215546Sopenharmony_ci         if (xehp_3src_control_index_table[i] == uncompacted) {
1298bf215546Sopenharmony_ci            brw_compact_inst_set_3src_control_index(devinfo, dst, i);
1299bf215546Sopenharmony_ci            return true;
1300bf215546Sopenharmony_ci         }
1301bf215546Sopenharmony_ci      }
1302bf215546Sopenharmony_ci   } else if (devinfo->ver >= 12) {
1303bf215546Sopenharmony_ci      uint64_t uncompacted =             /* 36b/TGL+ */
1304bf215546Sopenharmony_ci         (brw_inst_bits(src, 95, 92) << 32) | /*  4b */
1305bf215546Sopenharmony_ci         (brw_inst_bits(src, 90, 88) << 29) | /*  3b */
1306bf215546Sopenharmony_ci         (brw_inst_bits(src, 82, 80) << 26) | /*  3b */
1307bf215546Sopenharmony_ci         (brw_inst_bits(src, 50, 50) << 25) | /*  1b */
1308bf215546Sopenharmony_ci         (brw_inst_bits(src, 48, 48) << 24) | /*  1b */
1309bf215546Sopenharmony_ci         (brw_inst_bits(src, 42, 40) << 21) | /*  3b */
1310bf215546Sopenharmony_ci         (brw_inst_bits(src, 39, 39) << 20) | /*  1b */
1311bf215546Sopenharmony_ci         (brw_inst_bits(src, 38, 36) << 17) | /*  3b */
1312bf215546Sopenharmony_ci         (brw_inst_bits(src, 34, 34) << 16) | /*  1b */
1313bf215546Sopenharmony_ci         (brw_inst_bits(src, 33, 33) << 15) | /*  1b */
1314bf215546Sopenharmony_ci         (brw_inst_bits(src, 32, 32) << 14) | /*  1b */
1315bf215546Sopenharmony_ci         (brw_inst_bits(src, 31, 31) << 13) | /*  1b */
1316bf215546Sopenharmony_ci         (brw_inst_bits(src, 28, 28) << 12) | /*  1b */
1317bf215546Sopenharmony_ci         (brw_inst_bits(src, 27, 24) <<  8) | /*  4b */
1318bf215546Sopenharmony_ci         (brw_inst_bits(src, 23, 23) <<  7) | /*  1b */
1319bf215546Sopenharmony_ci         (brw_inst_bits(src, 22, 22) <<  6) | /*  1b */
1320bf215546Sopenharmony_ci         (brw_inst_bits(src, 21, 19) <<  3) | /*  3b */
1321bf215546Sopenharmony_ci         (brw_inst_bits(src, 18, 16));        /*  3b */
1322bf215546Sopenharmony_ci
1323bf215546Sopenharmony_ci      for (unsigned i = 0; i < ARRAY_SIZE(gfx12_3src_control_index_table); i++) {
1324bf215546Sopenharmony_ci         if (gfx12_3src_control_index_table[i] == uncompacted) {
1325bf215546Sopenharmony_ci            brw_compact_inst_set_3src_control_index(devinfo, dst, i);
1326bf215546Sopenharmony_ci            return true;
1327bf215546Sopenharmony_ci         }
1328bf215546Sopenharmony_ci      }
1329bf215546Sopenharmony_ci   } else {
1330bf215546Sopenharmony_ci      uint32_t uncompacted = /* 24b/BDW; 26b/CHV/SKL+ */
1331bf215546Sopenharmony_ci         (brw_inst_bits(src, 34, 32) << 21) |  /*  3b */
1332bf215546Sopenharmony_ci         (brw_inst_bits(src, 28,  8));         /* 21b */
1333bf215546Sopenharmony_ci
1334bf215546Sopenharmony_ci      if (devinfo->ver >= 9 || devinfo->platform == INTEL_PLATFORM_CHV) {
1335bf215546Sopenharmony_ci         uncompacted |=
1336bf215546Sopenharmony_ci            brw_inst_bits(src, 36, 35) << 24;  /*  2b */
1337bf215546Sopenharmony_ci      }
1338bf215546Sopenharmony_ci
1339bf215546Sopenharmony_ci      for (unsigned i = 0; i < ARRAY_SIZE(gfx8_3src_control_index_table); i++) {
1340bf215546Sopenharmony_ci         if (gfx8_3src_control_index_table[i] == uncompacted) {
1341bf215546Sopenharmony_ci            brw_compact_inst_set_3src_control_index(devinfo, dst, i);
1342bf215546Sopenharmony_ci            return true;
1343bf215546Sopenharmony_ci         }
1344bf215546Sopenharmony_ci      }
1345bf215546Sopenharmony_ci   }
1346bf215546Sopenharmony_ci
1347bf215546Sopenharmony_ci   return false;
1348bf215546Sopenharmony_ci}
1349bf215546Sopenharmony_ci
1350bf215546Sopenharmony_cistatic bool
1351bf215546Sopenharmony_ciset_3src_source_index(const struct intel_device_info *devinfo,
1352bf215546Sopenharmony_ci                      brw_compact_inst *dst, const brw_inst *src)
1353bf215546Sopenharmony_ci{
1354bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
1355bf215546Sopenharmony_ci
1356bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1357bf215546Sopenharmony_ci      uint32_t uncompacted =               /* 21b/TGL+ */
1358bf215546Sopenharmony_ci         (brw_inst_bits(src, 114, 114) << 20) | /*  1b */
1359bf215546Sopenharmony_ci         (brw_inst_bits(src, 113, 112) << 18) | /*  2b */
1360bf215546Sopenharmony_ci         (brw_inst_bits(src,  98,  98) << 17) | /*  1b */
1361bf215546Sopenharmony_ci         (brw_inst_bits(src,  97,  96) << 15) | /*  2b */
1362bf215546Sopenharmony_ci         (brw_inst_bits(src,  91,  91) << 14) | /*  1b */
1363bf215546Sopenharmony_ci         (brw_inst_bits(src,  87,  86) << 12) | /*  2b */
1364bf215546Sopenharmony_ci         (brw_inst_bits(src,  85,  84) << 10) | /*  2b */
1365bf215546Sopenharmony_ci         (brw_inst_bits(src,  83,  83) <<  9) | /*  1b */
1366bf215546Sopenharmony_ci         (brw_inst_bits(src,  66,  66) <<  8) | /*  1b */
1367bf215546Sopenharmony_ci         (brw_inst_bits(src,  65,  64) <<  6) | /*  2b */
1368bf215546Sopenharmony_ci         (brw_inst_bits(src,  47,  47) <<  5) | /*  1b */
1369bf215546Sopenharmony_ci         (brw_inst_bits(src,  46,  46) <<  4) | /*  1b */
1370bf215546Sopenharmony_ci         (brw_inst_bits(src,  45,  44) <<  2) | /*  2b */
1371bf215546Sopenharmony_ci         (brw_inst_bits(src,  43,  43) <<  1) | /*  1b */
1372bf215546Sopenharmony_ci         (brw_inst_bits(src,  35,  35));        /*  1b */
1373bf215546Sopenharmony_ci
1374bf215546Sopenharmony_ci      const uint32_t *three_src_source_index_table =
1375bf215546Sopenharmony_ci         devinfo->verx10 >= 125 ?
1376bf215546Sopenharmony_ci         xehp_3src_source_index_table : gfx12_3src_source_index_table;
1377bf215546Sopenharmony_ci      const uint32_t three_src_source_index_table_len =
1378bf215546Sopenharmony_ci         devinfo->verx10 >= 125 ? ARRAY_SIZE(xehp_3src_source_index_table) :
1379bf215546Sopenharmony_ci                                  ARRAY_SIZE(gfx12_3src_source_index_table);
1380bf215546Sopenharmony_ci
1381bf215546Sopenharmony_ci      for (unsigned i = 0; i < three_src_source_index_table_len; i++) {
1382bf215546Sopenharmony_ci         if (three_src_source_index_table[i] == uncompacted) {
1383bf215546Sopenharmony_ci            brw_compact_inst_set_3src_source_index(devinfo, dst, i);
1384bf215546Sopenharmony_ci            return true;
1385bf215546Sopenharmony_ci         }
1386bf215546Sopenharmony_ci      }
1387bf215546Sopenharmony_ci   } else {
1388bf215546Sopenharmony_ci      uint64_t uncompacted =    /* 46b/BDW; 49b/CHV/SKL+ */
1389bf215546Sopenharmony_ci         (brw_inst_bits(src,  83,  83) << 43) |   /*  1b */
1390bf215546Sopenharmony_ci         (brw_inst_bits(src, 114, 107) << 35) |   /*  8b */
1391bf215546Sopenharmony_ci         (brw_inst_bits(src,  93,  86) << 27) |   /*  8b */
1392bf215546Sopenharmony_ci         (brw_inst_bits(src,  72,  65) << 19) |   /*  8b */
1393bf215546Sopenharmony_ci         (brw_inst_bits(src,  55,  37));          /* 19b */
1394bf215546Sopenharmony_ci
1395bf215546Sopenharmony_ci      if (devinfo->ver >= 9 || devinfo->platform == INTEL_PLATFORM_CHV) {
1396bf215546Sopenharmony_ci         uncompacted |=
1397bf215546Sopenharmony_ci            (brw_inst_bits(src, 126, 125) << 47) | /* 2b */
1398bf215546Sopenharmony_ci            (brw_inst_bits(src, 105, 104) << 45) | /* 2b */
1399bf215546Sopenharmony_ci            (brw_inst_bits(src,  84,  84) << 44);  /* 1b */
1400bf215546Sopenharmony_ci      } else {
1401bf215546Sopenharmony_ci         uncompacted |=
1402bf215546Sopenharmony_ci            (brw_inst_bits(src, 125, 125) << 45) | /* 1b */
1403bf215546Sopenharmony_ci            (brw_inst_bits(src, 104, 104) << 44);  /* 1b */
1404bf215546Sopenharmony_ci      }
1405bf215546Sopenharmony_ci
1406bf215546Sopenharmony_ci      for (unsigned i = 0; i < ARRAY_SIZE(gfx8_3src_source_index_table); i++) {
1407bf215546Sopenharmony_ci         if (gfx8_3src_source_index_table[i] == uncompacted) {
1408bf215546Sopenharmony_ci            brw_compact_inst_set_3src_source_index(devinfo, dst, i);
1409bf215546Sopenharmony_ci            return true;
1410bf215546Sopenharmony_ci         }
1411bf215546Sopenharmony_ci      }
1412bf215546Sopenharmony_ci   }
1413bf215546Sopenharmony_ci
1414bf215546Sopenharmony_ci   return false;
1415bf215546Sopenharmony_ci}
1416bf215546Sopenharmony_ci
1417bf215546Sopenharmony_cistatic bool
1418bf215546Sopenharmony_ciset_3src_subreg_index(const struct intel_device_info *devinfo,
1419bf215546Sopenharmony_ci                      brw_compact_inst *dst, const brw_inst *src)
1420bf215546Sopenharmony_ci{
1421bf215546Sopenharmony_ci   assert(devinfo->ver >= 12);
1422bf215546Sopenharmony_ci
1423bf215546Sopenharmony_ci   uint32_t uncompacted =               /* 20b/TGL+ */
1424bf215546Sopenharmony_ci      (brw_inst_bits(src, 119, 115) << 15) | /*  5b */
1425bf215546Sopenharmony_ci      (brw_inst_bits(src, 103,  99) << 10) | /*  5b */
1426bf215546Sopenharmony_ci      (brw_inst_bits(src,  71,  67) <<  5) | /*  5b */
1427bf215546Sopenharmony_ci      (brw_inst_bits(src,  55,  51));        /*  5b */
1428bf215546Sopenharmony_ci
1429bf215546Sopenharmony_ci   for (unsigned i = 0; i < ARRAY_SIZE(gfx12_3src_subreg_table); i++) {
1430bf215546Sopenharmony_ci      if (gfx12_3src_subreg_table[i] == uncompacted) {
1431bf215546Sopenharmony_ci         brw_compact_inst_set_3src_subreg_index(devinfo, dst, i);
1432bf215546Sopenharmony_ci	 return true;
1433bf215546Sopenharmony_ci      }
1434bf215546Sopenharmony_ci   }
1435bf215546Sopenharmony_ci
1436bf215546Sopenharmony_ci   return false;
1437bf215546Sopenharmony_ci}
1438bf215546Sopenharmony_ci
1439bf215546Sopenharmony_cistatic bool
1440bf215546Sopenharmony_cihas_unmapped_bits(const struct brw_isa_info *isa, const brw_inst *src)
1441bf215546Sopenharmony_ci{
1442bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = isa->devinfo;
1443bf215546Sopenharmony_ci
1444bf215546Sopenharmony_ci   /* EOT can only be mapped on a send if the src1 is an immediate */
1445bf215546Sopenharmony_ci   if ((brw_inst_opcode(isa, src) == BRW_OPCODE_SENDC ||
1446bf215546Sopenharmony_ci        brw_inst_opcode(isa, src) == BRW_OPCODE_SEND) &&
1447bf215546Sopenharmony_ci       brw_inst_eot(devinfo, src))
1448bf215546Sopenharmony_ci      return true;
1449bf215546Sopenharmony_ci
1450bf215546Sopenharmony_ci   /* Check for instruction bits that don't map to any of the fields of the
1451bf215546Sopenharmony_ci    * compacted instruction.  The instruction cannot be compacted if any of
1452bf215546Sopenharmony_ci    * them are set.  They overlap with:
1453bf215546Sopenharmony_ci    *  - NibCtrl (bit 47 on Gfx7, bit 11 on Gfx8)
1454bf215546Sopenharmony_ci    *  - Dst.AddrImm[9] (bit 47 on Gfx8)
1455bf215546Sopenharmony_ci    *  - Src0.AddrImm[9] (bit 95 on Gfx8)
1456bf215546Sopenharmony_ci    *  - Imm64[27:31] (bits 91-95 on Gfx7, bit 95 on Gfx8)
1457bf215546Sopenharmony_ci    *  - UIP[31] (bit 95 on Gfx8)
1458bf215546Sopenharmony_ci    */
1459bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1460bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 7,  7));
1461bf215546Sopenharmony_ci      return false;
1462bf215546Sopenharmony_ci   } else if (devinfo->ver >= 8) {
1463bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 7,  7));
1464bf215546Sopenharmony_ci      return brw_inst_bits(src, 95, 95) ||
1465bf215546Sopenharmony_ci             brw_inst_bits(src, 47, 47) ||
1466bf215546Sopenharmony_ci             brw_inst_bits(src, 11, 11);
1467bf215546Sopenharmony_ci   } else {
1468bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 7,  7) &&
1469bf215546Sopenharmony_ci             !(devinfo->ver < 7 && brw_inst_bits(src, 90, 90)));
1470bf215546Sopenharmony_ci      return brw_inst_bits(src, 95, 91) ||
1471bf215546Sopenharmony_ci             brw_inst_bits(src, 47, 47);
1472bf215546Sopenharmony_ci   }
1473bf215546Sopenharmony_ci}
1474bf215546Sopenharmony_ci
1475bf215546Sopenharmony_cistatic bool
1476bf215546Sopenharmony_cihas_3src_unmapped_bits(const struct intel_device_info *devinfo,
1477bf215546Sopenharmony_ci                       const brw_inst *src)
1478bf215546Sopenharmony_ci{
1479bf215546Sopenharmony_ci   /* Check for three-source instruction bits that don't map to any of the
1480bf215546Sopenharmony_ci    * fields of the compacted instruction.  All of them seem to be reserved
1481bf215546Sopenharmony_ci    * bits currently.
1482bf215546Sopenharmony_ci    */
1483bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1484bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 7, 7));
1485bf215546Sopenharmony_ci   } else if (devinfo->ver >= 9 || devinfo->platform == INTEL_PLATFORM_CHV) {
1486bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 127, 127) &&
1487bf215546Sopenharmony_ci             !brw_inst_bits(src, 7,  7));
1488bf215546Sopenharmony_ci   } else {
1489bf215546Sopenharmony_ci      assert(devinfo->ver >= 8);
1490bf215546Sopenharmony_ci      assert(!brw_inst_bits(src, 127, 126) &&
1491bf215546Sopenharmony_ci             !brw_inst_bits(src, 105, 105) &&
1492bf215546Sopenharmony_ci             !brw_inst_bits(src, 84, 84) &&
1493bf215546Sopenharmony_ci             !brw_inst_bits(src, 7,  7));
1494bf215546Sopenharmony_ci
1495bf215546Sopenharmony_ci      /* Src1Type and Src2Type, used for mixed-precision floating point */
1496bf215546Sopenharmony_ci      if (brw_inst_bits(src, 36, 35))
1497bf215546Sopenharmony_ci         return true;
1498bf215546Sopenharmony_ci   }
1499bf215546Sopenharmony_ci
1500bf215546Sopenharmony_ci   return false;
1501bf215546Sopenharmony_ci}
1502bf215546Sopenharmony_ci
1503bf215546Sopenharmony_cistatic bool
1504bf215546Sopenharmony_cibrw_try_compact_3src_instruction(const struct intel_device_info *devinfo,
1505bf215546Sopenharmony_ci                                 brw_compact_inst *dst, const brw_inst *src)
1506bf215546Sopenharmony_ci{
1507bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
1508bf215546Sopenharmony_ci
1509bf215546Sopenharmony_ci   if (has_3src_unmapped_bits(devinfo, src))
1510bf215546Sopenharmony_ci      return false;
1511bf215546Sopenharmony_ci
1512bf215546Sopenharmony_ci#define compact(field) \
1513bf215546Sopenharmony_ci   brw_compact_inst_set_3src_##field(devinfo, dst, brw_inst_3src_##field(devinfo, src))
1514bf215546Sopenharmony_ci#define compact_a16(field) \
1515bf215546Sopenharmony_ci   brw_compact_inst_set_3src_##field(devinfo, dst, brw_inst_3src_a16_##field(devinfo, src))
1516bf215546Sopenharmony_ci
1517bf215546Sopenharmony_ci   compact(hw_opcode);
1518bf215546Sopenharmony_ci
1519bf215546Sopenharmony_ci   if (!set_3src_control_index(devinfo, dst, src))
1520bf215546Sopenharmony_ci      return false;
1521bf215546Sopenharmony_ci
1522bf215546Sopenharmony_ci   if (!set_3src_source_index(devinfo, dst, src))
1523bf215546Sopenharmony_ci      return false;
1524bf215546Sopenharmony_ci
1525bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1526bf215546Sopenharmony_ci      if (!set_3src_subreg_index(devinfo, dst, src))
1527bf215546Sopenharmony_ci         return false;
1528bf215546Sopenharmony_ci
1529bf215546Sopenharmony_ci      compact(swsb);
1530bf215546Sopenharmony_ci      compact(debug_control);
1531bf215546Sopenharmony_ci      compact(dst_reg_nr);
1532bf215546Sopenharmony_ci      compact(src0_reg_nr);
1533bf215546Sopenharmony_ci      compact(src1_reg_nr);
1534bf215546Sopenharmony_ci      compact(src2_reg_nr);
1535bf215546Sopenharmony_ci   } else {
1536bf215546Sopenharmony_ci      compact(dst_reg_nr);
1537bf215546Sopenharmony_ci      compact_a16(src0_rep_ctrl);
1538bf215546Sopenharmony_ci      compact(debug_control);
1539bf215546Sopenharmony_ci      compact(saturate);
1540bf215546Sopenharmony_ci      compact_a16(src1_rep_ctrl);
1541bf215546Sopenharmony_ci      compact_a16(src2_rep_ctrl);
1542bf215546Sopenharmony_ci      compact(src0_reg_nr);
1543bf215546Sopenharmony_ci      compact(src1_reg_nr);
1544bf215546Sopenharmony_ci      compact(src2_reg_nr);
1545bf215546Sopenharmony_ci      compact_a16(src0_subreg_nr);
1546bf215546Sopenharmony_ci      compact_a16(src1_subreg_nr);
1547bf215546Sopenharmony_ci      compact_a16(src2_subreg_nr);
1548bf215546Sopenharmony_ci   }
1549bf215546Sopenharmony_ci   brw_compact_inst_set_3src_cmpt_control(devinfo, dst, true);
1550bf215546Sopenharmony_ci
1551bf215546Sopenharmony_ci#undef compact
1552bf215546Sopenharmony_ci#undef compact_a16
1553bf215546Sopenharmony_ci
1554bf215546Sopenharmony_ci   return true;
1555bf215546Sopenharmony_ci}
1556bf215546Sopenharmony_ci
1557bf215546Sopenharmony_ci/* On SNB through ICL, compacted instructions have 12-bits for immediate
1558bf215546Sopenharmony_ci * sources, and a 13th bit that's replicated through the high 20 bits.
1559bf215546Sopenharmony_ci *
1560bf215546Sopenharmony_ci * Effectively this means we get 12-bit integers, 0.0f, and some limited uses
1561bf215546Sopenharmony_ci * of packed vectors as compactable immediates.
1562bf215546Sopenharmony_ci *
1563bf215546Sopenharmony_ci * On TGL+, the high 12-bits of floating-point values (:f and :hf) are encoded
1564bf215546Sopenharmony_ci * rather than the low 12-bits. For signed integer the 12th bit is replicated,
1565bf215546Sopenharmony_ci * while for unsigned integers it is not.
1566bf215546Sopenharmony_ci *
1567bf215546Sopenharmony_ci * Returns the compacted immediate, or -1 if immediate cannot be compacted
1568bf215546Sopenharmony_ci */
1569bf215546Sopenharmony_cistatic int
1570bf215546Sopenharmony_cicompact_immediate(const struct intel_device_info *devinfo,
1571bf215546Sopenharmony_ci                  enum brw_reg_type type, unsigned imm)
1572bf215546Sopenharmony_ci{
1573bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1574bf215546Sopenharmony_ci      /* 16-bit immediates need to be replicated through the 32-bit immediate
1575bf215546Sopenharmony_ci       * field
1576bf215546Sopenharmony_ci       */
1577bf215546Sopenharmony_ci      switch (type) {
1578bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_W:
1579bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UW:
1580bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_HF:
1581bf215546Sopenharmony_ci         if ((imm >> 16) != (imm & 0xffff))
1582bf215546Sopenharmony_ci            return -1;
1583bf215546Sopenharmony_ci         break;
1584bf215546Sopenharmony_ci      default:
1585bf215546Sopenharmony_ci         break;
1586bf215546Sopenharmony_ci      }
1587bf215546Sopenharmony_ci
1588bf215546Sopenharmony_ci      switch (type) {
1589bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_F:
1590bf215546Sopenharmony_ci         /* We get the high 12-bits as-is; rest must be zero */
1591bf215546Sopenharmony_ci         if ((imm & 0xfffff) == 0)
1592bf215546Sopenharmony_ci            return (imm >> 20) & 0xfff;
1593bf215546Sopenharmony_ci         break;
1594bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_HF:
1595bf215546Sopenharmony_ci         /* We get the high 12-bits as-is; rest must be zero */
1596bf215546Sopenharmony_ci         if ((imm & 0xf) == 0)
1597bf215546Sopenharmony_ci            return (imm >> 4) & 0xfff;
1598bf215546Sopenharmony_ci         break;
1599bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UD:
1600bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_VF:
1601bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UV:
1602bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_V:
1603bf215546Sopenharmony_ci         /* We get the low 12-bits as-is; rest must be zero */
1604bf215546Sopenharmony_ci         if ((imm & 0xfffff000) == 0)
1605bf215546Sopenharmony_ci            return imm & 0xfff;
1606bf215546Sopenharmony_ci         break;
1607bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UW:
1608bf215546Sopenharmony_ci         /* We get the low 12-bits as-is; rest must be zero */
1609bf215546Sopenharmony_ci         if ((imm & 0xf000) == 0)
1610bf215546Sopenharmony_ci            return imm & 0xfff;
1611bf215546Sopenharmony_ci         break;
1612bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_D:
1613bf215546Sopenharmony_ci         /* We get the low 11-bits as-is; 12th is replicated */
1614bf215546Sopenharmony_ci         if (((int)imm >> 11) == 0 || ((int)imm >> 11) == -1)
1615bf215546Sopenharmony_ci            return imm & 0xfff;
1616bf215546Sopenharmony_ci         break;
1617bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_W:
1618bf215546Sopenharmony_ci         /* We get the low 11-bits as-is; 12th is replicated */
1619bf215546Sopenharmony_ci         if (((short)imm >> 11) == 0 || ((short)imm >> 11) == -1)
1620bf215546Sopenharmony_ci            return imm & 0xfff;
1621bf215546Sopenharmony_ci         break;
1622bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_NF:
1623bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_DF:
1624bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_Q:
1625bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UQ:
1626bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_B:
1627bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UB:
1628bf215546Sopenharmony_ci         return -1;
1629bf215546Sopenharmony_ci      }
1630bf215546Sopenharmony_ci   } else {
1631bf215546Sopenharmony_ci      /* We get the low 12 bits as-is; 13th is replicated */
1632bf215546Sopenharmony_ci      if (((int)imm >> 12) == 0 || ((int)imm >> 12 == -1)) {
1633bf215546Sopenharmony_ci         return imm & 0x1fff;
1634bf215546Sopenharmony_ci      }
1635bf215546Sopenharmony_ci   }
1636bf215546Sopenharmony_ci
1637bf215546Sopenharmony_ci   return -1;
1638bf215546Sopenharmony_ci}
1639bf215546Sopenharmony_ci
1640bf215546Sopenharmony_cistatic int
1641bf215546Sopenharmony_ciuncompact_immediate(const struct intel_device_info *devinfo,
1642bf215546Sopenharmony_ci                    enum brw_reg_type type, unsigned compact_imm)
1643bf215546Sopenharmony_ci{
1644bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1645bf215546Sopenharmony_ci      switch (type) {
1646bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_F:
1647bf215546Sopenharmony_ci         return compact_imm << 20;
1648bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_HF:
1649bf215546Sopenharmony_ci         return (compact_imm << 20) | (compact_imm << 4);
1650bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UD:
1651bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_VF:
1652bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UV:
1653bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_V:
1654bf215546Sopenharmony_ci         return compact_imm;
1655bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UW:
1656bf215546Sopenharmony_ci         /* Replicate */
1657bf215546Sopenharmony_ci         return compact_imm << 16 | compact_imm;
1658bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_D:
1659bf215546Sopenharmony_ci         /* Extend the 12th bit into the high 20 bits */
1660bf215546Sopenharmony_ci         return (int)(compact_imm << 20) >> 20;
1661bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_W:
1662bf215546Sopenharmony_ci         /* Extend the 12th bit into the high 4 bits and replicate */
1663bf215546Sopenharmony_ci         return ((int)(compact_imm << 20) >> 4) |
1664bf215546Sopenharmony_ci                ((unsigned short)((short)(compact_imm << 4) >> 4));
1665bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_NF:
1666bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_DF:
1667bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_Q:
1668bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UQ:
1669bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_B:
1670bf215546Sopenharmony_ci      case BRW_REGISTER_TYPE_UB:
1671bf215546Sopenharmony_ci         unreachable("not reached");
1672bf215546Sopenharmony_ci      }
1673bf215546Sopenharmony_ci   } else {
1674bf215546Sopenharmony_ci      /* Replicate the 13th bit into the high 19 bits */
1675bf215546Sopenharmony_ci      return (int)(compact_imm << 19) >> 19;
1676bf215546Sopenharmony_ci   }
1677bf215546Sopenharmony_ci
1678bf215546Sopenharmony_ci   unreachable("not reached");
1679bf215546Sopenharmony_ci}
1680bf215546Sopenharmony_ci
1681bf215546Sopenharmony_cistatic bool
1682bf215546Sopenharmony_cihas_immediate(const struct intel_device_info *devinfo, const brw_inst *inst,
1683bf215546Sopenharmony_ci              enum brw_reg_type *type)
1684bf215546Sopenharmony_ci{
1685bf215546Sopenharmony_ci   if (brw_inst_src0_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
1686bf215546Sopenharmony_ci      *type = brw_inst_src0_type(devinfo, inst);
1687bf215546Sopenharmony_ci      return *type != INVALID_REG_TYPE;
1688bf215546Sopenharmony_ci   } else if (brw_inst_src1_reg_file(devinfo, inst) == BRW_IMMEDIATE_VALUE) {
1689bf215546Sopenharmony_ci      *type = brw_inst_src1_type(devinfo, inst);
1690bf215546Sopenharmony_ci      return *type != INVALID_REG_TYPE;
1691bf215546Sopenharmony_ci   }
1692bf215546Sopenharmony_ci
1693bf215546Sopenharmony_ci   return false;
1694bf215546Sopenharmony_ci}
1695bf215546Sopenharmony_ci
1696bf215546Sopenharmony_ci/**
1697bf215546Sopenharmony_ci * Applies some small changes to instruction types to increase chances of
1698bf215546Sopenharmony_ci * compaction.
1699bf215546Sopenharmony_ci */
1700bf215546Sopenharmony_cistatic brw_inst
1701bf215546Sopenharmony_ciprecompact(const struct brw_isa_info *isa, brw_inst inst)
1702bf215546Sopenharmony_ci{
1703bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = isa->devinfo;
1704bf215546Sopenharmony_ci
1705bf215546Sopenharmony_ci   /* In XeHP the compaction tables removed the entries for source regions
1706bf215546Sopenharmony_ci    * <8;8,1> giving preference to <1;1,0> as the way to indicate
1707bf215546Sopenharmony_ci    * sequential elements, so convert to those before compacting.
1708bf215546Sopenharmony_ci    */
1709bf215546Sopenharmony_ci   if (devinfo->verx10 >= 125) {
1710bf215546Sopenharmony_ci      if (brw_inst_src0_reg_file(devinfo, &inst) == BRW_GENERAL_REGISTER_FILE &&
1711bf215546Sopenharmony_ci          brw_inst_src0_vstride(devinfo, &inst) > BRW_VERTICAL_STRIDE_1 &&
1712bf215546Sopenharmony_ci          brw_inst_src0_vstride(devinfo, &inst) == (brw_inst_src0_width(devinfo, &inst) + 1) &&
1713bf215546Sopenharmony_ci          brw_inst_src0_hstride(devinfo, &inst) == BRW_HORIZONTAL_STRIDE_1) {
1714bf215546Sopenharmony_ci         brw_inst_set_src0_vstride(devinfo, &inst, BRW_VERTICAL_STRIDE_1);
1715bf215546Sopenharmony_ci         brw_inst_set_src0_width(devinfo, &inst, BRW_WIDTH_1);
1716bf215546Sopenharmony_ci         brw_inst_set_src0_hstride(devinfo, &inst, BRW_HORIZONTAL_STRIDE_0);
1717bf215546Sopenharmony_ci      }
1718bf215546Sopenharmony_ci
1719bf215546Sopenharmony_ci      if (brw_inst_src1_reg_file(devinfo, &inst) == BRW_GENERAL_REGISTER_FILE &&
1720bf215546Sopenharmony_ci          brw_inst_src1_vstride(devinfo, &inst) > BRW_VERTICAL_STRIDE_1 &&
1721bf215546Sopenharmony_ci          brw_inst_src1_vstride(devinfo, &inst) == (brw_inst_src1_width(devinfo, &inst) + 1) &&
1722bf215546Sopenharmony_ci          brw_inst_src1_hstride(devinfo, &inst) == BRW_HORIZONTAL_STRIDE_1) {
1723bf215546Sopenharmony_ci         brw_inst_set_src1_vstride(devinfo, &inst, BRW_VERTICAL_STRIDE_1);
1724bf215546Sopenharmony_ci         brw_inst_set_src1_width(devinfo, &inst, BRW_WIDTH_1);
1725bf215546Sopenharmony_ci         brw_inst_set_src1_hstride(devinfo, &inst, BRW_HORIZONTAL_STRIDE_0);
1726bf215546Sopenharmony_ci      }
1727bf215546Sopenharmony_ci   }
1728bf215546Sopenharmony_ci
1729bf215546Sopenharmony_ci   if (brw_inst_src0_reg_file(devinfo, &inst) != BRW_IMMEDIATE_VALUE)
1730bf215546Sopenharmony_ci      return inst;
1731bf215546Sopenharmony_ci
1732bf215546Sopenharmony_ci   /* The Bspec's section titled "Non-present Operands" claims that if src0
1733bf215546Sopenharmony_ci    * is an immediate that src1's type must be the same as that of src0.
1734bf215546Sopenharmony_ci    *
1735bf215546Sopenharmony_ci    * The SNB+ DataTypeIndex instruction compaction tables contain mappings
1736bf215546Sopenharmony_ci    * that do not follow this rule. E.g., from the IVB/HSW table:
1737bf215546Sopenharmony_ci    *
1738bf215546Sopenharmony_ci    *  DataTypeIndex   18-Bit Mapping       Mapped Meaning
1739bf215546Sopenharmony_ci    *        3         001000001011111101   r:f | i:vf | a:ud | <1> | dir |
1740bf215546Sopenharmony_ci    *
1741bf215546Sopenharmony_ci    * And from the SNB table:
1742bf215546Sopenharmony_ci    *
1743bf215546Sopenharmony_ci    *  DataTypeIndex   18-Bit Mapping       Mapped Meaning
1744bf215546Sopenharmony_ci    *        8         001000000111101100   a:w | i:w | a:ud | <1> | dir |
1745bf215546Sopenharmony_ci    *
1746bf215546Sopenharmony_ci    * Neither of these cause warnings from the simulator when used,
1747bf215546Sopenharmony_ci    * compacted or otherwise. In fact, all compaction mappings that have an
1748bf215546Sopenharmony_ci    * immediate in src0 use a:ud for src1.
1749bf215546Sopenharmony_ci    *
1750bf215546Sopenharmony_ci    * The GM45 instruction compaction tables do not contain mapped meanings
1751bf215546Sopenharmony_ci    * so it's not clear whether it has the restriction. We'll assume it was
1752bf215546Sopenharmony_ci    * lifted on SNB. (FINISHME: decode the GM45 tables and check.)
1753bf215546Sopenharmony_ci    *
1754bf215546Sopenharmony_ci    * Don't do any of this for 64-bit immediates, since the src1 fields
1755bf215546Sopenharmony_ci    * overlap with the immediate and setting them would overwrite the
1756bf215546Sopenharmony_ci    * immediate we set.
1757bf215546Sopenharmony_ci    */
1758bf215546Sopenharmony_ci   if (devinfo->ver >= 6 &&
1759bf215546Sopenharmony_ci       !(devinfo->platform == INTEL_PLATFORM_HSW &&
1760bf215546Sopenharmony_ci         brw_inst_opcode(isa, &inst) == BRW_OPCODE_DIM) &&
1761bf215546Sopenharmony_ci       !(devinfo->ver >= 8 &&
1762bf215546Sopenharmony_ci         (brw_inst_src0_type(devinfo, &inst) == BRW_REGISTER_TYPE_DF ||
1763bf215546Sopenharmony_ci          brw_inst_src0_type(devinfo, &inst) == BRW_REGISTER_TYPE_UQ ||
1764bf215546Sopenharmony_ci          brw_inst_src0_type(devinfo, &inst) == BRW_REGISTER_TYPE_Q))) {
1765bf215546Sopenharmony_ci      brw_inst_set_src1_reg_hw_type(devinfo, &inst, 0);
1766bf215546Sopenharmony_ci   }
1767bf215546Sopenharmony_ci
1768bf215546Sopenharmony_ci   /* Compacted instructions only have 12-bits (plus 1 for the other 20)
1769bf215546Sopenharmony_ci    * for immediate values. Presumably the hardware engineers realized
1770bf215546Sopenharmony_ci    * that the only useful floating-point value that could be represented
1771bf215546Sopenharmony_ci    * in this format is 0.0, which can also be represented as a VF-typed
1772bf215546Sopenharmony_ci    * immediate, so they gave us the previously mentioned mapping on IVB+.
1773bf215546Sopenharmony_ci    *
1774bf215546Sopenharmony_ci    * Strangely, we do have a mapping for imm:f in src1, so we don't need
1775bf215546Sopenharmony_ci    * to do this there.
1776bf215546Sopenharmony_ci    *
1777bf215546Sopenharmony_ci    * If we see a 0.0:F, change the type to VF so that it can be compacted.
1778bf215546Sopenharmony_ci    *
1779bf215546Sopenharmony_ci    * Compaction of floating-point immediates is improved on Gfx12, thus
1780bf215546Sopenharmony_ci    * removing the need for this.
1781bf215546Sopenharmony_ci    */
1782bf215546Sopenharmony_ci   if (devinfo->ver < 12 &&
1783bf215546Sopenharmony_ci       brw_inst_imm_ud(devinfo, &inst) == 0x0 &&
1784bf215546Sopenharmony_ci       brw_inst_src0_type(devinfo, &inst) == BRW_REGISTER_TYPE_F &&
1785bf215546Sopenharmony_ci       brw_inst_dst_type(devinfo, &inst) == BRW_REGISTER_TYPE_F &&
1786bf215546Sopenharmony_ci       brw_inst_dst_hstride(devinfo, &inst) == BRW_HORIZONTAL_STRIDE_1) {
1787bf215546Sopenharmony_ci      enum brw_reg_file file = brw_inst_src0_reg_file(devinfo, &inst);
1788bf215546Sopenharmony_ci      brw_inst_set_src0_file_type(devinfo, &inst, file, BRW_REGISTER_TYPE_VF);
1789bf215546Sopenharmony_ci   }
1790bf215546Sopenharmony_ci
1791bf215546Sopenharmony_ci   /* There are no mappings for dst:d | i:d, so if the immediate is suitable
1792bf215546Sopenharmony_ci    * set the types to :UD so the instruction can be compacted.
1793bf215546Sopenharmony_ci    *
1794bf215546Sopenharmony_ci    * FINISHME: Use dst:f | imm:f on Gfx12
1795bf215546Sopenharmony_ci    */
1796bf215546Sopenharmony_ci   if (devinfo->ver < 12 &&
1797bf215546Sopenharmony_ci       compact_immediate(devinfo, BRW_REGISTER_TYPE_D,
1798bf215546Sopenharmony_ci                         brw_inst_imm_ud(devinfo, &inst)) != -1 &&
1799bf215546Sopenharmony_ci       brw_inst_cond_modifier(devinfo, &inst) == BRW_CONDITIONAL_NONE &&
1800bf215546Sopenharmony_ci       brw_inst_src0_type(devinfo, &inst) == BRW_REGISTER_TYPE_D &&
1801bf215546Sopenharmony_ci       brw_inst_dst_type(devinfo, &inst) == BRW_REGISTER_TYPE_D) {
1802bf215546Sopenharmony_ci      enum brw_reg_file src_file = brw_inst_src0_reg_file(devinfo, &inst);
1803bf215546Sopenharmony_ci      enum brw_reg_file dst_file = brw_inst_dst_reg_file(devinfo, &inst);
1804bf215546Sopenharmony_ci
1805bf215546Sopenharmony_ci      brw_inst_set_src0_file_type(devinfo, &inst, src_file, BRW_REGISTER_TYPE_UD);
1806bf215546Sopenharmony_ci      brw_inst_set_dst_file_type(devinfo, &inst, dst_file, BRW_REGISTER_TYPE_UD);
1807bf215546Sopenharmony_ci   }
1808bf215546Sopenharmony_ci
1809bf215546Sopenharmony_ci   return inst;
1810bf215546Sopenharmony_ci}
1811bf215546Sopenharmony_ci
1812bf215546Sopenharmony_ci/**
1813bf215546Sopenharmony_ci * Tries to compact instruction src into dst.
1814bf215546Sopenharmony_ci *
1815bf215546Sopenharmony_ci * It doesn't modify dst unless src is compactable, which is relied on by
1816bf215546Sopenharmony_ci * brw_compact_instructions().
1817bf215546Sopenharmony_ci */
1818bf215546Sopenharmony_cistatic bool
1819bf215546Sopenharmony_citry_compact_instruction(const struct compaction_state *c,
1820bf215546Sopenharmony_ci                        brw_compact_inst *dst, const brw_inst *src)
1821bf215546Sopenharmony_ci{
1822bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1823bf215546Sopenharmony_ci   brw_compact_inst temp;
1824bf215546Sopenharmony_ci
1825bf215546Sopenharmony_ci   assert(brw_inst_cmpt_control(devinfo, src) == 0);
1826bf215546Sopenharmony_ci
1827bf215546Sopenharmony_ci   if (is_3src(c->isa, brw_inst_opcode(c->isa, src))) {
1828bf215546Sopenharmony_ci      if (devinfo->ver >= 8) {
1829bf215546Sopenharmony_ci         memset(&temp, 0, sizeof(temp));
1830bf215546Sopenharmony_ci         if (brw_try_compact_3src_instruction(devinfo, &temp, src)) {
1831bf215546Sopenharmony_ci            *dst = temp;
1832bf215546Sopenharmony_ci            return true;
1833bf215546Sopenharmony_ci         } else {
1834bf215546Sopenharmony_ci            return false;
1835bf215546Sopenharmony_ci         }
1836bf215546Sopenharmony_ci      } else {
1837bf215546Sopenharmony_ci         return false;
1838bf215546Sopenharmony_ci      }
1839bf215546Sopenharmony_ci   }
1840bf215546Sopenharmony_ci
1841bf215546Sopenharmony_ci   enum brw_reg_type type;
1842bf215546Sopenharmony_ci   bool is_immediate = has_immediate(devinfo, src, &type);
1843bf215546Sopenharmony_ci
1844bf215546Sopenharmony_ci   unsigned compacted_imm = 0;
1845bf215546Sopenharmony_ci
1846bf215546Sopenharmony_ci   if (is_immediate) {
1847bf215546Sopenharmony_ci      /* Instructions with immediates cannot be compacted on Gen < 6 */
1848bf215546Sopenharmony_ci      if (devinfo->ver < 6)
1849bf215546Sopenharmony_ci         return false;
1850bf215546Sopenharmony_ci
1851bf215546Sopenharmony_ci      compacted_imm = compact_immediate(devinfo, type,
1852bf215546Sopenharmony_ci                                        brw_inst_imm_ud(devinfo, src));
1853bf215546Sopenharmony_ci      if (compacted_imm == -1)
1854bf215546Sopenharmony_ci         return false;
1855bf215546Sopenharmony_ci   }
1856bf215546Sopenharmony_ci
1857bf215546Sopenharmony_ci   if (has_unmapped_bits(c->isa, src))
1858bf215546Sopenharmony_ci      return false;
1859bf215546Sopenharmony_ci
1860bf215546Sopenharmony_ci   memset(&temp, 0, sizeof(temp));
1861bf215546Sopenharmony_ci
1862bf215546Sopenharmony_ci#define compact(field) \
1863bf215546Sopenharmony_ci   brw_compact_inst_set_##field(devinfo, &temp, brw_inst_##field(devinfo, src))
1864bf215546Sopenharmony_ci#define compact_reg(field) \
1865bf215546Sopenharmony_ci   brw_compact_inst_set_##field##_reg_nr(devinfo, &temp, \
1866bf215546Sopenharmony_ci                                       brw_inst_##field##_da_reg_nr(devinfo, src))
1867bf215546Sopenharmony_ci
1868bf215546Sopenharmony_ci   compact(hw_opcode);
1869bf215546Sopenharmony_ci   compact(debug_control);
1870bf215546Sopenharmony_ci
1871bf215546Sopenharmony_ci   if (!set_control_index(c, &temp, src))
1872bf215546Sopenharmony_ci      return false;
1873bf215546Sopenharmony_ci   if (!set_datatype_index(c, &temp, src, is_immediate))
1874bf215546Sopenharmony_ci      return false;
1875bf215546Sopenharmony_ci   if (!set_subreg_index(c, &temp, src, is_immediate))
1876bf215546Sopenharmony_ci      return false;
1877bf215546Sopenharmony_ci   if (!set_src0_index(c, &temp, src))
1878bf215546Sopenharmony_ci      return false;
1879bf215546Sopenharmony_ci   if (!set_src1_index(c, &temp, src, is_immediate, compacted_imm))
1880bf215546Sopenharmony_ci      return false;
1881bf215546Sopenharmony_ci
1882bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1883bf215546Sopenharmony_ci      compact(swsb);
1884bf215546Sopenharmony_ci      compact_reg(dst);
1885bf215546Sopenharmony_ci      compact_reg(src0);
1886bf215546Sopenharmony_ci
1887bf215546Sopenharmony_ci      if (is_immediate) {
1888bf215546Sopenharmony_ci         /* src1 reg takes the high 8 bits (of the 12-bit compacted value) */
1889bf215546Sopenharmony_ci         brw_compact_inst_set_src1_reg_nr(devinfo, &temp, compacted_imm >> 4);
1890bf215546Sopenharmony_ci      } else {
1891bf215546Sopenharmony_ci         compact_reg(src1);
1892bf215546Sopenharmony_ci      }
1893bf215546Sopenharmony_ci   } else {
1894bf215546Sopenharmony_ci      if (devinfo->ver >= 6) {
1895bf215546Sopenharmony_ci         compact(acc_wr_control);
1896bf215546Sopenharmony_ci      } else {
1897bf215546Sopenharmony_ci         compact(mask_control_ex);
1898bf215546Sopenharmony_ci      }
1899bf215546Sopenharmony_ci
1900bf215546Sopenharmony_ci      if (devinfo->ver <= 6)
1901bf215546Sopenharmony_ci         compact(flag_subreg_nr);
1902bf215546Sopenharmony_ci
1903bf215546Sopenharmony_ci      compact(cond_modifier);
1904bf215546Sopenharmony_ci
1905bf215546Sopenharmony_ci      compact_reg(dst);
1906bf215546Sopenharmony_ci      compact_reg(src0);
1907bf215546Sopenharmony_ci
1908bf215546Sopenharmony_ci      if (is_immediate) {
1909bf215546Sopenharmony_ci         /* src1 reg takes the low 8 bits (of the 13-bit compacted value) */
1910bf215546Sopenharmony_ci         brw_compact_inst_set_src1_reg_nr(devinfo, &temp, compacted_imm & 0xff);
1911bf215546Sopenharmony_ci      } else {
1912bf215546Sopenharmony_ci         compact_reg(src1);
1913bf215546Sopenharmony_ci      }
1914bf215546Sopenharmony_ci   }
1915bf215546Sopenharmony_ci   brw_compact_inst_set_cmpt_control(devinfo, &temp, true);
1916bf215546Sopenharmony_ci
1917bf215546Sopenharmony_ci#undef compact
1918bf215546Sopenharmony_ci#undef compact_reg
1919bf215546Sopenharmony_ci
1920bf215546Sopenharmony_ci   *dst = temp;
1921bf215546Sopenharmony_ci
1922bf215546Sopenharmony_ci   return true;
1923bf215546Sopenharmony_ci}
1924bf215546Sopenharmony_ci
1925bf215546Sopenharmony_cibool
1926bf215546Sopenharmony_cibrw_try_compact_instruction(const struct brw_isa_info *isa,
1927bf215546Sopenharmony_ci                            brw_compact_inst *dst, const brw_inst *src)
1928bf215546Sopenharmony_ci{
1929bf215546Sopenharmony_ci   struct compaction_state c;
1930bf215546Sopenharmony_ci   compaction_state_init(&c, isa);
1931bf215546Sopenharmony_ci   return try_compact_instruction(&c, dst, src);
1932bf215546Sopenharmony_ci}
1933bf215546Sopenharmony_ci
1934bf215546Sopenharmony_cistatic void
1935bf215546Sopenharmony_ciset_uncompacted_control(const struct compaction_state *c, brw_inst *dst,
1936bf215546Sopenharmony_ci                        brw_compact_inst *src)
1937bf215546Sopenharmony_ci{
1938bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1939bf215546Sopenharmony_ci   uint32_t uncompacted =
1940bf215546Sopenharmony_ci      c->control_index_table[brw_compact_inst_control_index(devinfo, src)];
1941bf215546Sopenharmony_ci
1942bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1943bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 95, 92, (uncompacted >> 17));
1944bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 34, 34, (uncompacted >> 16) & 0x1);
1945bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 33, 33, (uncompacted >> 15) & 0x1);
1946bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 32, 32, (uncompacted >> 14) & 0x1);
1947bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 31, 31, (uncompacted >> 13) & 0x1);
1948bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 28, 28, (uncompacted >> 12) & 0x1);
1949bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 27, 24, (uncompacted >>  8) & 0xf);
1950bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 23, 22, (uncompacted >>  6) & 0x3);
1951bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 21, 19, (uncompacted >>  3) & 0x7);
1952bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 18, 16, (uncompacted >>  0) & 0x7);
1953bf215546Sopenharmony_ci   } else if (devinfo->ver >= 8) {
1954bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 33, 31, (uncompacted >> 16));
1955bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 23, 12, (uncompacted >>  4) & 0xfff);
1956bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 10,  9, (uncompacted >>  2) & 0x3);
1957bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 34, 34, (uncompacted >>  1) & 0x1);
1958bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  8,  8, (uncompacted >>  0) & 0x1);
1959bf215546Sopenharmony_ci   } else {
1960bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 31, 31, (uncompacted >> 16) & 0x1);
1961bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 23,  8, (uncompacted & 0xffff));
1962bf215546Sopenharmony_ci
1963bf215546Sopenharmony_ci      if (devinfo->ver == 7)
1964bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 90, 89, uncompacted >> 17);
1965bf215546Sopenharmony_ci   }
1966bf215546Sopenharmony_ci}
1967bf215546Sopenharmony_ci
1968bf215546Sopenharmony_cistatic void
1969bf215546Sopenharmony_ciset_uncompacted_datatype(const struct compaction_state *c, brw_inst *dst,
1970bf215546Sopenharmony_ci                         brw_compact_inst *src)
1971bf215546Sopenharmony_ci{
1972bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
1973bf215546Sopenharmony_ci   uint32_t uncompacted =
1974bf215546Sopenharmony_ci      c->datatype_table[brw_compact_inst_datatype_index(devinfo, src)];
1975bf215546Sopenharmony_ci
1976bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
1977bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 98, 98, (uncompacted >> 19));
1978bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 91, 88, (uncompacted >> 15) & 0xf);
1979bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 66, 66, (uncompacted >> 14) & 0x1);
1980bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 50, 50, (uncompacted >> 13) & 0x1);
1981bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 49, 48, (uncompacted >> 11) & 0x3);
1982bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 47, 47, (uncompacted >> 10) & 0x1);
1983bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 46, 46, (uncompacted >>  9) & 0x1);
1984bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 43, 40, (uncompacted >>  5) & 0xf);
1985bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 39, 36, (uncompacted >>  1) & 0xf);
1986bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 35, 35, (uncompacted >>  0) & 0x1);
1987bf215546Sopenharmony_ci   } else if (devinfo->ver >= 8) {
1988bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 63, 61, (uncompacted >> 18));
1989bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 94, 89, (uncompacted >> 12) & 0x3f);
1990bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 46, 35, (uncompacted >>  0) & 0xfff);
1991bf215546Sopenharmony_ci   } else {
1992bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 63, 61, (uncompacted >> 15));
1993bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 46, 32, (uncompacted & 0x7fff));
1994bf215546Sopenharmony_ci   }
1995bf215546Sopenharmony_ci}
1996bf215546Sopenharmony_ci
1997bf215546Sopenharmony_cistatic void
1998bf215546Sopenharmony_ciset_uncompacted_subreg(const struct compaction_state *c, brw_inst *dst,
1999bf215546Sopenharmony_ci                       brw_compact_inst *src)
2000bf215546Sopenharmony_ci{
2001bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2002bf215546Sopenharmony_ci   uint16_t uncompacted =
2003bf215546Sopenharmony_ci      c->subreg_table[brw_compact_inst_subreg_index(devinfo, src)];
2004bf215546Sopenharmony_ci
2005bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2006bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 103, 99, (uncompacted >> 10));
2007bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  71, 67, (uncompacted >>  5) & 0x1f);
2008bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  55, 51, (uncompacted >>  0) & 0x1f);
2009bf215546Sopenharmony_ci   } else {
2010bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 100, 96, (uncompacted >> 10));
2011bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  68, 64, (uncompacted >>  5) & 0x1f);
2012bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  52, 48, (uncompacted >>  0) & 0x1f);
2013bf215546Sopenharmony_ci   }
2014bf215546Sopenharmony_ci}
2015bf215546Sopenharmony_ci
2016bf215546Sopenharmony_cistatic void
2017bf215546Sopenharmony_ciset_uncompacted_src0(const struct compaction_state *c, brw_inst *dst,
2018bf215546Sopenharmony_ci                     brw_compact_inst *src)
2019bf215546Sopenharmony_ci{
2020bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2021bf215546Sopenharmony_ci   uint32_t compacted = brw_compact_inst_src0_index(devinfo, src);
2022bf215546Sopenharmony_ci   uint16_t uncompacted = c->src0_index_table[compacted];
2023bf215546Sopenharmony_ci
2024bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2025bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 87, 84, (uncompacted >> 8));
2026bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 83, 81, (uncompacted >> 5) & 0x7);
2027bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 80, 80, (uncompacted >> 4) & 0x1);
2028bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 65, 64, (uncompacted >> 2) & 0x3);
2029bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 45, 44, (uncompacted >> 0) & 0x3);
2030bf215546Sopenharmony_ci   } else {
2031bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 88, 77, uncompacted);
2032bf215546Sopenharmony_ci   }
2033bf215546Sopenharmony_ci}
2034bf215546Sopenharmony_ci
2035bf215546Sopenharmony_cistatic void
2036bf215546Sopenharmony_ciset_uncompacted_src1(const struct compaction_state *c, brw_inst *dst,
2037bf215546Sopenharmony_ci                     brw_compact_inst *src)
2038bf215546Sopenharmony_ci{
2039bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2040bf215546Sopenharmony_ci   uint16_t uncompacted =
2041bf215546Sopenharmony_ci      c->src1_index_table[brw_compact_inst_src1_index(devinfo, src)];
2042bf215546Sopenharmony_ci
2043bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2044bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 121, 120, (uncompacted >> 10));
2045bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 119, 116, (uncompacted >>  6) & 0xf);
2046bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 115, 113, (uncompacted >>  3) & 0x7);
2047bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 112, 112, (uncompacted >>  2) & 0x1);
2048bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  97,  96, (uncompacted >>  0) & 0x3);
2049bf215546Sopenharmony_ci   } else {
2050bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 120, 109, uncompacted);
2051bf215546Sopenharmony_ci   }
2052bf215546Sopenharmony_ci}
2053bf215546Sopenharmony_ci
2054bf215546Sopenharmony_cistatic void
2055bf215546Sopenharmony_ciset_uncompacted_3src_control_index(const struct compaction_state *c,
2056bf215546Sopenharmony_ci                                   brw_inst *dst, brw_compact_inst *src)
2057bf215546Sopenharmony_ci{
2058bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2059bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
2060bf215546Sopenharmony_ci
2061bf215546Sopenharmony_ci   if (devinfo->verx10 >= 125) {
2062bf215546Sopenharmony_ci      uint64_t compacted = brw_compact_inst_3src_control_index(devinfo, src);
2063bf215546Sopenharmony_ci      uint64_t uncompacted = xehp_3src_control_index_table[compacted];
2064bf215546Sopenharmony_ci
2065bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 95, 92, (uncompacted >> 33));
2066bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 90, 88, (uncompacted >> 30) & 0x7);
2067bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 82, 80, (uncompacted >> 27) & 0x7);
2068bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 50, 50, (uncompacted >> 26) & 0x1);
2069bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 49, 48, (uncompacted >> 24) & 0x3);
2070bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 42, 40, (uncompacted >> 21) & 0x7);
2071bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 39, 39, (uncompacted >> 20) & 0x1);
2072bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 38, 36, (uncompacted >> 17) & 0x7);
2073bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 34, 34, (uncompacted >> 16) & 0x1);
2074bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 33, 33, (uncompacted >> 15) & 0x1);
2075bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 32, 32, (uncompacted >> 14) & 0x1);
2076bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 31, 31, (uncompacted >> 13) & 0x1);
2077bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 28, 28, (uncompacted >> 12) & 0x1);
2078bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 27, 24, (uncompacted >>  8) & 0xf);
2079bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 23, 23, (uncompacted >>  7) & 0x1);
2080bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 22, 22, (uncompacted >>  6) & 0x1);
2081bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 21, 19, (uncompacted >>  3) & 0x7);
2082bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 18, 16, (uncompacted >>  0) & 0x7);
2083bf215546Sopenharmony_ci
2084bf215546Sopenharmony_ci   } else if (devinfo->ver >= 12) {
2085bf215546Sopenharmony_ci      uint64_t compacted = brw_compact_inst_3src_control_index(devinfo, src);
2086bf215546Sopenharmony_ci      uint64_t uncompacted = gfx12_3src_control_index_table[compacted];
2087bf215546Sopenharmony_ci
2088bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 95, 92, (uncompacted >> 32));
2089bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 90, 88, (uncompacted >> 29) & 0x7);
2090bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 82, 80, (uncompacted >> 26) & 0x7);
2091bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 50, 50, (uncompacted >> 25) & 0x1);
2092bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 48, 48, (uncompacted >> 24) & 0x1);
2093bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 42, 40, (uncompacted >> 21) & 0x7);
2094bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 39, 39, (uncompacted >> 20) & 0x1);
2095bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 38, 36, (uncompacted >> 17) & 0x7);
2096bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 34, 34, (uncompacted >> 16) & 0x1);
2097bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 33, 33, (uncompacted >> 15) & 0x1);
2098bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 32, 32, (uncompacted >> 14) & 0x1);
2099bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 31, 31, (uncompacted >> 13) & 0x1);
2100bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 28, 28, (uncompacted >> 12) & 0x1);
2101bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 27, 24, (uncompacted >>  8) & 0xf);
2102bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 23, 23, (uncompacted >>  7) & 0x1);
2103bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 22, 22, (uncompacted >>  6) & 0x1);
2104bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 21, 19, (uncompacted >>  3) & 0x7);
2105bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 18, 16, (uncompacted >>  0) & 0x7);
2106bf215546Sopenharmony_ci   } else {
2107bf215546Sopenharmony_ci      uint32_t compacted = brw_compact_inst_3src_control_index(devinfo, src);
2108bf215546Sopenharmony_ci      uint32_t uncompacted = gfx8_3src_control_index_table[compacted];
2109bf215546Sopenharmony_ci
2110bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 34, 32, (uncompacted >> 21) & 0x7);
2111bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 28,  8, (uncompacted >>  0) & 0x1fffff);
2112bf215546Sopenharmony_ci
2113bf215546Sopenharmony_ci      if (devinfo->ver >= 9 || devinfo->platform == INTEL_PLATFORM_CHV)
2114bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 36, 35, (uncompacted >> 24) & 0x3);
2115bf215546Sopenharmony_ci   }
2116bf215546Sopenharmony_ci}
2117bf215546Sopenharmony_ci
2118bf215546Sopenharmony_cistatic void
2119bf215546Sopenharmony_ciset_uncompacted_3src_source_index(const struct intel_device_info *devinfo,
2120bf215546Sopenharmony_ci                                  brw_inst *dst, brw_compact_inst *src)
2121bf215546Sopenharmony_ci{
2122bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
2123bf215546Sopenharmony_ci
2124bf215546Sopenharmony_ci   uint32_t compacted = brw_compact_inst_3src_source_index(devinfo, src);
2125bf215546Sopenharmony_ci
2126bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2127bf215546Sopenharmony_ci      const uint32_t *three_src_source_index_table =
2128bf215546Sopenharmony_ci         devinfo->verx10 >= 125 ?
2129bf215546Sopenharmony_ci         xehp_3src_source_index_table : gfx12_3src_source_index_table;
2130bf215546Sopenharmony_ci      uint32_t uncompacted = three_src_source_index_table[compacted];
2131bf215546Sopenharmony_ci
2132bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 114, 114, (uncompacted >> 20));
2133bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 113, 112, (uncompacted >> 18) & 0x3);
2134bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  98,  98, (uncompacted >> 17) & 0x1);
2135bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  97,  96, (uncompacted >> 15) & 0x3);
2136bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  91,  91, (uncompacted >> 14) & 0x1);
2137bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  87,  86, (uncompacted >> 12) & 0x3);
2138bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  85,  84, (uncompacted >> 10) & 0x3);
2139bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  83,  83, (uncompacted >>  9) & 0x1);
2140bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  66,  66, (uncompacted >>  8) & 0x1);
2141bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  65,  64, (uncompacted >>  6) & 0x3);
2142bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  47,  47, (uncompacted >>  5) & 0x1);
2143bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  46,  46, (uncompacted >>  4) & 0x1);
2144bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  45,  44, (uncompacted >>  2) & 0x3);
2145bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  43,  43, (uncompacted >>  1) & 0x1);
2146bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  35,  35, (uncompacted >>  0) & 0x1);
2147bf215546Sopenharmony_ci   } else {
2148bf215546Sopenharmony_ci      uint64_t uncompacted = gfx8_3src_source_index_table[compacted];
2149bf215546Sopenharmony_ci
2150bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  83,  83, (uncompacted >> 43) & 0x1);
2151bf215546Sopenharmony_ci      brw_inst_set_bits(dst, 114, 107, (uncompacted >> 35) & 0xff);
2152bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  93,  86, (uncompacted >> 27) & 0xff);
2153bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  72,  65, (uncompacted >> 19) & 0xff);
2154bf215546Sopenharmony_ci      brw_inst_set_bits(dst,  55,  37, (uncompacted >>  0) & 0x7ffff);
2155bf215546Sopenharmony_ci
2156bf215546Sopenharmony_ci      if (devinfo->ver >= 9 || devinfo->platform == INTEL_PLATFORM_CHV) {
2157bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 126, 125, (uncompacted >> 47) & 0x3);
2158bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 105, 104, (uncompacted >> 45) & 0x3);
2159bf215546Sopenharmony_ci         brw_inst_set_bits(dst,  84,  84, (uncompacted >> 44) & 0x1);
2160bf215546Sopenharmony_ci      } else {
2161bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 125, 125, (uncompacted >> 45) & 0x1);
2162bf215546Sopenharmony_ci         brw_inst_set_bits(dst, 104, 104, (uncompacted >> 44) & 0x1);
2163bf215546Sopenharmony_ci      }
2164bf215546Sopenharmony_ci   }
2165bf215546Sopenharmony_ci}
2166bf215546Sopenharmony_ci
2167bf215546Sopenharmony_cistatic void
2168bf215546Sopenharmony_ciset_uncompacted_3src_subreg_index(const struct intel_device_info *devinfo,
2169bf215546Sopenharmony_ci                                  brw_inst *dst, brw_compact_inst *src)
2170bf215546Sopenharmony_ci{
2171bf215546Sopenharmony_ci   assert(devinfo->ver >= 12);
2172bf215546Sopenharmony_ci
2173bf215546Sopenharmony_ci   uint32_t compacted = brw_compact_inst_3src_subreg_index(devinfo, src);
2174bf215546Sopenharmony_ci   uint32_t uncompacted = gfx12_3src_subreg_table[compacted];
2175bf215546Sopenharmony_ci
2176bf215546Sopenharmony_ci   brw_inst_set_bits(dst, 119, 115, (uncompacted >> 15));
2177bf215546Sopenharmony_ci   brw_inst_set_bits(dst, 103,  99, (uncompacted >> 10) & 0x1f);
2178bf215546Sopenharmony_ci   brw_inst_set_bits(dst,  71,  67, (uncompacted >>  5) & 0x1f);
2179bf215546Sopenharmony_ci   brw_inst_set_bits(dst,  55,  51, (uncompacted >>  0) & 0x1f);
2180bf215546Sopenharmony_ci}
2181bf215546Sopenharmony_ci
2182bf215546Sopenharmony_cistatic void
2183bf215546Sopenharmony_cibrw_uncompact_3src_instruction(const struct compaction_state *c,
2184bf215546Sopenharmony_ci                               brw_inst *dst, brw_compact_inst *src)
2185bf215546Sopenharmony_ci{
2186bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2187bf215546Sopenharmony_ci   assert(devinfo->ver >= 8);
2188bf215546Sopenharmony_ci
2189bf215546Sopenharmony_ci#define uncompact(field) \
2190bf215546Sopenharmony_ci   brw_inst_set_3src_##field(devinfo, dst, brw_compact_inst_3src_##field(devinfo, src))
2191bf215546Sopenharmony_ci#define uncompact_a16(field) \
2192bf215546Sopenharmony_ci   brw_inst_set_3src_a16_##field(devinfo, dst, brw_compact_inst_3src_##field(devinfo, src))
2193bf215546Sopenharmony_ci
2194bf215546Sopenharmony_ci   uncompact(hw_opcode);
2195bf215546Sopenharmony_ci
2196bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2197bf215546Sopenharmony_ci      set_uncompacted_3src_control_index(c, dst, src);
2198bf215546Sopenharmony_ci      set_uncompacted_3src_source_index(devinfo, dst, src);
2199bf215546Sopenharmony_ci      set_uncompacted_3src_subreg_index(devinfo, dst, src);
2200bf215546Sopenharmony_ci
2201bf215546Sopenharmony_ci      uncompact(debug_control);
2202bf215546Sopenharmony_ci      uncompact(swsb);
2203bf215546Sopenharmony_ci      uncompact(dst_reg_nr);
2204bf215546Sopenharmony_ci      uncompact(src0_reg_nr);
2205bf215546Sopenharmony_ci      uncompact(src1_reg_nr);
2206bf215546Sopenharmony_ci      uncompact(src2_reg_nr);
2207bf215546Sopenharmony_ci   } else {
2208bf215546Sopenharmony_ci      set_uncompacted_3src_control_index(c, dst, src);
2209bf215546Sopenharmony_ci      set_uncompacted_3src_source_index(devinfo, dst, src);
2210bf215546Sopenharmony_ci
2211bf215546Sopenharmony_ci      uncompact(dst_reg_nr);
2212bf215546Sopenharmony_ci      uncompact_a16(src0_rep_ctrl);
2213bf215546Sopenharmony_ci      uncompact(debug_control);
2214bf215546Sopenharmony_ci      uncompact(saturate);
2215bf215546Sopenharmony_ci      uncompact_a16(src1_rep_ctrl);
2216bf215546Sopenharmony_ci      uncompact_a16(src2_rep_ctrl);
2217bf215546Sopenharmony_ci      uncompact(src0_reg_nr);
2218bf215546Sopenharmony_ci      uncompact(src1_reg_nr);
2219bf215546Sopenharmony_ci      uncompact(src2_reg_nr);
2220bf215546Sopenharmony_ci      uncompact_a16(src0_subreg_nr);
2221bf215546Sopenharmony_ci      uncompact_a16(src1_subreg_nr);
2222bf215546Sopenharmony_ci      uncompact_a16(src2_subreg_nr);
2223bf215546Sopenharmony_ci   }
2224bf215546Sopenharmony_ci   brw_inst_set_3src_cmpt_control(devinfo, dst, false);
2225bf215546Sopenharmony_ci
2226bf215546Sopenharmony_ci#undef uncompact
2227bf215546Sopenharmony_ci#undef uncompact_a16
2228bf215546Sopenharmony_ci}
2229bf215546Sopenharmony_ci
2230bf215546Sopenharmony_cistatic void
2231bf215546Sopenharmony_ciuncompact_instruction(const struct compaction_state *c, brw_inst *dst,
2232bf215546Sopenharmony_ci                      brw_compact_inst *src)
2233bf215546Sopenharmony_ci{
2234bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = c->isa->devinfo;
2235bf215546Sopenharmony_ci   memset(dst, 0, sizeof(*dst));
2236bf215546Sopenharmony_ci
2237bf215546Sopenharmony_ci   if (devinfo->ver >= 8 &&
2238bf215546Sopenharmony_ci       is_3src(c->isa, brw_opcode_decode(c->isa,
2239bf215546Sopenharmony_ci                  brw_compact_inst_3src_hw_opcode(devinfo, src)))) {
2240bf215546Sopenharmony_ci      brw_uncompact_3src_instruction(c, dst, src);
2241bf215546Sopenharmony_ci      return;
2242bf215546Sopenharmony_ci   }
2243bf215546Sopenharmony_ci
2244bf215546Sopenharmony_ci#define uncompact(field) \
2245bf215546Sopenharmony_ci   brw_inst_set_##field(devinfo, dst, brw_compact_inst_##field(devinfo, src))
2246bf215546Sopenharmony_ci#define uncompact_reg(field) \
2247bf215546Sopenharmony_ci   brw_inst_set_##field##_da_reg_nr(devinfo, dst, \
2248bf215546Sopenharmony_ci                                    brw_compact_inst_##field##_reg_nr(devinfo, src))
2249bf215546Sopenharmony_ci
2250bf215546Sopenharmony_ci   uncompact(hw_opcode);
2251bf215546Sopenharmony_ci   uncompact(debug_control);
2252bf215546Sopenharmony_ci
2253bf215546Sopenharmony_ci   set_uncompacted_control(c, dst, src);
2254bf215546Sopenharmony_ci   set_uncompacted_datatype(c, dst, src);
2255bf215546Sopenharmony_ci   set_uncompacted_subreg(c, dst, src);
2256bf215546Sopenharmony_ci   set_uncompacted_src0(c, dst, src);
2257bf215546Sopenharmony_ci
2258bf215546Sopenharmony_ci   enum brw_reg_type type;
2259bf215546Sopenharmony_ci   if (has_immediate(devinfo, dst, &type)) {
2260bf215546Sopenharmony_ci      unsigned imm = uncompact_immediate(devinfo, type,
2261bf215546Sopenharmony_ci                                         brw_compact_inst_imm(devinfo, src));
2262bf215546Sopenharmony_ci      brw_inst_set_imm_ud(devinfo, dst, imm);
2263bf215546Sopenharmony_ci   } else {
2264bf215546Sopenharmony_ci      set_uncompacted_src1(c, dst, src);
2265bf215546Sopenharmony_ci      uncompact_reg(src1);
2266bf215546Sopenharmony_ci   }
2267bf215546Sopenharmony_ci
2268bf215546Sopenharmony_ci   if (devinfo->ver >= 12) {
2269bf215546Sopenharmony_ci      uncompact(swsb);
2270bf215546Sopenharmony_ci      uncompact_reg(dst);
2271bf215546Sopenharmony_ci      uncompact_reg(src0);
2272bf215546Sopenharmony_ci   } else {
2273bf215546Sopenharmony_ci      if (devinfo->ver >= 6) {
2274bf215546Sopenharmony_ci         uncompact(acc_wr_control);
2275bf215546Sopenharmony_ci      } else {
2276bf215546Sopenharmony_ci         uncompact(mask_control_ex);
2277bf215546Sopenharmony_ci      }
2278bf215546Sopenharmony_ci
2279bf215546Sopenharmony_ci      uncompact(cond_modifier);
2280bf215546Sopenharmony_ci
2281bf215546Sopenharmony_ci      if (devinfo->ver <= 6)
2282bf215546Sopenharmony_ci         uncompact(flag_subreg_nr);
2283bf215546Sopenharmony_ci
2284bf215546Sopenharmony_ci      uncompact_reg(dst);
2285bf215546Sopenharmony_ci      uncompact_reg(src0);
2286bf215546Sopenharmony_ci   }
2287bf215546Sopenharmony_ci   brw_inst_set_cmpt_control(devinfo, dst, false);
2288bf215546Sopenharmony_ci
2289bf215546Sopenharmony_ci#undef uncompact
2290bf215546Sopenharmony_ci#undef uncompact_reg
2291bf215546Sopenharmony_ci}
2292bf215546Sopenharmony_ci
2293bf215546Sopenharmony_civoid
2294bf215546Sopenharmony_cibrw_uncompact_instruction(const struct brw_isa_info *isa,
2295bf215546Sopenharmony_ci                          brw_inst *dst, brw_compact_inst *src)
2296bf215546Sopenharmony_ci{
2297bf215546Sopenharmony_ci   struct compaction_state c;
2298bf215546Sopenharmony_ci   compaction_state_init(&c, isa);
2299bf215546Sopenharmony_ci   uncompact_instruction(&c, dst, src);
2300bf215546Sopenharmony_ci}
2301bf215546Sopenharmony_ci
2302bf215546Sopenharmony_civoid
2303bf215546Sopenharmony_cibrw_debug_compact_uncompact(const struct brw_isa_info *isa,
2304bf215546Sopenharmony_ci                            brw_inst *orig,
2305bf215546Sopenharmony_ci                            brw_inst *uncompacted)
2306bf215546Sopenharmony_ci{
2307bf215546Sopenharmony_ci   fprintf(stderr, "Instruction compact/uncompact changed (gen%d):\n",
2308bf215546Sopenharmony_ci           isa->devinfo->ver);
2309bf215546Sopenharmony_ci
2310bf215546Sopenharmony_ci   fprintf(stderr, "  before: ");
2311bf215546Sopenharmony_ci   brw_disassemble_inst(stderr, isa, orig, true, 0, NULL);
2312bf215546Sopenharmony_ci
2313bf215546Sopenharmony_ci   fprintf(stderr, "  after:  ");
2314bf215546Sopenharmony_ci   brw_disassemble_inst(stderr, isa, uncompacted, false, 0, NULL);
2315bf215546Sopenharmony_ci
2316bf215546Sopenharmony_ci   uint32_t *before_bits = (uint32_t *)orig;
2317bf215546Sopenharmony_ci   uint32_t *after_bits = (uint32_t *)uncompacted;
2318bf215546Sopenharmony_ci   fprintf(stderr, "  changed bits:\n");
2319bf215546Sopenharmony_ci   for (int i = 0; i < 128; i++) {
2320bf215546Sopenharmony_ci      uint32_t before = before_bits[i / 32] & (1 << (i & 31));
2321bf215546Sopenharmony_ci      uint32_t after = after_bits[i / 32] & (1 << (i & 31));
2322bf215546Sopenharmony_ci
2323bf215546Sopenharmony_ci      if (before != after) {
2324bf215546Sopenharmony_ci         fprintf(stderr, "  bit %d, %s to %s\n", i,
2325bf215546Sopenharmony_ci                 before ? "set" : "unset",
2326bf215546Sopenharmony_ci                 after ? "set" : "unset");
2327bf215546Sopenharmony_ci      }
2328bf215546Sopenharmony_ci   }
2329bf215546Sopenharmony_ci}
2330bf215546Sopenharmony_ci
2331bf215546Sopenharmony_cistatic int
2332bf215546Sopenharmony_cicompacted_between(int old_ip, int old_target_ip, int *compacted_counts)
2333bf215546Sopenharmony_ci{
2334bf215546Sopenharmony_ci   int this_compacted_count = compacted_counts[old_ip];
2335bf215546Sopenharmony_ci   int target_compacted_count = compacted_counts[old_target_ip];
2336bf215546Sopenharmony_ci   return target_compacted_count - this_compacted_count;
2337bf215546Sopenharmony_ci}
2338bf215546Sopenharmony_ci
2339bf215546Sopenharmony_cistatic void
2340bf215546Sopenharmony_ciupdate_uip_jip(const struct brw_isa_info *isa, brw_inst *insn,
2341bf215546Sopenharmony_ci               int this_old_ip, int *compacted_counts)
2342bf215546Sopenharmony_ci{
2343bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = isa->devinfo;
2344bf215546Sopenharmony_ci
2345bf215546Sopenharmony_ci   /* JIP and UIP are in units of:
2346bf215546Sopenharmony_ci    *    - bytes on Gfx8+; and
2347bf215546Sopenharmony_ci    *    - compacted instructions on Gfx6+.
2348bf215546Sopenharmony_ci    */
2349bf215546Sopenharmony_ci   int shift = devinfo->ver >= 8 ? 3 : 0;
2350bf215546Sopenharmony_ci
2351bf215546Sopenharmony_ci   int32_t jip_compacted = brw_inst_jip(devinfo, insn) >> shift;
2352bf215546Sopenharmony_ci   jip_compacted -= compacted_between(this_old_ip,
2353bf215546Sopenharmony_ci                                      this_old_ip + (jip_compacted / 2),
2354bf215546Sopenharmony_ci                                      compacted_counts);
2355bf215546Sopenharmony_ci   brw_inst_set_jip(devinfo, insn, jip_compacted << shift);
2356bf215546Sopenharmony_ci
2357bf215546Sopenharmony_ci   if (brw_inst_opcode(isa, insn) == BRW_OPCODE_ENDIF ||
2358bf215546Sopenharmony_ci       brw_inst_opcode(isa, insn) == BRW_OPCODE_WHILE ||
2359bf215546Sopenharmony_ci       (brw_inst_opcode(isa, insn) == BRW_OPCODE_ELSE && devinfo->ver <= 7))
2360bf215546Sopenharmony_ci      return;
2361bf215546Sopenharmony_ci
2362bf215546Sopenharmony_ci   int32_t uip_compacted = brw_inst_uip(devinfo, insn) >> shift;
2363bf215546Sopenharmony_ci   uip_compacted -= compacted_between(this_old_ip,
2364bf215546Sopenharmony_ci                                      this_old_ip + (uip_compacted / 2),
2365bf215546Sopenharmony_ci                                      compacted_counts);
2366bf215546Sopenharmony_ci   brw_inst_set_uip(devinfo, insn, uip_compacted << shift);
2367bf215546Sopenharmony_ci}
2368bf215546Sopenharmony_ci
2369bf215546Sopenharmony_cistatic void
2370bf215546Sopenharmony_ciupdate_gfx4_jump_count(const struct intel_device_info *devinfo, brw_inst *insn,
2371bf215546Sopenharmony_ci                       int this_old_ip, int *compacted_counts)
2372bf215546Sopenharmony_ci{
2373bf215546Sopenharmony_ci   assert(devinfo->ver == 5 || devinfo->platform == INTEL_PLATFORM_G4X);
2374bf215546Sopenharmony_ci
2375bf215546Sopenharmony_ci   /* Jump Count is in units of:
2376bf215546Sopenharmony_ci    *    - uncompacted instructions on G45; and
2377bf215546Sopenharmony_ci    *    - compacted instructions on Gfx5.
2378bf215546Sopenharmony_ci    */
2379bf215546Sopenharmony_ci   int shift = devinfo->platform == INTEL_PLATFORM_G4X ? 1 : 0;
2380bf215546Sopenharmony_ci
2381bf215546Sopenharmony_ci   int jump_count_compacted = brw_inst_gfx4_jump_count(devinfo, insn) << shift;
2382bf215546Sopenharmony_ci
2383bf215546Sopenharmony_ci   int target_old_ip = this_old_ip + (jump_count_compacted / 2);
2384bf215546Sopenharmony_ci
2385bf215546Sopenharmony_ci   int this_compacted_count = compacted_counts[this_old_ip];
2386bf215546Sopenharmony_ci   int target_compacted_count = compacted_counts[target_old_ip];
2387bf215546Sopenharmony_ci
2388bf215546Sopenharmony_ci   jump_count_compacted -= (target_compacted_count - this_compacted_count);
2389bf215546Sopenharmony_ci   brw_inst_set_gfx4_jump_count(devinfo, insn, jump_count_compacted >> shift);
2390bf215546Sopenharmony_ci}
2391bf215546Sopenharmony_ci
2392bf215546Sopenharmony_cistatic void
2393bf215546Sopenharmony_cicompaction_state_init(struct compaction_state *c,
2394bf215546Sopenharmony_ci                      const struct brw_isa_info *isa)
2395bf215546Sopenharmony_ci{
2396bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = isa->devinfo;
2397bf215546Sopenharmony_ci
2398bf215546Sopenharmony_ci   assert(g45_control_index_table[ARRAY_SIZE(g45_control_index_table) - 1] != 0);
2399bf215546Sopenharmony_ci   assert(g45_datatype_table[ARRAY_SIZE(g45_datatype_table) - 1] != 0);
2400bf215546Sopenharmony_ci   assert(g45_subreg_table[ARRAY_SIZE(g45_subreg_table) - 1] != 0);
2401bf215546Sopenharmony_ci   assert(g45_src_index_table[ARRAY_SIZE(g45_src_index_table) - 1] != 0);
2402bf215546Sopenharmony_ci   assert(gfx6_control_index_table[ARRAY_SIZE(gfx6_control_index_table) - 1] != 0);
2403bf215546Sopenharmony_ci   assert(gfx6_datatype_table[ARRAY_SIZE(gfx6_datatype_table) - 1] != 0);
2404bf215546Sopenharmony_ci   assert(gfx6_subreg_table[ARRAY_SIZE(gfx6_subreg_table) - 1] != 0);
2405bf215546Sopenharmony_ci   assert(gfx6_src_index_table[ARRAY_SIZE(gfx6_src_index_table) - 1] != 0);
2406bf215546Sopenharmony_ci   assert(gfx7_control_index_table[ARRAY_SIZE(gfx7_control_index_table) - 1] != 0);
2407bf215546Sopenharmony_ci   assert(gfx7_datatype_table[ARRAY_SIZE(gfx7_datatype_table) - 1] != 0);
2408bf215546Sopenharmony_ci   assert(gfx7_subreg_table[ARRAY_SIZE(gfx7_subreg_table) - 1] != 0);
2409bf215546Sopenharmony_ci   assert(gfx7_src_index_table[ARRAY_SIZE(gfx7_src_index_table) - 1] != 0);
2410bf215546Sopenharmony_ci   assert(gfx8_control_index_table[ARRAY_SIZE(gfx8_control_index_table) - 1] != 0);
2411bf215546Sopenharmony_ci   assert(gfx8_datatype_table[ARRAY_SIZE(gfx8_datatype_table) - 1] != 0);
2412bf215546Sopenharmony_ci   assert(gfx8_subreg_table[ARRAY_SIZE(gfx8_subreg_table) - 1] != 0);
2413bf215546Sopenharmony_ci   assert(gfx8_src_index_table[ARRAY_SIZE(gfx8_src_index_table) - 1] != 0);
2414bf215546Sopenharmony_ci   assert(gfx11_datatype_table[ARRAY_SIZE(gfx11_datatype_table) - 1] != 0);
2415bf215546Sopenharmony_ci   assert(gfx12_control_index_table[ARRAY_SIZE(gfx12_control_index_table) - 1] != 0);
2416bf215546Sopenharmony_ci   assert(gfx12_datatype_table[ARRAY_SIZE(gfx12_datatype_table) - 1] != 0);
2417bf215546Sopenharmony_ci   assert(gfx12_subreg_table[ARRAY_SIZE(gfx12_subreg_table) - 1] != 0);
2418bf215546Sopenharmony_ci   assert(gfx12_src0_index_table[ARRAY_SIZE(gfx12_src0_index_table) - 1] != 0);
2419bf215546Sopenharmony_ci   assert(gfx12_src1_index_table[ARRAY_SIZE(gfx12_src1_index_table) - 1] != 0);
2420bf215546Sopenharmony_ci   assert(xehp_src0_index_table[ARRAY_SIZE(xehp_src0_index_table) - 1] != 0);
2421bf215546Sopenharmony_ci   assert(xehp_src1_index_table[ARRAY_SIZE(xehp_src1_index_table) - 1] != 0);
2422bf215546Sopenharmony_ci
2423bf215546Sopenharmony_ci   c->isa = isa;
2424bf215546Sopenharmony_ci   switch (devinfo->ver) {
2425bf215546Sopenharmony_ci   case 12:
2426bf215546Sopenharmony_ci      c->control_index_table = gfx12_control_index_table;;
2427bf215546Sopenharmony_ci      c->datatype_table = gfx12_datatype_table;
2428bf215546Sopenharmony_ci      c->subreg_table = gfx12_subreg_table;
2429bf215546Sopenharmony_ci      if (devinfo->verx10 >= 125) {
2430bf215546Sopenharmony_ci         c->src0_index_table = xehp_src0_index_table;
2431bf215546Sopenharmony_ci         c->src1_index_table = xehp_src1_index_table;
2432bf215546Sopenharmony_ci      } else {
2433bf215546Sopenharmony_ci         c->src0_index_table = gfx12_src0_index_table;
2434bf215546Sopenharmony_ci         c->src1_index_table = gfx12_src1_index_table;
2435bf215546Sopenharmony_ci      }
2436bf215546Sopenharmony_ci      break;
2437bf215546Sopenharmony_ci   case 11:
2438bf215546Sopenharmony_ci      c->control_index_table = gfx8_control_index_table;
2439bf215546Sopenharmony_ci      c->datatype_table = gfx11_datatype_table;
2440bf215546Sopenharmony_ci      c->subreg_table = gfx8_subreg_table;
2441bf215546Sopenharmony_ci      c->src0_index_table = gfx8_src_index_table;
2442bf215546Sopenharmony_ci      c->src1_index_table = gfx8_src_index_table;
2443bf215546Sopenharmony_ci      break;
2444bf215546Sopenharmony_ci   case 9:
2445bf215546Sopenharmony_ci   case 8:
2446bf215546Sopenharmony_ci      c->control_index_table = gfx8_control_index_table;
2447bf215546Sopenharmony_ci      c->datatype_table = gfx8_datatype_table;
2448bf215546Sopenharmony_ci      c->subreg_table = gfx8_subreg_table;
2449bf215546Sopenharmony_ci      c->src0_index_table = gfx8_src_index_table;
2450bf215546Sopenharmony_ci      c->src1_index_table = gfx8_src_index_table;
2451bf215546Sopenharmony_ci      break;
2452bf215546Sopenharmony_ci   case 7:
2453bf215546Sopenharmony_ci      c->control_index_table = gfx7_control_index_table;
2454bf215546Sopenharmony_ci      c->datatype_table = gfx7_datatype_table;
2455bf215546Sopenharmony_ci      c->subreg_table = gfx7_subreg_table;
2456bf215546Sopenharmony_ci      c->src0_index_table = gfx7_src_index_table;
2457bf215546Sopenharmony_ci      c->src1_index_table = gfx7_src_index_table;
2458bf215546Sopenharmony_ci      break;
2459bf215546Sopenharmony_ci   case 6:
2460bf215546Sopenharmony_ci      c->control_index_table = gfx6_control_index_table;
2461bf215546Sopenharmony_ci      c->datatype_table = gfx6_datatype_table;
2462bf215546Sopenharmony_ci      c->subreg_table = gfx6_subreg_table;
2463bf215546Sopenharmony_ci      c->src0_index_table = gfx6_src_index_table;
2464bf215546Sopenharmony_ci      c->src1_index_table = gfx6_src_index_table;
2465bf215546Sopenharmony_ci      break;
2466bf215546Sopenharmony_ci   case 5:
2467bf215546Sopenharmony_ci   case 4:
2468bf215546Sopenharmony_ci      c->control_index_table = g45_control_index_table;
2469bf215546Sopenharmony_ci      c->datatype_table = g45_datatype_table;
2470bf215546Sopenharmony_ci      c->subreg_table = g45_subreg_table;
2471bf215546Sopenharmony_ci      c->src0_index_table = g45_src_index_table;
2472bf215546Sopenharmony_ci      c->src1_index_table = g45_src_index_table;
2473bf215546Sopenharmony_ci      break;
2474bf215546Sopenharmony_ci   default:
2475bf215546Sopenharmony_ci      unreachable("unknown generation");
2476bf215546Sopenharmony_ci   }
2477bf215546Sopenharmony_ci}
2478bf215546Sopenharmony_ci
2479bf215546Sopenharmony_civoid
2480bf215546Sopenharmony_cibrw_compact_instructions(struct brw_codegen *p, int start_offset,
2481bf215546Sopenharmony_ci                         struct disasm_info *disasm)
2482bf215546Sopenharmony_ci{
2483bf215546Sopenharmony_ci   if (INTEL_DEBUG(DEBUG_NO_COMPACTION))
2484bf215546Sopenharmony_ci      return;
2485bf215546Sopenharmony_ci
2486bf215546Sopenharmony_ci   const struct intel_device_info *devinfo = p->devinfo;
2487bf215546Sopenharmony_ci   if (devinfo->ver == 4 && devinfo->platform != INTEL_PLATFORM_G4X)
2488bf215546Sopenharmony_ci      return;
2489bf215546Sopenharmony_ci
2490bf215546Sopenharmony_ci   void *store = p->store + start_offset / 16;
2491bf215546Sopenharmony_ci   /* For an instruction at byte offset 16*i before compaction, this is the
2492bf215546Sopenharmony_ci    * number of compacted instructions minus the number of padding NOP/NENOPs
2493bf215546Sopenharmony_ci    * that preceded it.
2494bf215546Sopenharmony_ci    */
2495bf215546Sopenharmony_ci   unsigned num_compacted_counts =
2496bf215546Sopenharmony_ci      (p->next_insn_offset - start_offset) / sizeof(brw_inst);
2497bf215546Sopenharmony_ci   int *compacted_counts =
2498bf215546Sopenharmony_ci      calloc(1, sizeof(*compacted_counts) * num_compacted_counts);
2499bf215546Sopenharmony_ci
2500bf215546Sopenharmony_ci   /* For an instruction at byte offset 8*i after compaction, this was its IP
2501bf215546Sopenharmony_ci    * (in 16-byte units) before compaction.
2502bf215546Sopenharmony_ci    */
2503bf215546Sopenharmony_ci   unsigned num_old_ip =
2504bf215546Sopenharmony_ci      (p->next_insn_offset - start_offset) / sizeof(brw_compact_inst) + 1;
2505bf215546Sopenharmony_ci   int *old_ip = calloc(1, sizeof(*old_ip) * num_old_ip);
2506bf215546Sopenharmony_ci
2507bf215546Sopenharmony_ci   struct compaction_state c;
2508bf215546Sopenharmony_ci   compaction_state_init(&c, p->isa);
2509bf215546Sopenharmony_ci
2510bf215546Sopenharmony_ci   int offset = 0;
2511bf215546Sopenharmony_ci   int compacted_count = 0;
2512bf215546Sopenharmony_ci   for (int src_offset = 0; src_offset < p->next_insn_offset - start_offset;
2513bf215546Sopenharmony_ci        src_offset += sizeof(brw_inst)) {
2514bf215546Sopenharmony_ci      brw_inst *src = store + src_offset;
2515bf215546Sopenharmony_ci      void *dst = store + offset;
2516bf215546Sopenharmony_ci
2517bf215546Sopenharmony_ci      old_ip[offset / sizeof(brw_compact_inst)] = src_offset / sizeof(brw_inst);
2518bf215546Sopenharmony_ci      compacted_counts[src_offset / sizeof(brw_inst)] = compacted_count;
2519bf215546Sopenharmony_ci
2520bf215546Sopenharmony_ci      brw_inst inst = precompact(p->isa, *src);
2521bf215546Sopenharmony_ci      brw_inst saved = inst;
2522bf215546Sopenharmony_ci
2523bf215546Sopenharmony_ci      if (try_compact_instruction(&c, dst, &inst)) {
2524bf215546Sopenharmony_ci         compacted_count++;
2525bf215546Sopenharmony_ci
2526bf215546Sopenharmony_ci         if (INTEL_DEBUG(DEBUG_ANY)) {
2527bf215546Sopenharmony_ci            brw_inst uncompacted;
2528bf215546Sopenharmony_ci            uncompact_instruction(&c, &uncompacted, dst);
2529bf215546Sopenharmony_ci            if (memcmp(&saved, &uncompacted, sizeof(uncompacted))) {
2530bf215546Sopenharmony_ci               brw_debug_compact_uncompact(p->isa, &saved, &uncompacted);
2531bf215546Sopenharmony_ci            }
2532bf215546Sopenharmony_ci         }
2533bf215546Sopenharmony_ci
2534bf215546Sopenharmony_ci         offset += sizeof(brw_compact_inst);
2535bf215546Sopenharmony_ci      } else {
2536bf215546Sopenharmony_ci         /* All uncompacted instructions need to be aligned on G45. */
2537bf215546Sopenharmony_ci         if ((offset & sizeof(brw_compact_inst)) != 0 &&
2538bf215546Sopenharmony_ci             devinfo->platform == INTEL_PLATFORM_G4X) {
2539bf215546Sopenharmony_ci            brw_compact_inst *align = store + offset;
2540bf215546Sopenharmony_ci            memset(align, 0, sizeof(*align));
2541bf215546Sopenharmony_ci            brw_compact_inst_set_hw_opcode(
2542bf215546Sopenharmony_ci               devinfo, align, brw_opcode_encode(p->isa, BRW_OPCODE_NENOP));
2543bf215546Sopenharmony_ci            brw_compact_inst_set_cmpt_control(devinfo, align, true);
2544bf215546Sopenharmony_ci            offset += sizeof(brw_compact_inst);
2545bf215546Sopenharmony_ci            compacted_count--;
2546bf215546Sopenharmony_ci            compacted_counts[src_offset / sizeof(brw_inst)] = compacted_count;
2547bf215546Sopenharmony_ci            old_ip[offset / sizeof(brw_compact_inst)] = src_offset / sizeof(brw_inst);
2548bf215546Sopenharmony_ci
2549bf215546Sopenharmony_ci            dst = store + offset;
2550bf215546Sopenharmony_ci         }
2551bf215546Sopenharmony_ci
2552bf215546Sopenharmony_ci         /* If we didn't compact this instruction, we need to move it down into
2553bf215546Sopenharmony_ci          * place.
2554bf215546Sopenharmony_ci          */
2555bf215546Sopenharmony_ci         if (offset != src_offset) {
2556bf215546Sopenharmony_ci            memmove(dst, src, sizeof(brw_inst));
2557bf215546Sopenharmony_ci         }
2558bf215546Sopenharmony_ci         offset += sizeof(brw_inst);
2559bf215546Sopenharmony_ci      }
2560bf215546Sopenharmony_ci   }
2561bf215546Sopenharmony_ci
2562bf215546Sopenharmony_ci   /* Add an entry for the ending offset of the program. This greatly
2563bf215546Sopenharmony_ci    * simplifies the linked list walk at the end of the function.
2564bf215546Sopenharmony_ci    */
2565bf215546Sopenharmony_ci   old_ip[offset / sizeof(brw_compact_inst)] =
2566bf215546Sopenharmony_ci      (p->next_insn_offset - start_offset) / sizeof(brw_inst);
2567bf215546Sopenharmony_ci
2568bf215546Sopenharmony_ci   /* Fix up control flow offsets. */
2569bf215546Sopenharmony_ci   p->next_insn_offset = start_offset + offset;
2570bf215546Sopenharmony_ci   for (offset = 0; offset < p->next_insn_offset - start_offset;
2571bf215546Sopenharmony_ci        offset = next_offset(devinfo, store, offset)) {
2572bf215546Sopenharmony_ci      brw_inst *insn = store + offset;
2573bf215546Sopenharmony_ci      int this_old_ip = old_ip[offset / sizeof(brw_compact_inst)];
2574bf215546Sopenharmony_ci      int this_compacted_count = compacted_counts[this_old_ip];
2575bf215546Sopenharmony_ci
2576bf215546Sopenharmony_ci      switch (brw_inst_opcode(p->isa, insn)) {
2577bf215546Sopenharmony_ci      case BRW_OPCODE_BREAK:
2578bf215546Sopenharmony_ci      case BRW_OPCODE_CONTINUE:
2579bf215546Sopenharmony_ci      case BRW_OPCODE_HALT:
2580bf215546Sopenharmony_ci         if (devinfo->ver >= 6) {
2581bf215546Sopenharmony_ci            update_uip_jip(p->isa, insn, this_old_ip, compacted_counts);
2582bf215546Sopenharmony_ci         } else {
2583bf215546Sopenharmony_ci            update_gfx4_jump_count(devinfo, insn, this_old_ip,
2584bf215546Sopenharmony_ci                                   compacted_counts);
2585bf215546Sopenharmony_ci         }
2586bf215546Sopenharmony_ci         break;
2587bf215546Sopenharmony_ci
2588bf215546Sopenharmony_ci      case BRW_OPCODE_IF:
2589bf215546Sopenharmony_ci      case BRW_OPCODE_IFF:
2590bf215546Sopenharmony_ci      case BRW_OPCODE_ELSE:
2591bf215546Sopenharmony_ci      case BRW_OPCODE_ENDIF:
2592bf215546Sopenharmony_ci      case BRW_OPCODE_WHILE:
2593bf215546Sopenharmony_ci         if (devinfo->ver >= 7) {
2594bf215546Sopenharmony_ci            if (brw_inst_cmpt_control(devinfo, insn)) {
2595bf215546Sopenharmony_ci               brw_inst uncompacted;
2596bf215546Sopenharmony_ci               uncompact_instruction(&c, &uncompacted,
2597bf215546Sopenharmony_ci                                     (brw_compact_inst *)insn);
2598bf215546Sopenharmony_ci
2599bf215546Sopenharmony_ci               update_uip_jip(p->isa, &uncompacted, this_old_ip,
2600bf215546Sopenharmony_ci                              compacted_counts);
2601bf215546Sopenharmony_ci
2602bf215546Sopenharmony_ci               bool ret = try_compact_instruction(&c, (brw_compact_inst *)insn,
2603bf215546Sopenharmony_ci                                                  &uncompacted);
2604bf215546Sopenharmony_ci               assert(ret); (void)ret;
2605bf215546Sopenharmony_ci            } else {
2606bf215546Sopenharmony_ci               update_uip_jip(p->isa, insn, this_old_ip, compacted_counts);
2607bf215546Sopenharmony_ci            }
2608bf215546Sopenharmony_ci         } else if (devinfo->ver == 6) {
2609bf215546Sopenharmony_ci            assert(!brw_inst_cmpt_control(devinfo, insn));
2610bf215546Sopenharmony_ci
2611bf215546Sopenharmony_ci            /* Jump Count is in units of compacted instructions on Gfx6. */
2612bf215546Sopenharmony_ci            int jump_count_compacted = brw_inst_gfx6_jump_count(devinfo, insn);
2613bf215546Sopenharmony_ci
2614bf215546Sopenharmony_ci            int target_old_ip = this_old_ip + (jump_count_compacted / 2);
2615bf215546Sopenharmony_ci            int target_compacted_count = compacted_counts[target_old_ip];
2616bf215546Sopenharmony_ci            jump_count_compacted -= (target_compacted_count - this_compacted_count);
2617bf215546Sopenharmony_ci            brw_inst_set_gfx6_jump_count(devinfo, insn, jump_count_compacted);
2618bf215546Sopenharmony_ci         } else {
2619bf215546Sopenharmony_ci            update_gfx4_jump_count(devinfo, insn, this_old_ip,
2620bf215546Sopenharmony_ci                                   compacted_counts);
2621bf215546Sopenharmony_ci         }
2622bf215546Sopenharmony_ci         break;
2623bf215546Sopenharmony_ci
2624bf215546Sopenharmony_ci      case BRW_OPCODE_ADD:
2625bf215546Sopenharmony_ci         /* Add instructions modifying the IP register use an immediate src1,
2626bf215546Sopenharmony_ci          * and Gens that use this cannot compact instructions with immediate
2627bf215546Sopenharmony_ci          * operands.
2628bf215546Sopenharmony_ci          */
2629bf215546Sopenharmony_ci         if (brw_inst_cmpt_control(devinfo, insn))
2630bf215546Sopenharmony_ci            break;
2631bf215546Sopenharmony_ci
2632bf215546Sopenharmony_ci         if (brw_inst_dst_reg_file(devinfo, insn) == BRW_ARCHITECTURE_REGISTER_FILE &&
2633bf215546Sopenharmony_ci             brw_inst_dst_da_reg_nr(devinfo, insn) == BRW_ARF_IP) {
2634bf215546Sopenharmony_ci            assert(brw_inst_src1_reg_file(devinfo, insn) == BRW_IMMEDIATE_VALUE);
2635bf215546Sopenharmony_ci
2636bf215546Sopenharmony_ci            int shift = 3;
2637bf215546Sopenharmony_ci            int jump_compacted = brw_inst_imm_d(devinfo, insn) >> shift;
2638bf215546Sopenharmony_ci
2639bf215546Sopenharmony_ci            int target_old_ip = this_old_ip + (jump_compacted / 2);
2640bf215546Sopenharmony_ci            int target_compacted_count = compacted_counts[target_old_ip];
2641bf215546Sopenharmony_ci            jump_compacted -= (target_compacted_count - this_compacted_count);
2642bf215546Sopenharmony_ci            brw_inst_set_imm_ud(devinfo, insn, jump_compacted << shift);
2643bf215546Sopenharmony_ci         }
2644bf215546Sopenharmony_ci         break;
2645bf215546Sopenharmony_ci
2646bf215546Sopenharmony_ci      default:
2647bf215546Sopenharmony_ci         break;
2648bf215546Sopenharmony_ci      }
2649bf215546Sopenharmony_ci   }
2650bf215546Sopenharmony_ci
2651bf215546Sopenharmony_ci   /* p->nr_insn is counting the number of uncompacted instructions still, so
2652bf215546Sopenharmony_ci    * divide.  We do want to be sure there's a valid instruction in any
2653bf215546Sopenharmony_ci    * alignment padding, so that the next compression pass (for the FS 8/16
2654bf215546Sopenharmony_ci    * compile passes) parses correctly.
2655bf215546Sopenharmony_ci    */
2656bf215546Sopenharmony_ci   if (p->next_insn_offset & sizeof(brw_compact_inst)) {
2657bf215546Sopenharmony_ci      brw_compact_inst *align = store + offset;
2658bf215546Sopenharmony_ci      memset(align, 0, sizeof(*align));
2659bf215546Sopenharmony_ci      brw_compact_inst_set_hw_opcode(
2660bf215546Sopenharmony_ci         devinfo, align, brw_opcode_encode(p->isa, BRW_OPCODE_NOP));
2661bf215546Sopenharmony_ci      brw_compact_inst_set_cmpt_control(devinfo, align, true);
2662bf215546Sopenharmony_ci      p->next_insn_offset += sizeof(brw_compact_inst);
2663bf215546Sopenharmony_ci   }
2664bf215546Sopenharmony_ci   p->nr_insn = p->next_insn_offset / sizeof(brw_inst);
2665bf215546Sopenharmony_ci
2666bf215546Sopenharmony_ci   for (int i = 0; i < p->num_relocs; i++) {
2667bf215546Sopenharmony_ci      if (p->relocs[i].offset < (uint32_t)start_offset)
2668bf215546Sopenharmony_ci         continue;
2669bf215546Sopenharmony_ci
2670bf215546Sopenharmony_ci      assert(p->relocs[i].offset % 16 == 0);
2671bf215546Sopenharmony_ci      unsigned idx = (p->relocs[i].offset - start_offset) / 16;
2672bf215546Sopenharmony_ci      p->relocs[i].offset -= compacted_counts[idx] * 8;
2673bf215546Sopenharmony_ci   }
2674bf215546Sopenharmony_ci
2675bf215546Sopenharmony_ci   /* Update the instruction offsets for each group. */
2676bf215546Sopenharmony_ci   if (disasm) {
2677bf215546Sopenharmony_ci      int offset = 0;
2678bf215546Sopenharmony_ci
2679bf215546Sopenharmony_ci      foreach_list_typed(struct inst_group, group, link, &disasm->group_list) {
2680bf215546Sopenharmony_ci         while (start_offset + old_ip[offset / sizeof(brw_compact_inst)] *
2681bf215546Sopenharmony_ci                sizeof(brw_inst) != group->offset) {
2682bf215546Sopenharmony_ci            assert(start_offset + old_ip[offset / sizeof(brw_compact_inst)] *
2683bf215546Sopenharmony_ci                   sizeof(brw_inst) < group->offset);
2684bf215546Sopenharmony_ci            offset = next_offset(devinfo, store, offset);
2685bf215546Sopenharmony_ci         }
2686bf215546Sopenharmony_ci
2687bf215546Sopenharmony_ci         group->offset = start_offset + offset;
2688bf215546Sopenharmony_ci
2689bf215546Sopenharmony_ci         offset = next_offset(devinfo, store, offset);
2690bf215546Sopenharmony_ci      }
2691bf215546Sopenharmony_ci   }
2692bf215546Sopenharmony_ci
2693bf215546Sopenharmony_ci   free(compacted_counts);
2694bf215546Sopenharmony_ci   free(old_ip);
2695bf215546Sopenharmony_ci}
2696