• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "util/macros.h"
2 #include "disassemble.h"
3 #define _BITS(bits, pos, width) (((bits) >> (pos)) & ((1 << (width)) - 1))
4 static void
bi_disasm_add_ld_var_special_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5 bi_disasm_add_ld_var_special_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6 {
7     static const char *register_format_table[] = {
8         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".auto", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
9     };
10     const char *register_format = register_format_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 10, 4) << 2)];
11     static const char *vecsize_table[] = {
12         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".v2", ".reserved", "", ".reserved", ".v2", ".reserved", "", ".reserved", ".v2", ".reserved", "", ".reserved", ".v2", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
13     };
14     const char *vecsize = vecsize_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 10, 4) << 2)];
15     static const char *varying_name_table[] = {
16         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".point", ".reserved", ".frag_w", ".reserved", ".point", ".reserved", ".frag_w", ".reserved", ".point", ".reserved", ".frag_w", ".reserved", ".point", ".reserved", ".frag_w", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
17     };
18     const char *varying_name = varying_name_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 10, 4) << 2)];
19     static const char *update_table[] = {
20         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
21     };
22     const char *update = update_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 10, 4) << 2)];
23     static const char *sample_table[] = {
24         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".center", ".reserved", ".center", ".reserved", ".centroid", ".reserved", ".centroid", ".reserved", ".sample", ".reserved", ".sample", ".reserved", ".explicit", ".reserved", ".explicit", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
25     };
26     const char *sample = sample_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 10, 4) << 2)];
27     fputs("+LD_VAR_SPECIAL", fp);
28     fputs(varying_name, fp);
29     fputs(vecsize, fp);
30     fputs(update, fp);
31     fputs(register_format, fp);
32     fputs(sample, fp);
33     fputs(" ", fp);
34     bi_disasm_dest_add(fp, next_regs, last);
35     fputs(", ", fp);
36     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
37     fprintf(fp, ", @r%u", staging_register);
38     fputs("\n", fp);
39 }
40 
41 static void
bi_disasm_add_frcp_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)42 bi_disasm_add_frcp_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
43 {
44     static const char *neg_table[] = {
45         "", ".neg"
46     };
47 
48     const char *neg = neg_table[_BITS(bits, 3, 1)];
49 
50     static const char *abs0_table[] = {
51         "", ".abs0"
52     };
53 
54     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
55 
56     static const char *divzero_table[] = {
57         "", ".divzero"
58     };
59 
60     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
61 
62     static const char *lane0_table[] = {
63         "", ".h1"
64     };
65 
66     const char *lane0 = lane0_table[_BITS(bits, 8, 1)];
67 
68     fputs("+FRCP.f16", fp);
69     fputs(neg, fp);
70     fputs(divzero, fp);
71     fputs(" ", fp);
72     bi_disasm_dest_add(fp, next_regs, last);
73     fputs(", ", fp);
74     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
75     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
76     fputs(abs0, fp);
77     fputs(lane0, fp);
78     fputs("\n", fp);
79 }
80 
81 static void
bi_disasm_add_ld_var_imm_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)82 bi_disasm_add_ld_var_imm_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
83 {
84     static const char *register_format_table[] = {
85         ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".reserved", ".reserved", ".reserved", ".reserved"
86     };
87     const char *register_format = register_format_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
88     static const char *sample_table[] = {
89         ".center", ".center", ".centroid", ".centroid", ".sample", ".sample", ".explicit", ".explicit", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".center", ".center", ".centroid", ".centroid", ".center", ".center", ".centroid", ".centroid", ".sample", ".sample", ".explicit", ".explicit", ".reserved", ".reserved", ".reserved", ".reserved"
90     };
91     const char *sample = sample_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
92     static const char *update_table[] = {
93         ".store", ".store", ".store", ".store", ".store", ".store", ".store", ".store", ".retrieve", ".retrieve", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".conditional", ".conditional", ".conditional", ".conditional", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".reserved", ".reserved", ".reserved", ".reserved"
94     };
95     const char *update = update_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
96     static const char *vecsize_table[] = {
97         "", ".v2", ".v3", ".v4"
98     };
99 
100     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
101 
102     fputs("+LD_VAR_IMM", fp);
103     fputs(vecsize, fp);
104     fputs(update, fp);
105     fputs(register_format, fp);
106     fputs(sample, fp);
107     fputs(" ", fp);
108     bi_disasm_dest_add(fp, next_regs, last);
109     fputs(", ", fp);
110     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
111     fprintf(fp, ", index:%u", _BITS(bits, 3, 5));
112     fprintf(fp, ", @r%u", staging_register);
113     fputs("\n", fp);
114 }
115 
116 static void
bi_disasm_add_ld_gclk_u64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)117 bi_disasm_add_ld_gclk_u64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
118 {
119     static const char *source_table[] = {
120         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".system_timestamp", ".cycle_counter"
121     };
122 
123     const char *source = source_table[_BITS(bits, 0, 3)];
124 
125     fputs("+LD_GCLK.u64", fp);
126     fputs(source, fp);
127     fputs(" ", fp);
128     bi_disasm_dest_add(fp, next_regs, last);
129     fprintf(fp, ", @r%u", staging_register);
130     fputs("\n", fp);
131 }
132 
133 static void
bi_disasm_add_iadd_v4s8_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)134 bi_disasm_add_iadd_v4s8_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
135 {
136     static const char *lanes1_table[] = {
137         ".b0101", ".b2323"
138     };
139     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
140     static const char *lanes0_table[] = {
141         "", ""
142     };
143     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
144     static const char *saturate_table[] = {
145         "", ".sat"
146     };
147 
148     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
149 
150     fputs("+IADD.v4s8", fp);
151     fputs(saturate, fp);
152     fputs(" ", fp);
153     bi_disasm_dest_add(fp, next_regs, last);
154     fputs(", ", fp);
155     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
156     fputs(lanes0, fp);
157     fputs(", ", fp);
158     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
159     fputs(lanes1, fp);
160     fputs("\n", fp);
161 }
162 
163 static void
bi_disasm_add_f32_to_u32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)164 bi_disasm_add_f32_to_u32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
165 {
166     static const char *round_table[] = {
167         "", ".rtp", ".rtn", ".rtz"
168     };
169     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
170     fputs("+F32_TO_U32", fp);
171     fputs(round, fp);
172     fputs(" ", fp);
173     bi_disasm_dest_add(fp, next_regs, last);
174     fputs(", ", fp);
175     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
176     fputs("\n", fp);
177 }
178 
179 static void
bi_disasm_add_load_i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)180 bi_disasm_add_load_i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
181 {
182     static const char *extend_table[] = {
183         "", "", "", ""
184     };
185     const char *extend = extend_table[(_BITS(bits, 9, 2) << 0)];
186     static const char *lane_table[] = {
187         "", ".b1", ".b2", ".b3"
188     };
189     const char *lane = lane_table[(_BITS(bits, 9, 2) << 0)];
190     static const char *seg_table[] = {
191         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
192     };
193 
194     const char *seg = seg_table[_BITS(bits, 6, 3)];
195 
196     fputs("+LOAD.i8", fp);
197     fputs(seg, fp);
198     fputs(lane, fp);
199     fputs(extend, fp);
200     fputs(" ", fp);
201     bi_disasm_dest_add(fp, next_regs, last);
202     fputs(", ", fp);
203     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
204     fputs(", ", fp);
205     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
206     fprintf(fp, ", @r%u", staging_register);
207     fputs("\n", fp);
208 }
209 
210 static void
bi_disasm_add_icmp_v4i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)211 bi_disasm_add_icmp_v4i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
212 {
213     static const char *result_type_table[] = {
214         "", ".m1"
215     };
216 
217     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
218 
219     static const char *cmpf_table[] = {
220         ".eq", ".ne"
221     };
222 
223     const char *cmpf = cmpf_table[_BITS(bits, 6, 1)];
224 
225     fputs("+ICMP.v4i8", fp);
226     fputs(result_type, fp);
227     fputs(cmpf, fp);
228     fputs(" ", fp);
229     bi_disasm_dest_add(fp, next_regs, last);
230     fputs(", ", fp);
231     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
232     fputs(", ", fp);
233     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
234     fputs("\n", fp);
235 }
236 
237 static void
bi_disasm_add_isub_v4u8_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)238 bi_disasm_add_isub_v4u8_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
239 {
240     static const char *lanes1_table[] = {
241         ".reserved", ".b0101", ".reserved", ".b2323"
242     };
243     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
244     static const char *lanes0_table[] = {
245         ".reserved", "", ".reserved", ""
246     };
247     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
248     static const char *saturate_table[] = {
249         "", ".sat"
250     };
251 
252     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
253 
254     fputs("+ISUB.v4u8", fp);
255     fputs(saturate, fp);
256     fputs(" ", fp);
257     bi_disasm_dest_add(fp, next_regs, last);
258     fputs(", ", fp);
259     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
260     fputs(lanes0, fp);
261     fputs(", ", fp);
262     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
263     fputs(lanes1, fp);
264     fputs("\n", fp);
265 }
266 
267 static void
bi_disasm_add_vn_asst2_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)268 bi_disasm_add_vn_asst2_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
269 {
270     static const char *scale_table[] = {
271         ".scale"
272     };
273     const char *scale = scale_table[0];
274     static const char *neg0_table[] = {
275         "", ".neg0"
276     };
277 
278     const char *neg0 = neg0_table[_BITS(bits, 4, 1)];
279 
280     fputs("+VN_ASST2.f32", fp);
281     fputs(scale, fp);
282     fputs(" ", fp);
283     bi_disasm_dest_add(fp, next_regs, last);
284     fputs(", ", fp);
285     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
286     fputs(neg0, fp);
287     fputs("\n", fp);
288 }
289 
290 static void
bi_disasm_fma_imul_i32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)291 bi_disasm_fma_imul_i32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
292 {
293     static const char *widen1_table[] = {
294         ".b0", ".b1", ".b2", ".b3", ".b0", ".b1", ".b2", ".b3"
295     };
296     const char *widen1 = widen1_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 11, 1) << 2)];
297     static const char *extend1_table[] = {
298         ".zext", ".zext", ".zext", ".zext", ".sext", ".sext", ".sext", ".sext"
299     };
300     const char *extend1 = extend1_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 11, 1) << 2)];
301     fputs("*IMUL.i32", fp);
302     fputs(" ", fp);
303     bi_disasm_dest_fma(fp, next_regs, last);
304     fputs(", ", fp);
305     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
306     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
307     fputs(", ", fp);
308     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
309     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
310     fputs(widen1, fp);
311     fputs(extend1, fp);
312     fputs("\n", fp);
313 }
314 
315 static void
bi_disasm_add_icmp_v2s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)316 bi_disasm_add_icmp_v2s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
317 {
318     static const char *cmpf_table[] = {
319         ".gt", ".ge"
320     };
321     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
322     static const char *swz0_table[] = {
323         ".h00", ".h10", "", ".h11"
324     };
325 
326     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
327 
328     static const char *swz1_table[] = {
329         ".h00", ".h10", "", ".h11"
330     };
331 
332     const char *swz1 = swz1_table[_BITS(bits, 8, 2)];
333 
334     static const char *result_type_table[] = {
335         "", ".m1"
336     };
337 
338     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
339 
340     fputs("+ICMP.v2s16", fp);
341     fputs(result_type, fp);
342     fputs(cmpf, fp);
343     fputs(" ", fp);
344     bi_disasm_dest_add(fp, next_regs, last);
345     fputs(", ", fp);
346     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
347     fputs(swz0, fp);
348     fputs(", ", fp);
349     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
350     fputs(swz1, fp);
351     fputs("\n", fp);
352 }
353 
354 static void
bi_disasm_add_iadd_v2u16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)355 bi_disasm_add_iadd_v2u16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
356 {
357     static const char *lanes1_table[] = {
358         ".reserved", ".h00", ".reserved", ".h11"
359     };
360     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
361     static const char *lanes0_table[] = {
362         ".reserved", "", ".reserved", ""
363     };
364     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
365     static const char *saturate_table[] = {
366         "", ".sat"
367     };
368 
369     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
370 
371     fputs("+IADD.v2u16", fp);
372     fputs(saturate, fp);
373     fputs(" ", fp);
374     bi_disasm_dest_add(fp, next_regs, last);
375     fputs(", ", fp);
376     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
377     fputs(lanes0, fp);
378     fputs(", ", fp);
379     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
380     fputs(lanes1, fp);
381     fputs("\n", fp);
382 }
383 
384 static void
bi_disasm_fma_lshift_xor_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)385 bi_disasm_fma_lshift_xor_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
386 {
387     static const char *lanes2_table[] = {
388         ".b00", ".b11", ".b22", ".b33"
389     };
390     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
391     static const char *not_result_table[] = {
392         "", ".not"
393     };
394 
395     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
396 
397     fputs("*LSHIFT_XOR.v2i16", fp);
398     fputs(not_result, fp);
399     fputs(" ", fp);
400     bi_disasm_dest_fma(fp, next_regs, last);
401     fputs(", ", fp);
402     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
403     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
404     fputs(", ", fp);
405     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
406     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
407     fputs(", ", fp);
408     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
409     fputs(lanes2, fp);
410     fputs("\n", fp);
411 }
412 
413 static void
bi_disasm_fma_atom_c_return_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)414 bi_disasm_fma_atom_c_return_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
415 {
416     static const char *atom_opc_table[] = {
417         ".reserved", ".reserved", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
418     };
419 
420     const char *atom_opc = atom_opc_table[_BITS(bits, 9, 4)];
421 
422     fputs("*ATOM_C_RETURN.i32", fp);
423     fputs(atom_opc, fp);
424     fputs(" ", fp);
425     bi_disasm_dest_fma(fp, next_regs, last);
426     fputs(", ", fp);
427     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
428     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
429     fputs(", ", fp);
430     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
431     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
432     fputs(", ", fp);
433     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
434     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
435     fputs("\n", fp);
436 }
437 
438 static void
bi_disasm_add_cube_tsel(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)439 bi_disasm_add_cube_tsel(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
440 {
441     static const char *neg0_table[] = {
442         "", ".neg"
443     };
444     const char *neg0 = neg0_table[(_BITS(bits, 9, 1) << 0)];
445     static const char *neg1_table[] = {
446         "", ".neg"
447     };
448     const char *neg1 = neg1_table[(_BITS(bits, 9, 1) << 0)];
449     fputs("+CUBE_TSEL", fp);
450     fputs(" ", fp);
451     bi_disasm_dest_add(fp, next_regs, last);
452     fputs(", ", fp);
453     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
454     fputs(neg0, fp);
455     fputs(", ", fp);
456     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
457     fputs(neg1, fp);
458     fputs(", ", fp);
459     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
460     fputs("\n", fp);
461 }
462 
463 static void
bi_disasm_add_atest(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)464 bi_disasm_add_atest(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
465 {
466     static const char *widen1_table[] = {
467         ".reserved", "", ".h0", ".h1"
468     };
469 
470     const char *widen1 = widen1_table[_BITS(bits, 6, 2)];
471 
472     fputs("+ATEST", fp);
473     fputs(" ", fp);
474     bi_disasm_dest_add(fp, next_regs, last);
475     fputs(", ", fp);
476     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
477     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
478     fputs(", ", fp);
479     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
480     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
481     fputs(widen1, fp);
482     fprintf(fp, ", @r%u", staging_register);
483     fputs("\n", fp);
484 }
485 
486 static void
bi_disasm_add_fmin_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)487 bi_disasm_add_fmin_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
488 {
489     static const char *abs1_table[] = {
490         "", ".abs"
491     };
492 
493     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
494 
495     static const char *neg0_table[] = {
496         "", ".neg"
497     };
498 
499     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
500 
501     static const char *neg1_table[] = {
502         "", ".neg"
503     };
504 
505     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
506 
507     static const char *clamp_table[] = {
508         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
509     };
510 
511     const char *clamp = clamp_table[_BITS(bits, 11, 2)];
512 
513     static const char *sem_table[] = {
514         "", ".nan_propagate", ".c", ".inverse_c"
515     };
516 
517     const char *sem = sem_table[_BITS(bits, 13, 2)];
518 
519     static const char *abs0_table[] = {
520         "", ".abs"
521     };
522 
523     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
524 
525     fputs("+FMIN.f32", fp);
526     fputs(clamp, fp);
527     fputs(sem, fp);
528     fputs(" ", fp);
529     bi_disasm_dest_add(fp, next_regs, last);
530     fputs(", ", fp);
531     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
532     fputs(neg0, fp);
533     fputs(abs0, fp);
534     fputs(", ", fp);
535     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
536     fputs(abs1, fp);
537     fputs(neg1, fp);
538     fputs("\n", fp);
539 }
540 
541 static void
bi_disasm_fma_rshift_or_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)542 bi_disasm_fma_rshift_or_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
543 {
544     static const char *lanes2_table[] = {
545         ""
546     };
547     const char *lanes2 = lanes2_table[0];
548     static const char *not1_table[] = {
549         ".not", ""
550     };
551 
552     const char *not1 = not1_table[_BITS(bits, 14, 1)];
553 
554     static const char *not_result_table[] = {
555         "", ".not"
556     };
557 
558     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
559 
560     fputs("*RSHIFT_OR.v4i8", fp);
561     fputs(not_result, fp);
562     fputs(" ", fp);
563     bi_disasm_dest_fma(fp, next_regs, last);
564     fputs(", ", fp);
565     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
566     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
567     fputs(", ", fp);
568     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
569     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
570     fputs(not1, fp);
571     fputs(", ", fp);
572     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
573     fputs(lanes2, fp);
574     fputs("\n", fp);
575 }
576 
577 static void
bi_disasm_add_branchc_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)578 bi_disasm_add_branchc_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
579 {
580     static const char *combine_table[] = {
581         ".any", ".all"
582     };
583 
584     const char *combine = combine_table[_BITS(bits, 10, 1)];
585 
586     fputs("+BRANCHC.i32", fp);
587     fputs(combine, fp);
588     fputs(" ", fp);
589     bi_disasm_dest_add(fp, next_regs, last);
590     fputs(", ", fp);
591     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
592     fputs(", ", fp);
593     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
594     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
595     fputs("\n", fp);
596 }
597 
598 static void
bi_disasm_add_frexpe_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)599 bi_disasm_add_frexpe_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
600 {
601     static const char *sqrt_table[] = {
602         ""
603     };
604     const char *sqrt = sqrt_table[0];
605     static const char *log_table[] = {
606         ".log"
607     };
608     const char *log = log_table[0];
609     static const char *neg_table[] = {
610         ""
611     };
612     const char *neg = neg_table[0];
613     static const char *swz0_table[] = {
614         ".h00", ".h10", "", ".h11"
615     };
616 
617     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
618 
619     fputs("+FREXPE.v2f16", fp);
620     fputs(neg, fp);
621     fputs(sqrt, fp);
622     fputs(log, fp);
623     fputs(" ", fp);
624     bi_disasm_dest_add(fp, next_regs, last);
625     fputs(", ", fp);
626     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
627     fputs(swz0, fp);
628     fputs("\n", fp);
629 }
630 
631 static void
bi_disasm_add_v2f16_to_v2s16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)632 bi_disasm_add_v2f16_to_v2s16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
633 {
634     static const char *round_table[] = {
635         "", ".rtp", ".rtn", ".rtz"
636     };
637     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
638     static const char *swz0_table[] = {
639         ".h00", ".h10", "", ".h11"
640     };
641 
642     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
643 
644     fputs("+V2F16_TO_V2S16", fp);
645     fputs(round, fp);
646     fputs(" ", fp);
647     bi_disasm_dest_add(fp, next_regs, last);
648     fputs(", ", fp);
649     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
650     fputs(swz0, fp);
651     fputs("\n", fp);
652 }
653 
654 static void
bi_disasm_add_isub_u32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)655 bi_disasm_add_isub_u32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
656 {
657     static const char *lanes1_table[] = {
658         ".reserved", ".h0", ".reserved", ".h1"
659     };
660     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
661     static const char *saturate_table[] = {
662         "", ".sat"
663     };
664 
665     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
666 
667     fputs("+ISUB.u32", fp);
668     fputs(saturate, fp);
669     fputs(" ", fp);
670     bi_disasm_dest_add(fp, next_regs, last);
671     fputs(", ", fp);
672     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
673     fputs(", ", fp);
674     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
675     fputs(lanes1, fp);
676     fputs("\n", fp);
677 }
678 
679 static void
bi_disasm_add_load_i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)680 bi_disasm_add_load_i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
681 {
682     static const char *extend_table[] = {
683         ".sext", ".zext"
684     };
685     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
686     static const char *lane_table[] = {
687         ".w0", ".w0"
688     };
689     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
690     static const char *seg_table[] = {
691         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
692     };
693 
694     const char *seg = seg_table[_BITS(bits, 6, 3)];
695 
696     fputs("+LOAD.i16", fp);
697     fputs(seg, fp);
698     fputs(lane, fp);
699     fputs(extend, fp);
700     fputs(" ", fp);
701     bi_disasm_dest_add(fp, next_regs, last);
702     fputs(", ", fp);
703     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
704     fputs(", ", fp);
705     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
706     fprintf(fp, ", @r%u", staging_register);
707     fputs("\n", fp);
708 }
709 
710 static void
bi_disasm_fma_csel_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)711 bi_disasm_fma_csel_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
712 {
713     static const char *cmpf_table[] = {
714         ".eq", ".gt", ".ge", ".reserved"
715     };
716     const char *cmpf = cmpf_table[(_BITS(bits, 12, 2) << 0)];
717     fputs("*CSEL.f32", fp);
718     fputs(cmpf, fp);
719     fputs(" ", fp);
720     bi_disasm_dest_fma(fp, next_regs, last);
721     fputs(", ", fp);
722     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
723     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
724     fputs(", ", fp);
725     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
726     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
727     fputs(", ", fp);
728     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
729     fputs(", ", fp);
730     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
731     fputs("\n", fp);
732 }
733 
734 static void
bi_disasm_add_isub_v2s16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)735 bi_disasm_add_isub_v2s16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
736 {
737     static const char *lanes1_table[] = {
738         "", ".h10", "", ".h10"
739     };
740     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
741     static const char *lanes0_table[] = {
742         "", "", ".h10", ".h10"
743     };
744     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
745     static const char *saturate_table[] = {
746         "", ".sat"
747     };
748 
749     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
750 
751     fputs("+ISUB.v2s16", fp);
752     fputs(saturate, fp);
753     fputs(" ", fp);
754     bi_disasm_dest_add(fp, next_regs, last);
755     fputs(", ", fp);
756     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
757     fputs(lanes0, fp);
758     fputs(", ", fp);
759     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
760     fputs(lanes1, fp);
761     fputs("\n", fp);
762 }
763 
764 static void
bi_disasm_fma_atom_post_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)765 bi_disasm_fma_atom_post_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
766 {
767     static const char *atom_opc_table[] = {
768         ".reserved", ".reserved", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
769     };
770 
771     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 4)];
772 
773     fputs("*ATOM_POST.i32", fp);
774     fputs(atom_opc, fp);
775     fputs(" ", fp);
776     bi_disasm_dest_fma(fp, next_regs, last);
777     fputs(", ", fp);
778     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
779     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
780     fputs(", ", fp);
781     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
782     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
783     fputs("\n", fp);
784 }
785 
786 static void
bi_disasm_add_frexpm_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)787 bi_disasm_add_frexpm_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
788 {
789     static const char *sqrt_table[] = {
790         ""
791     };
792     const char *sqrt = sqrt_table[0];
793     static const char *log_table[] = {
794         ".log"
795     };
796     const char *log = log_table[0];
797     static const char *abs0_table[] = {
798         "", ".abs0"
799     };
800 
801     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
802 
803     static const char *swz0_table[] = {
804         ".h00", ".h10", "", ".h11"
805     };
806 
807     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
808 
809     static const char *neg0_table[] = {
810         "", ".neg0"
811     };
812 
813     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
814 
815     fputs("+FREXPM.v2f16", fp);
816     fputs(sqrt, fp);
817     fputs(log, fp);
818     fputs(" ", fp);
819     bi_disasm_dest_add(fp, next_regs, last);
820     fputs(", ", fp);
821     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
822     fputs(abs0, fp);
823     fputs(swz0, fp);
824     fputs(neg0, fp);
825     fputs("\n", fp);
826 }
827 
828 static void
bi_disasm_add_u8_to_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)829 bi_disasm_add_u8_to_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
830 {
831     static const char *lane0_table[] = {
832         "", ".b1", ".b2", ".b3"
833     };
834 
835     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
836 
837     fputs("+U8_TO_U32", fp);
838     fputs(" ", fp);
839     bi_disasm_dest_add(fp, next_regs, last);
840     fputs(", ", fp);
841     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
842     fputs(lane0, fp);
843     fputs("\n", fp);
844 }
845 
846 static void
bi_disasm_add_store_i128(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)847 bi_disasm_add_store_i128(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
848 {
849     static const char *seg_table[] = {
850         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
851     };
852 
853     const char *seg = seg_table[_BITS(bits, 6, 3)];
854 
855     fputs("+STORE.i128", fp);
856     fputs(seg, fp);
857     fputs(" ", fp);
858     bi_disasm_dest_add(fp, next_regs, last);
859     fputs(", ", fp);
860     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
861     fputs(", ", fp);
862     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
863     fprintf(fp, ", @r%u", staging_register);
864     fputs("\n", fp);
865 }
866 
867 static void
bi_disasm_add_ld_attr_tex_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)868 bi_disasm_add_ld_attr_tex_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
869 {
870     static const char *register_format_table[] = {
871         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
872     };
873     const char *register_format = register_format_table[(_BITS(bits, 13, 3) << 0)];
874     static const char *vecsize_table[] = {
875         "", ".v2", ".v3", ".v4"
876     };
877 
878     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
879 
880     fputs("+LD_ATTR_TEX", fp);
881     fputs(register_format, fp);
882     fputs(vecsize, fp);
883     fputs(" ", fp);
884     bi_disasm_dest_add(fp, next_regs, last);
885     fputs(", ", fp);
886     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
887     fputs(", ", fp);
888     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
889     fputs(", ", fp);
890     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
891     fprintf(fp, ", @r%u", staging_register);
892     fputs("\n", fp);
893 }
894 
895 static void
bi_disasm_add_store_i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)896 bi_disasm_add_store_i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
897 {
898     static const char *seg_table[] = {
899         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
900     };
901 
902     const char *seg = seg_table[_BITS(bits, 6, 3)];
903 
904     fputs("+STORE.i16", fp);
905     fputs(seg, fp);
906     fputs(" ", fp);
907     bi_disasm_dest_add(fp, next_regs, last);
908     fputs(", ", fp);
909     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
910     fputs(", ", fp);
911     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
912     fprintf(fp, ", @r%u", staging_register);
913     fputs("\n", fp);
914 }
915 
916 static void
bi_disasm_add_quiet_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)917 bi_disasm_add_quiet_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
918 {
919     static const char *swz0_table[] = {
920         ".h00", ".h10", "", ".h11"
921     };
922 
923     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
924 
925     fputs("+QUIET.v2f16", fp);
926     fputs(" ", fp);
927     bi_disasm_dest_add(fp, next_regs, last);
928     fputs(", ", fp);
929     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
930     fputs(swz0, fp);
931     fputs("\n", fp);
932 }
933 
934 static void
bi_disasm_fma_arshift_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)935 bi_disasm_fma_arshift_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
936 {
937     static const char *lanes2_table[] = {
938         ""
939     };
940     const char *lanes2 = lanes2_table[0];
941     fputs("*ARSHIFT.v4i8", fp);
942     fputs(" ", fp);
943     bi_disasm_dest_fma(fp, next_regs, last);
944     fputs(", ", fp);
945     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
946     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
947     fputs(", ", fp);
948     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
949     if (!(0x8 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
950     fputs(", ", fp);
951     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
952     fputs(lanes2, fp);
953     fputs("\n", fp);
954 }
955 
956 static void
bi_disasm_add_store_i96(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)957 bi_disasm_add_store_i96(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
958 {
959     static const char *seg_table[] = {
960         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
961     };
962 
963     const char *seg = seg_table[_BITS(bits, 6, 3)];
964 
965     fputs("+STORE.i96", fp);
966     fputs(seg, fp);
967     fputs(" ", fp);
968     bi_disasm_dest_add(fp, next_regs, last);
969     fputs(", ", fp);
970     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
971     fputs(", ", fp);
972     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
973     fprintf(fp, ", @r%u", staging_register);
974     fputs("\n", fp);
975 }
976 
977 static void
bi_disasm_add_u16_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)978 bi_disasm_add_u16_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
979 {
980     static const char *lane0_table[] = {
981         "", ".h1"
982     };
983 
984     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
985 
986     fputs("+U16_TO_F32", fp);
987     fputs(" ", fp);
988     bi_disasm_dest_add(fp, next_regs, last);
989     fputs(", ", fp);
990     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
991     fputs(lane0, fp);
992     fputs("\n", fp);
993 }
994 
995 static void
bi_disasm_add_zs_emit(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)996 bi_disasm_add_zs_emit(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
997 {
998     static const char *z_table[] = {
999         ".reserved", "", ".z", ".z"
1000     };
1001     const char *z = z_table[(_BITS(bits, 9, 2) << 0)];
1002     static const char *stencil_table[] = {
1003         ".reserved", ".stencil", "", ".stencil"
1004     };
1005     const char *stencil = stencil_table[(_BITS(bits, 9, 2) << 0)];
1006     fputs("+ZS_EMIT", fp);
1007     fputs(stencil, fp);
1008     fputs(z, fp);
1009     fputs(" ", fp);
1010     bi_disasm_dest_add(fp, next_regs, last);
1011     fputs(", ", fp);
1012     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1013     fputs(", ", fp);
1014     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1015     fputs(", ", fp);
1016     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1017     fprintf(fp, ", @r%u", staging_register);
1018     fputs("\n", fp);
1019 }
1020 
1021 static void
bi_disasm_add_discard_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1022 bi_disasm_add_discard_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1023 {
1024     static const char *cmpf_table[] = {
1025         ".eq", ".ne", ".lt", ".le", ".eq", ".ne", ".lt", ".le", ".eq", ".ne", ".lt", ".le", ".eq", ".ne", ".lt", ".le", ".eq", ".ne", ".lt", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1026     };
1027     const char *cmpf = cmpf_table[(_BITS(bits, 6, 2) << 0) | (_BITS(bits, 8, 3) << 2)];
1028     static const char *widen1_table[] = {
1029         ".h0", ".h0", ".h0", ".h0", ".h0", ".h0", ".h0", ".h0", ".h1", ".h1", ".h1", ".h1", ".h1", ".h1", ".h1", ".h1", "", "", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1030     };
1031     const char *widen1 = widen1_table[(_BITS(bits, 6, 2) << 0) | (_BITS(bits, 8, 3) << 2)];
1032     static const char *widen0_table[] = {
1033         ".h0", ".h0", ".h0", ".h0", ".h1", ".h1", ".h1", ".h1", ".h0", ".h0", ".h0", ".h0", ".h1", ".h1", ".h1", ".h1", "", "", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1034     };
1035     const char *widen0 = widen0_table[(_BITS(bits, 6, 2) << 0) | (_BITS(bits, 8, 3) << 2)];
1036     fputs("+DISCARD.f32", fp);
1037     fputs(cmpf, fp);
1038     fputs(" ", fp);
1039     bi_disasm_dest_add(fp, next_regs, last);
1040     fputs(", ", fp);
1041     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1042     fputs(widen0, fp);
1043     fputs(", ", fp);
1044     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1045     fputs(widen1, fp);
1046     fputs("\n", fp);
1047 }
1048 
1049 static void
bi_disasm_fma_isubb_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1050 bi_disasm_fma_isubb_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1051 {
1052     fputs("*ISUBB.i32", fp);
1053     fputs(" ", fp);
1054     bi_disasm_dest_fma(fp, next_regs, last);
1055     fputs(", ", fp);
1056     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1057     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1058     fputs(", ", fp);
1059     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1060     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1061     fputs(", ", fp);
1062     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1063     fputs("\n", fp);
1064 }
1065 
1066 static void
bi_disasm_add_fadd_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1067 bi_disasm_add_fadd_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1068 {
1069     static const char *abs1_table[] = {
1070         ""
1071     };
1072     const char *abs1 = abs1_table[0];
1073     static const char *neg0_table[] = {
1074         ""
1075     };
1076     const char *neg0 = neg0_table[0];
1077     static const char *widen0_table[] = {
1078         ""
1079     };
1080     const char *widen0 = widen0_table[0];
1081     static const char *neg1_table[] = {
1082         ""
1083     };
1084     const char *neg1 = neg1_table[0];
1085     static const char *abs0_table[] = {
1086         ""
1087     };
1088     const char *abs0 = abs0_table[0];
1089     static const char *clamp_table[] = {
1090         ""
1091     };
1092     const char *clamp = clamp_table[0];
1093     static const char *round_table[] = {
1094         ".rto"
1095     };
1096     const char *round = round_table[0];
1097     static const char *widen1_table[] = {
1098         ""
1099     };
1100     const char *widen1 = widen1_table[0];
1101     fputs("+FADD.f32", fp);
1102     fputs(round, fp);
1103     fputs(clamp, fp);
1104     fputs(" ", fp);
1105     bi_disasm_dest_add(fp, next_regs, last);
1106     fputs(", ", fp);
1107     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1108     fputs(neg0, fp);
1109     fputs(abs0, fp);
1110     fputs(widen0, fp);
1111     fputs(", ", fp);
1112     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1113     fputs(abs1, fp);
1114     fputs(neg1, fp);
1115     fputs(widen1, fp);
1116     fputs("\n", fp);
1117 }
1118 
1119 static void
bi_disasm_add_s8_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1120 bi_disasm_add_s8_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1121 {
1122     static const char *lane0_table[] = {
1123         "", ".b1", ".b2", ".b3"
1124     };
1125 
1126     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
1127 
1128     fputs("+S8_TO_F32", fp);
1129     fputs(" ", fp);
1130     bi_disasm_dest_add(fp, next_regs, last);
1131     fputs(", ", fp);
1132     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1133     fputs(lane0, fp);
1134     fputs("\n", fp);
1135 }
1136 
1137 static void
bi_disasm_add_fpclass_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1138 bi_disasm_add_fpclass_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1139 {
1140     fputs("+FPCLASS.f32", fp);
1141     fputs(" ", fp);
1142     bi_disasm_dest_add(fp, next_regs, last);
1143     fputs(", ", fp);
1144     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1145     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1146     fputs("\n", fp);
1147 }
1148 
1149 static void
bi_disasm_add_icmpf_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1150 bi_disasm_add_icmpf_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1151 {
1152     fputs("+ICMPF.i32", fp);
1153     fputs(" ", fp);
1154     bi_disasm_dest_add(fp, next_regs, last);
1155     fputs(", ", fp);
1156     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1157     fputs(", ", fp);
1158     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1159     fputs(", ", fp);
1160     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1161     fputs("\n", fp);
1162 }
1163 
1164 static void
bi_disasm_add_fadd_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1165 bi_disasm_add_fadd_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1166 {
1167     static const char *widen0_table[] = {
1168         "", "", "", "", "", "", "", "", "", "", "", "", ".h0", ".h0", ".h0", ".h0"
1169     };
1170     const char *widen0 = widen0_table[(_BITS(bits, 13, 2) << 0) | (_BITS(bits, 9, 2) << 2)];
1171     static const char *widen1_table[] = {
1172         "", "", "", "", ".h0", ".h0", ".h0", ".h0", ".h1", ".h1", ".h1", ".h1", ".h0", ".h0", ".h0", ".h0"
1173     };
1174     const char *widen1 = widen1_table[(_BITS(bits, 13, 2) << 0) | (_BITS(bits, 9, 2) << 2)];
1175     static const char *round_table[] = {
1176         "", ".rtp", ".rtn", ".rtz", "", ".rtp", ".rtn", ".rtz", "", ".rtp", ".rtn", ".rtz", "", ".rtp", ".rtn", ".rtz"
1177     };
1178     const char *round = round_table[(_BITS(bits, 13, 2) << 0) | (_BITS(bits, 9, 2) << 2)];
1179     static const char *abs1_table[] = {
1180         "", ".abs"
1181     };
1182 
1183     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
1184 
1185     static const char *neg0_table[] = {
1186         "", ".neg"
1187     };
1188 
1189     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
1190 
1191     static const char *neg1_table[] = {
1192         "", ".neg"
1193     };
1194 
1195     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
1196 
1197     static const char *clamp_table[] = {
1198         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
1199     };
1200 
1201     const char *clamp = clamp_table[_BITS(bits, 11, 2)];
1202 
1203     static const char *abs0_table[] = {
1204         "", ".abs"
1205     };
1206 
1207     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
1208 
1209     fputs("+FADD.f32", fp);
1210     fputs(round, fp);
1211     fputs(clamp, fp);
1212     fputs(" ", fp);
1213     bi_disasm_dest_add(fp, next_regs, last);
1214     fputs(", ", fp);
1215     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1216     fputs(neg0, fp);
1217     fputs(abs0, fp);
1218     fputs(widen0, fp);
1219     fputs(", ", fp);
1220     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1221     fputs(abs1, fp);
1222     fputs(neg1, fp);
1223     fputs(widen1, fp);
1224     fputs("\n", fp);
1225 }
1226 
1227 static void
bi_disasm_add_ld_var_imm_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1228 bi_disasm_add_ld_var_imm_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1229 {
1230     static const char *register_format_table[] = {
1231         ".auto", ".auto", ".auto", ".auto", ".auto", ".reserved", ".reserved", ".reserved", ".auto", ".auto", ".auto", ".auto", ".auto", ".auto", ".reserved", ".reserved"
1232     };
1233     const char *register_format = register_format_table[(_BITS(bits, 10, 4) << 0)];
1234     static const char *sample_table[] = {
1235         ".center", ".centroid", ".sample", ".explicit", "", ".reserved", ".reserved", ".reserved", ".center", ".centroid", ".center", ".centroid", ".sample", ".explicit", ".reserved", ".reserved"
1236     };
1237     const char *sample = sample_table[(_BITS(bits, 10, 4) << 0)];
1238     static const char *update_table[] = {
1239         ".store", ".store", ".store", ".store", ".retrieve", ".reserved", ".reserved", ".reserved", ".conditional", ".conditional", ".clobber", ".clobber", ".clobber", ".clobber", ".reserved", ".reserved"
1240     };
1241     const char *update = update_table[(_BITS(bits, 10, 4) << 0)];
1242     static const char *vecsize_table[] = {
1243         "", ".v2", ".v3", ".v4"
1244     };
1245 
1246     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
1247 
1248     fputs("+LD_VAR_IMM", fp);
1249     fputs(vecsize, fp);
1250     fputs(update, fp);
1251     fputs(register_format, fp);
1252     fputs(sample, fp);
1253     fputs(" ", fp);
1254     bi_disasm_dest_add(fp, next_regs, last);
1255     fputs(", ", fp);
1256     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1257     fprintf(fp, ", index:%u", _BITS(bits, 3, 5));
1258     fprintf(fp, ", @r%u", staging_register);
1259     fputs("\n", fp);
1260 }
1261 
1262 static void
bi_disasm_add_isub_v2s16_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1263 bi_disasm_add_isub_v2s16_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1264 {
1265     static const char *lanes1_table[] = {
1266         ".b01", ".b23"
1267     };
1268     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
1269     static const char *lanes0_table[] = {
1270         "", ""
1271     };
1272     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
1273     static const char *saturate_table[] = {
1274         "", ".sat"
1275     };
1276 
1277     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
1278 
1279     fputs("+ISUB.v2s16", fp);
1280     fputs(saturate, fp);
1281     fputs(" ", fp);
1282     bi_disasm_dest_add(fp, next_regs, last);
1283     fputs(", ", fp);
1284     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1285     fputs(lanes0, fp);
1286     fputs(", ", fp);
1287     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1288     fputs(lanes1, fp);
1289     fputs("\n", fp);
1290 }
1291 
1292 static void
bi_disasm_fma_mkvec_v4i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1293 bi_disasm_fma_mkvec_v4i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1294 {
1295     static const char *lane0_table[] = {
1296         "", ".b2"
1297     };
1298 
1299     const char *lane0 = lane0_table[_BITS(bits, 12, 1)];
1300 
1301     static const char *lane1_table[] = {
1302         "", ".b2"
1303     };
1304 
1305     const char *lane1 = lane1_table[_BITS(bits, 13, 1)];
1306 
1307     static const char *lane2_table[] = {
1308         "", ".b2"
1309     };
1310 
1311     const char *lane2 = lane2_table[_BITS(bits, 14, 1)];
1312 
1313     static const char *lane3_table[] = {
1314         "", ".b2"
1315     };
1316 
1317     const char *lane3 = lane3_table[_BITS(bits, 15, 1)];
1318 
1319     fputs("*MKVEC.v4i8", fp);
1320     fputs(" ", fp);
1321     bi_disasm_dest_fma(fp, next_regs, last);
1322     fputs(", ", fp);
1323     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1324     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1325     fputs(lane0, fp);
1326     fputs(", ", fp);
1327     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1328     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1329     fputs(lane1, fp);
1330     fputs(", ", fp);
1331     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1332     fputs(lane2, fp);
1333     fputs(", ", fp);
1334     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
1335     fputs(lane3, fp);
1336     fputs("\n", fp);
1337 }
1338 
1339 static void
bi_disasm_add_clper_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1340 bi_disasm_add_clper_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1341 {
1342     static const char *lane_op_table[] = {
1343         "", ".xor", ".accumulate", ".shift"
1344     };
1345 
1346     const char *lane_op = lane_op_table[_BITS(bits, 6, 2)];
1347 
1348     static const char *subgroup_table[] = {
1349         ".subgroup2", ".subgroup4", ".subgroup8", ".reserved"
1350     };
1351 
1352     const char *subgroup = subgroup_table[_BITS(bits, 8, 2)];
1353 
1354     static const char *inactive_result_table[] = {
1355         ".zero", ".umax", ".i1", ".v2i1", ".smin", ".smax", ".v2smin", ".v2smax", ".v4smin", ".v4smax", ".f1", ".v2f1", ".infn", ".inf", ".v2infn", ".v2inf"
1356     };
1357 
1358     const char *inactive_result = inactive_result_table[_BITS(bits, 10, 4)];
1359 
1360     fputs("+CLPER.i32", fp);
1361     fputs(lane_op, fp);
1362     fputs(subgroup, fp);
1363     fputs(inactive_result, fp);
1364     fputs(" ", fp);
1365     bi_disasm_dest_add(fp, next_regs, last);
1366     fputs(", ", fp);
1367     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1368     if (!(0x7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1369     fputs(", ", fp);
1370     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1371     fputs("\n", fp);
1372 }
1373 
1374 static void
bi_disasm_fma_atom_pre_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1375 bi_disasm_fma_atom_pre_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1376 {
1377     static const char *atom_opc_table[] = {
1378         ".aaddu", ".aadds", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
1379     };
1380 
1381     const char *atom_opc = atom_opc_table[_BITS(bits, 9, 4)];
1382 
1383     fputs("*ATOM_PRE.i64", fp);
1384     fputs(atom_opc, fp);
1385     fputs(" ", fp);
1386     bi_disasm_dest_fma(fp, next_regs, last);
1387     fputs(", ", fp);
1388     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1389     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1390     fputs(", ", fp);
1391     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1392     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1393     fputs(", ", fp);
1394     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1395     fputs("\n", fp);
1396 }
1397 
1398 static void
bi_disasm_add_v2u16_to_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1399 bi_disasm_add_v2u16_to_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1400 {
1401     static const char *round_table[] = {
1402         "", ".rtp", ".rtn", ".rtz"
1403     };
1404     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
1405     static const char *swz0_table[] = {
1406         ".h00", ".h10", "", ".h11"
1407     };
1408 
1409     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
1410 
1411     fputs("+V2U16_TO_V2F16", fp);
1412     fputs(round, fp);
1413     fputs(" ", fp);
1414     bi_disasm_dest_add(fp, next_regs, last);
1415     fputs(", ", fp);
1416     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1417     fputs(swz0, fp);
1418     fputs("\n", fp);
1419 }
1420 
1421 static void
bi_disasm_add_frexpm_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1422 bi_disasm_add_frexpm_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1423 {
1424     static const char *neg0_table[] = {
1425         ""
1426     };
1427     const char *neg0 = neg0_table[0];
1428     static const char *log_table[] = {
1429         ""
1430     };
1431     const char *log = log_table[0];
1432     static const char *abs0_table[] = {
1433         "", ".abs0"
1434     };
1435 
1436     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
1437 
1438     static const char *sqrt_table[] = {
1439         "", ".sqrt"
1440     };
1441 
1442     const char *sqrt = sqrt_table[_BITS(bits, 7, 1)];
1443 
1444     static const char *widen0_table[] = {
1445         ".reserved", "", ".h0", ".h1"
1446     };
1447 
1448     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
1449 
1450     fputs("+FREXPM.f32", fp);
1451     fputs(sqrt, fp);
1452     fputs(log, fp);
1453     fputs(" ", fp);
1454     bi_disasm_dest_add(fp, next_regs, last);
1455     fputs(", ", fp);
1456     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1457     fputs(abs0, fp);
1458     fputs(widen0, fp);
1459     fputs(neg0, fp);
1460     fputs("\n", fp);
1461 }
1462 
1463 static void
bi_disasm_add_texs_2d_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1464 bi_disasm_add_texs_2d_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1465 {
1466     static const char *skip_table[] = {
1467         "", ".skip"
1468     };
1469 
1470     const char *skip = skip_table[_BITS(bits, 9, 1)];
1471 
1472     static const char *lod_mode_table[] = {
1473         ".computed_lod", ""
1474     };
1475 
1476     const char *lod_mode = lod_mode_table[_BITS(bits, 13, 1)];
1477 
1478     fputs("+TEXS_2D.f16", fp);
1479     fputs(skip, fp);
1480     fputs(lod_mode, fp);
1481     fputs(" ", fp);
1482     bi_disasm_dest_add(fp, next_regs, last);
1483     fputs(", ", fp);
1484     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1485     fputs(", ", fp);
1486     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1487     fprintf(fp, ", texture_index:%u", _BITS(bits, 6, 3));
1488     fprintf(fp, ", sampler_index:%u", _BITS(bits, 10, 3));
1489     fprintf(fp, ", @r%u", staging_register);
1490     fputs("\n", fp);
1491 }
1492 
1493 static void
bi_disasm_add_blend(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1494 bi_disasm_add_blend(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1495 {
1496     fputs("+BLEND", fp);
1497     fputs(" ", fp);
1498     bi_disasm_dest_add(fp, next_regs, last);
1499     fputs(", ", fp);
1500     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1501     fputs(", ", fp);
1502     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1503     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1504     fputs(", ", fp);
1505     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1506     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
1507     fprintf(fp, ", @r%u", staging_register);
1508     fputs("\n", fp);
1509 }
1510 
1511 static void
bi_disasm_add_v2f16_to_v2u16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1512 bi_disasm_add_v2f16_to_v2u16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1513 {
1514     static const char *round_table[] = {
1515         "", ".rtp", ".rtn", ".rtz"
1516     };
1517     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
1518     static const char *swz0_table[] = {
1519         ".h00", ".h10", "", ".h11"
1520     };
1521 
1522     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
1523 
1524     fputs("+V2F16_TO_V2U16", fp);
1525     fputs(round, fp);
1526     fputs(" ", fp);
1527     bi_disasm_dest_add(fp, next_regs, last);
1528     fputs(", ", fp);
1529     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1530     fputs(swz0, fp);
1531     fputs("\n", fp);
1532 }
1533 
1534 static void
bi_disasm_fma_u16_to_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1535 bi_disasm_fma_u16_to_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1536 {
1537     static const char *lane0_table[] = {
1538         "", ".h1"
1539     };
1540 
1541     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
1542 
1543     fputs("*U16_TO_U32", fp);
1544     fputs(" ", fp);
1545     bi_disasm_dest_fma(fp, next_regs, last);
1546     fputs(", ", fp);
1547     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1548     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1549     fputs(lane0, fp);
1550     fputs("\n", fp);
1551 }
1552 
1553 static void
bi_disasm_add_branch_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1554 bi_disasm_add_branch_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1555 {
1556     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
1557     static const char *widen0_0[] = {
1558         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved"
1559     };
1560     static const char *widen0_1[] = {
1561         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved"
1562     };
1563     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1564     static const char *cmpf_0[] = {
1565         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".eq", ".ne", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".gt", ".ge", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".lt", ".lt", ".le", ".lt", ".reserved", ".reserved", ".reserved"
1566     };
1567     static const char *cmpf_1[] = {
1568         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".ne", ".ne", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".ge", ".ge", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".le", ".le", ".lt", ".reserved", ".reserved", ".reserved"
1569     };
1570     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1571     static const char *widen1_0[] = {
1572         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved"
1573     };
1574     static const char *widen1_1[] = {
1575         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved"
1576     };
1577     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1578     fputs("+BRANCH.f16", fp);
1579     fputs(cmpf, fp);
1580     fputs(" ", fp);
1581     bi_disasm_dest_add(fp, next_regs, last);
1582     fputs(", ", fp);
1583     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1584     fputs(widen0, fp);
1585     fputs(", ", fp);
1586     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1587     fputs(widen1, fp);
1588     fputs(", ", fp);
1589     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1590     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
1591     fputs("\n", fp);
1592 }
1593 
1594 static void
bi_disasm_fma_rshift_xor_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1595 bi_disasm_fma_rshift_xor_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1596 {
1597     static const char *lanes2_table[] = {
1598         ".reserved", ".b01", ".b23", ""
1599     };
1600     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
1601     static const char *not_result_table[] = {
1602         "", ".not"
1603     };
1604 
1605     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
1606 
1607     fputs("*RSHIFT_XOR.v2i16", fp);
1608     fputs(not_result, fp);
1609     fputs(" ", fp);
1610     bi_disasm_dest_fma(fp, next_regs, last);
1611     fputs(", ", fp);
1612     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1613     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1614     fputs(", ", fp);
1615     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1616     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1617     fputs(", ", fp);
1618     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1619     fputs(lanes2, fp);
1620     fputs("\n", fp);
1621 }
1622 
1623 static void
bi_disasm_fma_rrot_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1624 bi_disasm_fma_rrot_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1625 {
1626     static const char *bytes2_table[] = {
1627         "", ".bytes2"
1628     };
1629 
1630     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
1631 
1632     static const char *lane2_table[] = {
1633         "", ".b2"
1634     };
1635 
1636     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
1637 
1638     static const char *result_word_table[] = {
1639         "", ".w1"
1640     };
1641 
1642     const char *result_word = result_word_table[_BITS(bits, 11, 1)];
1643 
1644     fputs("*RROT_DOUBLE.i32", fp);
1645     fputs(result_word, fp);
1646     fputs(" ", fp);
1647     bi_disasm_dest_fma(fp, next_regs, last);
1648     fputs(", ", fp);
1649     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1650     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1651     fputs(", ", fp);
1652     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1653     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1654     fputs(", ", fp);
1655     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1656     fputs(bytes2, fp);
1657     fputs(lane2, fp);
1658     fputs("\n", fp);
1659 }
1660 
1661 static void
bi_disasm_add_quiet_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1662 bi_disasm_add_quiet_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1663 {
1664     fputs("+QUIET.f32", fp);
1665     fputs(" ", fp);
1666     bi_disasm_dest_add(fp, next_regs, last);
1667     fputs(", ", fp);
1668     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1669     fputs("\n", fp);
1670 }
1671 
1672 static void
bi_disasm_add_branch_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1673 bi_disasm_add_branch_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1674 {
1675     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
1676     static const char *widen0_0[] = {
1677         "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1678     };
1679     static const char *widen0_1[] = {
1680         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1681     };
1682     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1683     static const char *cmpf_0[] = {
1684         ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1685     };
1686     static const char *cmpf_1[] = {
1687         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1688     };
1689     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1690     static const char *widen1_0[] = {
1691         "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1692     };
1693     static const char *widen1_1[] = {
1694         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1695     };
1696     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1697     fputs("+BRANCH.s32", fp);
1698     fputs(cmpf, fp);
1699     fputs(" ", fp);
1700     bi_disasm_dest_add(fp, next_regs, last);
1701     fputs(", ", fp);
1702     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1703     fputs(widen0, fp);
1704     fputs(", ", fp);
1705     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1706     fputs(widen1, fp);
1707     fputs(", ", fp);
1708     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1709     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
1710     fputs("\n", fp);
1711 }
1712 
1713 static void
bi_disasm_add_load_i8_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1714 bi_disasm_add_load_i8_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1715 {
1716     static const char *extend_table[] = {
1717         ".sext", ".zext"
1718     };
1719     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
1720     static const char *lane_table[] = {
1721         ".w0", ".w0"
1722     };
1723     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
1724     static const char *seg_table[] = {
1725         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
1726     };
1727 
1728     const char *seg = seg_table[_BITS(bits, 6, 3)];
1729 
1730     fputs("+LOAD.i8", fp);
1731     fputs(seg, fp);
1732     fputs(lane, fp);
1733     fputs(extend, fp);
1734     fputs(" ", fp);
1735     bi_disasm_dest_add(fp, next_regs, last);
1736     fputs(", ", fp);
1737     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1738     fputs(", ", fp);
1739     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1740     fprintf(fp, ", @r%u", staging_register);
1741     fputs("\n", fp);
1742 }
1743 
1744 static void
bi_disasm_fma_fma_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1745 bi_disasm_fma_fma_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1746 {
1747     static const char *widen0_table[] = {
1748         "", "", "", ".h0", ".h0", ".h1", ".h0", ".h1", "", "", "", ".h0", ".h0", ".h1", ".h0", ".h1"
1749     };
1750     const char *widen0 = widen0_table[(_BITS(bits, 9, 3) << 0) | (_BITS(bits, 17, 1) << 3)];
1751     static const char *neg0_table[] = {
1752         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
1753     };
1754     const char *neg0 = neg0_table[(_BITS(bits, 9, 3) << 0) | (_BITS(bits, 17, 1) << 3)];
1755     static const char *widen1_table[] = {
1756         "", ".h0", ".h1", ".h0", ".h1", ".h1", "", "", "", ".h0", ".h1", ".h0", ".h1", ".h1", "", ""
1757     };
1758     const char *widen1 = widen1_table[(_BITS(bits, 9, 3) << 0) | (_BITS(bits, 17, 1) << 3)];
1759     static const char *neg1_table[] = {
1760         "", "", "", "", "", "", "", "", ".neg", ".neg", ".neg", ".neg", ".neg", ".neg", ".neg", ".neg"
1761     };
1762     const char *neg1 = neg1_table[(_BITS(bits, 9, 3) << 0) | (_BITS(bits, 17, 1) << 3)];
1763     static const char *abs0_table[] = {
1764         "", ".abs"
1765     };
1766 
1767     const char *abs0 = abs0_table[_BITS(bits, 12, 1)];
1768 
1769     static const char *round_table[] = {
1770         "", ".rtp", ".rtn", ".rtz"
1771     };
1772 
1773     const char *round = round_table[_BITS(bits, 13, 2)];
1774 
1775     static const char *clamp_table[] = {
1776         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
1777     };
1778 
1779     const char *clamp = clamp_table[_BITS(bits, 15, 2)];
1780 
1781     static const char *abs1_table[] = {
1782         "", ".abs"
1783     };
1784 
1785     const char *abs1 = abs1_table[_BITS(bits, 19, 1)];
1786 
1787     static const char *neg2_table[] = {
1788         "", ".neg"
1789     };
1790 
1791     const char *neg2 = neg2_table[_BITS(bits, 18, 1)];
1792 
1793     static const char *abs2_table[] = {
1794         "", ".abs"
1795     };
1796 
1797     const char *abs2 = abs2_table[_BITS(bits, 20, 1)];
1798 
1799     fputs("*FMA.f32", fp);
1800     fputs(round, fp);
1801     fputs(clamp, fp);
1802     fputs(" ", fp);
1803     bi_disasm_dest_fma(fp, next_regs, last);
1804     fputs(", ", fp);
1805     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1806     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1807     fputs(widen0, fp);
1808     fputs(neg0, fp);
1809     fputs(abs0, fp);
1810     fputs(", ", fp);
1811     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1812     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1813     fputs(widen1, fp);
1814     fputs(neg1, fp);
1815     fputs(abs1, fp);
1816     fputs(", ", fp);
1817     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1818     fputs(neg2, fp);
1819     fputs(abs2, fp);
1820     fputs("\n", fp);
1821 }
1822 
1823 static void
bi_disasm_add_branch_diverg(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1824 bi_disasm_add_branch_diverg(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1825 {
1826     fputs("+BRANCH_DIVERG", fp);
1827     fputs(" ", fp);
1828     bi_disasm_dest_add(fp, next_regs, last);
1829     fputs(", ", fp);
1830     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1831     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
1832     fputs("\n", fp);
1833 }
1834 
1835 static void
bi_disasm_add_s16_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1836 bi_disasm_add_s16_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1837 {
1838     static const char *lane0_table[] = {
1839         "", ".h1"
1840     };
1841 
1842     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
1843 
1844     fputs("+S16_TO_F32", fp);
1845     fputs(" ", fp);
1846     bi_disasm_dest_add(fp, next_regs, last);
1847     fputs(", ", fp);
1848     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1849     fputs(lane0, fp);
1850     fputs("\n", fp);
1851 }
1852 
1853 static void
bi_disasm_fma_rshift_or_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1854 bi_disasm_fma_rshift_or_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1855 {
1856     static const char *lane2_table[] = {
1857         "", ".b1", ".b2", ".b3"
1858     };
1859 
1860     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
1861 
1862     static const char *not1_table[] = {
1863         ".not", ""
1864     };
1865 
1866     const char *not1 = not1_table[_BITS(bits, 14, 1)];
1867 
1868     static const char *not_result_table[] = {
1869         "", ".not"
1870     };
1871 
1872     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
1873 
1874     fputs("*RSHIFT_OR.i32", fp);
1875     fputs(not_result, fp);
1876     fputs(" ", fp);
1877     bi_disasm_dest_fma(fp, next_regs, last);
1878     fputs(", ", fp);
1879     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1880     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1881     fputs(", ", fp);
1882     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1883     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1884     fputs(not1, fp);
1885     fputs(", ", fp);
1886     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1887     fputs(lane2, fp);
1888     fputs("\n", fp);
1889 }
1890 
1891 static void
bi_disasm_add_store_i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1892 bi_disasm_add_store_i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1893 {
1894     static const char *seg_table[] = {
1895         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
1896     };
1897 
1898     const char *seg = seg_table[_BITS(bits, 6, 3)];
1899 
1900     fputs("+STORE.i8", fp);
1901     fputs(seg, fp);
1902     fputs(" ", fp);
1903     bi_disasm_dest_add(fp, next_regs, last);
1904     fputs(", ", fp);
1905     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1906     fputs(", ", fp);
1907     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1908     fprintf(fp, ", @r%u", staging_register);
1909     fputs("\n", fp);
1910 }
1911 
1912 static void
bi_disasm_add_branch_u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1913 bi_disasm_add_branch_u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1914 {
1915     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
1916     static const char *cmpf_0[] = {
1917         ".reserved", ".reserved", ".reserved", ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1918     };
1919     static const char *cmpf_1[] = {
1920         ".reserved", ".lt", ".lt", ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".le", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".ge", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".gt", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1921     };
1922     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1923     static const char *widen0_0[] = {
1924         ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1925     };
1926     static const char *widen0_1[] = {
1927         ".reserved", ".h0", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1928     };
1929     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1930     static const char *widen1_0[] = {
1931         ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1932     };
1933     static const char *widen1_1[] = {
1934         ".reserved", ".h0", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
1935     };
1936     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
1937     fputs("+BRANCH.u16", fp);
1938     fputs(cmpf, fp);
1939     fputs(" ", fp);
1940     bi_disasm_dest_add(fp, next_regs, last);
1941     fputs(", ", fp);
1942     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
1943     fputs(widen0, fp);
1944     fputs(", ", fp);
1945     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
1946     fputs(widen1, fp);
1947     fputs(", ", fp);
1948     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
1949     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
1950     fputs("\n", fp);
1951 }
1952 
1953 static void
bi_disasm_fma_lshift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1954 bi_disasm_fma_lshift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1955 {
1956     static const char *bytes2_table[] = {
1957         "", ".bytes2"
1958     };
1959 
1960     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
1961 
1962     static const char *lane2_table[] = {
1963         "", ".b2"
1964     };
1965 
1966     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
1967 
1968     static const char *result_word_table[] = {
1969         "", ".w1"
1970     };
1971 
1972     const char *result_word = result_word_table[_BITS(bits, 11, 1)];
1973 
1974     fputs("*LSHIFT_DOUBLE.i32", fp);
1975     fputs(result_word, fp);
1976     fputs(" ", fp);
1977     bi_disasm_dest_fma(fp, next_regs, last);
1978     fputs(", ", fp);
1979     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
1980     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
1981     fputs(", ", fp);
1982     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
1983     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
1984     fputs(", ", fp);
1985     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
1986     fputs(bytes2, fp);
1987     fputs(lane2, fp);
1988     fputs("\n", fp);
1989 }
1990 
1991 static void
bi_disasm_fma_frexpm_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)1992 bi_disasm_fma_frexpm_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
1993 {
1994     static const char *sqrt_table[] = {
1995         ""
1996     };
1997     const char *sqrt = sqrt_table[0];
1998     static const char *log_table[] = {
1999         ".log"
2000     };
2001     const char *log = log_table[0];
2002     static const char *abs0_table[] = {
2003         "", ".abs0"
2004     };
2005 
2006     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
2007 
2008     static const char *swz0_table[] = {
2009         ".h00", ".h10", "", ".h11"
2010     };
2011 
2012     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
2013 
2014     static const char *neg0_table[] = {
2015         "", ".neg0"
2016     };
2017 
2018     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
2019 
2020     fputs("*FREXPM.v2f16", fp);
2021     fputs(sqrt, fp);
2022     fputs(log, fp);
2023     fputs(" ", fp);
2024     bi_disasm_dest_fma(fp, next_regs, last);
2025     fputs(", ", fp);
2026     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2027     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2028     fputs(abs0, fp);
2029     fputs(swz0, fp);
2030     fputs(neg0, fp);
2031     fputs("\n", fp);
2032 }
2033 
2034 static void
bi_disasm_fma_dtsel_imm(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2035 bi_disasm_fma_dtsel_imm(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2036 {
2037     fputs("*DTSEL_IMM", fp);
2038     fputs(" ", fp);
2039     bi_disasm_dest_fma(fp, next_regs, last);
2040     fputs(", ", fp);
2041     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2042     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2043     fprintf(fp, ", table:%u", _BITS(bits, 3, 6));
2044     fputs("\n", fp);
2045 }
2046 
2047 static void
bi_disasm_add_fatan_assist_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2048 bi_disasm_add_fatan_assist_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2049 {
2050     fputs("+FATAN_ASSIST.f32", fp);
2051     fputs(" ", fp);
2052     bi_disasm_dest_add(fp, next_regs, last);
2053     fputs(", ", fp);
2054     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2055     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2056     fputs(", ", fp);
2057     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2058     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2059     fputs("\n", fp);
2060 }
2061 
2062 static void
bi_disasm_fma_vn_asst1_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2063 bi_disasm_fma_vn_asst1_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2064 {
2065     static const char *h_table[] = {
2066         "", ".h"
2067     };
2068 
2069     const char *h = h_table[_BITS(bits, 9, 1)];
2070 
2071     static const char *l_table[] = {
2072         "", ".l"
2073     };
2074 
2075     const char *l = l_table[_BITS(bits, 10, 1)];
2076 
2077     static const char *neg2_table[] = {
2078         "", ".neg2"
2079     };
2080 
2081     const char *neg2 = neg2_table[_BITS(bits, 11, 1)];
2082 
2083     fputs("*VN_ASST1.f16", fp);
2084     fputs(h, fp);
2085     fputs(l, fp);
2086     fputs(" ", fp);
2087     bi_disasm_dest_fma(fp, next_regs, last);
2088     fputs(", ", fp);
2089     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2090     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2091     fputs(", ", fp);
2092     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2093     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2094     fputs(", ", fp);
2095     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2096     fputs(neg2, fp);
2097     fputs("\n", fp);
2098 }
2099 
2100 static void
bi_disasm_add_load_i48(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2101 bi_disasm_add_load_i48(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2102 {
2103     static const char *seg_table[] = {
2104         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
2105     };
2106 
2107     const char *seg = seg_table[_BITS(bits, 6, 3)];
2108 
2109     fputs("+LOAD.i48", fp);
2110     fputs(seg, fp);
2111     fputs(" ", fp);
2112     bi_disasm_dest_add(fp, next_regs, last);
2113     fputs(", ", fp);
2114     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2115     fputs(", ", fp);
2116     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2117     fprintf(fp, ", @r%u", staging_register);
2118     fputs("\n", fp);
2119 }
2120 
2121 static void
bi_disasm_fma_atom_post_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2122 bi_disasm_fma_atom_post_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2123 {
2124     static const char *atom_opc_table[] = {
2125         ".aaddu", ".aadds", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
2126     };
2127 
2128     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 4)];
2129 
2130     fputs("*ATOM_POST.i64", fp);
2131     fputs(atom_opc, fp);
2132     fputs(" ", fp);
2133     bi_disasm_dest_fma(fp, next_regs, last);
2134     fputs(", ", fp);
2135     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2136     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2137     fputs(", ", fp);
2138     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2139     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2140     fputs("\n", fp);
2141 }
2142 
2143 static void
bi_disasm_fma_arshift_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2144 bi_disasm_fma_arshift_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2145 {
2146     static const char *lanes2_table[] = {
2147         ".reserved", ".b01", ".b23", ""
2148     };
2149     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
2150     fputs("*ARSHIFT.v2i16", fp);
2151     fputs(" ", fp);
2152     bi_disasm_dest_fma(fp, next_regs, last);
2153     fputs(", ", fp);
2154     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2155     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2156     fputs(", ", fp);
2157     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2158     if (!(0x8 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2159     fputs(", ", fp);
2160     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2161     fputs(lanes2, fp);
2162     fputs("\n", fp);
2163 }
2164 
2165 static void
bi_disasm_fma_fadd_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2166 bi_disasm_fma_fadd_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2167 {
2168     static const char *widen0_table[] = {
2169         "", "", "", ".h0", ".h0", ".h1", ".h0", ".h1"
2170     };
2171     const char *widen0 = widen0_table[(_BITS(bits, 9, 3) << 0)];
2172     static const char *widen1_table[] = {
2173         "", ".h0", ".h1", ".h0", ".h1", ".h1", "", ""
2174     };
2175     const char *widen1 = widen1_table[(_BITS(bits, 9, 3) << 0)];
2176     static const char *abs1_table[] = {
2177         "", ".abs"
2178     };
2179 
2180     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
2181 
2182     static const char *neg0_table[] = {
2183         "", ".neg"
2184     };
2185 
2186     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
2187 
2188     static const char *neg1_table[] = {
2189         "", ".neg"
2190     };
2191 
2192     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
2193 
2194     static const char *abs0_table[] = {
2195         "", ".abs"
2196     };
2197 
2198     const char *abs0 = abs0_table[_BITS(bits, 12, 1)];
2199 
2200     static const char *round_table[] = {
2201         "", ".rtp", ".rtn", ".rtz"
2202     };
2203 
2204     const char *round = round_table[_BITS(bits, 13, 2)];
2205 
2206     static const char *clamp_table[] = {
2207         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
2208     };
2209 
2210     const char *clamp = clamp_table[_BITS(bits, 15, 2)];
2211 
2212     fputs("*FADD.f32", fp);
2213     fputs(round, fp);
2214     fputs(clamp, fp);
2215     fputs(" ", fp);
2216     bi_disasm_dest_fma(fp, next_regs, last);
2217     fputs(", ", fp);
2218     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2219     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2220     fputs(neg0, fp);
2221     fputs(abs0, fp);
2222     fputs(widen0, fp);
2223     fputs(", ", fp);
2224     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2225     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2226     fputs(abs1, fp);
2227     fputs(neg1, fp);
2228     fputs(widen1, fp);
2229     fputs("\n", fp);
2230 }
2231 
2232 static void
bi_disasm_add_v2f32_to_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2233 bi_disasm_add_v2f32_to_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2234 {
2235     static const char *abs1_table[] = {
2236         "", ".abs", "", ".abs"
2237     };
2238     const char *abs1 = abs1_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
2239     static const char *neg0_table[] = {
2240         "", "", ".neg", ".neg"
2241     };
2242     const char *neg0 = neg0_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
2243     static const char *neg1_table[] = {
2244         "", "", ".neg", ".neg"
2245     };
2246     const char *neg1 = neg1_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
2247     static const char *abs0_table[] = {
2248         "", ".abs", "", ".abs"
2249     };
2250     const char *abs0 = abs0_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
2251     static const char *clamp_table[] = {
2252         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
2253     };
2254 
2255     const char *clamp = clamp_table[_BITS(bits, 8, 2)];
2256 
2257     static const char *round_table[] = {
2258         "", ".rtp", ".rtn", ".rtz", ".rtna", ".reserved", ".reserved", ".reserved"
2259     };
2260 
2261     const char *round = round_table[_BITS(bits, 10, 3)];
2262 
2263     fputs("+V2F32_TO_V2F16", fp);
2264     fputs(clamp, fp);
2265     fputs(round, fp);
2266     fputs(" ", fp);
2267     bi_disasm_dest_add(fp, next_regs, last);
2268     fputs(", ", fp);
2269     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2270     fputs(abs0, fp);
2271     fputs(neg0, fp);
2272     fputs(", ", fp);
2273     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2274     fputs(abs1, fp);
2275     fputs(neg1, fp);
2276     fputs("\n", fp);
2277 }
2278 
2279 static void
bi_disasm_add_icmp_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2280 bi_disasm_add_icmp_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2281 {
2282     static const char *cmpf_table[] = {
2283         ".gt", ".ge"
2284     };
2285     const char *cmpf = cmpf_table[(_BITS(bits, 6, 1) << 0)];
2286     static const char *result_type_table[] = {
2287         "", ".m1"
2288     };
2289 
2290     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
2291 
2292     fputs("+ICMP.s32", fp);
2293     fputs(result_type, fp);
2294     fputs(cmpf, fp);
2295     fputs(" ", fp);
2296     bi_disasm_dest_add(fp, next_regs, last);
2297     fputs(", ", fp);
2298     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2299     fputs(", ", fp);
2300     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2301     fputs("\n", fp);
2302 }
2303 
2304 static void
bi_disasm_add_var_tex_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2305 bi_disasm_add_var_tex_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2306 {
2307     static const char *update_table[] = {
2308         ".store", ".retrieve", ".reserved", ".reserved"
2309     };
2310     const char *update = update_table[(_BITS(bits, 5, 2) << 0)];
2311     static const char *sample_table[] = {
2312         ".center", "", ".reserved", ".reserved"
2313     };
2314     const char *sample = sample_table[(_BITS(bits, 5, 2) << 0)];
2315     static const char *skip_table[] = {
2316         "", ".skip"
2317     };
2318 
2319     const char *skip = skip_table[_BITS(bits, 7, 1)];
2320 
2321     static const char *lod_mode_table[] = {
2322         ".computed_lod", ""
2323     };
2324 
2325     const char *lod_mode = lod_mode_table[_BITS(bits, 9, 1)];
2326 
2327     fputs("+VAR_TEX.f16", fp);
2328     fputs(update, fp);
2329     fputs(skip, fp);
2330     fputs(lod_mode, fp);
2331     fputs(sample, fp);
2332     fputs(" ", fp);
2333     bi_disasm_dest_add(fp, next_regs, last);
2334     fprintf(fp, ", varying_index:%u", _BITS(bits, 0, 3));
2335     fprintf(fp, ", texture_index:%u", _BITS(bits, 3, 2));
2336     fprintf(fp, ", @r%u", staging_register);
2337     fputs("\n", fp);
2338 }
2339 
2340 static void
bi_disasm_add_f16_to_s32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2341 bi_disasm_add_f16_to_s32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2342 {
2343     static const char *round_table[] = {
2344         ".rtna"
2345     };
2346     const char *round = round_table[0];
2347     static const char *lane0_table[] = {
2348         "", ".h1"
2349     };
2350 
2351     const char *lane0 = lane0_table[_BITS(bits, 5, 1)];
2352 
2353     fputs("+F16_TO_S32", fp);
2354     fputs(round, fp);
2355     fputs(" ", fp);
2356     bi_disasm_dest_add(fp, next_regs, last);
2357     fputs(", ", fp);
2358     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2359     fputs(lane0, fp);
2360     fputs("\n", fp);
2361 }
2362 
2363 static void
bi_disasm_fma_imul_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2364 bi_disasm_fma_imul_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2365 {
2366     static const char *replicate1_table[] = {
2367         ".b0000", ".b1111", ".b2222", ".b3333"
2368     };
2369     const char *replicate1 = replicate1_table[(_BITS(bits, 9, 2) << 0)];
2370     static const char *replicate0_table[] = {
2371         "", "", "", ""
2372     };
2373     const char *replicate0 = replicate0_table[(_BITS(bits, 9, 2) << 0)];
2374     fputs("*IMUL.v4i8", fp);
2375     fputs(" ", fp);
2376     bi_disasm_dest_fma(fp, next_regs, last);
2377     fputs(", ", fp);
2378     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2379     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2380     fputs(replicate0, fp);
2381     fputs(", ", fp);
2382     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2383     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2384     fputs(replicate1, fp);
2385     fputs("\n", fp);
2386 }
2387 
2388 static void
bi_disasm_fma_fma_rscale_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2389 bi_disasm_fma_fma_rscale_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2390 {
2391     static const char *neg0_table[] = {
2392         "", "", "", "", "", "", "", "", "", "", "", "", ".reserved", ".reserved", "", ""
2393     };
2394     const char *neg0 = neg0_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
2395     static const char *neg1_table[] = {
2396         "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg", ".reserved", ".reserved", "", ".neg"
2397     };
2398     const char *neg1 = neg1_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
2399     static const char *clamp_table[] = {
2400         "", "", ".clamp_0_inf", ".clamp_0_inf", ".clamp_m1_1", ".clamp_m1_1", ".clamp_0_1", ".clamp_0_1", "", "", "", "", ".reserved", ".reserved", "", ""
2401     };
2402     const char *clamp = clamp_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
2403     static const char *round_table[] = {
2404         "", "", "", "", "", "", "", "", "", "", ".rtz", ".rtz", ".reserved", ".reserved", "", ""
2405     };
2406     const char *round = round_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
2407     static const char *special_table[] = {
2408         "", "", "", "", "", "", "", "", ".n", ".n", ".n", ".n", ".reserved", ".reserved", ".left", ".left"
2409     };
2410     const char *special = special_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
2411     static const char *abs0_table[] = {
2412         "", ".abs"
2413     };
2414 
2415     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
2416 
2417     static const char *neg2_table[] = {
2418         "", ".neg"
2419     };
2420 
2421     const char *neg2 = neg2_table[_BITS(bits, 17, 1)];
2422 
2423     fputs("*FMA_RSCALE.v2f16", fp);
2424     fputs(round, fp);
2425     fputs(clamp, fp);
2426     fputs(special, fp);
2427     fputs(" ", fp);
2428     bi_disasm_dest_fma(fp, next_regs, last);
2429     fputs(", ", fp);
2430     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2431     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2432     fputs(neg0, fp);
2433     fputs(abs0, fp);
2434     fputs(", ", fp);
2435     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2436     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2437     fputs(neg1, fp);
2438     fputs(", ", fp);
2439     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2440     fputs(neg2, fp);
2441     fputs(", ", fp);
2442     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
2443     fputs("\n", fp);
2444 }
2445 
2446 static void
bi_disasm_add_v2s16_to_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2447 bi_disasm_add_v2s16_to_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2448 {
2449     static const char *round_table[] = {
2450         ".rtna"
2451     };
2452     const char *round = round_table[0];
2453     static const char *swz0_table[] = {
2454         ".h00", ".h10", "", ".h11"
2455     };
2456 
2457     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
2458 
2459     fputs("+V2S16_TO_V2F16", fp);
2460     fputs(round, fp);
2461     fputs(" ", fp);
2462     bi_disasm_dest_add(fp, next_regs, last);
2463     fputs(", ", fp);
2464     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2465     fputs(swz0, fp);
2466     fputs("\n", fp);
2467 }
2468 
2469 static void
bi_disasm_add_ld_var_flat_imm_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2470 bi_disasm_add_ld_var_flat_imm_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2471 {
2472     static const char *register_format_table[] = {
2473         ".auto"
2474     };
2475     const char *register_format = register_format_table[0];
2476     static const char *vecsize_table[] = {
2477         "", ".v2", ".v3", ".v4"
2478     };
2479 
2480     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
2481 
2482     static const char *function_table[] = {
2483         ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".and", ".or"
2484     };
2485 
2486     const char *function = function_table[_BITS(bits, 0, 3)];
2487 
2488     fputs("+LD_VAR_FLAT_IMM", fp);
2489     fputs(vecsize, fp);
2490     fputs(register_format, fp);
2491     fputs(function, fp);
2492     fputs(" ", fp);
2493     bi_disasm_dest_add(fp, next_regs, last);
2494     fprintf(fp, ", index:%u", _BITS(bits, 3, 5));
2495     fprintf(fp, ", @r%u", staging_register);
2496     fputs("\n", fp);
2497 }
2498 
2499 static void
bi_disasm_add_var_tex_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2500 bi_disasm_add_var_tex_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2501 {
2502     static const char *update_table[] = {
2503         ".store", ".retrieve", ".reserved", ".reserved"
2504     };
2505     const char *update = update_table[(_BITS(bits, 5, 2) << 0)];
2506     static const char *sample_table[] = {
2507         ".center", "", ".reserved", ".reserved"
2508     };
2509     const char *sample = sample_table[(_BITS(bits, 5, 2) << 0)];
2510     static const char *skip_table[] = {
2511         "", ".skip"
2512     };
2513 
2514     const char *skip = skip_table[_BITS(bits, 7, 1)];
2515 
2516     static const char *lod_mode_table[] = {
2517         ".computed_lod", ""
2518     };
2519 
2520     const char *lod_mode = lod_mode_table[_BITS(bits, 9, 1)];
2521 
2522     fputs("+VAR_TEX.f32", fp);
2523     fputs(update, fp);
2524     fputs(skip, fp);
2525     fputs(lod_mode, fp);
2526     fputs(sample, fp);
2527     fputs(" ", fp);
2528     bi_disasm_dest_add(fp, next_regs, last);
2529     fprintf(fp, ", varying_index:%u", _BITS(bits, 0, 3));
2530     fprintf(fp, ", texture_index:%u", _BITS(bits, 3, 2));
2531     fprintf(fp, ", @r%u", staging_register);
2532     fputs("\n", fp);
2533 }
2534 
2535 static void
bi_disasm_add_lea_attr_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2536 bi_disasm_add_lea_attr_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2537 {
2538     static const char *register_format_table[] = {
2539         ".auto"
2540     };
2541     const char *register_format = register_format_table[0];
2542     fputs("+LEA_ATTR", fp);
2543     fputs(register_format, fp);
2544     fputs(" ", fp);
2545     bi_disasm_dest_add(fp, next_regs, last);
2546     fputs(", ", fp);
2547     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2548     fputs(", ", fp);
2549     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2550     fputs(", ", fp);
2551     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
2552     fprintf(fp, ", @r%u", staging_register);
2553     fputs("\n", fp);
2554 }
2555 
2556 static void
bi_disasm_add_doorbell(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2557 bi_disasm_add_doorbell(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2558 {
2559     fputs("+DOORBELL", fp);
2560     fputs(" ", fp);
2561     bi_disasm_dest_add(fp, next_regs, last);
2562     fputs(", ", fp);
2563     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2564     fputs("\n", fp);
2565 }
2566 
2567 static void
bi_disasm_fma_csel_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2568 bi_disasm_fma_csel_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2569 {
2570     static const char *cmpf_table[] = {
2571         ".gt", ".ge"
2572     };
2573     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
2574     fputs("*CSEL.u32", fp);
2575     fputs(cmpf, fp);
2576     fputs(" ", fp);
2577     bi_disasm_dest_fma(fp, next_regs, last);
2578     fputs(", ", fp);
2579     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2580     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2581     fputs(", ", fp);
2582     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2583     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2584     fputs(", ", fp);
2585     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2586     fputs(", ", fp);
2587     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
2588     fputs("\n", fp);
2589 }
2590 
2591 static void
bi_disasm_fma_iaddc_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2592 bi_disasm_fma_iaddc_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2593 {
2594     fputs("*IADDC.i32", fp);
2595     fputs(" ", fp);
2596     bi_disasm_dest_fma(fp, next_regs, last);
2597     fputs(", ", fp);
2598     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2599     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2600     fputs(", ", fp);
2601     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2602     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2603     fputs(", ", fp);
2604     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2605     fputs("\n", fp);
2606 }
2607 
2608 static void
bi_disasm_add_isub_v2s16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2609 bi_disasm_add_isub_v2s16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2610 {
2611     static const char *lanes1_table[] = {
2612         ".h00", ".h11"
2613     };
2614     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
2615     static const char *lanes0_table[] = {
2616         "", ""
2617     };
2618     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
2619     static const char *saturate_table[] = {
2620         "", ".sat"
2621     };
2622 
2623     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
2624 
2625     fputs("+ISUB.v2s16", fp);
2626     fputs(saturate, fp);
2627     fputs(" ", fp);
2628     bi_disasm_dest_add(fp, next_regs, last);
2629     fputs(", ", fp);
2630     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2631     fputs(lanes0, fp);
2632     fputs(", ", fp);
2633     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2634     fputs(lanes1, fp);
2635     fputs("\n", fp);
2636 }
2637 
2638 static void
bi_disasm_add_fadd_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2639 bi_disasm_add_fadd_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2640 {
2641     static const char *abs1_table[] = {
2642         "", ".abs"
2643     };
2644 
2645     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
2646 
2647     static const char *neg0_table[] = {
2648         "", ".neg"
2649     };
2650 
2651     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
2652 
2653     static const char *neg1_table[] = {
2654         "", ".neg"
2655     };
2656 
2657     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
2658 
2659     static const char *swz0_table[] = {
2660         ".h00", ".h10", "", ".h11"
2661     };
2662 
2663     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
2664 
2665     static const char *swz1_table[] = {
2666         ".h00", ".h10", "", ".h11"
2667     };
2668 
2669     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
2670 
2671     static const char *round_table[] = {
2672         "", ".rtp", ".rtn", ".rtz"
2673     };
2674 
2675     const char *round = round_table[_BITS(bits, 13, 2)];
2676 
2677     static const char *abs0_table[] = {
2678         "", ".abs"
2679     };
2680 
2681     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
2682 
2683     fputs("+FADD.v2f16", fp);
2684     fputs(round, fp);
2685     fputs(" ", fp);
2686     bi_disasm_dest_add(fp, next_regs, last);
2687     fputs(", ", fp);
2688     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2689     fputs(neg0, fp);
2690     fputs(swz0, fp);
2691     fputs(abs0, fp);
2692     fputs(", ", fp);
2693     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2694     fputs(abs1, fp);
2695     fputs(neg1, fp);
2696     fputs(swz1, fp);
2697     fputs("\n", fp);
2698 }
2699 
2700 static void
bi_disasm_add_frexpm_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2701 bi_disasm_add_frexpm_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2702 {
2703     static const char *neg0_table[] = {
2704         ""
2705     };
2706     const char *neg0 = neg0_table[0];
2707     static const char *log_table[] = {
2708         ""
2709     };
2710     const char *log = log_table[0];
2711     static const char *abs0_table[] = {
2712         "", ".abs0"
2713     };
2714 
2715     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
2716 
2717     static const char *sqrt_table[] = {
2718         "", ".sqrt"
2719     };
2720 
2721     const char *sqrt = sqrt_table[_BITS(bits, 7, 1)];
2722 
2723     static const char *swz0_table[] = {
2724         ".h00", ".h10", "", ".h11"
2725     };
2726 
2727     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
2728 
2729     fputs("+FREXPM.v2f16", fp);
2730     fputs(sqrt, fp);
2731     fputs(log, fp);
2732     fputs(" ", fp);
2733     bi_disasm_dest_add(fp, next_regs, last);
2734     fputs(", ", fp);
2735     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2736     fputs(abs0, fp);
2737     fputs(swz0, fp);
2738     fputs(neg0, fp);
2739     fputs("\n", fp);
2740 }
2741 
2742 static void
bi_disasm_fma_frexpm_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2743 bi_disasm_fma_frexpm_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2744 {
2745     static const char *neg0_table[] = {
2746         ""
2747     };
2748     const char *neg0 = neg0_table[0];
2749     static const char *log_table[] = {
2750         ""
2751     };
2752     const char *log = log_table[0];
2753     static const char *abs0_table[] = {
2754         "", ".abs0"
2755     };
2756 
2757     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
2758 
2759     static const char *sqrt_table[] = {
2760         "", ".sqrt"
2761     };
2762 
2763     const char *sqrt = sqrt_table[_BITS(bits, 7, 1)];
2764 
2765     static const char *swz0_table[] = {
2766         ".h00", ".h10", "", ".h11"
2767     };
2768 
2769     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
2770 
2771     fputs("*FREXPM.v2f16", fp);
2772     fputs(sqrt, fp);
2773     fputs(log, fp);
2774     fputs(" ", fp);
2775     bi_disasm_dest_fma(fp, next_regs, last);
2776     fputs(", ", fp);
2777     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2778     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2779     fputs(abs0, fp);
2780     fputs(swz0, fp);
2781     fputs(neg0, fp);
2782     fputs("\n", fp);
2783 }
2784 
2785 static void
bi_disasm_add_isub_s32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2786 bi_disasm_add_isub_s32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2787 {
2788     static const char *lanes1_table[] = {
2789         ".b0", ".b1", ".b2", ".b3"
2790     };
2791     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 2) << 0)];
2792     static const char *saturate_table[] = {
2793         "", ".sat"
2794     };
2795 
2796     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
2797 
2798     fputs("+ISUB.s32", fp);
2799     fputs(saturate, fp);
2800     fputs(" ", fp);
2801     bi_disasm_dest_add(fp, next_regs, last);
2802     fputs(", ", fp);
2803     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2804     fputs(", ", fp);
2805     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2806     fputs(lanes1, fp);
2807     fputs("\n", fp);
2808 }
2809 
2810 static void
bi_disasm_add_v2u16_to_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2811 bi_disasm_add_v2u16_to_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2812 {
2813     static const char *round_table[] = {
2814         ".rtna"
2815     };
2816     const char *round = round_table[0];
2817     static const char *swz0_table[] = {
2818         ".h00", ".h10", "", ".h11"
2819     };
2820 
2821     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
2822 
2823     fputs("+V2U16_TO_V2F16", fp);
2824     fputs(round, fp);
2825     fputs(" ", fp);
2826     bi_disasm_dest_add(fp, next_regs, last);
2827     fputs(", ", fp);
2828     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2829     fputs(swz0, fp);
2830     fputs("\n", fp);
2831 }
2832 
2833 static void
bi_disasm_add_iadd_s32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2834 bi_disasm_add_iadd_s32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2835 {
2836     static const char *lanes1_table[] = {
2837         ".b0", ".b1", ".b2", ".b3"
2838     };
2839     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 2) << 0)];
2840     static const char *saturate_table[] = {
2841         "", ".sat"
2842     };
2843 
2844     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
2845 
2846     fputs("+IADD.s32", fp);
2847     fputs(saturate, fp);
2848     fputs(" ", fp);
2849     bi_disasm_dest_add(fp, next_regs, last);
2850     fputs(", ", fp);
2851     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2852     fputs(", ", fp);
2853     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2854     fputs(lanes1, fp);
2855     fputs("\n", fp);
2856 }
2857 
2858 static void
bi_disasm_add_iadd_v4u8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2859 bi_disasm_add_iadd_v4u8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2860 {
2861     static const char *lanes1_table[] = {
2862         ".reserved", ""
2863     };
2864     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0)];
2865     static const char *lanes0_table[] = {
2866         ".reserved", ""
2867     };
2868     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0)];
2869     static const char *saturate_table[] = {
2870         "", ".sat"
2871     };
2872 
2873     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
2874 
2875     fputs("+IADD.v4u8", fp);
2876     fputs(saturate, fp);
2877     fputs(" ", fp);
2878     bi_disasm_dest_add(fp, next_regs, last);
2879     fputs(", ", fp);
2880     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2881     fputs(lanes0, fp);
2882     fputs(", ", fp);
2883     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2884     fputs(lanes1, fp);
2885     fputs("\n", fp);
2886 }
2887 
2888 static void
bi_disasm_add_eureka(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2889 bi_disasm_add_eureka(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2890 {
2891     fputs("+EUREKA", fp);
2892     fputs(" ", fp);
2893     bi_disasm_dest_add(fp, next_regs, last);
2894     fputs(", ", fp);
2895     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2896     fputs("\n", fp);
2897 }
2898 
2899 static void
bi_disasm_add_lea_attr_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2900 bi_disasm_add_lea_attr_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2901 {
2902     static const char *register_format_table[] = {
2903         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
2904     };
2905     const char *register_format = register_format_table[(_BITS(bits, 11, 3) << 0)];
2906     fputs("+LEA_ATTR", fp);
2907     fputs(register_format, fp);
2908     fputs(" ", fp);
2909     bi_disasm_dest_add(fp, next_regs, last);
2910     fputs(", ", fp);
2911     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2912     fputs(", ", fp);
2913     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2914     fputs(", ", fp);
2915     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
2916     fprintf(fp, ", @r%u", staging_register);
2917     fputs("\n", fp);
2918 }
2919 
2920 static void
bi_disasm_add_ld_var_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2921 bi_disasm_add_ld_var_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2922 {
2923     static const char *register_format_table[] = {
2924         ".auto", ".auto", ".auto", ".auto", ".auto", ".reserved", ".reserved", ".reserved", ".auto", ".auto", ".auto", ".auto", ".auto", ".auto", ".reserved", ".reserved"
2925     };
2926     const char *register_format = register_format_table[(_BITS(bits, 10, 4) << 0)];
2927     static const char *sample_table[] = {
2928         ".center", ".centroid", ".sample", ".explicit", "", ".reserved", ".reserved", ".reserved", ".center", ".centroid", ".center", ".centroid", ".sample", ".explicit", ".reserved", ".reserved"
2929     };
2930     const char *sample = sample_table[(_BITS(bits, 10, 4) << 0)];
2931     static const char *update_table[] = {
2932         ".store", ".store", ".store", ".store", ".retrieve", ".reserved", ".reserved", ".reserved", ".conditional", ".conditional", ".clobber", ".clobber", ".clobber", ".clobber", ".reserved", ".reserved"
2933     };
2934     const char *update = update_table[(_BITS(bits, 10, 4) << 0)];
2935     static const char *vecsize_table[] = {
2936         "", ".v2", ".v3", ".v4"
2937     };
2938 
2939     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
2940 
2941     fputs("+LD_VAR", fp);
2942     fputs(vecsize, fp);
2943     fputs(update, fp);
2944     fputs(register_format, fp);
2945     fputs(sample, fp);
2946     fputs(" ", fp);
2947     bi_disasm_dest_add(fp, next_regs, last);
2948     fputs(", ", fp);
2949     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2950     fputs(", ", fp);
2951     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
2952     fprintf(fp, ", @r%u", staging_register);
2953     fputs("\n", fp);
2954 }
2955 
2956 static void
bi_disasm_add_swz_v4i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2957 bi_disasm_add_swz_v4i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2958 {
2959     static const char *swz0_table[] = {
2960         ".b0000", ".b1111", ".b2222", ".b3333", ".b0011", ".b2233", ".b1032", ".b3210"
2961     };
2962 
2963     const char *swz0 = swz0_table[_BITS(bits, 3, 3)];
2964 
2965     fputs("+SWZ.v4i8", fp);
2966     fputs(" ", fp);
2967     bi_disasm_dest_add(fp, next_regs, last);
2968     fputs(", ", fp);
2969     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
2970     fputs(swz0, fp);
2971     fputs("\n", fp);
2972 }
2973 
2974 static void
bi_disasm_fma_arshift_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2975 bi_disasm_fma_arshift_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2976 {
2977     static const char *lanes2_table[] = {
2978         ".b00", ".b11", ".b22", ".b33"
2979     };
2980     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
2981     fputs("*ARSHIFT.v2i16", fp);
2982     fputs(" ", fp);
2983     bi_disasm_dest_fma(fp, next_regs, last);
2984     fputs(", ", fp);
2985     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
2986     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
2987     fputs(", ", fp);
2988     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
2989     if (!(0x8 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
2990     fputs(", ", fp);
2991     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
2992     fputs(lanes2, fp);
2993     fputs("\n", fp);
2994 }
2995 
2996 static void
bi_disasm_add_isub_v4u8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)2997 bi_disasm_add_isub_v4u8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
2998 {
2999     static const char *lanes1_table[] = {
3000         ".reserved", ""
3001     };
3002     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0)];
3003     static const char *lanes0_table[] = {
3004         ".reserved", ""
3005     };
3006     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0)];
3007     static const char *saturate_table[] = {
3008         "", ".sat"
3009     };
3010 
3011     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
3012 
3013     fputs("+ISUB.v4u8", fp);
3014     fputs(saturate, fp);
3015     fputs(" ", fp);
3016     bi_disasm_dest_add(fp, next_regs, last);
3017     fputs(", ", fp);
3018     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3019     fputs(lanes0, fp);
3020     fputs(", ", fp);
3021     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3022     fputs(lanes1, fp);
3023     fputs("\n", fp);
3024 }
3025 
3026 static void
bi_disasm_add_s32_to_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3027 bi_disasm_add_s32_to_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3028 {
3029     static const char *round_table[] = {
3030         "", ".rtp", ".rtn", ".rtz"
3031     };
3032     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
3033     fputs("+S32_TO_F32", fp);
3034     fputs(round, fp);
3035     fputs(" ", fp);
3036     bi_disasm_dest_add(fp, next_regs, last);
3037     fputs(", ", fp);
3038     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3039     fputs("\n", fp);
3040 }
3041 
3042 static void
bi_disasm_add_hadd_v4s8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3043 bi_disasm_add_hadd_v4s8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3044 {
3045     static const char *round_table[] = {
3046         ".rtn", ".rtp"
3047     };
3048 
3049     const char *round = round_table[_BITS(bits, 12, 1)];
3050 
3051     fputs("+HADD.v4s8", fp);
3052     fputs(round, fp);
3053     fputs(" ", fp);
3054     bi_disasm_dest_add(fp, next_regs, last);
3055     fputs(", ", fp);
3056     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3057     fputs(", ", fp);
3058     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3059     fputs("\n", fp);
3060 }
3061 
3062 static void
bi_disasm_fma_atom_c1_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3063 bi_disasm_fma_atom_c1_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3064 {
3065     static const char *atom_opc_table[] = {
3066         ".ainc", ".adec", ".aumax1", ".asmax1", ".aor1", ".reserved", ".reserved", ".reserved"
3067     };
3068 
3069     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 3)];
3070 
3071     fputs("*ATOM_C1.i64", fp);
3072     fputs(atom_opc, fp);
3073     fputs(" ", fp);
3074     bi_disasm_dest_fma(fp, next_regs, last);
3075     fputs(", ", fp);
3076     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3077     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3078     fputs(", ", fp);
3079     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3080     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3081     fputs("\n", fp);
3082 }
3083 
3084 static void
bi_disasm_add_s32_to_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3085 bi_disasm_add_s32_to_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3086 {
3087     static const char *round_table[] = {
3088         ".rtna"
3089     };
3090     const char *round = round_table[0];
3091     fputs("+S32_TO_F32", fp);
3092     fputs(round, fp);
3093     fputs(" ", fp);
3094     bi_disasm_dest_add(fp, next_regs, last);
3095     fputs(", ", fp);
3096     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3097     fputs("\n", fp);
3098 }
3099 
3100 static void
bi_disasm_fma_rshift_xor_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3101 bi_disasm_fma_rshift_xor_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3102 {
3103     static const char *lanes2_table[] = {
3104         ""
3105     };
3106     const char *lanes2 = lanes2_table[0];
3107     static const char *not_result_table[] = {
3108         "", ".not"
3109     };
3110 
3111     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
3112 
3113     fputs("*RSHIFT_XOR.v4i8", fp);
3114     fputs(not_result, fp);
3115     fputs(" ", fp);
3116     bi_disasm_dest_fma(fp, next_regs, last);
3117     fputs(", ", fp);
3118     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3119     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3120     fputs(", ", fp);
3121     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3122     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3123     fputs(", ", fp);
3124     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3125     fputs(lanes2, fp);
3126     fputs("\n", fp);
3127 }
3128 
3129 static void
bi_disasm_fma_u8_to_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3130 bi_disasm_fma_u8_to_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3131 {
3132     static const char *lane0_table[] = {
3133         "", ".b1", ".b2", ".b3"
3134     };
3135 
3136     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
3137 
3138     fputs("*U8_TO_U32", fp);
3139     fputs(" ", fp);
3140     bi_disasm_dest_fma(fp, next_regs, last);
3141     fputs(", ", fp);
3142     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3143     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3144     fputs(lane0, fp);
3145     fputs("\n", fp);
3146 }
3147 
3148 static void
bi_disasm_add_iadd_v2s16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3149 bi_disasm_add_iadd_v2s16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3150 {
3151     static const char *lanes1_table[] = {
3152         ".h00", ".h11"
3153     };
3154     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
3155     static const char *lanes0_table[] = {
3156         "", ""
3157     };
3158     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
3159     static const char *saturate_table[] = {
3160         "", ".sat"
3161     };
3162 
3163     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
3164 
3165     fputs("+IADD.v2s16", fp);
3166     fputs(saturate, fp);
3167     fputs(" ", fp);
3168     bi_disasm_dest_add(fp, next_regs, last);
3169     fputs(", ", fp);
3170     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3171     fputs(lanes0, fp);
3172     fputs(", ", fp);
3173     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3174     fputs(lanes1, fp);
3175     fputs("\n", fp);
3176 }
3177 
3178 static void
bi_disasm_add_store_i24(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3179 bi_disasm_add_store_i24(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3180 {
3181     static const char *seg_table[] = {
3182         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
3183     };
3184 
3185     const char *seg = seg_table[_BITS(bits, 6, 3)];
3186 
3187     fputs("+STORE.i24", fp);
3188     fputs(seg, fp);
3189     fputs(" ", fp);
3190     bi_disasm_dest_add(fp, next_regs, last);
3191     fputs(", ", fp);
3192     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3193     fputs(", ", fp);
3194     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3195     fprintf(fp, ", @r%u", staging_register);
3196     fputs("\n", fp);
3197 }
3198 
3199 static void
bi_disasm_add_fcos_table_u6(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3200 bi_disasm_add_fcos_table_u6(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3201 {
3202     static const char *offset_table[] = {
3203         "", ".offset"
3204     };
3205 
3206     const char *offset = offset_table[_BITS(bits, 4, 1)];
3207 
3208     fputs("+FCOS_TABLE.u6", fp);
3209     fputs(offset, fp);
3210     fputs(" ", fp);
3211     bi_disasm_dest_add(fp, next_regs, last);
3212     fputs(", ", fp);
3213     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3214     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3215     fputs("\n", fp);
3216 }
3217 
3218 static void
bi_disasm_fma_lshift_xor_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3219 bi_disasm_fma_lshift_xor_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3220 {
3221     static const char *lane2_table[] = {
3222         "", ".b1", ".b2", ".b3"
3223     };
3224 
3225     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
3226 
3227     static const char *not_result_table[] = {
3228         "", ".not"
3229     };
3230 
3231     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
3232 
3233     fputs("*LSHIFT_XOR.i32", fp);
3234     fputs(not_result, fp);
3235     fputs(" ", fp);
3236     bi_disasm_dest_fma(fp, next_regs, last);
3237     fputs(", ", fp);
3238     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3239     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3240     fputs(", ", fp);
3241     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3242     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3243     fputs(", ", fp);
3244     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3245     fputs(lane2, fp);
3246     fputs("\n", fp);
3247 }
3248 
3249 static void
bi_disasm_fma_seg_add(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3250 bi_disasm_fma_seg_add(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3251 {
3252     static const char *seg_table[] = {
3253         ".reserved", ".reserved", ".wgl", ".reserved", ".reserved", ".reserved", ".reserved", ".tl"
3254     };
3255 
3256     const char *seg = seg_table[_BITS(bits, 3, 3)];
3257 
3258     static const char *preserve_null_table[] = {
3259         "", ".preserve_null"
3260     };
3261 
3262     const char *preserve_null = preserve_null_table[_BITS(bits, 7, 1)];
3263 
3264     fputs("*SEG_ADD", fp);
3265     fputs(seg, fp);
3266     fputs(preserve_null, fp);
3267     fputs(" ", fp);
3268     bi_disasm_dest_fma(fp, next_regs, last);
3269     fputs(", ", fp);
3270     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3271     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3272     fputs("\n", fp);
3273 }
3274 
3275 static void
bi_disasm_fma_csel_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3276 bi_disasm_fma_csel_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3277 {
3278     static const char *cmpf_table[] = {
3279         ".reserved", ".reserved", ".reserved", ".eq", ".reserved", ".reserved", ".reserved", ".reserved"
3280     };
3281     const char *cmpf = cmpf_table[(_BITS(bits, 12, 3) << 0)];
3282     fputs("*CSEL.v2i16", fp);
3283     fputs(cmpf, fp);
3284     fputs(" ", fp);
3285     bi_disasm_dest_fma(fp, next_regs, last);
3286     fputs(", ", fp);
3287     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3288     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3289     fputs(", ", fp);
3290     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3291     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3292     fputs(", ", fp);
3293     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3294     fputs(", ", fp);
3295     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
3296     fputs("\n", fp);
3297 }
3298 
3299 static void
bi_disasm_add_fatan_table_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3300 bi_disasm_add_fatan_table_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3301 {
3302     fputs("+FATAN_TABLE.f32", fp);
3303     fputs(" ", fp);
3304     bi_disasm_dest_add(fp, next_regs, last);
3305     fputs(", ", fp);
3306     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3307     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3308     fputs(", ", fp);
3309     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3310     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3311     fputs("\n", fp);
3312 }
3313 
3314 static void
bi_disasm_add_logb_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3315 bi_disasm_add_logb_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3316 {
3317     static const char *widen0_table[] = {
3318         ".reserved", "", ".h0", ".h1"
3319     };
3320 
3321     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
3322 
3323     fputs("+LOGB.f32", fp);
3324     fputs(" ", fp);
3325     bi_disasm_dest_add(fp, next_regs, last);
3326     fputs(", ", fp);
3327     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3328     fputs(widen0, fp);
3329     fputs("\n", fp);
3330 }
3331 
3332 static void
bi_disasm_fma_lshift_or_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3333 bi_disasm_fma_lshift_or_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3334 {
3335     static const char *lanes2_table[] = {
3336         ".b0000", ".b1111", ".b2222", ".b3333"
3337     };
3338     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
3339     static const char *not1_table[] = {
3340         ".not", ""
3341     };
3342 
3343     const char *not1 = not1_table[_BITS(bits, 14, 1)];
3344 
3345     static const char *not_result_table[] = {
3346         "", ".not"
3347     };
3348 
3349     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
3350 
3351     fputs("*LSHIFT_OR.v4i8", fp);
3352     fputs(not_result, fp);
3353     fputs(" ", fp);
3354     bi_disasm_dest_fma(fp, next_regs, last);
3355     fputs(", ", fp);
3356     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3357     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3358     fputs(", ", fp);
3359     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3360     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3361     fputs(not1, fp);
3362     fputs(", ", fp);
3363     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3364     fputs(lanes2, fp);
3365     fputs("\n", fp);
3366 }
3367 
3368 static void
bi_disasm_fma_atom_c1_return_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3369 bi_disasm_fma_atom_c1_return_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3370 {
3371     static const char *atom_opc_table[] = {
3372         ".ainc", ".adec", ".aumax1", ".asmax1", ".aor1", ".reserved", ".reserved", ".reserved"
3373     };
3374 
3375     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 3)];
3376 
3377     fputs("*ATOM_C1_RETURN.i32", fp);
3378     fputs(atom_opc, fp);
3379     fputs(" ", fp);
3380     bi_disasm_dest_fma(fp, next_regs, last);
3381     fputs(", ", fp);
3382     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3383     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3384     fputs(", ", fp);
3385     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3386     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3387     fputs("\n", fp);
3388 }
3389 
3390 static void
bi_disasm_add_store_i48(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3391 bi_disasm_add_store_i48(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3392 {
3393     static const char *seg_table[] = {
3394         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
3395     };
3396 
3397     const char *seg = seg_table[_BITS(bits, 6, 3)];
3398 
3399     fputs("+STORE.i48", fp);
3400     fputs(seg, fp);
3401     fputs(" ", fp);
3402     bi_disasm_dest_add(fp, next_regs, last);
3403     fputs(", ", fp);
3404     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3405     fputs(", ", fp);
3406     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3407     fprintf(fp, ", @r%u", staging_register);
3408     fputs("\n", fp);
3409 }
3410 
3411 static void
bi_disasm_add_branchz_i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3412 bi_disasm_add_branchz_i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3413 {
3414     static const char *cmpf_table[] = {
3415         ".reserved", ".ne", ".ne", ".reserved", ".reserved", ".eq", ".eq", ".reserved"
3416     };
3417     const char *cmpf = cmpf_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 3, 1) << 2)];
3418     static const char *widen0_table[] = {
3419         ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved"
3420     };
3421     const char *widen0 = widen0_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 3, 1) << 2)];
3422     fputs("+BRANCHZ.i16", fp);
3423     fputs(cmpf, fp);
3424     fputs(" ", fp);
3425     bi_disasm_dest_add(fp, next_regs, last);
3426     fputs(", ", fp);
3427     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3428     fputs(widen0, fp);
3429     fputs(", ", fp);
3430     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
3431     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
3432     fputs("\n", fp);
3433 }
3434 
3435 static void
bi_disasm_add_icmp_v2u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3436 bi_disasm_add_icmp_v2u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3437 {
3438     static const char *cmpf_table[] = {
3439         ".gt", ".ge"
3440     };
3441     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
3442     static const char *swz0_table[] = {
3443         ".h00", ".h10", "", ".h11"
3444     };
3445 
3446     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
3447 
3448     static const char *swz1_table[] = {
3449         ".h00", ".h10", "", ".h11"
3450     };
3451 
3452     const char *swz1 = swz1_table[_BITS(bits, 8, 2)];
3453 
3454     static const char *result_type_table[] = {
3455         "", ".m1"
3456     };
3457 
3458     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
3459 
3460     fputs("+ICMP.v2u16", fp);
3461     fputs(result_type, fp);
3462     fputs(cmpf, fp);
3463     fputs(" ", fp);
3464     bi_disasm_dest_add(fp, next_regs, last);
3465     fputs(", ", fp);
3466     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3467     fputs(swz0, fp);
3468     fputs(", ", fp);
3469     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3470     fputs(swz1, fp);
3471     fputs("\n", fp);
3472 }
3473 
3474 static void
bi_disasm_add_fexp_table_u4(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3475 bi_disasm_add_fexp_table_u4(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3476 {
3477     static const char *adj_table[] = {
3478         "", ".small", ".low", ".reserved"
3479     };
3480 
3481     const char *adj = adj_table[_BITS(bits, 3, 2)];
3482 
3483     fputs("+FEXP_TABLE.u4", fp);
3484     fputs(adj, fp);
3485     fputs(" ", fp);
3486     bi_disasm_dest_add(fp, next_regs, last);
3487     fputs(", ", fp);
3488     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3489     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3490     fputs("\n", fp);
3491 }
3492 
3493 static void
bi_disasm_add_load_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3494 bi_disasm_add_load_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3495 {
3496     static const char *seg_table[] = {
3497         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
3498     };
3499 
3500     const char *seg = seg_table[_BITS(bits, 6, 3)];
3501 
3502     fputs("+LOAD.i64", fp);
3503     fputs(seg, fp);
3504     fputs(" ", fp);
3505     bi_disasm_dest_add(fp, next_regs, last);
3506     fputs(", ", fp);
3507     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3508     fputs(", ", fp);
3509     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3510     fprintf(fp, ", @r%u", staging_register);
3511     fputs("\n", fp);
3512 }
3513 
3514 static void
bi_disasm_add_ilogb_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3515 bi_disasm_add_ilogb_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3516 {
3517     static const char *widen0_table[] = {
3518         ".reserved", "", ".h0", ".h1"
3519     };
3520 
3521     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
3522 
3523     fputs("+ILOGB.f32", fp);
3524     fputs(" ", fp);
3525     bi_disasm_dest_add(fp, next_regs, last);
3526     fputs(", ", fp);
3527     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3528     fputs(widen0, fp);
3529     fputs("\n", fp);
3530 }
3531 
3532 static void
bi_disasm_fma_imul_i32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3533 bi_disasm_fma_imul_i32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3534 {
3535     static const char *widen1_table[] = {
3536         ".h0", ".h1", ".h0", ".h1"
3537     };
3538     const char *widen1 = widen1_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
3539     static const char *extend1_table[] = {
3540         ".zext", ".zext", ".sext", ".sext"
3541     };
3542     const char *extend1 = extend1_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
3543     fputs("*IMUL.i32", fp);
3544     fputs(" ", fp);
3545     bi_disasm_dest_fma(fp, next_regs, last);
3546     fputs(", ", fp);
3547     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3548     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3549     fputs(", ", fp);
3550     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3551     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3552     fputs(widen1, fp);
3553     fputs(extend1, fp);
3554     fputs("\n", fp);
3555 }
3556 
3557 static void
bi_disasm_add_iadd_v4s8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3558 bi_disasm_add_iadd_v4s8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3559 {
3560     static const char *lanes1_table[] = {
3561         ".b0000", ".b1111", ".b2222", ".b3333"
3562     };
3563     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 2) << 0)];
3564     static const char *lanes0_table[] = {
3565         "", "", "", ""
3566     };
3567     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 2) << 0)];
3568     static const char *saturate_table[] = {
3569         "", ".sat"
3570     };
3571 
3572     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
3573 
3574     fputs("+IADD.v4s8", fp);
3575     fputs(saturate, fp);
3576     fputs(" ", fp);
3577     bi_disasm_dest_add(fp, next_regs, last);
3578     fputs(", ", fp);
3579     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3580     fputs(lanes0, fp);
3581     fputs(", ", fp);
3582     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3583     fputs(lanes1, fp);
3584     fputs("\n", fp);
3585 }
3586 
3587 static void
bi_disasm_fma_lshift_and_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3588 bi_disasm_fma_lshift_and_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3589 {
3590     static const char *lanes2_table[] = {
3591         ".b0000", ".b1111", ".b2222", ".b3333"
3592     };
3593     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
3594     static const char *not1_table[] = {
3595         "", ".not"
3596     };
3597 
3598     const char *not1 = not1_table[_BITS(bits, 14, 1)];
3599 
3600     static const char *not_result_table[] = {
3601         ".not", ""
3602     };
3603 
3604     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
3605 
3606     fputs("*LSHIFT_AND.v4i8", fp);
3607     fputs(not_result, fp);
3608     fputs(" ", fp);
3609     bi_disasm_dest_fma(fp, next_regs, last);
3610     fputs(", ", fp);
3611     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3612     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3613     fputs(", ", fp);
3614     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3615     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3616     fputs(not1, fp);
3617     fputs(", ", fp);
3618     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3619     fputs(lanes2, fp);
3620     fputs("\n", fp);
3621 }
3622 
3623 static void
bi_disasm_add_store_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3624 bi_disasm_add_store_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3625 {
3626     static const char *seg_table[] = {
3627         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
3628     };
3629 
3630     const char *seg = seg_table[_BITS(bits, 6, 3)];
3631 
3632     fputs("+STORE.i32", fp);
3633     fputs(seg, fp);
3634     fputs(" ", fp);
3635     bi_disasm_dest_add(fp, next_regs, last);
3636     fputs(", ", fp);
3637     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3638     fputs(", ", fp);
3639     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3640     fprintf(fp, ", @r%u", staging_register);
3641     fputs("\n", fp);
3642 }
3643 
3644 static void
bi_disasm_fma_rshift_and_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3645 bi_disasm_fma_rshift_and_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3646 {
3647     static const char *lanes2_table[] = {
3648         ".b00", ".b11", ".b22", ".b33"
3649     };
3650     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
3651     static const char *not1_table[] = {
3652         "", ".not"
3653     };
3654 
3655     const char *not1 = not1_table[_BITS(bits, 14, 1)];
3656 
3657     static const char *not_result_table[] = {
3658         ".not", ""
3659     };
3660 
3661     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
3662 
3663     fputs("*RSHIFT_AND.v2i16", fp);
3664     fputs(not_result, fp);
3665     fputs(" ", fp);
3666     bi_disasm_dest_fma(fp, next_regs, last);
3667     fputs(", ", fp);
3668     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3669     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3670     fputs(", ", fp);
3671     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3672     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3673     fputs(not1, fp);
3674     fputs(", ", fp);
3675     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3676     fputs(lanes2, fp);
3677     fputs("\n", fp);
3678 }
3679 
3680 static void
bi_disasm_add_frsq_approx_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3681 bi_disasm_add_frsq_approx_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3682 {
3683     static const char *widen0_table[] = {
3684         ".h0", ".h1"
3685     };
3686     const char *widen0 = widen0_table[(_BITS(bits, 7, 1) << 0)];
3687     static const char *neg_table[] = {
3688         "", ".neg"
3689     };
3690 
3691     const char *neg = neg_table[_BITS(bits, 3, 1)];
3692 
3693     static const char *abs0_table[] = {
3694         "", ".abs0"
3695     };
3696 
3697     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
3698 
3699     static const char *divzero_table[] = {
3700         "", ".divzero"
3701     };
3702 
3703     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
3704 
3705     fputs("+FRSQ_APPROX.f32", fp);
3706     fputs(neg, fp);
3707     fputs(divzero, fp);
3708     fputs(" ", fp);
3709     bi_disasm_dest_add(fp, next_regs, last);
3710     fputs(", ", fp);
3711     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3712     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3713     fputs(widen0, fp);
3714     fputs(abs0, fp);
3715     fputs("\n", fp);
3716 }
3717 
3718 static void
bi_disasm_add_isub_v2u16_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3719 bi_disasm_add_isub_v2u16_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3720 {
3721     static const char *lanes1_table[] = {
3722         ".reserved", ".b01", ".reserved", ".b23"
3723     };
3724     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
3725     static const char *lanes0_table[] = {
3726         ".reserved", "", ".reserved", ""
3727     };
3728     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
3729     static const char *saturate_table[] = {
3730         "", ".sat"
3731     };
3732 
3733     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
3734 
3735     fputs("+ISUB.v2u16", fp);
3736     fputs(saturate, fp);
3737     fputs(" ", fp);
3738     bi_disasm_dest_add(fp, next_regs, last);
3739     fputs(", ", fp);
3740     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3741     fputs(lanes0, fp);
3742     fputs(", ", fp);
3743     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3744     fputs(lanes1, fp);
3745     fputs("\n", fp);
3746 }
3747 
3748 static void
bi_disasm_add_icmp_v4u8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3749 bi_disasm_add_icmp_v4u8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3750 {
3751     static const char *cmpf_table[] = {
3752         ".gt", ".ge"
3753     };
3754     const char *cmpf = cmpf_table[(_BITS(bits, 6, 1) << 0)];
3755     static const char *result_type_table[] = {
3756         "", ".m1"
3757     };
3758 
3759     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
3760 
3761     fputs("+ICMP.v4u8", fp);
3762     fputs(result_type, fp);
3763     fputs(cmpf, fp);
3764     fputs(" ", fp);
3765     bi_disasm_dest_add(fp, next_regs, last);
3766     fputs(", ", fp);
3767     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3768     fputs(", ", fp);
3769     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3770     fputs("\n", fp);
3771 }
3772 
3773 static void
bi_disasm_add_ld_cvt(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3774 bi_disasm_add_ld_cvt(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3775 {
3776     static const char *vecsize_table[] = {
3777         "", ".v2", ".v3", ".v4"
3778     };
3779 
3780     const char *vecsize = vecsize_table[_BITS(bits, 9, 2)];
3781 
3782     fputs("+LD_CVT", fp);
3783     fputs(vecsize, fp);
3784     fputs(" ", fp);
3785     bi_disasm_dest_add(fp, next_regs, last);
3786     fputs(", ", fp);
3787     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3788     fputs(", ", fp);
3789     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3790     fputs(", ", fp);
3791     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
3792     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
3793     fprintf(fp, ", @r%u", staging_register);
3794     fputs("\n", fp);
3795 }
3796 
3797 static void
bi_disasm_add_hadd_v2s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3798 bi_disasm_add_hadd_v2s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3799 {
3800     static const char *round_table[] = {
3801         ".rtn", ".rtp"
3802     };
3803 
3804     const char *round = round_table[_BITS(bits, 12, 1)];
3805 
3806     static const char *swap1_table[] = {
3807         "", ".h10"
3808     };
3809 
3810     const char *swap1 = swap1_table[_BITS(bits, 9, 1)];
3811 
3812     static const char *swap0_table[] = {
3813         "", ".h10"
3814     };
3815 
3816     const char *swap0 = swap0_table[_BITS(bits, 10, 1)];
3817 
3818     fputs("+HADD.v2s16", fp);
3819     fputs(round, fp);
3820     fputs(" ", fp);
3821     bi_disasm_dest_add(fp, next_regs, last);
3822     fputs(", ", fp);
3823     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3824     fputs(swap0, fp);
3825     fputs(", ", fp);
3826     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3827     fputs(swap1, fp);
3828     fputs("\n", fp);
3829 }
3830 
3831 static void
bi_disasm_fma_frshift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3832 bi_disasm_fma_frshift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3833 {
3834     static const char *bytes2_table[] = {
3835         "", ".bytes2"
3836     };
3837 
3838     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
3839 
3840     static const char *lane2_table[] = {
3841         "", ".b2"
3842     };
3843 
3844     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
3845 
3846     fputs("*FRSHIFT_DOUBLE.i32", fp);
3847     fputs(" ", fp);
3848     bi_disasm_dest_fma(fp, next_regs, last);
3849     fputs(", ", fp);
3850     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3851     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3852     fputs(", ", fp);
3853     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3854     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3855     fputs(", ", fp);
3856     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3857     fputs(bytes2, fp);
3858     fputs(lane2, fp);
3859     fputs("\n", fp);
3860 }
3861 
3862 static void
bi_disasm_add_branchz_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3863 bi_disasm_add_branchz_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3864 {
3865     static const char *cmpf_table[] = {
3866         ".ne", ".eq"
3867     };
3868     const char *cmpf = cmpf_table[(_BITS(bits, 3, 1) << 0)];
3869     fputs("+BRANCHZ.i32", fp);
3870     fputs(cmpf, fp);
3871     fputs(" ", fp);
3872     bi_disasm_dest_add(fp, next_regs, last);
3873     fputs(", ", fp);
3874     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3875     fputs(", ", fp);
3876     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
3877     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
3878     fputs("\n", fp);
3879 }
3880 
3881 static void
bi_disasm_add_iadd_u32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3882 bi_disasm_add_iadd_u32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3883 {
3884     static const char *lanes1_table[] = {
3885         ".reserved", ".b0", ".reserved", ".b1", ".reserved", ".b2", ".reserved", ".b3"
3886     };
3887     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
3888     static const char *saturate_table[] = {
3889         "", ".sat"
3890     };
3891 
3892     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
3893 
3894     fputs("+IADD.u32", fp);
3895     fputs(saturate, fp);
3896     fputs(" ", fp);
3897     bi_disasm_dest_add(fp, next_regs, last);
3898     fputs(", ", fp);
3899     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3900     fputs(", ", fp);
3901     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3902     fputs(lanes1, fp);
3903     fputs("\n", fp);
3904 }
3905 
3906 static void
bi_disasm_add_st_cvt(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3907 bi_disasm_add_st_cvt(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3908 {
3909     static const char *vecsize_table[] = {
3910         "", ".v2", ".v3", ".v4"
3911     };
3912 
3913     const char *vecsize = vecsize_table[_BITS(bits, 9, 2)];
3914 
3915     fputs("+ST_CVT", fp);
3916     fputs(vecsize, fp);
3917     fputs(" ", fp);
3918     bi_disasm_dest_add(fp, next_regs, last);
3919     fputs(", ", fp);
3920     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3921     fputs(", ", fp);
3922     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
3923     fputs(", ", fp);
3924     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
3925     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
3926     fprintf(fp, ", @r%u", staging_register);
3927     fputs("\n", fp);
3928 }
3929 
3930 static void
bi_disasm_add_frexpe_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3931 bi_disasm_add_frexpe_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3932 {
3933     static const char *log_table[] = {
3934         ""
3935     };
3936     const char *log = log_table[0];
3937     static const char *neg_table[] = {
3938         "", ".neg"
3939     };
3940 
3941     const char *neg = neg_table[_BITS(bits, 6, 1)];
3942 
3943     static const char *sqrt_table[] = {
3944         "", ".sqrt"
3945     };
3946 
3947     const char *sqrt = sqrt_table[_BITS(bits, 8, 1)];
3948 
3949     static const char *widen0_table[] = {
3950         ".reserved", "", ".h0", ".h1"
3951     };
3952 
3953     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
3954 
3955     fputs("+FREXPE.f32", fp);
3956     fputs(neg, fp);
3957     fputs(sqrt, fp);
3958     fputs(log, fp);
3959     fputs(" ", fp);
3960     bi_disasm_dest_add(fp, next_regs, last);
3961     fputs(", ", fp);
3962     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
3963     fputs(widen0, fp);
3964     fputs("\n", fp);
3965 }
3966 
3967 static void
bi_disasm_fma_arshift_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3968 bi_disasm_fma_arshift_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3969 {
3970     static const char *lanes2_table[] = {
3971         ".b0000", ".b1111", ".b2222", ".b3333"
3972     };
3973     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
3974     fputs("*ARSHIFT.v4i8", fp);
3975     fputs(" ", fp);
3976     bi_disasm_dest_fma(fp, next_regs, last);
3977     fputs(", ", fp);
3978     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
3979     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
3980     fputs(", ", fp);
3981     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
3982     if (!(0x8 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
3983     fputs(", ", fp);
3984     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
3985     fputs(lanes2, fp);
3986     fputs("\n", fp);
3987 }
3988 
3989 static void
bi_disasm_add_branchz_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)3990 bi_disasm_add_branchz_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
3991 {
3992     static const char *cmpf_table[] = {
3993         ".lt", ".le", ".ge", ".gt", ".reserved", ".reserved", ".reserved", ".reserved"
3994     };
3995     const char *cmpf = cmpf_table[(_BITS(bits, 9, 3) << 0)];
3996     fputs("+BRANCHZ.u32", fp);
3997     fputs(cmpf, fp);
3998     fputs(" ", fp);
3999     bi_disasm_dest_add(fp, next_regs, last);
4000     fputs(", ", fp);
4001     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4002     fputs(", ", fp);
4003     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
4004     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
4005     fputs("\n", fp);
4006 }
4007 
4008 static void
bi_disasm_add_iadd_s32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4009 bi_disasm_add_iadd_s32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4010 {
4011     static const char *lanes1_table[] = {
4012         ".h0", ".h1"
4013     };
4014     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
4015     static const char *saturate_table[] = {
4016         "", ".sat"
4017     };
4018 
4019     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4020 
4021     fputs("+IADD.s32", fp);
4022     fputs(saturate, fp);
4023     fputs(" ", fp);
4024     bi_disasm_dest_add(fp, next_regs, last);
4025     fputs(", ", fp);
4026     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4027     fputs(", ", fp);
4028     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4029     fputs(lanes1, fp);
4030     fputs("\n", fp);
4031 }
4032 
4033 static void
bi_disasm_add_f32_to_s32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4034 bi_disasm_add_f32_to_s32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4035 {
4036     static const char *round_table[] = {
4037         ".rtna"
4038     };
4039     const char *round = round_table[0];
4040     fputs("+F32_TO_S32", fp);
4041     fputs(round, fp);
4042     fputs(" ", fp);
4043     bi_disasm_dest_add(fp, next_regs, last);
4044     fputs(", ", fp);
4045     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4046     fputs("\n", fp);
4047 }
4048 
4049 static void
bi_disasm_add_fpow_sc_apply(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4050 bi_disasm_add_fpow_sc_apply(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4051 {
4052     fputs("+FPOW_SC_APPLY", fp);
4053     fputs(" ", fp);
4054     bi_disasm_dest_add(fp, next_regs, last);
4055     fputs(", ", fp);
4056     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4057     fputs(", ", fp);
4058     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4059     fputs("\n", fp);
4060 }
4061 
4062 static void
bi_disasm_fma_seg_sub(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4063 bi_disasm_fma_seg_sub(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4064 {
4065     static const char *seg_table[] = {
4066         ".reserved", ".reserved", ".wgl", ".reserved", ".reserved", ".reserved", ".reserved", ".tl"
4067     };
4068 
4069     const char *seg = seg_table[_BITS(bits, 3, 3)];
4070 
4071     static const char *preserve_null_table[] = {
4072         "", ".preserve_null"
4073     };
4074 
4075     const char *preserve_null = preserve_null_table[_BITS(bits, 7, 1)];
4076 
4077     fputs("*SEG_SUB", fp);
4078     fputs(seg, fp);
4079     fputs(preserve_null, fp);
4080     fputs(" ", fp);
4081     bi_disasm_dest_fma(fp, next_regs, last);
4082     fputs(", ", fp);
4083     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4084     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4085     fputs("\n", fp);
4086 }
4087 
4088 static void
bi_disasm_fma_mov_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4089 bi_disasm_fma_mov_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4090 {
4091     fputs("*MOV.i32", fp);
4092     fputs(" ", fp);
4093     bi_disasm_dest_fma(fp, next_regs, last);
4094     fputs(", ", fp);
4095     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4096     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4097     fputs("\n", fp);
4098 }
4099 
4100 static void
bi_disasm_fma_lrot_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4101 bi_disasm_fma_lrot_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4102 {
4103     static const char *bytes2_table[] = {
4104         "", ".bytes2"
4105     };
4106 
4107     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
4108 
4109     static const char *lane2_table[] = {
4110         "", ".b2"
4111     };
4112 
4113     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
4114 
4115     static const char *result_word_table[] = {
4116         "", ".w1"
4117     };
4118 
4119     const char *result_word = result_word_table[_BITS(bits, 11, 1)];
4120 
4121     fputs("*LROT_DOUBLE.i32", fp);
4122     fputs(result_word, fp);
4123     fputs(" ", fp);
4124     bi_disasm_dest_fma(fp, next_regs, last);
4125     fputs(", ", fp);
4126     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4127     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4128     fputs(", ", fp);
4129     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4130     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4131     fputs(", ", fp);
4132     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4133     fputs(bytes2, fp);
4134     fputs(lane2, fp);
4135     fputs("\n", fp);
4136 }
4137 
4138 static void
bi_disasm_fma_fcmp_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4139 bi_disasm_fma_fcmp_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4140 {
4141     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
4142     static const char *abs1_0[] = {
4143         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ".reserved"
4144     };
4145     static const char *abs1_1[] = {
4146         "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", ".reserved", ".reserved"
4147     };
4148     const char *abs1 = ordering ? abs1_1[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)] : abs1_0[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)];
4149     static const char *cmpf_0[] = {
4150         ".eq", ".eq", ".gt", ".gt", ".ge", ".ge", ".ne", ".ne", ".lt", ".lt", ".le", ".le", ".gtlt", ".gtlt", ".total", ".reserved"
4151     };
4152     static const char *cmpf_1[] = {
4153         ".eq", ".eq", ".gt", ".gt", ".ge", ".ge", ".ne", ".ne", ".lt", ".lt", ".le", ".le", ".gtlt", ".gtlt", ".reserved", ".reserved"
4154     };
4155     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)] : cmpf_0[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)];
4156     static const char *abs0_0[] = {
4157         "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".abs", "", ".reserved"
4158     };
4159     static const char *abs0_1[] = {
4160         ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".abs", ".reserved", ".reserved"
4161     };
4162     const char *abs0 = ordering ? abs0_1[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)] : abs0_0[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 13, 3) << 1)];
4163     static const char *neg0_table[] = {
4164         "", ".neg"
4165     };
4166 
4167     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
4168 
4169     static const char *neg1_table[] = {
4170         "", ".neg"
4171     };
4172 
4173     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
4174 
4175     static const char *swz0_table[] = {
4176         ".h00", ".h10", "", ".h11"
4177     };
4178 
4179     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
4180 
4181     static const char *swz1_table[] = {
4182         ".h00", ".h10", "", ".h11"
4183     };
4184 
4185     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
4186 
4187     static const char *result_type_table[] = {
4188         "", ".f1", ".m1", ".reserved"
4189     };
4190 
4191     const char *result_type = result_type_table[_BITS(bits, 16, 2)];
4192 
4193     fputs("*FCMP.v2f16", fp);
4194     fputs(cmpf, fp);
4195     fputs(result_type, fp);
4196     fputs(" ", fp);
4197     bi_disasm_dest_fma(fp, next_regs, last);
4198     fputs(", ", fp);
4199     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4200     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4201     fputs(abs0, fp);
4202     fputs(neg0, fp);
4203     fputs(swz0, fp);
4204     fputs(", ", fp);
4205     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4206     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4207     fputs(abs1, fp);
4208     fputs(neg1, fp);
4209     fputs(swz1, fp);
4210     fputs("\n", fp);
4211 }
4212 
4213 static void
bi_disasm_add_frcbrt_approx_b_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4214 bi_disasm_add_frcbrt_approx_b_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4215 {
4216     fputs("+FRCBRT_APPROX_B.f32", fp);
4217     fputs(" ", fp);
4218     bi_disasm_dest_add(fp, next_regs, last);
4219     fputs(", ", fp);
4220     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4221     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4222     fputs("\n", fp);
4223 }
4224 
4225 static void
bi_disasm_add_iadd_v2u16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4226 bi_disasm_add_iadd_v2u16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4227 {
4228     static const char *lanes1_table[] = {
4229         ".reserved", "", ".reserved", ".h10", ".reserved", "", ".reserved", ".h10"
4230     };
4231     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1) | (_BITS(bits, 10, 1) << 2)];
4232     static const char *lanes0_table[] = {
4233         ".reserved", "", ".reserved", "", ".reserved", ".h10", ".reserved", ".h10"
4234     };
4235     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1) | (_BITS(bits, 10, 1) << 2)];
4236     static const char *saturate_table[] = {
4237         "", ".sat"
4238     };
4239 
4240     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4241 
4242     fputs("+IADD.v2u16", fp);
4243     fputs(saturate, fp);
4244     fputs(" ", fp);
4245     bi_disasm_dest_add(fp, next_regs, last);
4246     fputs(", ", fp);
4247     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4248     fputs(lanes0, fp);
4249     fputs(", ", fp);
4250     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4251     fputs(lanes1, fp);
4252     fputs("\n", fp);
4253 }
4254 
4255 static void
bi_disasm_add_iadd_u32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4256 bi_disasm_add_iadd_u32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4257 {
4258     static const char *lanes1_table[] = {
4259         ".reserved", ""
4260     };
4261     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0)];
4262     static const char *saturate_table[] = {
4263         "", ".sat"
4264     };
4265 
4266     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4267 
4268     fputs("+IADD.u32", fp);
4269     fputs(saturate, fp);
4270     fputs(" ", fp);
4271     bi_disasm_dest_add(fp, next_regs, last);
4272     fputs(", ", fp);
4273     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4274     fputs(", ", fp);
4275     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4276     fputs(lanes1, fp);
4277     fputs("\n", fp);
4278 }
4279 
4280 static void
bi_disasm_add_icmp_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4281 bi_disasm_add_icmp_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4282 {
4283     static const char *swz0_table[] = {
4284         ".h00", ".h10", "", ".h11"
4285     };
4286 
4287     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
4288 
4289     static const char *swz1_table[] = {
4290         ".h00", ".h10", "", ".h11"
4291     };
4292 
4293     const char *swz1 = swz1_table[_BITS(bits, 8, 2)];
4294 
4295     static const char *result_type_table[] = {
4296         "", ".m1"
4297     };
4298 
4299     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
4300 
4301     static const char *cmpf_table[] = {
4302         ".eq", ".ne"
4303     };
4304 
4305     const char *cmpf = cmpf_table[_BITS(bits, 11, 1)];
4306 
4307     fputs("+ICMP.v2i16", fp);
4308     fputs(result_type, fp);
4309     fputs(cmpf, fp);
4310     fputs(" ", fp);
4311     bi_disasm_dest_add(fp, next_regs, last);
4312     fputs(", ", fp);
4313     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4314     fputs(swz0, fp);
4315     fputs(", ", fp);
4316     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4317     fputs(swz1, fp);
4318     fputs("\n", fp);
4319 }
4320 
4321 static void
bi_disasm_fma_rshift_or_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4322 bi_disasm_fma_rshift_or_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4323 {
4324     static const char *lanes2_table[] = {
4325         ".reserved", ".b01", ".b23", ""
4326     };
4327     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
4328     static const char *not1_table[] = {
4329         ".not", ""
4330     };
4331 
4332     const char *not1 = not1_table[_BITS(bits, 14, 1)];
4333 
4334     static const char *not_result_table[] = {
4335         "", ".not"
4336     };
4337 
4338     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
4339 
4340     fputs("*RSHIFT_OR.v2i16", fp);
4341     fputs(not_result, fp);
4342     fputs(" ", fp);
4343     bi_disasm_dest_fma(fp, next_regs, last);
4344     fputs(", ", fp);
4345     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4346     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4347     fputs(", ", fp);
4348     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4349     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4350     fputs(not1, fp);
4351     fputs(", ", fp);
4352     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4353     fputs(lanes2, fp);
4354     fputs("\n", fp);
4355 }
4356 
4357 static void
bi_disasm_add_jump(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4358 bi_disasm_add_jump(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4359 {
4360     fputs("+JUMP", fp);
4361     fputs(" ", fp);
4362     bi_disasm_dest_add(fp, next_regs, last);
4363     fputs(", ", fp);
4364     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
4365     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
4366     fputs("\n", fp);
4367 }
4368 
4369 static void
bi_disasm_add_fround_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4370 bi_disasm_add_fround_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4371 {
4372     static const char *abs0_table[] = {
4373         "", ".abs0"
4374     };
4375 
4376     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
4377 
4378     static const char *neg0_table[] = {
4379         "", ".neg0"
4380     };
4381 
4382     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
4383 
4384     static const char *swz0_table[] = {
4385         ".h00", ".h10", "", ".h11"
4386     };
4387 
4388     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
4389 
4390     static const char *round_table[] = {
4391         "", ".rtp", ".rtn", ".rtz"
4392     };
4393 
4394     const char *round = round_table[_BITS(bits, 9, 2)];
4395 
4396     fputs("+FROUND.v2f16", fp);
4397     fputs(round, fp);
4398     fputs(" ", fp);
4399     bi_disasm_dest_add(fp, next_regs, last);
4400     fputs(", ", fp);
4401     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4402     fputs(abs0, fp);
4403     fputs(neg0, fp);
4404     fputs(swz0, fp);
4405     fputs("\n", fp);
4406 }
4407 
4408 static void
bi_disasm_add_branch_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4409 bi_disasm_add_branch_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4410 {
4411     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
4412     static const char *widen0_0[] = {
4413         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4414     };
4415     static const char *widen0_1[] = {
4416         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4417     };
4418     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
4419     static const char *cmpf_0[] = {
4420         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4421     };
4422     static const char *cmpf_1[] = {
4423         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4424     };
4425     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
4426     static const char *widen1_0[] = {
4427         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4428     };
4429     static const char *widen1_1[] = {
4430         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
4431     };
4432     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
4433     fputs("+BRANCH.i32", fp);
4434     fputs(cmpf, fp);
4435     fputs(" ", fp);
4436     bi_disasm_dest_add(fp, next_regs, last);
4437     fputs(", ", fp);
4438     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4439     fputs(widen0, fp);
4440     fputs(", ", fp);
4441     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4442     fputs(widen1, fp);
4443     fputs(", ", fp);
4444     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
4445     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
4446     fputs("\n", fp);
4447 }
4448 
4449 static void
bi_disasm_add_isub_u32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4450 bi_disasm_add_isub_u32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4451 {
4452     static const char *lanes1_table[] = {
4453         ".reserved", ".b0", ".reserved", ".b1", ".reserved", ".b2", ".reserved", ".b3"
4454     };
4455     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
4456     static const char *saturate_table[] = {
4457         "", ".sat"
4458     };
4459 
4460     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4461 
4462     fputs("+ISUB.u32", fp);
4463     fputs(saturate, fp);
4464     fputs(" ", fp);
4465     bi_disasm_dest_add(fp, next_regs, last);
4466     fputs(", ", fp);
4467     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4468     fputs(", ", fp);
4469     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4470     fputs(lanes1, fp);
4471     fputs("\n", fp);
4472 }
4473 
4474 static void
bi_disasm_add_iadd_s32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4475 bi_disasm_add_iadd_s32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4476 {
4477     static const char *lanes1_table[] = {
4478         ""
4479     };
4480     const char *lanes1 = lanes1_table[0];
4481     static const char *saturate_table[] = {
4482         "", ".sat"
4483     };
4484 
4485     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4486 
4487     fputs("+IADD.s32", fp);
4488     fputs(saturate, fp);
4489     fputs(" ", fp);
4490     bi_disasm_dest_add(fp, next_regs, last);
4491     fputs(", ", fp);
4492     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4493     fputs(", ", fp);
4494     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4495     fputs(lanes1, fp);
4496     fputs("\n", fp);
4497 }
4498 
4499 static void
bi_disasm_add_vn_asst2_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4500 bi_disasm_add_vn_asst2_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4501 {
4502     static const char *scale_table[] = {
4503         ""
4504     };
4505     const char *scale = scale_table[0];
4506     static const char *neg0_table[] = {
4507         "", ".neg0"
4508     };
4509 
4510     const char *neg0 = neg0_table[_BITS(bits, 3, 1)];
4511 
4512     fputs("+VN_ASST2.f32", fp);
4513     fputs(scale, fp);
4514     fputs(" ", fp);
4515     bi_disasm_dest_add(fp, next_regs, last);
4516     fputs(", ", fp);
4517     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4518     fputs(neg0, fp);
4519     fputs("\n", fp);
4520 }
4521 
4522 static void
bi_disasm_fma_atom_c1_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4523 bi_disasm_fma_atom_c1_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4524 {
4525     static const char *atom_opc_table[] = {
4526         ".ainc", ".adec", ".aumax1", ".asmax1", ".aor1", ".reserved", ".reserved", ".reserved"
4527     };
4528 
4529     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 3)];
4530 
4531     fputs("*ATOM_C1.i32", fp);
4532     fputs(atom_opc, fp);
4533     fputs(" ", fp);
4534     bi_disasm_dest_fma(fp, next_regs, last);
4535     fputs(", ", fp);
4536     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4537     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4538     fputs(", ", fp);
4539     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4540     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4541     fputs("\n", fp);
4542 }
4543 
4544 static void
bi_disasm_fma_rshift_and_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4545 bi_disasm_fma_rshift_and_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4546 {
4547     static const char *lane2_table[] = {
4548         "", ".b1", ".b2", ".b3"
4549     };
4550 
4551     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
4552 
4553     static const char *not1_table[] = {
4554         "", ".not"
4555     };
4556 
4557     const char *not1 = not1_table[_BITS(bits, 14, 1)];
4558 
4559     static const char *not_result_table[] = {
4560         ".not", ""
4561     };
4562 
4563     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
4564 
4565     fputs("*RSHIFT_AND.i32", fp);
4566     fputs(not_result, fp);
4567     fputs(" ", fp);
4568     bi_disasm_dest_fma(fp, next_regs, last);
4569     fputs(", ", fp);
4570     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4571     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4572     fputs(", ", fp);
4573     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4574     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4575     fputs(not1, fp);
4576     fputs(", ", fp);
4577     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4578     fputs(lane2, fp);
4579     fputs("\n", fp);
4580 }
4581 
4582 static void
bi_disasm_add_swz_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4583 bi_disasm_add_swz_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4584 {
4585     static const char *swz0_table[] = {
4586         ".h00", ".h10", ".reserved", ".h11"
4587     };
4588 
4589     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
4590 
4591     fputs("+SWZ.v2i16", fp);
4592     fputs(" ", fp);
4593     bi_disasm_dest_add(fp, next_regs, last);
4594     fputs(", ", fp);
4595     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4596     fputs(swz0, fp);
4597     fputs("\n", fp);
4598 }
4599 
4600 static void
bi_disasm_fma_vn_asst1_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4601 bi_disasm_fma_vn_asst1_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4602 {
4603     static const char *neg2_table[] = {
4604         "", ".neg2"
4605     };
4606 
4607     const char *neg2 = neg2_table[_BITS(bits, 12, 1)];
4608 
4609     fputs("*VN_ASST1.f32", fp);
4610     fputs(" ", fp);
4611     bi_disasm_dest_fma(fp, next_regs, last);
4612     fputs(", ", fp);
4613     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4614     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4615     fputs(", ", fp);
4616     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4617     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4618     fputs(", ", fp);
4619     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4620     fputs(neg2, fp);
4621     fputs(", ", fp);
4622     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
4623     fputs("\n", fp);
4624 }
4625 
4626 static void
bi_disasm_add_seg_sub(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4627 bi_disasm_add_seg_sub(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4628 {
4629     static const char *seg_table[] = {
4630         ".reserved", ".reserved", ".wgl", ".reserved", ".reserved", ".reserved", ".reserved", ".tl"
4631     };
4632 
4633     const char *seg = seg_table[_BITS(bits, 3, 3)];
4634 
4635     static const char *preserve_null_table[] = {
4636         "", ".preserve_null"
4637     };
4638 
4639     const char *preserve_null = preserve_null_table[_BITS(bits, 7, 1)];
4640 
4641     fputs("+SEG_SUB", fp);
4642     fputs(seg, fp);
4643     fputs(preserve_null, fp);
4644     fputs(" ", fp);
4645     bi_disasm_dest_add(fp, next_regs, last);
4646     fputs(", ", fp);
4647     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4648     fputs("\n", fp);
4649 }
4650 
4651 static void
bi_disasm_add_ldexp_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4652 bi_disasm_add_ldexp_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4653 {
4654     static const char *round_table[] = {
4655         "", ".rtp", ".rtn", ".rtz", ".rtna", ".reserved", ".inf", ".inf0"
4656     };
4657 
4658     const char *round = round_table[_BITS(bits, 6, 3)];
4659 
4660     fputs("+LDEXP.f32", fp);
4661     fputs(round, fp);
4662     fputs(" ", fp);
4663     bi_disasm_dest_add(fp, next_regs, last);
4664     fputs(", ", fp);
4665     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4666     fputs(", ", fp);
4667     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4668     fputs("\n", fp);
4669 }
4670 
4671 static void
bi_disasm_add_icmpi_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4672 bi_disasm_add_icmpi_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4673 {
4674     static const char *result_type_table[] = {
4675         "", ".m1"
4676     };
4677 
4678     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
4679 
4680     static const char *cmpf_table[] = {
4681         ".gt", ".ge"
4682     };
4683 
4684     const char *cmpf = cmpf_table[_BITS(bits, 6, 1)];
4685 
4686     fputs("+ICMPI.u32", fp);
4687     fputs(result_type, fp);
4688     fputs(cmpf, fp);
4689     fputs(" ", fp);
4690     bi_disasm_dest_add(fp, next_regs, last);
4691     fputs(", ", fp);
4692     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4693     fputs(", ", fp);
4694     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4695     fputs("\n", fp);
4696 }
4697 
4698 static void
bi_disasm_fma_clz_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4699 bi_disasm_fma_clz_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4700 {
4701     static const char *mask_table[] = {
4702         "", ".mask"
4703     };
4704 
4705     const char *mask = mask_table[_BITS(bits, 3, 1)];
4706 
4707     fputs("*CLZ.u32", fp);
4708     fputs(mask, fp);
4709     fputs(" ", fp);
4710     bi_disasm_dest_fma(fp, next_regs, last);
4711     fputs(", ", fp);
4712     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4713     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4714     fputs("\n", fp);
4715 }
4716 
4717 static void
bi_disasm_add_branchz_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4718 bi_disasm_add_branchz_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4719 {
4720     static const char *cmpf_table[] = {
4721         ".lt", ".le", ".ge", ".gt", ".reserved", ".reserved", ".reserved", ".reserved"
4722     };
4723     const char *cmpf = cmpf_table[(_BITS(bits, 9, 3) << 0)];
4724     fputs("+BRANCHZ.s32", fp);
4725     fputs(cmpf, fp);
4726     fputs(" ", fp);
4727     bi_disasm_dest_add(fp, next_regs, last);
4728     fputs(", ", fp);
4729     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4730     fputs(", ", fp);
4731     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
4732     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
4733     fputs("\n", fp);
4734 }
4735 
4736 static void
bi_disasm_add_iabs_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4737 bi_disasm_add_iabs_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4738 {
4739     fputs("+IABS.s32", fp);
4740     fputs(" ", fp);
4741     bi_disasm_dest_add(fp, next_regs, last);
4742     fputs(", ", fp);
4743     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4744     fputs("\n", fp);
4745 }
4746 
4747 static void
bi_disasm_fma_lshift_or_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4748 bi_disasm_fma_lshift_or_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4749 {
4750     static const char *lane2_table[] = {
4751         "", ".b1", ".b2", ".b3"
4752     };
4753 
4754     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
4755 
4756     static const char *not1_table[] = {
4757         ".not", ""
4758     };
4759 
4760     const char *not1 = not1_table[_BITS(bits, 14, 1)];
4761 
4762     static const char *not_result_table[] = {
4763         "", ".not"
4764     };
4765 
4766     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
4767 
4768     fputs("*LSHIFT_OR.i32", fp);
4769     fputs(not_result, fp);
4770     fputs(" ", fp);
4771     bi_disasm_dest_fma(fp, next_regs, last);
4772     fputs(", ", fp);
4773     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4774     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4775     fputs(", ", fp);
4776     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4777     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4778     fputs(not1, fp);
4779     fputs(", ", fp);
4780     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4781     fputs(lane2, fp);
4782     fputs("\n", fp);
4783 }
4784 
4785 static void
bi_disasm_fma_csel_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4786 bi_disasm_fma_csel_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4787 {
4788     static const char *cmpf_table[] = {
4789         ".gt", ".ge"
4790     };
4791     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
4792     fputs("*CSEL.s32", fp);
4793     fputs(cmpf, fp);
4794     fputs(" ", fp);
4795     bi_disasm_dest_fma(fp, next_regs, last);
4796     fputs(", ", fp);
4797     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4798     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4799     fputs(", ", fp);
4800     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4801     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4802     fputs(", ", fp);
4803     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4804     fputs(", ", fp);
4805     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
4806     fputs("\n", fp);
4807 }
4808 
4809 static void
bi_disasm_fma_frexpm_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4810 bi_disasm_fma_frexpm_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4811 {
4812     static const char *neg0_table[] = {
4813         ""
4814     };
4815     const char *neg0 = neg0_table[0];
4816     static const char *log_table[] = {
4817         ""
4818     };
4819     const char *log = log_table[0];
4820     static const char *abs0_table[] = {
4821         "", ".abs0"
4822     };
4823 
4824     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
4825 
4826     static const char *sqrt_table[] = {
4827         "", ".sqrt"
4828     };
4829 
4830     const char *sqrt = sqrt_table[_BITS(bits, 7, 1)];
4831 
4832     static const char *widen0_table[] = {
4833         ".reserved", "", ".h0", ".h1"
4834     };
4835 
4836     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
4837 
4838     fputs("*FREXPM.f32", fp);
4839     fputs(sqrt, fp);
4840     fputs(log, fp);
4841     fputs(" ", fp);
4842     bi_disasm_dest_fma(fp, next_regs, last);
4843     fputs(", ", fp);
4844     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4845     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4846     fputs(abs0, fp);
4847     fputs(widen0, fp);
4848     fputs(neg0, fp);
4849     fputs("\n", fp);
4850 }
4851 
4852 static void
bi_disasm_fma_frexpe_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4853 bi_disasm_fma_frexpe_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4854 {
4855     static const char *sqrt_table[] = {
4856         ""
4857     };
4858     const char *sqrt = sqrt_table[0];
4859     static const char *log_table[] = {
4860         ".log"
4861     };
4862     const char *log = log_table[0];
4863     static const char *neg_table[] = {
4864         ""
4865     };
4866     const char *neg = neg_table[0];
4867     static const char *swz0_table[] = {
4868         ".h00", ".h10", "", ".h11"
4869     };
4870 
4871     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
4872 
4873     fputs("*FREXPE.v2f16", fp);
4874     fputs(neg, fp);
4875     fputs(sqrt, fp);
4876     fputs(log, fp);
4877     fputs(" ", fp);
4878     bi_disasm_dest_fma(fp, next_regs, last);
4879     fputs(", ", fp);
4880     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4881     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4882     fputs(swz0, fp);
4883     fputs("\n", fp);
4884 }
4885 
4886 static void
bi_disasm_fma_csel_v2u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4887 bi_disasm_fma_csel_v2u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4888 {
4889     static const char *cmpf_table[] = {
4890         ".gt", ".ge"
4891     };
4892     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
4893     fputs("*CSEL.v2u16", fp);
4894     fputs(cmpf, fp);
4895     fputs(" ", fp);
4896     bi_disasm_dest_fma(fp, next_regs, last);
4897     fputs(", ", fp);
4898     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
4899     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
4900     fputs(", ", fp);
4901     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
4902     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
4903     fputs(", ", fp);
4904     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
4905     fputs(", ", fp);
4906     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
4907     fputs("\n", fp);
4908 }
4909 
4910 static void
bi_disasm_add_load_i8_3(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4911 bi_disasm_add_load_i8_3(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4912 {
4913     static const char *extend_table[] = {
4914         ".sext", ".zext"
4915     };
4916     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
4917     static const char *lane_table[] = {
4918         ".d0", ".d0"
4919     };
4920     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
4921     static const char *seg_table[] = {
4922         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
4923     };
4924 
4925     const char *seg = seg_table[_BITS(bits, 6, 3)];
4926 
4927     fputs("+LOAD.i8", fp);
4928     fputs(seg, fp);
4929     fputs(lane, fp);
4930     fputs(extend, fp);
4931     fputs(" ", fp);
4932     bi_disasm_dest_add(fp, next_regs, last);
4933     fputs(", ", fp);
4934     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4935     fputs(", ", fp);
4936     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4937     fprintf(fp, ", @r%u", staging_register);
4938     fputs("\n", fp);
4939 }
4940 
4941 static void
bi_disasm_add_iadd_v2u16_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4942 bi_disasm_add_iadd_v2u16_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4943 {
4944     static const char *lanes1_table[] = {
4945         ".reserved", ".b01", ".reserved", ".b23"
4946     };
4947     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
4948     static const char *lanes0_table[] = {
4949         ".reserved", "", ".reserved", ""
4950     };
4951     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
4952     static const char *saturate_table[] = {
4953         "", ".sat"
4954     };
4955 
4956     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
4957 
4958     fputs("+IADD.v2u16", fp);
4959     fputs(saturate, fp);
4960     fputs(" ", fp);
4961     bi_disasm_dest_add(fp, next_regs, last);
4962     fputs(", ", fp);
4963     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4964     fputs(lanes0, fp);
4965     fputs(", ", fp);
4966     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4967     fputs(lanes1, fp);
4968     fputs("\n", fp);
4969 }
4970 
4971 static void
bi_disasm_add_st_tile(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4972 bi_disasm_add_st_tile(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4973 {
4974     static const char *vecsize_table[] = {
4975         "", ".v2", ".v3", ".v4"
4976     };
4977 
4978     const char *vecsize = vecsize_table[_BITS(bits, 9, 2)];
4979 
4980     fputs("+ST_TILE", fp);
4981     fputs(vecsize, fp);
4982     fputs(" ", fp);
4983     bi_disasm_dest_add(fp, next_regs, last);
4984     fputs(", ", fp);
4985     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
4986     fputs(", ", fp);
4987     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
4988     fputs(", ", fp);
4989     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
4990     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
4991     fprintf(fp, ", @r%u", staging_register);
4992     fputs("\n", fp);
4993 }
4994 
4995 static void
bi_disasm_add_flog_table_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)4996 bi_disasm_add_flog_table_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
4997 {
4998     static const char *mode_table[] = {
4999         ".red"
5000     };
5001     const char *mode = mode_table[0];
5002     static const char *precision_table[] = {
5003         ""
5004     };
5005     const char *precision = precision_table[0];
5006     static const char *widen0_table[] = {
5007         ""
5008     };
5009     const char *widen0 = widen0_table[0];
5010     static const char *neg_table[] = {
5011         "", ".neg"
5012     };
5013 
5014     const char *neg = neg_table[_BITS(bits, 3, 1)];
5015 
5016     static const char *abs0_table[] = {
5017         "", ".abs0"
5018     };
5019 
5020     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
5021 
5022     static const char *divzero_table[] = {
5023         "", ".divzero"
5024     };
5025 
5026     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
5027 
5028     fputs("+FLOG_TABLE.f32", fp);
5029     fputs(mode, fp);
5030     fputs(precision, fp);
5031     fputs(neg, fp);
5032     fputs(divzero, fp);
5033     fputs(" ", fp);
5034     bi_disasm_dest_add(fp, next_regs, last);
5035     fputs(", ", fp);
5036     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5037     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5038     fputs(widen0, fp);
5039     fputs(abs0, fp);
5040     fputs("\n", fp);
5041 }
5042 
5043 static void
bi_disasm_add_iadd_v2s16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5044 bi_disasm_add_iadd_v2s16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5045 {
5046     static const char *lanes1_table[] = {
5047         "", ".h10", "", ".h10"
5048     };
5049     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
5050     static const char *lanes0_table[] = {
5051         "", "", ".h10", ".h10"
5052     };
5053     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
5054     static const char *saturate_table[] = {
5055         "", ".sat"
5056     };
5057 
5058     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
5059 
5060     fputs("+IADD.v2s16", fp);
5061     fputs(saturate, fp);
5062     fputs(" ", fp);
5063     bi_disasm_dest_add(fp, next_regs, last);
5064     fputs(", ", fp);
5065     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5066     fputs(lanes0, fp);
5067     fputs(", ", fp);
5068     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5069     fputs(lanes1, fp);
5070     fputs("\n", fp);
5071 }
5072 
5073 static void
bi_disasm_add_texs_cube_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5074 bi_disasm_add_texs_cube_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5075 {
5076     static const char *skip_table[] = {
5077         "", ".skip"
5078     };
5079 
5080     const char *skip = skip_table[_BITS(bits, 9, 1)];
5081 
5082     fputs("+TEXS_CUBE.f32", fp);
5083     fputs(skip, fp);
5084     fputs(" ", fp);
5085     bi_disasm_dest_add(fp, next_regs, last);
5086     fputs(", ", fp);
5087     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5088     fputs(", ", fp);
5089     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5090     fputs(", ", fp);
5091     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
5092     fprintf(fp, ", sampler_index:%u", _BITS(bits, 10, 2));
5093     fprintf(fp, ", texture_index:%u", _BITS(bits, 12, 2));
5094     fprintf(fp, ", @r%u", staging_register);
5095     fputs("\n", fp);
5096 }
5097 
5098 static void
bi_disasm_fma_v2f32_to_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5099 bi_disasm_fma_v2f32_to_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5100 {
5101     static const char *abs1_table[] = {
5102         "", ".abs", "", ".abs"
5103     };
5104     const char *abs1 = abs1_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
5105     static const char *neg0_table[] = {
5106         "", "", ".neg", ".neg"
5107     };
5108     const char *neg0 = neg0_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
5109     static const char *neg1_table[] = {
5110         "", "", ".neg", ".neg"
5111     };
5112     const char *neg1 = neg1_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
5113     static const char *abs0_table[] = {
5114         "", ".abs", "", ".abs"
5115     };
5116     const char *abs0 = abs0_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
5117     static const char *clamp_table[] = {
5118         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
5119     };
5120 
5121     const char *clamp = clamp_table[_BITS(bits, 8, 2)];
5122 
5123     static const char *round_table[] = {
5124         "", ".rtp", ".rtn", ".rtz", ".rtna", ".reserved", ".reserved", ".reserved"
5125     };
5126 
5127     const char *round = round_table[_BITS(bits, 10, 3)];
5128 
5129     fputs("*V2F32_TO_V2F16", fp);
5130     fputs(clamp, fp);
5131     fputs(round, fp);
5132     fputs(" ", fp);
5133     bi_disasm_dest_fma(fp, next_regs, last);
5134     fputs(", ", fp);
5135     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5136     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5137     fputs(abs0, fp);
5138     fputs(neg0, fp);
5139     fputs(", ", fp);
5140     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5141     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5142     fputs(abs1, fp);
5143     fputs(neg1, fp);
5144     fputs("\n", fp);
5145 }
5146 
5147 static void
bi_disasm_add_load_i16_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5148 bi_disasm_add_load_i16_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5149 {
5150     static const char *extend_table[] = {
5151         ".sext", ".zext"
5152     };
5153     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
5154     static const char *lane_table[] = {
5155         ".d0", ".d0"
5156     };
5157     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
5158     static const char *seg_table[] = {
5159         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
5160     };
5161 
5162     const char *seg = seg_table[_BITS(bits, 6, 3)];
5163 
5164     fputs("+LOAD.i16", fp);
5165     fputs(seg, fp);
5166     fputs(lane, fp);
5167     fputs(extend, fp);
5168     fputs(" ", fp);
5169     bi_disasm_dest_add(fp, next_regs, last);
5170     fputs(", ", fp);
5171     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5172     fputs(", ", fp);
5173     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5174     fprintf(fp, ", @r%u", staging_register);
5175     fputs("\n", fp);
5176 }
5177 
5178 static void
bi_disasm_add_v2s8_to_v2s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5179 bi_disasm_add_v2s8_to_v2s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5180 {
5181     static const char *swz0_table[] = {
5182         ".b00", ".b10", ".b20", ".b30", "", ".b11", ".b21", ".b31", ".b02", ".b12", ".b22", ".b32", ".b03", ".b13", ".b23", ".b33"
5183     };
5184 
5185     const char *swz0 = swz0_table[_BITS(bits, 4, 4)];
5186 
5187     fputs("+V2S8_TO_V2S16", fp);
5188     fputs(" ", fp);
5189     bi_disasm_dest_add(fp, next_regs, last);
5190     fputs(", ", fp);
5191     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5192     fputs(swz0, fp);
5193     fputs("\n", fp);
5194 }
5195 
5196 static void
bi_disasm_fma_rshift_or_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5197 bi_disasm_fma_rshift_or_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5198 {
5199     static const char *lanes2_table[] = {
5200         ".b00", ".b11", ".b22", ".b33"
5201     };
5202     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
5203     static const char *not1_table[] = {
5204         ".not", ""
5205     };
5206 
5207     const char *not1 = not1_table[_BITS(bits, 14, 1)];
5208 
5209     static const char *not_result_table[] = {
5210         "", ".not"
5211     };
5212 
5213     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
5214 
5215     fputs("*RSHIFT_OR.v2i16", fp);
5216     fputs(not_result, fp);
5217     fputs(" ", fp);
5218     bi_disasm_dest_fma(fp, next_regs, last);
5219     fputs(", ", fp);
5220     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5221     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5222     fputs(", ", fp);
5223     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5224     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5225     fputs(not1, fp);
5226     fputs(", ", fp);
5227     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5228     fputs(lanes2, fp);
5229     fputs("\n", fp);
5230 }
5231 
5232 static void
bi_disasm_add_load_i24(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5233 bi_disasm_add_load_i24(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5234 {
5235     static const char *seg_table[] = {
5236         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
5237     };
5238 
5239     const char *seg = seg_table[_BITS(bits, 6, 3)];
5240 
5241     fputs("+LOAD.i24", fp);
5242     fputs(seg, fp);
5243     fputs(" ", fp);
5244     bi_disasm_dest_add(fp, next_regs, last);
5245     fputs(", ", fp);
5246     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5247     fputs(", ", fp);
5248     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5249     fprintf(fp, ", @r%u", staging_register);
5250     fputs("\n", fp);
5251 }
5252 
5253 static void
bi_disasm_fma_imul_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5254 bi_disasm_fma_imul_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5255 {
5256     static const char *swz0_table[] = {
5257         ".h00", ".h10", "", ".h11"
5258     };
5259 
5260     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
5261 
5262     static const char *swz1_table[] = {
5263         ".h00", ".h10", "", ".h11"
5264     };
5265 
5266     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
5267 
5268     fputs("*IMUL.v2i16", fp);
5269     fputs(" ", fp);
5270     bi_disasm_dest_fma(fp, next_regs, last);
5271     fputs(", ", fp);
5272     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5273     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5274     fputs(swz0, fp);
5275     fputs(", ", fp);
5276     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5277     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5278     fputs(swz1, fp);
5279     fputs("\n", fp);
5280 }
5281 
5282 static void
bi_disasm_add_f32_to_s32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5283 bi_disasm_add_f32_to_s32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5284 {
5285     static const char *round_table[] = {
5286         "", ".rtp", ".rtn", ".rtz"
5287     };
5288     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
5289     fputs("+F32_TO_S32", fp);
5290     fputs(round, fp);
5291     fputs(" ", fp);
5292     bi_disasm_dest_add(fp, next_regs, last);
5293     fputs(", ", fp);
5294     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5295     fputs("\n", fp);
5296 }
5297 
5298 static void
bi_disasm_add_iadd_v2s16_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5299 bi_disasm_add_iadd_v2s16_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5300 {
5301     static const char *lanes1_table[] = {
5302         ".b01", ".b23"
5303     };
5304     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
5305     static const char *lanes0_table[] = {
5306         "", ""
5307     };
5308     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
5309     static const char *saturate_table[] = {
5310         "", ".sat"
5311     };
5312 
5313     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
5314 
5315     fputs("+IADD.v2s16", fp);
5316     fputs(saturate, fp);
5317     fputs(" ", fp);
5318     bi_disasm_dest_add(fp, next_regs, last);
5319     fputs(", ", fp);
5320     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5321     fputs(lanes0, fp);
5322     fputs(", ", fp);
5323     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5324     fputs(lanes1, fp);
5325     fputs("\n", fp);
5326 }
5327 
5328 static void
bi_disasm_add_ld_var_flat_imm_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5329 bi_disasm_add_ld_var_flat_imm_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5330 {
5331     static const char *register_format_table[] = {
5332         ".f32", ".u32", ".f16", ".s32"
5333     };
5334     const char *register_format = register_format_table[(_BITS(bits, 10, 1) << 0) | (_BITS(bits, 19, 1) << 1)];
5335     static const char *vecsize_table[] = {
5336         "", ".v2", ".v3", ".v4"
5337     };
5338 
5339     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
5340 
5341     static const char *function_table[] = {
5342         ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".and", ".or"
5343     };
5344 
5345     const char *function = function_table[_BITS(bits, 0, 3)];
5346 
5347     fputs("+LD_VAR_FLAT_IMM", fp);
5348     fputs(vecsize, fp);
5349     fputs(register_format, fp);
5350     fputs(function, fp);
5351     fputs(" ", fp);
5352     bi_disasm_dest_add(fp, next_regs, last);
5353     fprintf(fp, ", index:%u", _BITS(bits, 3, 5));
5354     fprintf(fp, ", @r%u", staging_register);
5355     fputs("\n", fp);
5356 }
5357 
5358 static void
bi_disasm_add_frexpe_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5359 bi_disasm_add_frexpe_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5360 {
5361     static const char *sqrt_table[] = {
5362         ""
5363     };
5364     const char *sqrt = sqrt_table[0];
5365     static const char *log_table[] = {
5366         ".log"
5367     };
5368     const char *log = log_table[0];
5369     static const char *neg_table[] = {
5370         ""
5371     };
5372     const char *neg = neg_table[0];
5373     static const char *widen0_table[] = {
5374         ".reserved", "", ".h0", ".h1"
5375     };
5376 
5377     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
5378 
5379     fputs("+FREXPE.f32", fp);
5380     fputs(neg, fp);
5381     fputs(sqrt, fp);
5382     fputs(log, fp);
5383     fputs(" ", fp);
5384     bi_disasm_dest_add(fp, next_regs, last);
5385     fputs(", ", fp);
5386     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5387     fputs(widen0, fp);
5388     fputs("\n", fp);
5389 }
5390 
5391 static void
bi_disasm_fma_cubeface1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5392 bi_disasm_fma_cubeface1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5393 {
5394     static const char *neg2_table[] = {
5395         "", ".neg"
5396     };
5397     const char *neg2 = neg2_table[(_BITS(bits, 9, 1) << 0)];
5398     static const char *neg0_table[] = {
5399         "", ".neg"
5400     };
5401     const char *neg0 = neg0_table[(_BITS(bits, 9, 1) << 0)];
5402     static const char *neg1_table[] = {
5403         "", ".neg"
5404     };
5405     const char *neg1 = neg1_table[(_BITS(bits, 9, 1) << 0)];
5406     fputs("*CUBEFACE1", fp);
5407     fputs(" ", fp);
5408     bi_disasm_dest_fma(fp, next_regs, last);
5409     fputs(", ", fp);
5410     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5411     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5412     fputs(neg0, fp);
5413     fputs(", ", fp);
5414     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5415     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5416     fputs(neg1, fp);
5417     fputs(", ", fp);
5418     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5419     fputs(neg2, fp);
5420     fputs("\n", fp);
5421 }
5422 
5423 static void
bi_disasm_fma_rshift_and_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5424 bi_disasm_fma_rshift_and_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5425 {
5426     static const char *lanes2_table[] = {
5427         ""
5428     };
5429     const char *lanes2 = lanes2_table[0];
5430     static const char *not1_table[] = {
5431         "", ".not"
5432     };
5433 
5434     const char *not1 = not1_table[_BITS(bits, 14, 1)];
5435 
5436     static const char *not_result_table[] = {
5437         ".not", ""
5438     };
5439 
5440     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
5441 
5442     fputs("*RSHIFT_AND.v4i8", fp);
5443     fputs(not_result, fp);
5444     fputs(" ", fp);
5445     bi_disasm_dest_fma(fp, next_regs, last);
5446     fputs(", ", fp);
5447     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5448     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5449     fputs(", ", fp);
5450     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5451     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5452     fputs(not1, fp);
5453     fputs(", ", fp);
5454     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5455     fputs(lanes2, fp);
5456     fputs("\n", fp);
5457 }
5458 
5459 static void
bi_disasm_add_lea_attr_imm_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5460 bi_disasm_add_lea_attr_imm_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5461 {
5462     static const char *register_format_table[] = {
5463         ".auto"
5464     };
5465     const char *register_format = register_format_table[0];
5466     fputs("+LEA_ATTR_IMM", fp);
5467     fputs(register_format, fp);
5468     fputs(" ", fp);
5469     bi_disasm_dest_add(fp, next_regs, last);
5470     fputs(", ", fp);
5471     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5472     fputs(", ", fp);
5473     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5474     fprintf(fp, ", attribute_index:%u", _BITS(bits, 6, 4));
5475     fprintf(fp, ", @r%u", staging_register);
5476     fputs("\n", fp);
5477 }
5478 
5479 static void
bi_disasm_fma_s16_to_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5480 bi_disasm_fma_s16_to_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5481 {
5482     static const char *lane0_table[] = {
5483         "", ".h1"
5484     };
5485 
5486     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
5487 
5488     fputs("*S16_TO_S32", fp);
5489     fputs(" ", fp);
5490     bi_disasm_dest_fma(fp, next_regs, last);
5491     fputs(", ", fp);
5492     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5493     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5494     fputs(lane0, fp);
5495     fputs("\n", fp);
5496 }
5497 
5498 static void
bi_disasm_add_icmpm_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5499 bi_disasm_add_icmpm_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5500 {
5501     fputs("+ICMPM.i32", fp);
5502     fputs(" ", fp);
5503     bi_disasm_dest_add(fp, next_regs, last);
5504     fputs(", ", fp);
5505     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5506     fputs(", ", fp);
5507     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5508     fputs(", ", fp);
5509     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
5510     fputs("\n", fp);
5511 }
5512 
5513 static void
bi_disasm_fma_atom_c_return_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5514 bi_disasm_fma_atom_c_return_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5515 {
5516     static const char *atom_opc_table[] = {
5517         ".aaddu", ".aadds", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
5518     };
5519 
5520     const char *atom_opc = atom_opc_table[_BITS(bits, 9, 4)];
5521 
5522     fputs("*ATOM_C_RETURN.i64", fp);
5523     fputs(atom_opc, fp);
5524     fputs(" ", fp);
5525     bi_disasm_dest_fma(fp, next_regs, last);
5526     fputs(", ", fp);
5527     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5528     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5529     fputs(", ", fp);
5530     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5531     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5532     fputs(", ", fp);
5533     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5534     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
5535     fputs("\n", fp);
5536 }
5537 
5538 static void
bi_disasm_add_isub_v4s8_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5539 bi_disasm_add_isub_v4s8_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5540 {
5541     static const char *lanes1_table[] = {
5542         ".b0101", ".b2323"
5543     };
5544     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
5545     static const char *lanes0_table[] = {
5546         "", ""
5547     };
5548     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 1) << 0)];
5549     static const char *saturate_table[] = {
5550         "", ".sat"
5551     };
5552 
5553     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
5554 
5555     fputs("+ISUB.v4s8", fp);
5556     fputs(saturate, fp);
5557     fputs(" ", fp);
5558     bi_disasm_dest_add(fp, next_regs, last);
5559     fputs(", ", fp);
5560     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5561     fputs(lanes0, fp);
5562     fputs(", ", fp);
5563     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5564     fputs(lanes1, fp);
5565     fputs("\n", fp);
5566 }
5567 
5568 static void
bi_disasm_fma_bitrev_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5569 bi_disasm_fma_bitrev_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5570 {
5571     fputs("*BITREV.i32", fp);
5572     fputs(" ", fp);
5573     bi_disasm_dest_fma(fp, next_regs, last);
5574     fputs(", ", fp);
5575     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5576     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5577     fputs("\n", fp);
5578 }
5579 
5580 static void
bi_disasm_add_isub_u32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5581 bi_disasm_add_isub_u32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5582 {
5583     static const char *lanes1_table[] = {
5584         ".reserved", ""
5585     };
5586     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0)];
5587     static const char *saturate_table[] = {
5588         "", ".sat"
5589     };
5590 
5591     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
5592 
5593     fputs("+ISUB.u32", fp);
5594     fputs(saturate, fp);
5595     fputs(" ", fp);
5596     bi_disasm_dest_add(fp, next_regs, last);
5597     fputs(", ", fp);
5598     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5599     fputs(", ", fp);
5600     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5601     fputs(lanes1, fp);
5602     fputs("\n", fp);
5603 }
5604 
5605 static void
bi_disasm_fma_arshift_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5606 bi_disasm_fma_arshift_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5607 {
5608     static const char *lane2_table[] = {
5609         "", ".b1", ".b2", ".b3"
5610     };
5611 
5612     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
5613 
5614     fputs("*ARSHIFT.i32", fp);
5615     fputs(" ", fp);
5616     bi_disasm_dest_fma(fp, next_regs, last);
5617     fputs(", ", fp);
5618     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5619     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5620     fputs(", ", fp);
5621     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5622     if (!(0x8 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5623     fputs(", ", fp);
5624     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5625     fputs(lane2, fp);
5626     fputs("\n", fp);
5627 }
5628 
5629 static void
bi_disasm_fma_frexpe_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5630 bi_disasm_fma_frexpe_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5631 {
5632     static const char *log_table[] = {
5633         ""
5634     };
5635     const char *log = log_table[0];
5636     static const char *neg_table[] = {
5637         "", ".neg"
5638     };
5639 
5640     const char *neg = neg_table[_BITS(bits, 6, 1)];
5641 
5642     static const char *sqrt_table[] = {
5643         "", ".sqrt"
5644     };
5645 
5646     const char *sqrt = sqrt_table[_BITS(bits, 8, 1)];
5647 
5648     static const char *swz0_table[] = {
5649         ".h00", ".h10", "", ".h11"
5650     };
5651 
5652     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
5653 
5654     fputs("*FREXPE.v2f16", fp);
5655     fputs(neg, fp);
5656     fputs(sqrt, fp);
5657     fputs(log, fp);
5658     fputs(" ", fp);
5659     bi_disasm_dest_fma(fp, next_regs, last);
5660     fputs(", ", fp);
5661     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5662     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5663     fputs(swz0, fp);
5664     fputs("\n", fp);
5665 }
5666 
5667 static void
bi_disasm_add_f16_to_s32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5668 bi_disasm_add_f16_to_s32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5669 {
5670     static const char *round_table[] = {
5671         "", ".rtp", ".rtn", ".rtz"
5672     };
5673     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
5674     static const char *lane0_table[] = {
5675         "", ".h1"
5676     };
5677 
5678     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
5679 
5680     fputs("+F16_TO_S32", fp);
5681     fputs(round, fp);
5682     fputs(" ", fp);
5683     bi_disasm_dest_add(fp, next_regs, last);
5684     fputs(", ", fp);
5685     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5686     fputs(lane0, fp);
5687     fputs("\n", fp);
5688 }
5689 
5690 static void
bi_disasm_add_vn_asst2_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5691 bi_disasm_add_vn_asst2_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5692 {
5693     static const char *neg0_table[] = {
5694         "", ".neg0"
5695     };
5696 
5697     const char *neg0 = neg0_table[_BITS(bits, 3, 1)];
5698 
5699     fputs("+VN_ASST2.v2f16", fp);
5700     fputs(" ", fp);
5701     bi_disasm_dest_add(fp, next_regs, last);
5702     fputs(", ", fp);
5703     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5704     fputs(neg0, fp);
5705     fputs("\n", fp);
5706 }
5707 
5708 static void
bi_disasm_add_mkvec_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5709 bi_disasm_add_mkvec_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5710 {
5711     static const char *lane0_table[] = {
5712         "", ".h1"
5713     };
5714 
5715     const char *lane0 = lane0_table[_BITS(bits, 6, 1)];
5716 
5717     static const char *lane1_table[] = {
5718         "", ".h1"
5719     };
5720 
5721     const char *lane1 = lane1_table[_BITS(bits, 7, 1)];
5722 
5723     fputs("+MKVEC.v2i16", fp);
5724     fputs(" ", fp);
5725     bi_disasm_dest_add(fp, next_regs, last);
5726     fputs(", ", fp);
5727     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5728     fputs(lane0, fp);
5729     fputs(", ", fp);
5730     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5731     fputs(lane1, fp);
5732     fputs("\n", fp);
5733 }
5734 
5735 static void
bi_disasm_add_ldexp_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5736 bi_disasm_add_ldexp_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5737 {
5738     static const char *round_table[] = {
5739         "", ".rtp", ".rtn", ".rtz", ".rtna", ".reserved", ".inf", ".inf0"
5740     };
5741 
5742     const char *round = round_table[_BITS(bits, 6, 3)];
5743 
5744     fputs("+LDEXP.v2f16", fp);
5745     fputs(round, fp);
5746     fputs(" ", fp);
5747     bi_disasm_dest_add(fp, next_regs, last);
5748     fputs(", ", fp);
5749     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5750     fputs(", ", fp);
5751     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5752     fputs("\n", fp);
5753 }
5754 
5755 static void
bi_disasm_add_texc(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5756 bi_disasm_add_texc(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5757 {
5758     static const char *skip_table[] = {
5759         "", ".skip"
5760     };
5761 
5762     const char *skip = skip_table[_BITS(bits, 9, 1)];
5763 
5764     fputs("+TEXC", fp);
5765     fputs(skip, fp);
5766     fputs(" ", fp);
5767     bi_disasm_dest_add(fp, next_regs, last);
5768     fputs(", ", fp);
5769     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5770     fputs(", ", fp);
5771     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5772     fputs(", ", fp);
5773     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
5774     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
5775     fprintf(fp, ", @r%u", staging_register);
5776     fputs("\n", fp);
5777 }
5778 
5779 static void
bi_disasm_add_frexpm_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5780 bi_disasm_add_frexpm_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5781 {
5782     static const char *sqrt_table[] = {
5783         ""
5784     };
5785     const char *sqrt = sqrt_table[0];
5786     static const char *log_table[] = {
5787         ".log"
5788     };
5789     const char *log = log_table[0];
5790     static const char *abs0_table[] = {
5791         "", ".abs0"
5792     };
5793 
5794     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
5795 
5796     static const char *widen0_table[] = {
5797         ".reserved", "", ".h0", ".h1"
5798     };
5799 
5800     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
5801 
5802     static const char *neg0_table[] = {
5803         "", ".neg0"
5804     };
5805 
5806     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
5807 
5808     fputs("+FREXPM.f32", fp);
5809     fputs(sqrt, fp);
5810     fputs(log, fp);
5811     fputs(" ", fp);
5812     bi_disasm_dest_add(fp, next_regs, last);
5813     fputs(", ", fp);
5814     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5815     fputs(abs0, fp);
5816     fputs(widen0, fp);
5817     fputs(neg0, fp);
5818     fputs("\n", fp);
5819 }
5820 
5821 static void
bi_disasm_fma_rshift_and_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5822 bi_disasm_fma_rshift_and_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5823 {
5824     static const char *lanes2_table[] = {
5825         ".reserved", ".b01", ".b23", ""
5826     };
5827     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
5828     static const char *not1_table[] = {
5829         "", ".not"
5830     };
5831 
5832     const char *not1 = not1_table[_BITS(bits, 14, 1)];
5833 
5834     static const char *not_result_table[] = {
5835         ".not", ""
5836     };
5837 
5838     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
5839 
5840     fputs("*RSHIFT_AND.v2i16", fp);
5841     fputs(not_result, fp);
5842     fputs(" ", fp);
5843     bi_disasm_dest_fma(fp, next_regs, last);
5844     fputs(", ", fp);
5845     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5846     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5847     fputs(", ", fp);
5848     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5849     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5850     fputs(not1, fp);
5851     fputs(", ", fp);
5852     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
5853     fputs(lanes2, fp);
5854     fputs("\n", fp);
5855 }
5856 
5857 static void
bi_disasm_add_flog_table_f32_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5858 bi_disasm_add_flog_table_f32_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5859 {
5860     static const char *divzero_table[] = {
5861         "", ""
5862     };
5863     const char *divzero = divzero_table[(_BITS(bits, 5, 1) << 0)];
5864     static const char *mode_table[] = {
5865         ".base2", ".natural"
5866     };
5867     const char *mode = mode_table[(_BITS(bits, 5, 1) << 0)];
5868     static const char *precision_table[] = {
5869         "", ""
5870     };
5871     const char *precision = precision_table[(_BITS(bits, 5, 1) << 0)];
5872     static const char *widen0_table[] = {
5873         "", ""
5874     };
5875     const char *widen0 = widen0_table[(_BITS(bits, 5, 1) << 0)];
5876     static const char *neg_table[] = {
5877         "", ".neg"
5878     };
5879 
5880     const char *neg = neg_table[_BITS(bits, 3, 1)];
5881 
5882     static const char *abs0_table[] = {
5883         "", ".abs0"
5884     };
5885 
5886     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
5887 
5888     fputs("+FLOG_TABLE.f32", fp);
5889     fputs(mode, fp);
5890     fputs(precision, fp);
5891     fputs(neg, fp);
5892     fputs(divzero, fp);
5893     fputs(" ", fp);
5894     bi_disasm_dest_add(fp, next_regs, last);
5895     fputs(", ", fp);
5896     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5897     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5898     fputs(widen0, fp);
5899     fputs(abs0, fp);
5900     fputs("\n", fp);
5901 }
5902 
5903 static void
bi_disasm_add_frsq_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5904 bi_disasm_add_frsq_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5905 {
5906     static const char *widen0_table[] = {
5907         "", ".reserved"
5908     };
5909     const char *widen0 = widen0_table[(_BITS(bits, 6, 1) << 0)];
5910     static const char *neg_table[] = {
5911         "", ".neg"
5912     };
5913 
5914     const char *neg = neg_table[_BITS(bits, 3, 1)];
5915 
5916     static const char *abs0_table[] = {
5917         "", ".abs0"
5918     };
5919 
5920     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
5921 
5922     fputs("+FRSQ.f32", fp);
5923     fputs(neg, fp);
5924     fputs(" ", fp);
5925     bi_disasm_dest_add(fp, next_regs, last);
5926     fputs(", ", fp);
5927     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5928     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5929     fputs(widen0, fp);
5930     fputs(abs0, fp);
5931     fputs("\n", fp);
5932 }
5933 
5934 static void
bi_disasm_fma_fmul_cslice(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5935 bi_disasm_fma_fmul_cslice(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5936 {
5937     static const char *lane0_table[] = {
5938         "", ".h1"
5939     };
5940 
5941     const char *lane0 = lane0_table[_BITS(bits, 6, 1)];
5942 
5943     static const char *abs0_table[] = {
5944         "", ".abs"
5945     };
5946 
5947     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
5948 
5949     static const char *neg0_table[] = {
5950         "", ".neg"
5951     };
5952 
5953     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
5954 
5955     fputs("*FMUL_CSLICE", fp);
5956     fputs(" ", fp);
5957     bi_disasm_dest_fma(fp, next_regs, last);
5958     fputs(", ", fp);
5959     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
5960     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
5961     fputs(lane0, fp);
5962     fputs(abs0, fp);
5963     fputs(neg0, fp);
5964     fputs(", ", fp);
5965     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
5966     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
5967     fputs("\n", fp);
5968 }
5969 
5970 static void
bi_disasm_add_acmpxchg_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5971 bi_disasm_add_acmpxchg_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5972 {
5973     static const char *seg_table[] = {
5974         "", ".wgl"
5975     };
5976 
5977     const char *seg = seg_table[_BITS(bits, 9, 1)];
5978 
5979     fputs("+ACMPXCHG.i32", fp);
5980     fputs(seg, fp);
5981     fputs(" ", fp);
5982     bi_disasm_dest_add(fp, next_regs, last);
5983     fputs(", ", fp);
5984     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5985     fputs(", ", fp);
5986     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
5987     fprintf(fp, ", @r%u", staging_register);
5988     fputs("\n", fp);
5989 }
5990 
5991 static void
bi_disasm_add_branch_lowbits_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)5992 bi_disasm_add_branch_lowbits_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
5993 {
5994     fputs("+BRANCH_LOWBITS.f32", fp);
5995     fputs(" ", fp);
5996     bi_disasm_dest_add(fp, next_regs, last);
5997     fputs(", ", fp);
5998     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
5999     fputs(", ", fp);
6000     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6001     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6002     fputs("\n", fp);
6003 }
6004 
6005 static void
bi_disasm_add_branchz_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6006 bi_disasm_add_branchz_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6007 {
6008     static const char *cmpf_table[] = {
6009         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".ne", ".reserved", ".reserved", ".eq", ".eq", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".reserved", ".le", ".le", ".reserved", ".reserved", ".lt", ".lt", ".reserved"
6010     };
6011     const char *cmpf = cmpf_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 3, 1) << 2) | (_BITS(bits, 9, 3) << 3)];
6012     static const char *widen0_table[] = {
6013         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved"
6014     };
6015     const char *widen0 = widen0_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 3, 1) << 2) | (_BITS(bits, 9, 3) << 3)];
6016     fputs("+BRANCHZ.f16", fp);
6017     fputs(cmpf, fp);
6018     fputs(" ", fp);
6019     bi_disasm_dest_add(fp, next_regs, last);
6020     fputs(", ", fp);
6021     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6022     fputs(widen0, fp);
6023     fputs(", ", fp);
6024     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6025     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6026     fputs("\n", fp);
6027 }
6028 
6029 static void
bi_disasm_add_barrier(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6030 bi_disasm_add_barrier(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6031 {
6032     fputs("+BARRIER", fp);
6033     fputs(" ", fp);
6034     bi_disasm_dest_add(fp, next_regs, last);
6035     fputs("\n", fp);
6036 }
6037 
6038 static void
bi_disasm_fma_atom_c_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6039 bi_disasm_fma_atom_c_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6040 {
6041     static const char *atom_opc_table[] = {
6042         ".aaddu", ".aadds", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
6043     };
6044 
6045     const char *atom_opc = atom_opc_table[_BITS(bits, 9, 4)];
6046 
6047     fputs("*ATOM_C.i64", fp);
6048     fputs(atom_opc, fp);
6049     fputs(" ", fp);
6050     bi_disasm_dest_fma(fp, next_regs, last);
6051     fputs(", ", fp);
6052     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6053     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6054     fputs(", ", fp);
6055     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6056     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6057     fputs(", ", fp);
6058     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6059     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6060     fputs("\n", fp);
6061 }
6062 
6063 static void
bi_disasm_add_lea_attr_tex_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6064 bi_disasm_add_lea_attr_tex_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6065 {
6066     static const char *register_format_table[] = {
6067         ".auto"
6068     };
6069     const char *register_format = register_format_table[0];
6070     fputs("+LEA_ATTR_TEX", fp);
6071     fputs(register_format, fp);
6072     fputs(" ", fp);
6073     bi_disasm_dest_add(fp, next_regs, last);
6074     fputs(", ", fp);
6075     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6076     fputs(", ", fp);
6077     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6078     fputs(", ", fp);
6079     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6080     fprintf(fp, ", @r%u", staging_register);
6081     fputs("\n", fp);
6082 }
6083 
6084 static void
bi_disasm_fma_rshift_xor_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6085 bi_disasm_fma_rshift_xor_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6086 {
6087     static const char *lanes2_table[] = {
6088         ".b0000", ".b1111", ".b2222", ".b3333"
6089     };
6090     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
6091     static const char *not_result_table[] = {
6092         "", ".not"
6093     };
6094 
6095     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
6096 
6097     fputs("*RSHIFT_XOR.v4i8", fp);
6098     fputs(not_result, fp);
6099     fputs(" ", fp);
6100     bi_disasm_dest_fma(fp, next_regs, last);
6101     fputs(", ", fp);
6102     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6103     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6104     fputs(", ", fp);
6105     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6106     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6107     fputs(", ", fp);
6108     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6109     fputs(lanes2, fp);
6110     fputs("\n", fp);
6111 }
6112 
6113 static void
bi_disasm_add_branch_no_diverg(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6114 bi_disasm_add_branch_no_diverg(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6115 {
6116     fputs("+BRANCH_NO_DIVERG", fp);
6117     fputs(" ", fp);
6118     bi_disasm_dest_add(fp, next_regs, last);
6119     fputs(", ", fp);
6120     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6121     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6122     fputs("\n", fp);
6123 }
6124 
6125 static void
bi_disasm_add_lea_tex_imm(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6126 bi_disasm_add_lea_tex_imm(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6127 {
6128     static const char *format_table[] = {
6129         ".u16", ".u32"
6130     };
6131 
6132     const char *format = format_table[_BITS(bits, 11, 1)];
6133 
6134     fputs("+LEA_TEX_IMM", fp);
6135     fputs(format, fp);
6136     fputs(" ", fp);
6137     bi_disasm_dest_add(fp, next_regs, last);
6138     fputs(", ", fp);
6139     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6140     fputs(", ", fp);
6141     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6142     fprintf(fp, ", texture_index:%u", _BITS(bits, 6, 5));
6143     fprintf(fp, ", @r%u", staging_register);
6144     fputs("\n", fp);
6145 }
6146 
6147 static void
bi_disasm_fma_rshift_xor_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6148 bi_disasm_fma_rshift_xor_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6149 {
6150     static const char *lanes2_table[] = {
6151         ".b00", ".b11", ".b22", ".b33"
6152     };
6153     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
6154     static const char *not_result_table[] = {
6155         "", ".not"
6156     };
6157 
6158     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
6159 
6160     fputs("*RSHIFT_XOR.v2i16", fp);
6161     fputs(not_result, fp);
6162     fputs(" ", fp);
6163     bi_disasm_dest_fma(fp, next_regs, last);
6164     fputs(", ", fp);
6165     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6166     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6167     fputs(", ", fp);
6168     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6169     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6170     fputs(", ", fp);
6171     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6172     fputs(lanes2, fp);
6173     fputs("\n", fp);
6174 }
6175 
6176 static void
bi_disasm_add_frcp_approx_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6177 bi_disasm_add_frcp_approx_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6178 {
6179     static const char *widen0_table[] = {
6180         ".h0", ".h1"
6181     };
6182     const char *widen0 = widen0_table[(_BITS(bits, 7, 1) << 0)];
6183     static const char *neg_table[] = {
6184         "", ".neg"
6185     };
6186 
6187     const char *neg = neg_table[_BITS(bits, 3, 1)];
6188 
6189     static const char *abs0_table[] = {
6190         "", ".abs0"
6191     };
6192 
6193     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
6194 
6195     static const char *divzero_table[] = {
6196         "", ".divzero"
6197     };
6198 
6199     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
6200 
6201     fputs("+FRCP_APPROX.f32", fp);
6202     fputs(neg, fp);
6203     fputs(divzero, fp);
6204     fputs(" ", fp);
6205     bi_disasm_dest_add(fp, next_regs, last);
6206     fputs(", ", fp);
6207     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6208     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6209     fputs(widen0, fp);
6210     fputs(abs0, fp);
6211     fputs("\n", fp);
6212 }
6213 
6214 static void
bi_disasm_add_fpow_sc_det_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6215 bi_disasm_add_fpow_sc_det_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6216 {
6217     static const char *func_table[] = {
6218         ".pow", ".powr", ".pown", ".rootn"
6219     };
6220 
6221     const char *func = func_table[_BITS(bits, 7, 2)];
6222 
6223     fputs("+FPOW_SC_DET.f32", fp);
6224     fputs(func, fp);
6225     fputs(" ", fp);
6226     bi_disasm_dest_add(fp, next_regs, last);
6227     fputs(", ", fp);
6228     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6229     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6230     fputs(", ", fp);
6231     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6232     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6233     fputs("\n", fp);
6234 }
6235 
6236 static void
bi_disasm_fma_f16_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6237 bi_disasm_fma_f16_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6238 {
6239     static const char *lane0_table[] = {
6240         "", ".h1"
6241     };
6242 
6243     const char *lane0 = lane0_table[_BITS(bits, 3, 1)];
6244 
6245     fputs("*F16_TO_F32", fp);
6246     fputs(" ", fp);
6247     bi_disasm_dest_fma(fp, next_regs, last);
6248     fputs(", ", fp);
6249     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6250     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6251     fputs(lane0, fp);
6252     fputs("\n", fp);
6253 }
6254 
6255 static void
bi_disasm_add_texs_2d_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6256 bi_disasm_add_texs_2d_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6257 {
6258     static const char *skip_table[] = {
6259         "", ".skip"
6260     };
6261 
6262     const char *skip = skip_table[_BITS(bits, 9, 1)];
6263 
6264     static const char *lod_mode_table[] = {
6265         ".computed_lod", ""
6266     };
6267 
6268     const char *lod_mode = lod_mode_table[_BITS(bits, 13, 1)];
6269 
6270     fputs("+TEXS_2D.f32", fp);
6271     fputs(skip, fp);
6272     fputs(lod_mode, fp);
6273     fputs(" ", fp);
6274     bi_disasm_dest_add(fp, next_regs, last);
6275     fputs(", ", fp);
6276     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6277     fputs(", ", fp);
6278     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6279     fprintf(fp, ", texture_index:%u", _BITS(bits, 6, 3));
6280     fprintf(fp, ", sampler_index:%u", _BITS(bits, 10, 3));
6281     fprintf(fp, ", @r%u", staging_register);
6282     fputs("\n", fp);
6283 }
6284 
6285 static void
bi_disasm_fma_shaddxl_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6286 bi_disasm_fma_shaddxl_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6287 {
6288     static const char *lane1_table[] = {
6289         ".h0", ".h1", "", ".reserved"
6290     };
6291 
6292     const char *lane1 = lane1_table[_BITS(bits, 9, 2)];
6293 
6294     fputs("*SHADDXL.u32", fp);
6295     fputs(" ", fp);
6296     bi_disasm_dest_fma(fp, next_regs, last);
6297     fputs(", ", fp);
6298     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6299     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6300     fputs(", ", fp);
6301     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6302     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6303     fputs(lane1, fp);
6304     fprintf(fp, ", shift:%u", _BITS(bits, 6, 3));
6305     fputs("\n", fp);
6306 }
6307 
6308 static void
bi_disasm_add_texs_cube_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6309 bi_disasm_add_texs_cube_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6310 {
6311     static const char *skip_table[] = {
6312         "", ".skip"
6313     };
6314 
6315     const char *skip = skip_table[_BITS(bits, 9, 1)];
6316 
6317     fputs("+TEXS_CUBE.f16", fp);
6318     fputs(skip, fp);
6319     fputs(" ", fp);
6320     bi_disasm_dest_add(fp, next_regs, last);
6321     fputs(", ", fp);
6322     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6323     fputs(", ", fp);
6324     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6325     fputs(", ", fp);
6326     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6327     fprintf(fp, ", sampler_index:%u", _BITS(bits, 10, 2));
6328     fprintf(fp, ", texture_index:%u", _BITS(bits, 12, 2));
6329     fprintf(fp, ", @r%u", staging_register);
6330     fputs("\n", fp);
6331 }
6332 
6333 static void
bi_disasm_add_load_i32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6334 bi_disasm_add_load_i32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6335 {
6336     static const char *extend_table[] = {
6337         ".sext", ".zext"
6338     };
6339     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
6340     static const char *lane_table[] = {
6341         ".d0", ".d0"
6342     };
6343     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
6344     static const char *seg_table[] = {
6345         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
6346     };
6347 
6348     const char *seg = seg_table[_BITS(bits, 6, 3)];
6349 
6350     fputs("+LOAD.i32", fp);
6351     fputs(seg, fp);
6352     fputs(lane, fp);
6353     fputs(extend, fp);
6354     fputs(" ", fp);
6355     bi_disasm_dest_add(fp, next_regs, last);
6356     fputs(", ", fp);
6357     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6358     fputs(", ", fp);
6359     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6360     fprintf(fp, ", @r%u", staging_register);
6361     fputs("\n", fp);
6362 }
6363 
6364 static void
bi_disasm_add_branch_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6365 bi_disasm_add_branch_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6366 {
6367     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
6368     static const char *widen0_0[] = {
6369         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6370     };
6371     static const char *widen0_1[] = {
6372         "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6373     };
6374     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
6375     static const char *cmpf_0[] = {
6376         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6377     };
6378     static const char *cmpf_1[] = {
6379         ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6380     };
6381     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
6382     static const char *widen1_0[] = {
6383         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6384     };
6385     static const char *widen1_1[] = {
6386         "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
6387     };
6388     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
6389     fputs("+BRANCH.u32", fp);
6390     fputs(cmpf, fp);
6391     fputs(" ", fp);
6392     bi_disasm_dest_add(fp, next_regs, last);
6393     fputs(", ", fp);
6394     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6395     fputs(widen0, fp);
6396     fputs(", ", fp);
6397     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6398     fputs(widen1, fp);
6399     fputs(", ", fp);
6400     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6401     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6402     fputs("\n", fp);
6403 }
6404 
6405 static void
bi_disasm_add_v2u8_to_v2u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6406 bi_disasm_add_v2u8_to_v2u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6407 {
6408     static const char *swz0_table[] = {
6409         ".b00", ".b10", ".b20", ".b30", "", ".b11", ".b21", ".b31", ".b02", ".b12", ".b22", ".b32", ".b03", ".b13", ".b23", ".b33"
6410     };
6411 
6412     const char *swz0 = swz0_table[_BITS(bits, 4, 4)];
6413 
6414     fputs("+V2U8_TO_V2U16", fp);
6415     fputs(" ", fp);
6416     bi_disasm_dest_add(fp, next_regs, last);
6417     fputs(", ", fp);
6418     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6419     fputs(swz0, fp);
6420     fputs("\n", fp);
6421 }
6422 
6423 static void
bi_disasm_add_icmp_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6424 bi_disasm_add_icmp_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6425 {
6426     static const char *cmpf_table[] = {
6427         ".gt", ".ge"
6428     };
6429     const char *cmpf = cmpf_table[(_BITS(bits, 6, 1) << 0)];
6430     static const char *result_type_table[] = {
6431         "", ".m1"
6432     };
6433 
6434     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
6435 
6436     fputs("+ICMP.u32", fp);
6437     fputs(result_type, fp);
6438     fputs(cmpf, fp);
6439     fputs(" ", fp);
6440     bi_disasm_dest_add(fp, next_regs, last);
6441     fputs(", ", fp);
6442     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6443     fputs(", ", fp);
6444     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6445     fputs("\n", fp);
6446 }
6447 
6448 static void
bi_disasm_fma_rshift_or_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6449 bi_disasm_fma_rshift_or_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6450 {
6451     static const char *lanes2_table[] = {
6452         ".b0000", ".b1111", ".b2222", ".b3333"
6453     };
6454     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
6455     static const char *not1_table[] = {
6456         ".not", ""
6457     };
6458 
6459     const char *not1 = not1_table[_BITS(bits, 14, 1)];
6460 
6461     static const char *not_result_table[] = {
6462         "", ".not"
6463     };
6464 
6465     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
6466 
6467     fputs("*RSHIFT_OR.v4i8", fp);
6468     fputs(not_result, fp);
6469     fputs(" ", fp);
6470     bi_disasm_dest_fma(fp, next_regs, last);
6471     fputs(", ", fp);
6472     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6473     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6474     fputs(", ", fp);
6475     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6476     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6477     fputs(not1, fp);
6478     fputs(", ", fp);
6479     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6480     fputs(lanes2, fp);
6481     fputs("\n", fp);
6482 }
6483 
6484 static void
bi_disasm_add_ld_var_flat_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6485 bi_disasm_add_ld_var_flat_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6486 {
6487     static const char *register_format_table[] = {
6488         ".auto"
6489     };
6490     const char *register_format = register_format_table[0];
6491     static const char *vecsize_table[] = {
6492         "", ".v2", ".v3", ".v4"
6493     };
6494 
6495     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
6496 
6497     static const char *function_table[] = {
6498         ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".and", ".or"
6499     };
6500 
6501     const char *function = function_table[_BITS(bits, 0, 3)];
6502 
6503     fputs("+LD_VAR_FLAT", fp);
6504     fputs(vecsize, fp);
6505     fputs(register_format, fp);
6506     fputs(function, fp);
6507     fputs(" ", fp);
6508     bi_disasm_dest_add(fp, next_regs, last);
6509     fputs(", ", fp);
6510     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6511     fprintf(fp, ", @r%u", staging_register);
6512     fputs("\n", fp);
6513 }
6514 
6515 static void
bi_disasm_add_seg_add(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6516 bi_disasm_add_seg_add(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6517 {
6518     static const char *seg_table[] = {
6519         ".reserved", ".reserved", ".wgl", ".reserved", ".reserved", ".reserved", ".reserved", ".tl"
6520     };
6521 
6522     const char *seg = seg_table[_BITS(bits, 3, 3)];
6523 
6524     static const char *preserve_null_table[] = {
6525         "", ".preserve_null"
6526     };
6527 
6528     const char *preserve_null = preserve_null_table[_BITS(bits, 7, 1)];
6529 
6530     fputs("+SEG_ADD", fp);
6531     fputs(seg, fp);
6532     fputs(preserve_null, fp);
6533     fputs(" ", fp);
6534     bi_disasm_dest_add(fp, next_regs, last);
6535     fputs(", ", fp);
6536     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6537     fputs("\n", fp);
6538 }
6539 
6540 static void
bi_disasm_add_frsq_approx_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6541 bi_disasm_add_frsq_approx_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6542 {
6543     static const char *widen0_table[] = {
6544         ""
6545     };
6546     const char *widen0 = widen0_table[0];
6547     static const char *neg_table[] = {
6548         "", ".neg"
6549     };
6550 
6551     const char *neg = neg_table[_BITS(bits, 3, 1)];
6552 
6553     static const char *abs0_table[] = {
6554         "", ".abs0"
6555     };
6556 
6557     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
6558 
6559     static const char *divzero_table[] = {
6560         "", ".divzero"
6561     };
6562 
6563     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
6564 
6565     fputs("+FRSQ_APPROX.f32", fp);
6566     fputs(neg, fp);
6567     fputs(divzero, fp);
6568     fputs(" ", fp);
6569     bi_disasm_dest_add(fp, next_regs, last);
6570     fputs(", ", fp);
6571     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6572     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6573     fputs(widen0, fp);
6574     fputs(abs0, fp);
6575     fputs("\n", fp);
6576 }
6577 
6578 static void
bi_disasm_fma_lshift_xor_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6579 bi_disasm_fma_lshift_xor_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6580 {
6581     static const char *lanes2_table[] = {
6582         ""
6583     };
6584     const char *lanes2 = lanes2_table[0];
6585     static const char *not_result_table[] = {
6586         "", ".not"
6587     };
6588 
6589     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
6590 
6591     fputs("*LSHIFT_XOR.v4i8", fp);
6592     fputs(not_result, fp);
6593     fputs(" ", fp);
6594     bi_disasm_dest_fma(fp, next_regs, last);
6595     fputs(", ", fp);
6596     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6597     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6598     fputs(", ", fp);
6599     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6600     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6601     fputs(", ", fp);
6602     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6603     fputs(lanes2, fp);
6604     fputs("\n", fp);
6605 }
6606 
6607 static void
bi_disasm_add_cubeface2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6608 bi_disasm_add_cubeface2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6609 {
6610     fputs("+CUBEFACE2", fp);
6611     fputs(" ", fp);
6612     bi_disasm_dest_add(fp, next_regs, last);
6613     fputs(", ", fp);
6614     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6615     fputs("\n", fp);
6616 }
6617 
6618 static void
bi_disasm_add_ld_tile(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6619 bi_disasm_add_ld_tile(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6620 {
6621     static const char *vecsize_table[] = {
6622         "", ".v2", ".v3", ".v4"
6623     };
6624 
6625     const char *vecsize = vecsize_table[_BITS(bits, 9, 2)];
6626 
6627     fputs("+LD_TILE", fp);
6628     fputs(vecsize, fp);
6629     fputs(" ", fp);
6630     bi_disasm_dest_add(fp, next_regs, last);
6631     fputs(", ", fp);
6632     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6633     fputs(", ", fp);
6634     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6635     fputs(", ", fp);
6636     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6637     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
6638     fprintf(fp, ", @r%u", staging_register);
6639     fputs("\n", fp);
6640 }
6641 
6642 static void
bi_disasm_add_shaddxh_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6643 bi_disasm_add_shaddxh_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6644 {
6645     fputs("+SHADDXH.i32", fp);
6646     fputs(" ", fp);
6647     bi_disasm_dest_add(fp, next_regs, last);
6648     fputs(", ", fp);
6649     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6650     fputs(", ", fp);
6651     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6652     fputs("\n", fp);
6653 }
6654 
6655 static void
bi_disasm_fma_lshift_and_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6656 bi_disasm_fma_lshift_and_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6657 {
6658     static const char *lanes2_table[] = {
6659         ""
6660     };
6661     const char *lanes2 = lanes2_table[0];
6662     static const char *not1_table[] = {
6663         "", ".not"
6664     };
6665 
6666     const char *not1 = not1_table[_BITS(bits, 14, 1)];
6667 
6668     static const char *not_result_table[] = {
6669         ".not", ""
6670     };
6671 
6672     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
6673 
6674     fputs("*LSHIFT_AND.v4i8", fp);
6675     fputs(not_result, fp);
6676     fputs(" ", fp);
6677     bi_disasm_dest_fma(fp, next_regs, last);
6678     fputs(", ", fp);
6679     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6680     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6681     fputs(", ", fp);
6682     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6683     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6684     fputs(not1, fp);
6685     fputs(", ", fp);
6686     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6687     fputs(lanes2, fp);
6688     fputs("\n", fp);
6689 }
6690 
6691 static void
bi_disasm_fma_lshift_and_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6692 bi_disasm_fma_lshift_and_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6693 {
6694     static const char *lanes2_table[] = {
6695         ".reserved", ".b01", ".b23", ""
6696     };
6697     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
6698     static const char *not1_table[] = {
6699         "", ".not"
6700     };
6701 
6702     const char *not1 = not1_table[_BITS(bits, 14, 1)];
6703 
6704     static const char *not_result_table[] = {
6705         ".not", ""
6706     };
6707 
6708     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
6709 
6710     fputs("*LSHIFT_AND.v2i16", fp);
6711     fputs(not_result, fp);
6712     fputs(" ", fp);
6713     bi_disasm_dest_fma(fp, next_regs, last);
6714     fputs(", ", fp);
6715     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6716     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6717     fputs(", ", fp);
6718     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6719     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6720     fputs(not1, fp);
6721     fputs(", ", fp);
6722     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6723     fputs(lanes2, fp);
6724     fputs("\n", fp);
6725 }
6726 
6727 static void
bi_disasm_add_iadd_v4u8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6728 bi_disasm_add_iadd_v4u8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6729 {
6730     static const char *lanes1_table[] = {
6731         ".reserved", ".b0000", ".reserved", ".b1111", ".reserved", ".b2222", ".reserved", ".b3333"
6732     };
6733     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
6734     static const char *lanes0_table[] = {
6735         ".reserved", "", ".reserved", "", ".reserved", "", ".reserved", ""
6736     };
6737     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
6738     static const char *saturate_table[] = {
6739         "", ".sat"
6740     };
6741 
6742     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
6743 
6744     fputs("+IADD.v4u8", fp);
6745     fputs(saturate, fp);
6746     fputs(" ", fp);
6747     bi_disasm_dest_add(fp, next_regs, last);
6748     fputs(", ", fp);
6749     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6750     fputs(lanes0, fp);
6751     fputs(", ", fp);
6752     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6753     fputs(lanes1, fp);
6754     fputs("\n", fp);
6755 }
6756 
6757 static void
bi_disasm_add_ld_var_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6758 bi_disasm_add_ld_var_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6759 {
6760     static const char *register_format_table[] = {
6761         ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".f32", ".f16", ".reserved", ".reserved", ".reserved", ".reserved"
6762     };
6763     const char *register_format = register_format_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
6764     static const char *sample_table[] = {
6765         ".center", ".center", ".centroid", ".centroid", ".sample", ".sample", ".explicit", ".explicit", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".center", ".center", ".centroid", ".centroid", ".center", ".center", ".centroid", ".centroid", ".sample", ".sample", ".explicit", ".explicit", ".reserved", ".reserved", ".reserved", ".reserved"
6766     };
6767     const char *sample = sample_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
6768     static const char *update_table[] = {
6769         ".store", ".store", ".store", ".store", ".store", ".store", ".store", ".store", ".retrieve", ".retrieve", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".conditional", ".conditional", ".conditional", ".conditional", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".clobber", ".reserved", ".reserved", ".reserved", ".reserved"
6770     };
6771     const char *update = update_table[(_BITS(bits, 19, 1) << 0) | (_BITS(bits, 10, 4) << 1)];
6772     static const char *vecsize_table[] = {
6773         "", ".v2", ".v3", ".v4"
6774     };
6775 
6776     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
6777 
6778     fputs("+LD_VAR", fp);
6779     fputs(vecsize, fp);
6780     fputs(update, fp);
6781     fputs(register_format, fp);
6782     fputs(sample, fp);
6783     fputs(" ", fp);
6784     bi_disasm_dest_add(fp, next_regs, last);
6785     fputs(", ", fp);
6786     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6787     fputs(", ", fp);
6788     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6789     fprintf(fp, ", @r%u", staging_register);
6790     fputs("\n", fp);
6791 }
6792 
6793 static void
bi_disasm_add_v2s8_to_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6794 bi_disasm_add_v2s8_to_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6795 {
6796     static const char *swz0_table[] = {
6797         ".b00", ".b10", ".b20", ".b30", "", ".b11", ".b21", ".b31", ".b02", ".b12", ".b22", ".b32", ".b03", ".b13", ".b23", ".b33"
6798     };
6799 
6800     const char *swz0 = swz0_table[_BITS(bits, 4, 4)];
6801 
6802     fputs("+V2S8_TO_V2F16", fp);
6803     fputs(" ", fp);
6804     bi_disasm_dest_add(fp, next_regs, last);
6805     fputs(", ", fp);
6806     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6807     fputs(swz0, fp);
6808     fputs("\n", fp);
6809 }
6810 
6811 static void
bi_disasm_fma_csel_v2s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6812 bi_disasm_fma_csel_v2s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6813 {
6814     static const char *cmpf_table[] = {
6815         ".gt", ".ge"
6816     };
6817     const char *cmpf = cmpf_table[(_BITS(bits, 12, 1) << 0)];
6818     fputs("*CSEL.v2s16", fp);
6819     fputs(cmpf, fp);
6820     fputs(" ", fp);
6821     bi_disasm_dest_fma(fp, next_regs, last);
6822     fputs(", ", fp);
6823     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6824     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6825     fputs(", ", fp);
6826     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6827     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6828     fputs(", ", fp);
6829     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
6830     fputs(", ", fp);
6831     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
6832     fputs("\n", fp);
6833 }
6834 
6835 static void
bi_disasm_add_ld_attr_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6836 bi_disasm_add_ld_attr_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6837 {
6838     static const char *register_format_table[] = {
6839         ".auto"
6840     };
6841     const char *register_format = register_format_table[0];
6842     static const char *vecsize_table[] = {
6843         "", ".v2", ".v3", ".v4"
6844     };
6845 
6846     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
6847 
6848     fputs("+LD_ATTR", fp);
6849     fputs(register_format, fp);
6850     fputs(vecsize, fp);
6851     fputs(" ", fp);
6852     bi_disasm_dest_add(fp, next_regs, last);
6853     fputs(", ", fp);
6854     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6855     fputs(", ", fp);
6856     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6857     fputs(", ", fp);
6858     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
6859     fprintf(fp, ", @r%u", staging_register);
6860     fputs("\n", fp);
6861 }
6862 
6863 static void
bi_disasm_fma_quiet_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6864 bi_disasm_fma_quiet_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6865 {
6866     static const char *swz0_table[] = {
6867         ".h00", ".h10", "", ".h11"
6868     };
6869 
6870     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
6871 
6872     fputs("*QUIET.v2f16", fp);
6873     fputs(" ", fp);
6874     bi_disasm_dest_fma(fp, next_regs, last);
6875     fputs(", ", fp);
6876     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6877     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6878     fputs(swz0, fp);
6879     fputs("\n", fp);
6880 }
6881 
6882 static void
bi_disasm_fma_fadd_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6883 bi_disasm_fma_fadd_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6884 {
6885     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
6886     static const char *abs1_0[] = {
6887         "", ""
6888     };
6889     static const char *abs1_1[] = {
6890         "", ".abs"
6891     };
6892     const char *abs1 = ordering ? abs1_1[(_BITS(bits, 6, 1) << 0)] : abs1_0[(_BITS(bits, 6, 1) << 0)];
6893     static const char *abs0_0[] = {
6894         "", ".abs"
6895     };
6896     static const char *abs0_1[] = {
6897         ".abs", ".abs"
6898     };
6899     const char *abs0 = ordering ? abs0_1[(_BITS(bits, 6, 1) << 0)] : abs0_0[(_BITS(bits, 6, 1) << 0)];
6900     static const char *neg0_table[] = {
6901         "", ".neg"
6902     };
6903 
6904     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
6905 
6906     static const char *neg1_table[] = {
6907         "", ".neg"
6908     };
6909 
6910     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
6911 
6912     static const char *swz0_table[] = {
6913         ".h00", ".h10", "", ".h11"
6914     };
6915 
6916     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
6917 
6918     static const char *swz1_table[] = {
6919         ".h00", ".h10", "", ".h11"
6920     };
6921 
6922     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
6923 
6924     static const char *round_table[] = {
6925         "", ".rtp", ".rtn", ".rtz"
6926     };
6927 
6928     const char *round = round_table[_BITS(bits, 13, 2)];
6929 
6930     static const char *clamp_table[] = {
6931         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
6932     };
6933 
6934     const char *clamp = clamp_table[_BITS(bits, 15, 2)];
6935 
6936     fputs("*FADD.v2f16", fp);
6937     fputs(round, fp);
6938     fputs(clamp, fp);
6939     fputs(" ", fp);
6940     bi_disasm_dest_fma(fp, next_regs, last);
6941     fputs(", ", fp);
6942     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
6943     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
6944     fputs(abs0, fp);
6945     fputs(neg0, fp);
6946     fputs(swz0, fp);
6947     fputs(", ", fp);
6948     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
6949     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
6950     fputs(abs1, fp);
6951     fputs(neg1, fp);
6952     fputs(swz1, fp);
6953     fputs("\n", fp);
6954 }
6955 
6956 static void
bi_disasm_add_s8_to_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6957 bi_disasm_add_s8_to_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6958 {
6959     static const char *lane0_table[] = {
6960         "", ".b1", ".b2", ".b3"
6961     };
6962 
6963     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
6964 
6965     fputs("+S8_TO_S32", fp);
6966     fputs(" ", fp);
6967     bi_disasm_dest_add(fp, next_regs, last);
6968     fputs(", ", fp);
6969     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6970     fputs(lane0, fp);
6971     fputs("\n", fp);
6972 }
6973 
6974 static void
bi_disasm_add_hadd_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6975 bi_disasm_add_hadd_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6976 {
6977     static const char *round_table[] = {
6978         ".rtn", ".rtp"
6979     };
6980 
6981     const char *round = round_table[_BITS(bits, 12, 1)];
6982 
6983     fputs("+HADD.s32", fp);
6984     fputs(round, fp);
6985     fputs(" ", fp);
6986     bi_disasm_dest_add(fp, next_regs, last);
6987     fputs(", ", fp);
6988     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
6989     fputs(", ", fp);
6990     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
6991     fputs("\n", fp);
6992 }
6993 
6994 static void
bi_disasm_fma_idp_v4i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)6995 bi_disasm_fma_idp_v4i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
6996 {
6997     static const char *sign0_table[] = {
6998         ".zext", ".sext"
6999     };
7000 
7001     const char *sign0 = sign0_table[_BITS(bits, 9, 1)];
7002 
7003     static const char *sign1_table[] = {
7004         ".zext", ".sext"
7005     };
7006 
7007     const char *sign1 = sign1_table[_BITS(bits, 10, 1)];
7008 
7009     fputs("*IDP.v4i8", fp);
7010     fputs(" ", fp);
7011     bi_disasm_dest_fma(fp, next_regs, last);
7012     fputs(", ", fp);
7013     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7014     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7015     fputs(sign0, fp);
7016     fputs(", ", fp);
7017     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7018     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7019     fputs(sign1, fp);
7020     fputs("\n", fp);
7021 }
7022 
7023 static void
bi_disasm_add_ld_var_flat_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7024 bi_disasm_add_ld_var_flat_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7025 {
7026     static const char *register_format_table[] = {
7027         ".f32", ".u32", ".f16", ".s32"
7028     };
7029     const char *register_format = register_format_table[(_BITS(bits, 10, 1) << 0) | (_BITS(bits, 19, 1) << 1)];
7030     static const char *vecsize_table[] = {
7031         "", ".v2", ".v3", ".v4"
7032     };
7033 
7034     const char *vecsize = vecsize_table[_BITS(bits, 8, 2)];
7035 
7036     static const char *function_table[] = {
7037         ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".and", ".or"
7038     };
7039 
7040     const char *function = function_table[_BITS(bits, 0, 3)];
7041 
7042     fputs("+LD_VAR_FLAT", fp);
7043     fputs(vecsize, fp);
7044     fputs(register_format, fp);
7045     fputs(function, fp);
7046     fputs(" ", fp);
7047     bi_disasm_dest_add(fp, next_regs, last);
7048     fputs(", ", fp);
7049     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7050     fprintf(fp, ", @r%u", staging_register);
7051     fputs("\n", fp);
7052 }
7053 
7054 static void
bi_disasm_add_nop_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7055 bi_disasm_add_nop_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7056 {
7057     fputs("+NOP.i32", fp);
7058     fputs(" ", fp);
7059     bi_disasm_dest_add(fp, next_regs, last);
7060     fputs("\n", fp);
7061 }
7062 
7063 static void
bi_disasm_fma_csel_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7064 bi_disasm_fma_csel_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7065 {
7066     static const char *cmpf_table[] = {
7067         ".eq", ".gt", ".ge", ".reserved"
7068     };
7069     const char *cmpf = cmpf_table[(_BITS(bits, 12, 2) << 0)];
7070     fputs("*CSEL.v2f16", fp);
7071     fputs(cmpf, fp);
7072     fputs(" ", fp);
7073     bi_disasm_dest_fma(fp, next_regs, last);
7074     fputs(", ", fp);
7075     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7076     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7077     fputs(", ", fp);
7078     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7079     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7080     fputs(", ", fp);
7081     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
7082     fputs(", ", fp);
7083     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
7084     fputs("\n", fp);
7085 }
7086 
7087 static void
bi_disasm_fma_nop_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7088 bi_disasm_fma_nop_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7089 {
7090     fputs("*NOP.i32", fp);
7091     fputs(" ", fp);
7092     bi_disasm_dest_fma(fp, next_regs, last);
7093     fputs("\n", fp);
7094 }
7095 
7096 static void
bi_disasm_add_u8_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7097 bi_disasm_add_u8_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7098 {
7099     static const char *lane0_table[] = {
7100         "", ".b1", ".b2", ".b3"
7101     };
7102 
7103     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
7104 
7105     fputs("+U8_TO_F32", fp);
7106     fputs(" ", fp);
7107     bi_disasm_dest_add(fp, next_regs, last);
7108     fputs(", ", fp);
7109     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7110     fputs(lane0, fp);
7111     fputs("\n", fp);
7112 }
7113 
7114 static void
bi_disasm_add_fatan_table_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7115 bi_disasm_add_fatan_table_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7116 {
7117     static const char *lane1_table[] = {
7118         "", ".h1"
7119     };
7120 
7121     const char *lane1 = lane1_table[_BITS(bits, 6, 1)];
7122 
7123     static const char *lane0_table[] = {
7124         "", ".h1"
7125     };
7126 
7127     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
7128 
7129     fputs("+FATAN_TABLE.f16", fp);
7130     fputs(" ", fp);
7131     bi_disasm_dest_add(fp, next_regs, last);
7132     fputs(", ", fp);
7133     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7134     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7135     fputs(lane0, fp);
7136     fputs(", ", fp);
7137     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7138     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7139     fputs(lane1, fp);
7140     fputs("\n", fp);
7141 }
7142 
7143 static void
bi_disasm_add_fmax_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7144 bi_disasm_add_fmax_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7145 {
7146     static const char *abs1_table[] = {
7147         "", ".abs"
7148     };
7149 
7150     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
7151 
7152     static const char *neg0_table[] = {
7153         "", ".neg"
7154     };
7155 
7156     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
7157 
7158     static const char *neg1_table[] = {
7159         "", ".neg"
7160     };
7161 
7162     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
7163 
7164     static const char *clamp_table[] = {
7165         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
7166     };
7167 
7168     const char *clamp = clamp_table[_BITS(bits, 11, 2)];
7169 
7170     static const char *sem_table[] = {
7171         "", ".nan_propagate", ".c", ".inverse_c"
7172     };
7173 
7174     const char *sem = sem_table[_BITS(bits, 13, 2)];
7175 
7176     static const char *abs0_table[] = {
7177         "", ".abs"
7178     };
7179 
7180     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
7181 
7182     fputs("+FMAX.f32", fp);
7183     fputs(clamp, fp);
7184     fputs(sem, fp);
7185     fputs(" ", fp);
7186     bi_disasm_dest_add(fp, next_regs, last);
7187     fputs(", ", fp);
7188     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7189     fputs(neg0, fp);
7190     fputs(abs0, fp);
7191     fputs(", ", fp);
7192     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7193     fputs(abs1, fp);
7194     fputs(neg1, fp);
7195     fputs("\n", fp);
7196 }
7197 
7198 static void
bi_disasm_add_ld_var_special_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7199 bi_disasm_add_ld_var_special_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7200 {
7201     static const char *register_format_table[] = {
7202         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".f32", ".reserved", ".f32", ".f32", ".f16", ".reserved", ".f16", ".f16", ".f32", ".reserved", ".f32", ".f32", ".f16", ".reserved", ".f16", ".f16", ".f32", ".reserved", ".f32", ".f32", ".f16", ".reserved", ".f16", ".f16", ".f32", ".reserved", ".f32", ".reserved", ".f16", ".reserved", ".f16", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7203     };
7204     const char *register_format = register_format_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 19, 1) << 2) | (_BITS(bits, 10, 4) << 3)];
7205     static const char *vecsize_table[] = {
7206         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".v2", ".reserved", "", "", ".v2", ".reserved", "", "", ".v2", ".reserved", "", "", ".v2", ".reserved", "", "", ".v2", ".reserved", "", "", ".v2", ".reserved", "", "", ".v2", ".reserved", "", ".reserved", ".v2", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7207     };
7208     const char *vecsize = vecsize_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 19, 1) << 2) | (_BITS(bits, 10, 4) << 3)];
7209     static const char *varying_name_table[] = {
7210         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".frag_z", ".point", ".reserved", ".frag_w", ".reserved", ".point", ".reserved", ".frag_w", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7211     };
7212     const char *varying_name = varying_name_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 19, 1) << 2) | (_BITS(bits, 10, 4) << 3)];
7213     static const char *update_table[] = {
7214         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".clobber", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".clobber", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7215     };
7216     const char *update = update_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 19, 1) << 2) | (_BITS(bits, 10, 4) << 3)];
7217     static const char *sample_table[] = {
7218         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".center", ".reserved", ".center", ".center", ".center", ".reserved", ".center", ".center", ".centroid", ".reserved", ".centroid", ".centroid", ".centroid", ".reserved", ".centroid", ".centroid", ".sample", ".reserved", ".sample", ".sample", ".sample", ".reserved", ".sample", ".sample", ".explicit", ".reserved", ".explicit", ".reserved", ".explicit", ".reserved", ".explicit", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7219     };
7220     const char *sample = sample_table[(_BITS(bits, 3, 2) << 0) | (_BITS(bits, 19, 1) << 2) | (_BITS(bits, 10, 4) << 3)];
7221     fputs("+LD_VAR_SPECIAL", fp);
7222     fputs(varying_name, fp);
7223     fputs(vecsize, fp);
7224     fputs(update, fp);
7225     fputs(register_format, fp);
7226     fputs(sample, fp);
7227     fputs(" ", fp);
7228     bi_disasm_dest_add(fp, next_regs, last);
7229     fputs(", ", fp);
7230     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7231     fprintf(fp, ", @r%u", staging_register);
7232     fputs("\n", fp);
7233 }
7234 
7235 static void
bi_disasm_fma_imul_i32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7236 bi_disasm_fma_imul_i32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7237 {
7238     static const char *widen1_table[] = {
7239         ""
7240     };
7241     const char *widen1 = widen1_table[0];
7242     static const char *extend1_table[] = {
7243         ""
7244     };
7245     const char *extend1 = extend1_table[0];
7246     fputs("*IMUL.i32", fp);
7247     fputs(" ", fp);
7248     bi_disasm_dest_fma(fp, next_regs, last);
7249     fputs(", ", fp);
7250     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7251     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7252     fputs(", ", fp);
7253     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7254     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7255     fputs(widen1, fp);
7256     fputs(extend1, fp);
7257     fputs("\n", fp);
7258 }
7259 
7260 static void
bi_disasm_add_f16_to_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7261 bi_disasm_add_f16_to_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7262 {
7263     static const char *lane0_table[] = {
7264         "", ".h1"
7265     };
7266 
7267     const char *lane0 = lane0_table[_BITS(bits, 3, 1)];
7268 
7269     fputs("+F16_TO_F32", fp);
7270     fputs(" ", fp);
7271     bi_disasm_dest_add(fp, next_regs, last);
7272     fputs(", ", fp);
7273     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7274     fputs(lane0, fp);
7275     fputs("\n", fp);
7276 }
7277 
7278 static void
bi_disasm_add_isub_v2u16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7279 bi_disasm_add_isub_v2u16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7280 {
7281     static const char *lanes1_table[] = {
7282         ".reserved", "", ".reserved", ".h10", ".reserved", "", ".reserved", ".h10"
7283     };
7284     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1) | (_BITS(bits, 10, 1) << 2)];
7285     static const char *lanes0_table[] = {
7286         ".reserved", "", ".reserved", "", ".reserved", ".h10", ".reserved", ".h10"
7287     };
7288     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1) | (_BITS(bits, 10, 1) << 2)];
7289     static const char *saturate_table[] = {
7290         "", ".sat"
7291     };
7292 
7293     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
7294 
7295     fputs("+ISUB.v2u16", fp);
7296     fputs(saturate, fp);
7297     fputs(" ", fp);
7298     bi_disasm_dest_add(fp, next_regs, last);
7299     fputs(", ", fp);
7300     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7301     fputs(lanes0, fp);
7302     fputs(", ", fp);
7303     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7304     fputs(lanes1, fp);
7305     fputs("\n", fp);
7306 }
7307 
7308 static void
bi_disasm_fma_rshift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7309 bi_disasm_fma_rshift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7310 {
7311     static const char *bytes2_table[] = {
7312         "", ".bytes2"
7313     };
7314 
7315     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
7316 
7317     static const char *lane2_table[] = {
7318         "", ".b2"
7319     };
7320 
7321     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
7322 
7323     static const char *result_word_table[] = {
7324         "", ".w1"
7325     };
7326 
7327     const char *result_word = result_word_table[_BITS(bits, 11, 1)];
7328 
7329     fputs("*RSHIFT_DOUBLE.i32", fp);
7330     fputs(result_word, fp);
7331     fputs(" ", fp);
7332     bi_disasm_dest_fma(fp, next_regs, last);
7333     fputs(", ", fp);
7334     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7335     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7336     fputs(", ", fp);
7337     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7338     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7339     fputs(", ", fp);
7340     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
7341     fputs(bytes2, fp);
7342     fputs(lane2, fp);
7343     fputs("\n", fp);
7344 }
7345 
7346 static void
bi_disasm_add_fcmp_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7347 bi_disasm_add_fcmp_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7348 {
7349     static const char *widen0_table[] = {
7350         "", "", "", ".h0", "", "", "", ".h0"
7351     };
7352     const char *widen0 = widen0_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 13, 1) << 2)];
7353     static const char *neg0_table[] = {
7354         "", "", "", "", ".neg", ".neg", ".neg", ".neg"
7355     };
7356     const char *neg0 = neg0_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 13, 1) << 2)];
7357     static const char *widen1_table[] = {
7358         "", ".h0", ".h1", ".h0", "", ".h0", ".h1", ".h0"
7359     };
7360     const char *widen1 = widen1_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 13, 1) << 2)];
7361     static const char *neg1_table[] = {
7362         "", "", "", "", "", "", "", ""
7363     };
7364     const char *neg1 = neg1_table[(_BITS(bits, 9, 2) << 0) | (_BITS(bits, 13, 1) << 2)];
7365     static const char *cmpf_table[] = {
7366         ".eq", ".gt", ".ge", ".ne", ".lt", ".le", ".gtlt", ".total"
7367     };
7368 
7369     const char *cmpf = cmpf_table[_BITS(bits, 6, 3)];
7370 
7371     static const char *abs0_table[] = {
7372         "", ".abs"
7373     };
7374 
7375     const char *abs0 = abs0_table[_BITS(bits, 11, 1)];
7376 
7377     static const char *abs1_table[] = {
7378         "", ".abs"
7379     };
7380 
7381     const char *abs1 = abs1_table[_BITS(bits, 12, 1)];
7382 
7383     static const char *result_type_table[] = {
7384         "", ".f1", ".m1", ".reserved"
7385     };
7386 
7387     const char *result_type = result_type_table[_BITS(bits, 14, 2)];
7388 
7389     fputs("+FCMP.f32", fp);
7390     fputs(cmpf, fp);
7391     fputs(result_type, fp);
7392     fputs(" ", fp);
7393     bi_disasm_dest_add(fp, next_regs, last);
7394     fputs(", ", fp);
7395     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7396     fputs(widen0, fp);
7397     fputs(neg0, fp);
7398     fputs(abs0, fp);
7399     fputs(", ", fp);
7400     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7401     fputs(widen1, fp);
7402     fputs(neg1, fp);
7403     fputs(abs1, fp);
7404     fputs("\n", fp);
7405 }
7406 
7407 static void
bi_disasm_add_flog_table_f32_4(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7408 bi_disasm_add_flog_table_f32_4(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7409 {
7410     static const char *neg_table[] = {
7411         "", "", "", ""
7412     };
7413     const char *neg = neg_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7414     static const char *widen0_table[] = {
7415         "", "", "", ""
7416     };
7417     const char *widen0 = widen0_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7418     static const char *precision_table[] = {
7419         ".high", ".high", ".low", ".low"
7420     };
7421     const char *precision = precision_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7422     static const char *divzero_table[] = {
7423         "", "", "", ""
7424     };
7425     const char *divzero = divzero_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7426     static const char *mode_table[] = {
7427         ".natural", ".base2", ".natural", ".base2"
7428     };
7429     const char *mode = mode_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7430     static const char *abs0_table[] = {
7431         "", "", "", ""
7432     };
7433     const char *abs0 = abs0_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 4, 1) << 1)];
7434     fputs("+FLOG_TABLE.f32", fp);
7435     fputs(mode, fp);
7436     fputs(precision, fp);
7437     fputs(neg, fp);
7438     fputs(divzero, fp);
7439     fputs(" ", fp);
7440     bi_disasm_dest_add(fp, next_regs, last);
7441     fputs(", ", fp);
7442     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7443     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7444     fputs(widen0, fp);
7445     fputs(abs0, fp);
7446     fputs("\n", fp);
7447 }
7448 
7449 static void
bi_disasm_add_lea_attr_tex_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7450 bi_disasm_add_lea_attr_tex_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7451 {
7452     static const char *register_format_table[] = {
7453         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
7454     };
7455     const char *register_format = register_format_table[(_BITS(bits, 11, 3) << 0)];
7456     fputs("+LEA_ATTR_TEX", fp);
7457     fputs(register_format, fp);
7458     fputs(" ", fp);
7459     bi_disasm_dest_add(fp, next_regs, last);
7460     fputs(", ", fp);
7461     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7462     fputs(", ", fp);
7463     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7464     fputs(", ", fp);
7465     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
7466     fprintf(fp, ", @r%u", staging_register);
7467     fputs("\n", fp);
7468 }
7469 
7470 static void
bi_disasm_fma_lshift_or_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7471 bi_disasm_fma_lshift_or_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7472 {
7473     static const char *lanes2_table[] = {
7474         ".reserved", ".b01", ".b23", ""
7475     };
7476     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
7477     static const char *not1_table[] = {
7478         ".not", ""
7479     };
7480 
7481     const char *not1 = not1_table[_BITS(bits, 14, 1)];
7482 
7483     static const char *not_result_table[] = {
7484         "", ".not"
7485     };
7486 
7487     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
7488 
7489     fputs("*LSHIFT_OR.v2i16", fp);
7490     fputs(not_result, fp);
7491     fputs(" ", fp);
7492     bi_disasm_dest_fma(fp, next_regs, last);
7493     fputs(", ", fp);
7494     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7495     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7496     fputs(", ", fp);
7497     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7498     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7499     fputs(not1, fp);
7500     fputs(", ", fp);
7501     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
7502     fputs(lanes2, fp);
7503     fputs("\n", fp);
7504 }
7505 
7506 static void
bi_disasm_add_f32_to_u32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7507 bi_disasm_add_f32_to_u32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7508 {
7509     static const char *round_table[] = {
7510         ".rtna"
7511     };
7512     const char *round = round_table[0];
7513     fputs("+F32_TO_U32", fp);
7514     fputs(round, fp);
7515     fputs(" ", fp);
7516     bi_disasm_dest_add(fp, next_regs, last);
7517     fputs(", ", fp);
7518     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7519     fputs("\n", fp);
7520 }
7521 
7522 static void
bi_disasm_add_load_i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7523 bi_disasm_add_load_i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7524 {
7525     static const char *extend_table[] = {
7526         ".sext", ".zext", ".sext", ".zext"
7527     };
7528     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
7529     static const char *lane_table[] = {
7530         ".h0", ".h0", ".h1", ".h1"
7531     };
7532     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 10, 1) << 1)];
7533     static const char *seg_table[] = {
7534         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
7535     };
7536 
7537     const char *seg = seg_table[_BITS(bits, 6, 3)];
7538 
7539     fputs("+LOAD.i8", fp);
7540     fputs(seg, fp);
7541     fputs(lane, fp);
7542     fputs(extend, fp);
7543     fputs(" ", fp);
7544     bi_disasm_dest_add(fp, next_regs, last);
7545     fputs(", ", fp);
7546     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7547     fputs(", ", fp);
7548     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7549     fprintf(fp, ", @r%u", staging_register);
7550     fputs("\n", fp);
7551 }
7552 
7553 static void
bi_disasm_add_branchc_i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7554 bi_disasm_add_branchc_i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7555 {
7556     static const char *lane0_table[] = {
7557         ".reserved", ".h1", "", ".reserved"
7558     };
7559     const char *lane0 = lane0_table[(_BITS(bits, 9, 1) << 0) | (_BITS(bits, 3, 1) << 1)];
7560     static const char *combine_table[] = {
7561         ".any", ".all"
7562     };
7563 
7564     const char *combine = combine_table[_BITS(bits, 10, 1)];
7565 
7566     fputs("+BRANCHC.i16", fp);
7567     fputs(combine, fp);
7568     fputs(" ", fp);
7569     bi_disasm_dest_add(fp, next_regs, last);
7570     fputs(", ", fp);
7571     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7572     fputs(lane0, fp);
7573     fputs(", ", fp);
7574     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
7575     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
7576     fputs("\n", fp);
7577 }
7578 
7579 static void
bi_disasm_fma_popcount_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7580 bi_disasm_fma_popcount_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7581 {
7582     fputs("*POPCOUNT.i32", fp);
7583     fputs(" ", fp);
7584     bi_disasm_dest_fma(fp, next_regs, last);
7585     fputs(", ", fp);
7586     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7587     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7588     fputs("\n", fp);
7589 }
7590 
7591 static void
bi_disasm_add_ld_attr_tex_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7592 bi_disasm_add_ld_attr_tex_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7593 {
7594     static const char *register_format_table[] = {
7595         ".auto"
7596     };
7597     const char *register_format = register_format_table[0];
7598     static const char *vecsize_table[] = {
7599         "", ".v2", ".v3", ".v4"
7600     };
7601 
7602     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
7603 
7604     fputs("+LD_ATTR_TEX", fp);
7605     fputs(register_format, fp);
7606     fputs(vecsize, fp);
7607     fputs(" ", fp);
7608     bi_disasm_dest_add(fp, next_regs, last);
7609     fputs(", ", fp);
7610     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7611     fputs(", ", fp);
7612     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7613     fputs(", ", fp);
7614     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
7615     fprintf(fp, ", @r%u", staging_register);
7616     fputs("\n", fp);
7617 }
7618 
7619 static void
bi_disasm_add_fpow_sc_det_f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7620 bi_disasm_add_fpow_sc_det_f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7621 {
7622     static const char *func_table[] = {
7623         ".pow", ".pow", ".powr", ".powr"
7624     };
7625     const char *func = func_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 8, 1) << 1)];
7626     static const char *lane1_table[] = {
7627         ".h0", ".h1", ".h0", ".h1"
7628     };
7629     const char *lane1 = lane1_table[(_BITS(bits, 6, 1) << 0) | (_BITS(bits, 8, 1) << 1)];
7630     static const char *lane0_table[] = {
7631         "", ".h1"
7632     };
7633 
7634     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
7635 
7636     fputs("+FPOW_SC_DET.f16", fp);
7637     fputs(func, fp);
7638     fputs(" ", fp);
7639     bi_disasm_dest_add(fp, next_regs, last);
7640     fputs(", ", fp);
7641     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7642     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7643     fputs(lane0, fp);
7644     fputs(", ", fp);
7645     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7646     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7647     fputs(lane1, fp);
7648     fputs("\n", fp);
7649 }
7650 
7651 static void
bi_disasm_fma_lshift_and_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7652 bi_disasm_fma_lshift_and_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7653 {
7654     static const char *lane2_table[] = {
7655         "", ".b1", ".b2", ".b3"
7656     };
7657 
7658     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
7659 
7660     static const char *not1_table[] = {
7661         "", ".not"
7662     };
7663 
7664     const char *not1 = not1_table[_BITS(bits, 14, 1)];
7665 
7666     static const char *not_result_table[] = {
7667         ".not", ""
7668     };
7669 
7670     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
7671 
7672     fputs("*LSHIFT_AND.i32", fp);
7673     fputs(not_result, fp);
7674     fputs(" ", fp);
7675     bi_disasm_dest_fma(fp, next_regs, last);
7676     fputs(", ", fp);
7677     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7678     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7679     fputs(", ", fp);
7680     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7681     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7682     fputs(not1, fp);
7683     fputs(", ", fp);
7684     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
7685     fputs(lane2, fp);
7686     fputs("\n", fp);
7687 }
7688 
7689 static void
bi_disasm_fma_quiet_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7690 bi_disasm_fma_quiet_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7691 {
7692     fputs("*QUIET.f32", fp);
7693     fputs(" ", fp);
7694     bi_disasm_dest_fma(fp, next_regs, last);
7695     fputs(", ", fp);
7696     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7697     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7698     fputs("\n", fp);
7699 }
7700 
7701 static void
bi_disasm_add_f16_to_u32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7702 bi_disasm_add_f16_to_u32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7703 {
7704     static const char *round_table[] = {
7705         ".rtna"
7706     };
7707     const char *round = round_table[0];
7708     static const char *lane0_table[] = {
7709         "", ".h1"
7710     };
7711 
7712     const char *lane0 = lane0_table[_BITS(bits, 5, 1)];
7713 
7714     fputs("+F16_TO_U32", fp);
7715     fputs(round, fp);
7716     fputs(" ", fp);
7717     bi_disasm_dest_add(fp, next_regs, last);
7718     fputs(", ", fp);
7719     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7720     fputs(lane0, fp);
7721     fputs("\n", fp);
7722 }
7723 
7724 static void
bi_disasm_add_fmin_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7725 bi_disasm_add_fmin_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7726 {
7727     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
7728     static const char *abs1_0[] = {
7729         "", ""
7730     };
7731     static const char *abs1_1[] = {
7732         "", ".abs"
7733     };
7734     const char *abs1 = ordering ? abs1_1[(_BITS(bits, 6, 1) << 0)] : abs1_0[(_BITS(bits, 6, 1) << 0)];
7735     static const char *abs0_0[] = {
7736         "", ".abs"
7737     };
7738     static const char *abs0_1[] = {
7739         ".abs", ".abs"
7740     };
7741     const char *abs0 = ordering ? abs0_1[(_BITS(bits, 6, 1) << 0)] : abs0_0[(_BITS(bits, 6, 1) << 0)];
7742     static const char *neg0_table[] = {
7743         "", ".neg"
7744     };
7745 
7746     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
7747 
7748     static const char *neg1_table[] = {
7749         "", ".neg"
7750     };
7751 
7752     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
7753 
7754     static const char *swz0_table[] = {
7755         ".h00", ".h10", "", ".h11"
7756     };
7757 
7758     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
7759 
7760     static const char *swz1_table[] = {
7761         ".h00", ".h10", "", ".h11"
7762     };
7763 
7764     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
7765 
7766     static const char *sem_table[] = {
7767         "", ".nan_propagate", ".c", ".inverse_c"
7768     };
7769 
7770     const char *sem = sem_table[_BITS(bits, 13, 2)];
7771 
7772     fputs("+FMIN.v2f16", fp);
7773     fputs(sem, fp);
7774     fputs(" ", fp);
7775     bi_disasm_dest_add(fp, next_regs, last);
7776     fputs(", ", fp);
7777     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7778     fputs(abs0, fp);
7779     fputs(neg0, fp);
7780     fputs(swz0, fp);
7781     fputs(", ", fp);
7782     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7783     fputs(abs1, fp);
7784     fputs(neg1, fp);
7785     fputs(swz1, fp);
7786     fputs("\n", fp);
7787 }
7788 
7789 static void
bi_disasm_add_lea_tex(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7790 bi_disasm_add_lea_tex(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7791 {
7792     static const char *format_table[] = {
7793         ".u16", ".u32"
7794     };
7795 
7796     const char *format = format_table[_BITS(bits, 11, 1)];
7797 
7798     fputs("+LEA_TEX", fp);
7799     fputs(format, fp);
7800     fputs(" ", fp);
7801     bi_disasm_dest_add(fp, next_regs, last);
7802     fputs(", ", fp);
7803     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7804     fputs(", ", fp);
7805     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7806     fputs(", ", fp);
7807     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
7808     fprintf(fp, ", @r%u", staging_register);
7809     fputs("\n", fp);
7810 }
7811 
7812 static void
bi_disasm_add_ld_attr_imm_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7813 bi_disasm_add_ld_attr_imm_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7814 {
7815     static const char *register_format_table[] = {
7816         ".auto"
7817     };
7818     const char *register_format = register_format_table[0];
7819     static const char *vecsize_table[] = {
7820         "", ".v2", ".v3", ".v4"
7821     };
7822 
7823     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
7824 
7825     fputs("+LD_ATTR_IMM", fp);
7826     fputs(register_format, fp);
7827     fputs(vecsize, fp);
7828     fputs(" ", fp);
7829     bi_disasm_dest_add(fp, next_regs, last);
7830     fputs(", ", fp);
7831     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7832     fputs(", ", fp);
7833     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7834     fprintf(fp, ", attribute_index:%u", _BITS(bits, 6, 4));
7835     fprintf(fp, ", @r%u", staging_register);
7836     fputs("\n", fp);
7837 }
7838 
7839 static void
bi_disasm_add_branch_i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7840 bi_disasm_add_branch_i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7841 {
7842     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
7843     static const char *widen0_0[] = {
7844         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7845     };
7846     static const char *widen0_1[] = {
7847         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h1", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7848     };
7849     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
7850     static const char *cmpf_0[] = {
7851         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".eq", ".ne", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7852     };
7853     static const char *cmpf_1[] = {
7854         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".ne", ".ne", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7855     };
7856     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
7857     static const char *widen1_0[] = {
7858         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7859     };
7860     static const char *widen1_1[] = {
7861         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".h0", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
7862     };
7863     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
7864     fputs("+BRANCH.i16", fp);
7865     fputs(cmpf, fp);
7866     fputs(" ", fp);
7867     bi_disasm_dest_add(fp, next_regs, last);
7868     fputs(", ", fp);
7869     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7870     fputs(widen0, fp);
7871     fputs(", ", fp);
7872     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7873     fputs(widen1, fp);
7874     fputs(", ", fp);
7875     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
7876     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
7877     fputs("\n", fp);
7878 }
7879 
7880 static void
bi_disasm_fma_lshift_xor_v2i16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7881 bi_disasm_fma_lshift_xor_v2i16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7882 {
7883     static const char *lanes2_table[] = {
7884         ".reserved", ".b01", ".b23", ""
7885     };
7886     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
7887     static const char *not_result_table[] = {
7888         "", ".not"
7889     };
7890 
7891     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
7892 
7893     fputs("*LSHIFT_XOR.v2i16", fp);
7894     fputs(not_result, fp);
7895     fputs(" ", fp);
7896     bi_disasm_dest_fma(fp, next_regs, last);
7897     fputs(", ", fp);
7898     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7899     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7900     fputs(", ", fp);
7901     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7902     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7903     fputs(", ", fp);
7904     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
7905     fputs(lanes2, fp);
7906     fputs("\n", fp);
7907 }
7908 
7909 static void
bi_disasm_fma_mkvec_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7910 bi_disasm_fma_mkvec_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7911 {
7912     static const char *lane0_table[] = {
7913         "", ".h1"
7914     };
7915 
7916     const char *lane0 = lane0_table[_BITS(bits, 6, 1)];
7917 
7918     static const char *lane1_table[] = {
7919         "", ".h1"
7920     };
7921 
7922     const char *lane1 = lane1_table[_BITS(bits, 7, 1)];
7923 
7924     fputs("*MKVEC.v2i16", fp);
7925     fputs(" ", fp);
7926     bi_disasm_dest_fma(fp, next_regs, last);
7927     fputs(", ", fp);
7928     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
7929     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
7930     fputs(lane0, fp);
7931     fputs(", ", fp);
7932     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
7933     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
7934     fputs(lane1, fp);
7935     fputs("\n", fp);
7936 }
7937 
7938 static void
bi_disasm_add_axchg_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7939 bi_disasm_add_axchg_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7940 {
7941     static const char *seg_table[] = {
7942         "", ".wgl"
7943     };
7944 
7945     const char *seg = seg_table[_BITS(bits, 9, 1)];
7946 
7947     fputs("+AXCHG.i64", fp);
7948     fputs(seg, fp);
7949     fputs(" ", fp);
7950     bi_disasm_dest_add(fp, next_regs, last);
7951     fputs(", ", fp);
7952     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7953     fputs(", ", fp);
7954     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7955     fprintf(fp, ", @r%u", staging_register);
7956     fputs("\n", fp);
7957 }
7958 
7959 static void
bi_disasm_add_logb_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7960 bi_disasm_add_logb_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7961 {
7962     static const char *swz0_table[] = {
7963         ".h00", ".h10", "", ".h11"
7964     };
7965 
7966     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
7967 
7968     fputs("+LOGB.v2f16", fp);
7969     fputs(" ", fp);
7970     bi_disasm_dest_add(fp, next_regs, last);
7971     fputs(", ", fp);
7972     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7973     fputs(swz0, fp);
7974     fputs("\n", fp);
7975 }
7976 
7977 static void
bi_disasm_add_iadd_u32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)7978 bi_disasm_add_iadd_u32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
7979 {
7980     static const char *lanes1_table[] = {
7981         ".reserved", ".h0", ".reserved", ".h1"
7982     };
7983     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
7984     static const char *saturate_table[] = {
7985         "", ".sat"
7986     };
7987 
7988     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
7989 
7990     fputs("+IADD.u32", fp);
7991     fputs(saturate, fp);
7992     fputs(" ", fp);
7993     bi_disasm_dest_add(fp, next_regs, last);
7994     fputs(", ", fp);
7995     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
7996     fputs(", ", fp);
7997     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
7998     fputs(lanes1, fp);
7999     fputs("\n", fp);
8000 }
8001 
8002 static void
bi_disasm_add_fpclass_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8003 bi_disasm_add_fpclass_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8004 {
8005     static const char *lane0_table[] = {
8006         "", ".h1"
8007     };
8008 
8009     const char *lane0 = lane0_table[_BITS(bits, 3, 1)];
8010 
8011     fputs("+FPCLASS.f16", fp);
8012     fputs(" ", fp);
8013     bi_disasm_dest_add(fp, next_regs, last);
8014     fputs(", ", fp);
8015     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8016     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8017     fputs(lane0, fp);
8018     fputs("\n", fp);
8019 }
8020 
8021 static void
bi_disasm_add_isub_v4u8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8022 bi_disasm_add_isub_v4u8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8023 {
8024     static const char *lanes1_table[] = {
8025         ".reserved", ".b0000", ".reserved", ".b1111", ".reserved", ".b2222", ".reserved", ".b3333"
8026     };
8027     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
8028     static const char *lanes0_table[] = {
8029         ".reserved", "", ".reserved", "", ".reserved", "", ".reserved", ""
8030     };
8031     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 2) << 1)];
8032     static const char *saturate_table[] = {
8033         "", ".sat"
8034     };
8035 
8036     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
8037 
8038     fputs("+ISUB.v4u8", fp);
8039     fputs(saturate, fp);
8040     fputs(" ", fp);
8041     bi_disasm_dest_add(fp, next_regs, last);
8042     fputs(", ", fp);
8043     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8044     fputs(lanes0, fp);
8045     fputs(", ", fp);
8046     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8047     fputs(lanes1, fp);
8048     fputs("\n", fp);
8049 }
8050 
8051 static void
bi_disasm_add_fpow_sc_det_f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8052 bi_disasm_add_fpow_sc_det_f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8053 {
8054     static const char *func_table[] = {
8055         ".pown", ".rootn"
8056     };
8057     const char *func = func_table[(_BITS(bits, 8, 1) << 0)];
8058     static const char *lane1_table[] = {
8059         "", ""
8060     };
8061     const char *lane1 = lane1_table[(_BITS(bits, 8, 1) << 0)];
8062     static const char *lane0_table[] = {
8063         "", ".h1"
8064     };
8065 
8066     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
8067 
8068     fputs("+FPOW_SC_DET.f16", fp);
8069     fputs(func, fp);
8070     fputs(" ", fp);
8071     bi_disasm_dest_add(fp, next_regs, last);
8072     fputs(", ", fp);
8073     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8074     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8075     fputs(lane0, fp);
8076     fputs(", ", fp);
8077     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8078     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8079     fputs(lane1, fp);
8080     fputs("\n", fp);
8081 }
8082 
8083 static void
bi_disasm_add_lea_attr_imm_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8084 bi_disasm_add_lea_attr_imm_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8085 {
8086     static const char *register_format_table[] = {
8087         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
8088     };
8089     const char *register_format = register_format_table[(_BITS(bits, 11, 3) << 0)];
8090     fputs("+LEA_ATTR_IMM", fp);
8091     fputs(register_format, fp);
8092     fputs(" ", fp);
8093     bi_disasm_dest_add(fp, next_regs, last);
8094     fputs(", ", fp);
8095     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8096     fputs(", ", fp);
8097     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8098     fprintf(fp, ", attribute_index:%u", _BITS(bits, 6, 4));
8099     fprintf(fp, ", @r%u", staging_register);
8100     fputs("\n", fp);
8101 }
8102 
8103 static void
bi_disasm_add_flogd_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8104 bi_disasm_add_flogd_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8105 {
8106     fputs("+FLOGD.f32", fp);
8107     fputs(" ", fp);
8108     bi_disasm_dest_add(fp, next_regs, last);
8109     fputs(", ", fp);
8110     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8111     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8112     fputs("\n", fp);
8113 }
8114 
8115 static void
bi_disasm_add_ld_attr_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8116 bi_disasm_add_ld_attr_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8117 {
8118     static const char *register_format_table[] = {
8119         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
8120     };
8121     const char *register_format = register_format_table[(_BITS(bits, 13, 3) << 0)];
8122     static const char *vecsize_table[] = {
8123         "", ".v2", ".v3", ".v4"
8124     };
8125 
8126     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
8127 
8128     fputs("+LD_ATTR", fp);
8129     fputs(register_format, fp);
8130     fputs(vecsize, fp);
8131     fputs(" ", fp);
8132     bi_disasm_dest_add(fp, next_regs, last);
8133     fputs(", ", fp);
8134     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8135     fputs(", ", fp);
8136     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8137     fputs(", ", fp);
8138     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
8139     fprintf(fp, ", @r%u", staging_register);
8140     fputs("\n", fp);
8141 }
8142 
8143 static void
bi_disasm_add_iabs_v2s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8144 bi_disasm_add_iabs_v2s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8145 {
8146     static const char *swz0_table[] = {
8147         ".h00", ".h10", "", ".h11"
8148     };
8149 
8150     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
8151 
8152     fputs("+IABS.v2s16", fp);
8153     fputs(" ", fp);
8154     bi_disasm_dest_add(fp, next_regs, last);
8155     fputs(", ", fp);
8156     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8157     fputs(swz0, fp);
8158     fputs("\n", fp);
8159 }
8160 
8161 static void
bi_disasm_add_isub_v2u16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8162 bi_disasm_add_isub_v2u16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8163 {
8164     static const char *lanes1_table[] = {
8165         ".reserved", ".h00", ".reserved", ".h11"
8166     };
8167     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
8168     static const char *lanes0_table[] = {
8169         ".reserved", "", ".reserved", ""
8170     };
8171     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
8172     static const char *saturate_table[] = {
8173         "", ".sat"
8174     };
8175 
8176     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
8177 
8178     fputs("+ISUB.v2u16", fp);
8179     fputs(saturate, fp);
8180     fputs(" ", fp);
8181     bi_disasm_dest_add(fp, next_regs, last);
8182     fputs(", ", fp);
8183     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8184     fputs(lanes0, fp);
8185     fputs(", ", fp);
8186     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8187     fputs(lanes1, fp);
8188     fputs("\n", fp);
8189 }
8190 
8191 static void
bi_disasm_add_axchg_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8192 bi_disasm_add_axchg_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8193 {
8194     static const char *seg_table[] = {
8195         "", ".wgl"
8196     };
8197 
8198     const char *seg = seg_table[_BITS(bits, 9, 1)];
8199 
8200     fputs("+AXCHG.i32", fp);
8201     fputs(seg, fp);
8202     fputs(" ", fp);
8203     bi_disasm_dest_add(fp, next_regs, last);
8204     fputs(", ", fp);
8205     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8206     fputs(", ", fp);
8207     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8208     fprintf(fp, ", @r%u", staging_register);
8209     fputs("\n", fp);
8210 }
8211 
8212 static void
bi_disasm_add_iadd_v4u8_2(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8213 bi_disasm_add_iadd_v4u8_2(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8214 {
8215     static const char *lanes1_table[] = {
8216         ".reserved", ".b0101", ".reserved", ".b2323"
8217     };
8218     const char *lanes1 = lanes1_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
8219     static const char *lanes0_table[] = {
8220         ".reserved", "", ".reserved", ""
8221     };
8222     const char *lanes0 = lanes0_table[(_BITS(bits, 7, 1) << 0) | (_BITS(bits, 9, 1) << 1)];
8223     static const char *saturate_table[] = {
8224         "", ".sat"
8225     };
8226 
8227     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
8228 
8229     fputs("+IADD.v4u8", fp);
8230     fputs(saturate, fp);
8231     fputs(" ", fp);
8232     bi_disasm_dest_add(fp, next_regs, last);
8233     fputs(", ", fp);
8234     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8235     fputs(lanes0, fp);
8236     fputs(", ", fp);
8237     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8238     fputs(lanes1, fp);
8239     fputs("\n", fp);
8240 }
8241 
8242 static void
bi_disasm_add_f16_to_u32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8243 bi_disasm_add_f16_to_u32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8244 {
8245     static const char *round_table[] = {
8246         "", ".rtp", ".rtn", ".rtz"
8247     };
8248     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
8249     static const char *lane0_table[] = {
8250         "", ".h1"
8251     };
8252 
8253     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
8254 
8255     fputs("+F16_TO_U32", fp);
8256     fputs(round, fp);
8257     fputs(" ", fp);
8258     bi_disasm_dest_add(fp, next_regs, last);
8259     fputs(", ", fp);
8260     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8261     fputs(lane0, fp);
8262     fputs("\n", fp);
8263 }
8264 
8265 static void
bi_disasm_add_flog_table_f32_3(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8266 bi_disasm_add_flog_table_f32_3(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8267 {
8268     static const char *divzero_table[] = {
8269         "", "", "", ""
8270     };
8271     const char *divzero = divzero_table[(_BITS(bits, 5, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
8272     static const char *mode_table[] = {
8273         ".base2", ".natural", ".base2", ".natural"
8274     };
8275     const char *mode = mode_table[(_BITS(bits, 5, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
8276     static const char *precision_table[] = {
8277         "", "", "", ""
8278     };
8279     const char *precision = precision_table[(_BITS(bits, 5, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
8280     static const char *widen0_table[] = {
8281         ".h0", ".h0", ".h1", ".h1"
8282     };
8283     const char *widen0 = widen0_table[(_BITS(bits, 5, 1) << 0) | (_BITS(bits, 7, 1) << 1)];
8284     static const char *neg_table[] = {
8285         "", ".neg"
8286     };
8287 
8288     const char *neg = neg_table[_BITS(bits, 3, 1)];
8289 
8290     static const char *abs0_table[] = {
8291         "", ".abs0"
8292     };
8293 
8294     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
8295 
8296     fputs("+FLOG_TABLE.f32", fp);
8297     fputs(mode, fp);
8298     fputs(precision, fp);
8299     fputs(neg, fp);
8300     fputs(divzero, fp);
8301     fputs(" ", fp);
8302     bi_disasm_dest_add(fp, next_regs, last);
8303     fputs(", ", fp);
8304     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8305     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8306     fputs(widen0, fp);
8307     fputs(abs0, fp);
8308     fputs("\n", fp);
8309 }
8310 
8311 static void
bi_disasm_fma_jump_ex(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8312 bi_disasm_fma_jump_ex(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8313 {
8314     static const char *test_mode_table[] = {
8315         "", ".nz"
8316     };
8317 
8318     const char *test_mode = test_mode_table[_BITS(bits, 9, 1)];
8319 
8320     static const char *stack_mode_table[] = {
8321         ".return", ".call", "", ".replace"
8322     };
8323 
8324     const char *stack_mode = stack_mode_table[_BITS(bits, 10, 2)];
8325 
8326     fputs("*JUMP_EX", fp);
8327     fputs(test_mode, fp);
8328     fputs(stack_mode, fp);
8329     fputs(" ", fp);
8330     bi_disasm_dest_fma(fp, next_regs, last);
8331     fputs(", ", fp);
8332     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8333     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8334     fputs(", ", fp);
8335     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
8336     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8337     fputs(", ", fp);
8338     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
8339     fputs("\n", fp);
8340 }
8341 
8342 static void
bi_disasm_add_u32_to_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8343 bi_disasm_add_u32_to_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8344 {
8345     static const char *round_table[] = {
8346         ".rtna"
8347     };
8348     const char *round = round_table[0];
8349     fputs("+U32_TO_F32", fp);
8350     fputs(round, fp);
8351     fputs(" ", fp);
8352     bi_disasm_dest_add(fp, next_regs, last);
8353     fputs(", ", fp);
8354     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8355     fputs("\n", fp);
8356 }
8357 
8358 static void
bi_disasm_add_isub_s32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8359 bi_disasm_add_isub_s32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8360 {
8361     static const char *lanes1_table[] = {
8362         ".h0", ".h1"
8363     };
8364     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 1) << 0)];
8365     static const char *saturate_table[] = {
8366         "", ".sat"
8367     };
8368 
8369     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
8370 
8371     fputs("+ISUB.s32", fp);
8372     fputs(saturate, fp);
8373     fputs(" ", fp);
8374     bi_disasm_dest_add(fp, next_regs, last);
8375     fputs(", ", fp);
8376     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8377     fputs(", ", fp);
8378     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8379     fputs(lanes1, fp);
8380     fputs("\n", fp);
8381 }
8382 
8383 static void
bi_disasm_add_frcp_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8384 bi_disasm_add_frcp_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8385 {
8386     static const char *widen0_table[] = {
8387         "", ".reserved"
8388     };
8389     const char *widen0 = widen0_table[(_BITS(bits, 6, 1) << 0)];
8390     static const char *neg_table[] = {
8391         "", ".neg"
8392     };
8393 
8394     const char *neg = neg_table[_BITS(bits, 3, 1)];
8395 
8396     static const char *abs0_table[] = {
8397         "", ".abs0"
8398     };
8399 
8400     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
8401 
8402     fputs("+FRCP.f32", fp);
8403     fputs(neg, fp);
8404     fputs(" ", fp);
8405     bi_disasm_dest_add(fp, next_regs, last);
8406     fputs(", ", fp);
8407     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8408     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8409     fputs(widen0, fp);
8410     fputs(abs0, fp);
8411     fputs("\n", fp);
8412 }
8413 
8414 static void
bi_disasm_add_frcbrt_approx_c_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8415 bi_disasm_add_frcbrt_approx_c_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8416 {
8417     fputs("+FRCBRT_APPROX_C.f32", fp);
8418     fputs(" ", fp);
8419     bi_disasm_dest_add(fp, next_regs, last);
8420     fputs(", ", fp);
8421     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8422     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8423     fputs("\n", fp);
8424 }
8425 
8426 static void
bi_disasm_fma_atom_c_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8427 bi_disasm_fma_atom_c_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8428 {
8429     static const char *atom_opc_table[] = {
8430         ".reserved", ".reserved", ".aadd", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".asmin", ".asmax", ".aumin", ".aumax", ".aand", ".aor", ".axor", ".reserved"
8431     };
8432 
8433     const char *atom_opc = atom_opc_table[_BITS(bits, 9, 4)];
8434 
8435     fputs("*ATOM_C.i32", fp);
8436     fputs(atom_opc, fp);
8437     fputs(" ", fp);
8438     bi_disasm_dest_fma(fp, next_regs, last);
8439     fputs(", ", fp);
8440     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8441     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8442     fputs(", ", fp);
8443     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
8444     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8445     fputs(", ", fp);
8446     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
8447     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
8448     fputs("\n", fp);
8449 }
8450 
8451 static void
bi_disasm_add_ilogb_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8452 bi_disasm_add_ilogb_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8453 {
8454     static const char *swz0_table[] = {
8455         ".h00", ".h10", "", ".h11"
8456     };
8457 
8458     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
8459 
8460     fputs("+ILOGB.v2f16", fp);
8461     fputs(" ", fp);
8462     bi_disasm_dest_add(fp, next_regs, last);
8463     fputs(", ", fp);
8464     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8465     fputs(swz0, fp);
8466     fputs("\n", fp);
8467 }
8468 
8469 static void
bi_disasm_add_fmax_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8470 bi_disasm_add_fmax_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8471 {
8472     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
8473     static const char *abs1_0[] = {
8474         "", ""
8475     };
8476     static const char *abs1_1[] = {
8477         "", ".abs"
8478     };
8479     const char *abs1 = ordering ? abs1_1[(_BITS(bits, 6, 1) << 0)] : abs1_0[(_BITS(bits, 6, 1) << 0)];
8480     static const char *abs0_0[] = {
8481         "", ".abs"
8482     };
8483     static const char *abs0_1[] = {
8484         ".abs", ".abs"
8485     };
8486     const char *abs0 = ordering ? abs0_1[(_BITS(bits, 6, 1) << 0)] : abs0_0[(_BITS(bits, 6, 1) << 0)];
8487     static const char *neg0_table[] = {
8488         "", ".neg"
8489     };
8490 
8491     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
8492 
8493     static const char *neg1_table[] = {
8494         "", ".neg"
8495     };
8496 
8497     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
8498 
8499     static const char *swz0_table[] = {
8500         ".h00", ".h10", "", ".h11"
8501     };
8502 
8503     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
8504 
8505     static const char *swz1_table[] = {
8506         ".h00", ".h10", "", ".h11"
8507     };
8508 
8509     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
8510 
8511     static const char *sem_table[] = {
8512         "", ".nan_propagate", ".c", ".inverse_c"
8513     };
8514 
8515     const char *sem = sem_table[_BITS(bits, 13, 2)];
8516 
8517     fputs("+FMAX.v2f16", fp);
8518     fputs(sem, fp);
8519     fputs(" ", fp);
8520     bi_disasm_dest_add(fp, next_regs, last);
8521     fputs(", ", fp);
8522     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8523     fputs(abs0, fp);
8524     fputs(neg0, fp);
8525     fputs(swz0, fp);
8526     fputs(", ", fp);
8527     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8528     fputs(abs1, fp);
8529     fputs(neg1, fp);
8530     fputs(swz1, fp);
8531     fputs("\n", fp);
8532 }
8533 
8534 static void
bi_disasm_fma_flshift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8535 bi_disasm_fma_flshift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8536 {
8537     static const char *bytes2_table[] = {
8538         "", ".bytes2"
8539     };
8540 
8541     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
8542 
8543     static const char *lane2_table[] = {
8544         "", ".b2"
8545     };
8546 
8547     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
8548 
8549     fputs("*FLSHIFT_DOUBLE.i32", fp);
8550     fputs(" ", fp);
8551     bi_disasm_dest_fma(fp, next_regs, last);
8552     fputs(", ", fp);
8553     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8554     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8555     fputs(", ", fp);
8556     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
8557     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8558     fputs(", ", fp);
8559     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
8560     fputs(bytes2, fp);
8561     fputs(lane2, fp);
8562     fputs("\n", fp);
8563 }
8564 
8565 static void
bi_disasm_add_branchz_s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8566 bi_disasm_add_branchz_s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8567 {
8568     static const char *cmpf_table[] = {
8569         ".reserved", ".lt", ".lt", ".reserved", ".reserved", ".le", ".le", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
8570     };
8571     const char *cmpf = cmpf_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 9, 3) << 2)];
8572     static const char *widen0_table[] = {
8573         ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
8574     };
8575     const char *widen0 = widen0_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 9, 3) << 2)];
8576     fputs("+BRANCHZ.s16", fp);
8577     fputs(cmpf, fp);
8578     fputs(" ", fp);
8579     bi_disasm_dest_add(fp, next_regs, last);
8580     fputs(", ", fp);
8581     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8582     fputs(widen0, fp);
8583     fputs(", ", fp);
8584     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
8585     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
8586     fputs("\n", fp);
8587 }
8588 
8589 static void
bi_disasm_fma_clz_v2u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8590 bi_disasm_fma_clz_v2u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8591 {
8592     static const char *mask_table[] = {
8593         "", ".mask"
8594     };
8595 
8596     const char *mask = mask_table[_BITS(bits, 3, 1)];
8597 
8598     static const char *swz0_table[] = {
8599         ".h00", ".h10", "", ".h11"
8600     };
8601 
8602     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
8603 
8604     fputs("*CLZ.v2u16", fp);
8605     fputs(mask, fp);
8606     fputs(" ", fp);
8607     bi_disasm_dest_fma(fp, next_regs, last);
8608     fputs(", ", fp);
8609     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8610     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8611     fputs(swz0, fp);
8612     fputs("\n", fp);
8613 }
8614 
8615 static void
bi_disasm_add_frexpe_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8616 bi_disasm_add_frexpe_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8617 {
8618     static const char *log_table[] = {
8619         ""
8620     };
8621     const char *log = log_table[0];
8622     static const char *neg_table[] = {
8623         "", ".neg"
8624     };
8625 
8626     const char *neg = neg_table[_BITS(bits, 6, 1)];
8627 
8628     static const char *sqrt_table[] = {
8629         "", ".sqrt"
8630     };
8631 
8632     const char *sqrt = sqrt_table[_BITS(bits, 8, 1)];
8633 
8634     static const char *swz0_table[] = {
8635         ".h00", ".h10", "", ".h11"
8636     };
8637 
8638     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
8639 
8640     fputs("+FREXPE.v2f16", fp);
8641     fputs(neg, fp);
8642     fputs(sqrt, fp);
8643     fputs(log, fp);
8644     fputs(" ", fp);
8645     bi_disasm_dest_add(fp, next_regs, last);
8646     fputs(", ", fp);
8647     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8648     fputs(swz0, fp);
8649     fputs("\n", fp);
8650 }
8651 
8652 static void
bi_disasm_add_flog_table_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8653 bi_disasm_add_flog_table_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8654 {
8655     static const char *mode_table[] = {
8656         ".red", ".red"
8657     };
8658     const char *mode = mode_table[(_BITS(bits, 7, 1) << 0)];
8659     static const char *precision_table[] = {
8660         "", ""
8661     };
8662     const char *precision = precision_table[(_BITS(bits, 7, 1) << 0)];
8663     static const char *widen0_table[] = {
8664         ".h0", ".h1"
8665     };
8666     const char *widen0 = widen0_table[(_BITS(bits, 7, 1) << 0)];
8667     static const char *neg_table[] = {
8668         "", ".neg"
8669     };
8670 
8671     const char *neg = neg_table[_BITS(bits, 3, 1)];
8672 
8673     static const char *abs0_table[] = {
8674         "", ".abs0"
8675     };
8676 
8677     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
8678 
8679     static const char *divzero_table[] = {
8680         "", ".divzero"
8681     };
8682 
8683     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
8684 
8685     fputs("+FLOG_TABLE.f32", fp);
8686     fputs(mode, fp);
8687     fputs(precision, fp);
8688     fputs(neg, fp);
8689     fputs(divzero, fp);
8690     fputs(" ", fp);
8691     bi_disasm_dest_add(fp, next_regs, last);
8692     fputs(", ", fp);
8693     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8694     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8695     fputs(widen0, fp);
8696     fputs(abs0, fp);
8697     fputs("\n", fp);
8698 }
8699 
8700 static void
bi_disasm_fma_imul_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8701 bi_disasm_fma_imul_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8702 {
8703     static const char *replicate1_table[] = {
8704         ""
8705     };
8706     const char *replicate1 = replicate1_table[0];
8707     static const char *replicate0_table[] = {
8708         ""
8709     };
8710     const char *replicate0 = replicate0_table[0];
8711     fputs("*IMUL.v4i8", fp);
8712     fputs(" ", fp);
8713     bi_disasm_dest_fma(fp, next_regs, last);
8714     fputs(", ", fp);
8715     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8716     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8717     fputs(replicate0, fp);
8718     fputs(", ", fp);
8719     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
8720     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8721     fputs(replicate1, fp);
8722     fputs("\n", fp);
8723 }
8724 
8725 static void
bi_disasm_add_v2f16_to_v2s16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8726 bi_disasm_add_v2f16_to_v2s16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8727 {
8728     static const char *round_table[] = {
8729         ".rtna"
8730     };
8731     const char *round = round_table[0];
8732     static const char *swz0_table[] = {
8733         ".h00", ".h10", "", ".h11"
8734     };
8735 
8736     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
8737 
8738     fputs("+V2F16_TO_V2S16", fp);
8739     fputs(round, fp);
8740     fputs(" ", fp);
8741     bi_disasm_dest_add(fp, next_regs, last);
8742     fputs(", ", fp);
8743     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8744     fputs(swz0, fp);
8745     fputs("\n", fp);
8746 }
8747 
8748 static void
bi_disasm_add_fcmp_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8749 bi_disasm_add_fcmp_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8750 {
8751     static const char *neg0_table[] = {
8752         "", ".neg"
8753     };
8754     const char *neg0 = neg0_table[(_BITS(bits, 13, 1) << 0)];
8755     static const char *neg1_table[] = {
8756         "", ""
8757     };
8758     const char *neg1 = neg1_table[(_BITS(bits, 13, 1) << 0)];
8759     static const char *cmpf_table[] = {
8760         ".eq", ".gt", ".ge", ".ne", ".lt", ".le", ".gtlt", ".total"
8761     };
8762 
8763     const char *cmpf = cmpf_table[_BITS(bits, 6, 3)];
8764 
8765     static const char *swz0_table[] = {
8766         ".h00", ".h10", "", ".h11"
8767     };
8768 
8769     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
8770 
8771     static const char *swz1_table[] = {
8772         ".h00", ".h10", "", ".h11"
8773     };
8774 
8775     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
8776 
8777     static const char *result_type_table[] = {
8778         "", ".f1", ".m1", ".reserved"
8779     };
8780 
8781     const char *result_type = result_type_table[_BITS(bits, 14, 2)];
8782 
8783     fputs("+FCMP.v2f16", fp);
8784     fputs(cmpf, fp);
8785     fputs(result_type, fp);
8786     fputs(" ", fp);
8787     bi_disasm_dest_add(fp, next_regs, last);
8788     fputs(", ", fp);
8789     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8790     fputs(neg0, fp);
8791     fputs(swz0, fp);
8792     fputs(", ", fp);
8793     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8794     fputs(neg1, fp);
8795     fputs(swz1, fp);
8796     fputs("\n", fp);
8797 }
8798 
8799 static void
bi_disasm_fma_lshift_and_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8800 bi_disasm_fma_lshift_and_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8801 {
8802     static const char *lanes2_table[] = {
8803         ".b00", ".b11", ".b22", ".b33"
8804     };
8805     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
8806     static const char *not1_table[] = {
8807         "", ".not"
8808     };
8809 
8810     const char *not1 = not1_table[_BITS(bits, 14, 1)];
8811 
8812     static const char *not_result_table[] = {
8813         ".not", ""
8814     };
8815 
8816     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
8817 
8818     fputs("*LSHIFT_AND.v2i16", fp);
8819     fputs(not_result, fp);
8820     fputs(" ", fp);
8821     bi_disasm_dest_fma(fp, next_regs, last);
8822     fputs(", ", fp);
8823     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8824     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8825     fputs(", ", fp);
8826     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
8827     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
8828     fputs(not1, fp);
8829     fputs(", ", fp);
8830     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
8831     fputs(lanes2, fp);
8832     fputs("\n", fp);
8833 }
8834 
8835 static void
bi_disasm_fma_fround_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8836 bi_disasm_fma_fround_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8837 {
8838     static const char *round_table[] = {
8839         ".rtna"
8840     };
8841     const char *round = round_table[0];
8842     static const char *abs0_table[] = {
8843         "", ".abs0"
8844     };
8845 
8846     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
8847 
8848     static const char *neg0_table[] = {
8849         "", ".neg0"
8850     };
8851 
8852     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
8853 
8854     static const char *widen0_table[] = {
8855         ".reserved", "", ".h0", ".h1"
8856     };
8857 
8858     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
8859 
8860     fputs("*FROUND.f32", fp);
8861     fputs(round, fp);
8862     fputs(" ", fp);
8863     bi_disasm_dest_fma(fp, next_regs, last);
8864     fputs(", ", fp);
8865     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8866     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8867     fputs(abs0, fp);
8868     fputs(neg0, fp);
8869     fputs(widen0, fp);
8870     fputs("\n", fp);
8871 }
8872 
8873 static void
bi_disasm_add_branchz_u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8874 bi_disasm_add_branchz_u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8875 {
8876     static const char *cmpf_table[] = {
8877         ".reserved", ".lt", ".lt", ".reserved", ".reserved", ".le", ".le", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
8878     };
8879     const char *cmpf = cmpf_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 9, 3) << 2)];
8880     static const char *widen0_table[] = {
8881         ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".h1", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
8882     };
8883     const char *widen0 = widen0_table[(_BITS(bits, 4, 2) << 0) | (_BITS(bits, 9, 3) << 2)];
8884     fputs("+BRANCHZ.u16", fp);
8885     fputs(cmpf, fp);
8886     fputs(" ", fp);
8887     bi_disasm_dest_add(fp, next_regs, last);
8888     fputs(", ", fp);
8889     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8890     fputs(widen0, fp);
8891     fputs(", ", fp);
8892     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
8893     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
8894     fputs("\n", fp);
8895 }
8896 
8897 static void
bi_disasm_add_hadd_v2u16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8898 bi_disasm_add_hadd_v2u16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8899 {
8900     static const char *round_table[] = {
8901         ".rtn", ".rtp"
8902     };
8903 
8904     const char *round = round_table[_BITS(bits, 12, 1)];
8905 
8906     static const char *swap1_table[] = {
8907         "", ".h10"
8908     };
8909 
8910     const char *swap1 = swap1_table[_BITS(bits, 9, 1)];
8911 
8912     static const char *swap0_table[] = {
8913         "", ".h10"
8914     };
8915 
8916     const char *swap0 = swap0_table[_BITS(bits, 10, 1)];
8917 
8918     fputs("+HADD.v2u16", fp);
8919     fputs(round, fp);
8920     fputs(" ", fp);
8921     bi_disasm_dest_add(fp, next_regs, last);
8922     fputs(", ", fp);
8923     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8924     fputs(swap0, fp);
8925     fputs(", ", fp);
8926     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
8927     fputs(swap1, fp);
8928     fputs("\n", fp);
8929 }
8930 
8931 static void
bi_disasm_fma_fround_v2f16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8932 bi_disasm_fma_fround_v2f16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8933 {
8934     static const char *round_table[] = {
8935         ".rtna"
8936     };
8937     const char *round = round_table[0];
8938     static const char *abs0_table[] = {
8939         "", ".abs0"
8940     };
8941 
8942     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
8943 
8944     static const char *neg0_table[] = {
8945         "", ".neg0"
8946     };
8947 
8948     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
8949 
8950     static const char *swz0_table[] = {
8951         ".h00", ".h10", "", ".h11"
8952     };
8953 
8954     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
8955 
8956     fputs("*FROUND.v2f16", fp);
8957     fputs(round, fp);
8958     fputs(" ", fp);
8959     bi_disasm_dest_fma(fp, next_regs, last);
8960     fputs(", ", fp);
8961     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
8962     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8963     fputs(abs0, fp);
8964     fputs(neg0, fp);
8965     fputs(swz0, fp);
8966     fputs("\n", fp);
8967 }
8968 
8969 static void
bi_disasm_add_fsincos_offset_u6(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8970 bi_disasm_add_fsincos_offset_u6(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8971 {
8972     static const char *scale_table[] = {
8973         "", ".scale"
8974     };
8975 
8976     const char *scale = scale_table[_BITS(bits, 3, 1)];
8977 
8978     fputs("+FSINCOS_OFFSET.u6", fp);
8979     fputs(scale, fp);
8980     fputs(" ", fp);
8981     bi_disasm_dest_add(fp, next_regs, last);
8982     fputs(", ", fp);
8983     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
8984     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
8985     fputs("\n", fp);
8986 }
8987 
8988 static void
bi_disasm_fma_csel_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)8989 bi_disasm_fma_csel_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
8990 {
8991     static const char *cmpf_table[] = {
8992         ".reserved", ".reserved", ".reserved", ".eq", ".reserved", ".reserved", ".reserved", ".reserved"
8993     };
8994     const char *cmpf = cmpf_table[(_BITS(bits, 12, 3) << 0)];
8995     fputs("*CSEL.i32", fp);
8996     fputs(cmpf, fp);
8997     fputs(" ", fp);
8998     bi_disasm_dest_fma(fp, next_regs, last);
8999     fputs(", ", fp);
9000     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9001     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9002     fputs(", ", fp);
9003     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9004     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9005     fputs(", ", fp);
9006     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
9007     fputs(", ", fp);
9008     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
9009     fputs("\n", fp);
9010 }
9011 
9012 static void
bi_disasm_add_imov_fma(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9013 bi_disasm_add_imov_fma(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9014 {
9015     static const char *threads_table[] = {
9016         ".even", ""
9017     };
9018 
9019     const char *threads = threads_table[_BITS(bits, 3, 1)];
9020 
9021     fputs("+IMOV_FMA", fp);
9022     fputs(threads, fp);
9023     fputs(" ", fp);
9024     bi_disasm_dest_add(fp, next_regs, last);
9025     fputs("\n", fp);
9026 }
9027 
9028 static void
bi_disasm_fma_fma_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9029 bi_disasm_fma_fma_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9030 {
9031     static const char *neg0_table[] = {
9032         "", ""
9033     };
9034     const char *neg0 = neg0_table[(_BITS(bits, 17, 1) << 0)];
9035     static const char *neg1_table[] = {
9036         "", ".neg"
9037     };
9038     const char *neg1 = neg1_table[(_BITS(bits, 17, 1) << 0)];
9039     static const char *swz0_table[] = {
9040         ".h00", ".h10", "", ".h11"
9041     };
9042 
9043     const char *swz0 = swz0_table[_BITS(bits, 9, 2)];
9044 
9045     static const char *swz1_table[] = {
9046         ".h00", ".h10", "", ".h11"
9047     };
9048 
9049     const char *swz1 = swz1_table[_BITS(bits, 11, 2)];
9050 
9051     static const char *round_table[] = {
9052         "", ".rtp", ".rtn", ".rtz"
9053     };
9054 
9055     const char *round = round_table[_BITS(bits, 13, 2)];
9056 
9057     static const char *clamp_table[] = {
9058         "", ".clamp_0_inf", ".clamp_m1_1", ".clamp_0_1"
9059     };
9060 
9061     const char *clamp = clamp_table[_BITS(bits, 15, 2)];
9062 
9063     static const char *neg2_table[] = {
9064         "", ".neg"
9065     };
9066 
9067     const char *neg2 = neg2_table[_BITS(bits, 18, 1)];
9068 
9069     static const char *swz2_table[] = {
9070         ".h00", ".h10", "", ".h11"
9071     };
9072 
9073     const char *swz2 = swz2_table[_BITS(bits, 19, 2)];
9074 
9075     fputs("*FMA.v2f16", fp);
9076     fputs(round, fp);
9077     fputs(clamp, fp);
9078     fputs(" ", fp);
9079     bi_disasm_dest_fma(fp, next_regs, last);
9080     fputs(", ", fp);
9081     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9082     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9083     fputs(neg0, fp);
9084     fputs(swz0, fp);
9085     fputs(", ", fp);
9086     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9087     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9088     fputs(neg1, fp);
9089     fputs(swz1, fp);
9090     fputs(", ", fp);
9091     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
9092     fputs(neg2, fp);
9093     fputs(swz2, fp);
9094     fputs("\n", fp);
9095 }
9096 
9097 static void
bi_disasm_add_wmask(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9098 bi_disasm_add_wmask(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9099 {
9100     static const char *subgroup_table[] = {
9101         ".subgroup2", ".subgroup4", ".subgroup8", ".reserved"
9102     };
9103 
9104     const char *subgroup = subgroup_table[_BITS(bits, 4, 2)];
9105 
9106     fputs("+WMASK", fp);
9107     fputs(subgroup, fp);
9108     fputs(" ", fp);
9109     bi_disasm_dest_add(fp, next_regs, last);
9110     fputs(", ", fp);
9111     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9112     fprintf(fp, ", fill:%u", _BITS(bits, 3, 1));
9113     fputs("\n", fp);
9114 }
9115 
9116 static void
bi_disasm_add_kaboom(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9117 bi_disasm_add_kaboom(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9118 {
9119     fputs("+KABOOM", fp);
9120     fputs(" ", fp);
9121     bi_disasm_dest_add(fp, next_regs, last);
9122     fputs(", ", fp);
9123     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9124     fputs("\n", fp);
9125 }
9126 
9127 static void
bi_disasm_fma_rshift_xor_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9128 bi_disasm_fma_rshift_xor_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9129 {
9130     static const char *lane2_table[] = {
9131         "", ".b1", ".b2", ".b3"
9132     };
9133 
9134     const char *lane2 = lane2_table[_BITS(bits, 9, 2)];
9135 
9136     static const char *not_result_table[] = {
9137         "", ".not"
9138     };
9139 
9140     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
9141 
9142     fputs("*RSHIFT_XOR.i32", fp);
9143     fputs(not_result, fp);
9144     fputs(" ", fp);
9145     bi_disasm_dest_fma(fp, next_regs, last);
9146     fputs(", ", fp);
9147     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9148     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9149     fputs(", ", fp);
9150     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9151     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9152     fputs(", ", fp);
9153     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
9154     fputs(lane2, fp);
9155     fputs("\n", fp);
9156 }
9157 
9158 static void
bi_disasm_fma_fcmp_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9159 bi_disasm_fma_fcmp_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9160 {
9161     static const char *widen0_table[] = {
9162         "", "", "", ".h0", ".h0", ".h1", ".h0", ".h1"
9163     };
9164     const char *widen0 = widen0_table[(_BITS(bits, 9, 3) << 0)];
9165     static const char *widen1_table[] = {
9166         "", ".h0", ".h1", ".h0", ".h1", ".h1", "", ""
9167     };
9168     const char *widen1 = widen1_table[(_BITS(bits, 9, 3) << 0)];
9169     static const char *abs1_table[] = {
9170         "", ".abs"
9171     };
9172 
9173     const char *abs1 = abs1_table[_BITS(bits, 6, 1)];
9174 
9175     static const char *neg0_table[] = {
9176         "", ".neg"
9177     };
9178 
9179     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
9180 
9181     static const char *neg1_table[] = {
9182         "", ".neg"
9183     };
9184 
9185     const char *neg1 = neg1_table[_BITS(bits, 8, 1)];
9186 
9187     static const char *abs0_table[] = {
9188         "", ".abs"
9189     };
9190 
9191     const char *abs0 = abs0_table[_BITS(bits, 12, 1)];
9192 
9193     static const char *cmpf_table[] = {
9194         ".eq", ".gt", ".ge", ".ne", ".lt", ".le", ".gtlt", ".total"
9195     };
9196 
9197     const char *cmpf = cmpf_table[_BITS(bits, 13, 3)];
9198 
9199     static const char *result_type_table[] = {
9200         "", ".f1", ".m1", ".reserved"
9201     };
9202 
9203     const char *result_type = result_type_table[_BITS(bits, 16, 2)];
9204 
9205     fputs("*FCMP.f32", fp);
9206     fputs(cmpf, fp);
9207     fputs(result_type, fp);
9208     fputs(" ", fp);
9209     bi_disasm_dest_fma(fp, next_regs, last);
9210     fputs(", ", fp);
9211     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9212     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9213     fputs(widen0, fp);
9214     fputs(neg0, fp);
9215     fputs(abs0, fp);
9216     fputs(", ", fp);
9217     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9218     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9219     fputs(widen1, fp);
9220     fputs(abs1, fp);
9221     fputs(neg1, fp);
9222     fputs("\n", fp);
9223 }
9224 
9225 static void
bi_disasm_add_fsin_table_u6(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9226 bi_disasm_add_fsin_table_u6(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9227 {
9228     static const char *offset_table[] = {
9229         "", ".offset"
9230     };
9231 
9232     const char *offset = offset_table[_BITS(bits, 4, 1)];
9233 
9234     fputs("+FSIN_TABLE.u6", fp);
9235     fputs(offset, fp);
9236     fputs(" ", fp);
9237     bi_disasm_dest_add(fp, next_regs, last);
9238     fputs(", ", fp);
9239     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9240     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9241     fputs("\n", fp);
9242 }
9243 
9244 static void
bi_disasm_add_frcbrt_approx_a_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9245 bi_disasm_add_frcbrt_approx_a_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9246 {
9247     static const char *widen0_table[] = {
9248         ""
9249     };
9250     const char *widen0 = widen0_table[0];
9251     static const char *neg_table[] = {
9252         "", ".neg"
9253     };
9254 
9255     const char *neg = neg_table[_BITS(bits, 3, 1)];
9256 
9257     static const char *abs0_table[] = {
9258         "", ".abs0"
9259     };
9260 
9261     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
9262 
9263     static const char *divzero_table[] = {
9264         "", ".divzero"
9265     };
9266 
9267     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
9268 
9269     fputs("+FRCBRT_APPROX_A.f32", fp);
9270     fputs(neg, fp);
9271     fputs(divzero, fp);
9272     fputs(" ", fp);
9273     bi_disasm_dest_add(fp, next_regs, last);
9274     fputs(", ", fp);
9275     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9276     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9277     fputs(widen0, fp);
9278     fputs(abs0, fp);
9279     fputs("\n", fp);
9280 }
9281 
9282 static void
bi_disasm_fma_fmul_slice_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9283 bi_disasm_fma_fmul_slice_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9284 {
9285     fputs("*FMUL_SLICE.f32", fp);
9286     fputs(" ", fp);
9287     bi_disasm_dest_fma(fp, next_regs, last);
9288     fputs(", ", fp);
9289     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9290     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9291     fputs(", ", fp);
9292     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9293     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9294     fputs("\n", fp);
9295 }
9296 
9297 static void
bi_disasm_add_store_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9298 bi_disasm_add_store_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9299 {
9300     static const char *seg_table[] = {
9301         ".reserved", "", ".wgl", ".stream", ".reserved", ".reserved", ".reserved", ".tl"
9302     };
9303 
9304     const char *seg = seg_table[_BITS(bits, 6, 3)];
9305 
9306     fputs("+STORE.i64", fp);
9307     fputs(seg, fp);
9308     fputs(" ", fp);
9309     bi_disasm_dest_add(fp, next_regs, last);
9310     fputs(", ", fp);
9311     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9312     fputs(", ", fp);
9313     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9314     fprintf(fp, ", @r%u", staging_register);
9315     fputs("\n", fp);
9316 }
9317 
9318 static void
bi_disasm_add_isub_s32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9319 bi_disasm_add_isub_s32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9320 {
9321     static const char *lanes1_table[] = {
9322         ""
9323     };
9324     const char *lanes1 = lanes1_table[0];
9325     static const char *saturate_table[] = {
9326         "", ".sat"
9327     };
9328 
9329     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
9330 
9331     fputs("+ISUB.s32", fp);
9332     fputs(saturate, fp);
9333     fputs(" ", fp);
9334     bi_disasm_dest_add(fp, next_regs, last);
9335     fputs(", ", fp);
9336     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9337     fputs(", ", fp);
9338     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9339     fputs(lanes1, fp);
9340     fputs("\n", fp);
9341 }
9342 
9343 static void
bi_disasm_fma_atom_c1_return_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9344 bi_disasm_fma_atom_c1_return_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9345 {
9346     static const char *atom_opc_table[] = {
9347         ".ainc", ".adec", ".aumax1", ".asmax1", ".aor1", ".reserved", ".reserved", ".reserved"
9348     };
9349 
9350     const char *atom_opc = atom_opc_table[_BITS(bits, 6, 3)];
9351 
9352     fputs("*ATOM_C1_RETURN.i64", fp);
9353     fputs(atom_opc, fp);
9354     fputs(" ", fp);
9355     bi_disasm_dest_fma(fp, next_regs, last);
9356     fputs(", ", fp);
9357     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9358     if (!(0xf3 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9359     fputs(", ", fp);
9360     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9361     if (!(0xf3 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9362     fputs("\n", fp);
9363 }
9364 
9365 static void
bi_disasm_add_mux_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9366 bi_disasm_add_mux_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9367 {
9368     static const char *mux_table[] = {
9369         ".neg", "", ".fp_zero", ".bit"
9370     };
9371 
9372     const char *mux = mux_table[_BITS(bits, 9, 2)];
9373 
9374     fputs("+MUX.i32", fp);
9375     fputs(mux, fp);
9376     fputs(" ", fp);
9377     bi_disasm_dest_add(fp, next_regs, last);
9378     fputs(", ", fp);
9379     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9380     fputs(", ", fp);
9381     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9382     fputs(", ", fp);
9383     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
9384     fputs("\n", fp);
9385 }
9386 
9387 static void
bi_disasm_add_fadd_rscale_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9388 bi_disasm_add_fadd_rscale_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9389 {
9390     static const char *clamp_table[] = {
9391         "", ".reserved", ".clamp_0_1", "", "", "", "", ""
9392     };
9393     const char *clamp = clamp_table[(_BITS(bits, 9, 3) << 0)];
9394     static const char *round_table[] = {
9395         "", ".reserved", "", ".rtna", "", ".rtp", ".rtn", ".rtz"
9396     };
9397     const char *round = round_table[(_BITS(bits, 9, 3) << 0)];
9398     static const char *special_table[] = {
9399         "", ".reserved", "", ".n", ".n", ".n", ".n", ".n"
9400     };
9401     const char *special = special_table[(_BITS(bits, 9, 3) << 0)];
9402     static const char *abs1_table[] = {
9403         "", ".abs"
9404     };
9405 
9406     const char *abs1 = abs1_table[_BITS(bits, 12, 1)];
9407 
9408     static const char *neg0_table[] = {
9409         "", ".neg"
9410     };
9411 
9412     const char *neg0 = neg0_table[_BITS(bits, 13, 1)];
9413 
9414     static const char *neg1_table[] = {
9415         "", ".neg"
9416     };
9417 
9418     const char *neg1 = neg1_table[_BITS(bits, 14, 1)];
9419 
9420     static const char *abs0_table[] = {
9421         "", ".abs"
9422     };
9423 
9424     const char *abs0 = abs0_table[_BITS(bits, 16, 1)];
9425 
9426     fputs("+FADD_RSCALE.f32", fp);
9427     fputs(clamp, fp);
9428     fputs(special, fp);
9429     fputs(round, fp);
9430     fputs(" ", fp);
9431     bi_disasm_dest_add(fp, next_regs, last);
9432     fputs(", ", fp);
9433     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9434     fputs(neg0, fp);
9435     fputs(abs0, fp);
9436     fputs(", ", fp);
9437     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9438     fputs(abs1, fp);
9439     fputs(neg1, fp);
9440     fputs(", ", fp);
9441     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
9442     fputs("\n", fp);
9443 }
9444 
9445 static void
bi_disasm_add_load_i128(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9446 bi_disasm_add_load_i128(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9447 {
9448     static const char *seg_table[] = {
9449         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
9450     };
9451 
9452     const char *seg = seg_table[_BITS(bits, 6, 3)];
9453 
9454     fputs("+LOAD.i128", fp);
9455     fputs(seg, fp);
9456     fputs(" ", fp);
9457     bi_disasm_dest_add(fp, next_regs, last);
9458     fputs(", ", fp);
9459     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9460     fputs(", ", fp);
9461     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9462     fprintf(fp, ", @r%u", staging_register);
9463     fputs("\n", fp);
9464 }
9465 
9466 static void
bi_disasm_add_shift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9467 bi_disasm_add_shift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9468 {
9469     fputs("+SHIFT_DOUBLE.i32", fp);
9470     fputs(" ", fp);
9471     bi_disasm_dest_add(fp, next_regs, last);
9472     fputs(", ", fp);
9473     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9474     fputs(", ", fp);
9475     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9476     fputs(", ", fp);
9477     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
9478     fputs("\n", fp);
9479 }
9480 
9481 static void
bi_disasm_add_hadd_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9482 bi_disasm_add_hadd_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9483 {
9484     static const char *round_table[] = {
9485         ".rtn", ".rtp"
9486     };
9487 
9488     const char *round = round_table[_BITS(bits, 12, 1)];
9489 
9490     fputs("+HADD.u32", fp);
9491     fputs(round, fp);
9492     fputs(" ", fp);
9493     bi_disasm_dest_add(fp, next_regs, last);
9494     fputs(", ", fp);
9495     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9496     fputs(", ", fp);
9497     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9498     fputs("\n", fp);
9499 }
9500 
9501 static void
bi_disasm_fma_lshift_xor_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9502 bi_disasm_fma_lshift_xor_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9503 {
9504     static const char *lanes2_table[] = {
9505         ".b0000", ".b1111", ".b2222", ".b3333"
9506     };
9507     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
9508     static const char *not_result_table[] = {
9509         "", ".not"
9510     };
9511 
9512     const char *not_result = not_result_table[_BITS(bits, 13, 1)];
9513 
9514     fputs("*LSHIFT_XOR.v4i8", fp);
9515     fputs(not_result, fp);
9516     fputs(" ", fp);
9517     bi_disasm_dest_fma(fp, next_regs, last);
9518     fputs(", ", fp);
9519     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9520     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9521     fputs(", ", fp);
9522     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
9523     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9524     fputs(", ", fp);
9525     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
9526     fputs(lanes2, fp);
9527     fputs("\n", fp);
9528 }
9529 
9530 static void
bi_disasm_add_iabs_v4s8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9531 bi_disasm_add_iabs_v4s8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9532 {
9533     fputs("+IABS.v4s8", fp);
9534     fputs(" ", fp);
9535     bi_disasm_dest_add(fp, next_regs, last);
9536     fputs(", ", fp);
9537     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9538     fputs("\n", fp);
9539 }
9540 
9541 static void
bi_disasm_fma_s8_to_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9542 bi_disasm_fma_s8_to_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9543 {
9544     static const char *lane0_table[] = {
9545         "", ".b1", ".b2", ".b3"
9546     };
9547 
9548     const char *lane0 = lane0_table[_BITS(bits, 4, 2)];
9549 
9550     fputs("*S8_TO_S32", fp);
9551     fputs(" ", fp);
9552     bi_disasm_dest_fma(fp, next_regs, last);
9553     fputs(", ", fp);
9554     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9555     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9556     fputs(lane0, fp);
9557     fputs("\n", fp);
9558 }
9559 
9560 static void
bi_disasm_add_frcbrt_approx_a_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9561 bi_disasm_add_frcbrt_approx_a_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9562 {
9563     static const char *widen0_table[] = {
9564         ".h0", ".h1"
9565     };
9566     const char *widen0 = widen0_table[(_BITS(bits, 7, 1) << 0)];
9567     static const char *neg_table[] = {
9568         "", ".neg"
9569     };
9570 
9571     const char *neg = neg_table[_BITS(bits, 3, 1)];
9572 
9573     static const char *abs0_table[] = {
9574         "", ".abs0"
9575     };
9576 
9577     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
9578 
9579     static const char *divzero_table[] = {
9580         "", ".divzero"
9581     };
9582 
9583     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
9584 
9585     fputs("+FRCBRT_APPROX_A.f32", fp);
9586     fputs(neg, fp);
9587     fputs(divzero, fp);
9588     fputs(" ", fp);
9589     bi_disasm_dest_add(fp, next_regs, last);
9590     fputs(", ", fp);
9591     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9592     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9593     fputs(widen0, fp);
9594     fputs(abs0, fp);
9595     fputs("\n", fp);
9596 }
9597 
9598 static void
bi_disasm_fma_frexpm_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9599 bi_disasm_fma_frexpm_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9600 {
9601     static const char *sqrt_table[] = {
9602         ""
9603     };
9604     const char *sqrt = sqrt_table[0];
9605     static const char *log_table[] = {
9606         ".log"
9607     };
9608     const char *log = log_table[0];
9609     static const char *abs0_table[] = {
9610         "", ".abs0"
9611     };
9612 
9613     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
9614 
9615     static const char *widen0_table[] = {
9616         ".reserved", "", ".h0", ".h1"
9617     };
9618 
9619     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
9620 
9621     static const char *neg0_table[] = {
9622         "", ".neg0"
9623     };
9624 
9625     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
9626 
9627     fputs("*FREXPM.f32", fp);
9628     fputs(sqrt, fp);
9629     fputs(log, fp);
9630     fputs(" ", fp);
9631     bi_disasm_dest_fma(fp, next_regs, last);
9632     fputs(", ", fp);
9633     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9634     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9635     fputs(abs0, fp);
9636     fputs(widen0, fp);
9637     fputs(neg0, fp);
9638     fputs("\n", fp);
9639 }
9640 
9641 static void
bi_disasm_add_hadd_v4u8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9642 bi_disasm_add_hadd_v4u8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9643 {
9644     static const char *round_table[] = {
9645         ".rtn", ".rtp"
9646     };
9647 
9648     const char *round = round_table[_BITS(bits, 12, 1)];
9649 
9650     fputs("+HADD.v4u8", fp);
9651     fputs(round, fp);
9652     fputs(" ", fp);
9653     bi_disasm_dest_add(fp, next_regs, last);
9654     fputs(", ", fp);
9655     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9656     fputs(", ", fp);
9657     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9658     fputs("\n", fp);
9659 }
9660 
9661 static void
bi_disasm_add_fexp_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9662 bi_disasm_add_fexp_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9663 {
9664     fputs("+FEXP.f32", fp);
9665     fputs(" ", fp);
9666     bi_disasm_dest_add(fp, next_regs, last);
9667     fputs(", ", fp);
9668     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9669     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9670     fputs(", ", fp);
9671     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9672     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9673     fputs("\n", fp);
9674 }
9675 
9676 static void
bi_disasm_add_cube_ssel(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9677 bi_disasm_add_cube_ssel(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9678 {
9679     static const char *neg0_table[] = {
9680         "", ".neg"
9681     };
9682     const char *neg0 = neg0_table[(_BITS(bits, 9, 1) << 0)];
9683     static const char *neg1_table[] = {
9684         "", ".neg"
9685     };
9686     const char *neg1 = neg1_table[(_BITS(bits, 9, 1) << 0)];
9687     fputs("+CUBE_SSEL", fp);
9688     fputs(" ", fp);
9689     bi_disasm_dest_add(fp, next_regs, last);
9690     fputs(", ", fp);
9691     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9692     fputs(neg0, fp);
9693     fputs(", ", fp);
9694     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9695     fputs(neg1, fp);
9696     fputs(", ", fp);
9697     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
9698     fputs("\n", fp);
9699 }
9700 
9701 static void
bi_disasm_add_v2f16_to_v2u16_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9702 bi_disasm_add_v2f16_to_v2u16_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9703 {
9704     static const char *round_table[] = {
9705         ".rtna"
9706     };
9707     const char *round = round_table[0];
9708     static const char *swz0_table[] = {
9709         ".h00", ".h10", "", ".h11"
9710     };
9711 
9712     const char *swz0 = swz0_table[_BITS(bits, 4, 2)];
9713 
9714     fputs("+V2F16_TO_V2U16", fp);
9715     fputs(round, fp);
9716     fputs(" ", fp);
9717     bi_disasm_dest_add(fp, next_regs, last);
9718     fputs(", ", fp);
9719     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9720     fputs(swz0, fp);
9721     fputs("\n", fp);
9722 }
9723 
9724 static void
bi_disasm_add_branch_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9725 bi_disasm_add_branch_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9726 {
9727     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
9728     static const char *widen0_0[] = {
9729         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved"
9730     };
9731     static const char *widen0_1[] = {
9732         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", "", "", ".reserved"
9733     };
9734     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
9735     static const char *cmpf_0[] = {
9736         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".ne", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".eq", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".lt", ".lt", ".reserved"
9737     };
9738     static const char *cmpf_1[] = {
9739         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".ne", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".reserved", ".reserved", ".reserved", ".reserved", ".eq", ".eq", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".lt", ".lt", ".reserved"
9740     };
9741     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
9742     static const char *widen1_0[] = {
9743         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved"
9744     };
9745     static const char *widen1_1[] = {
9746         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", "", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved"
9747     };
9748     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
9749     fputs("+BRANCH.f32", fp);
9750     fputs(cmpf, fp);
9751     fputs(" ", fp);
9752     bi_disasm_dest_add(fp, next_regs, last);
9753     fputs(", ", fp);
9754     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9755     fputs(widen0, fp);
9756     fputs(", ", fp);
9757     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9758     fputs(widen1, fp);
9759     fputs(", ", fp);
9760     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
9761     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
9762     fputs("\n", fp);
9763 }
9764 
9765 static void
bi_disasm_add_fatan_assist_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9766 bi_disasm_add_fatan_assist_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9767 {
9768     static const char *lane1_table[] = {
9769         "", ".h1"
9770     };
9771 
9772     const char *lane1 = lane1_table[_BITS(bits, 6, 1)];
9773 
9774     static const char *lane0_table[] = {
9775         "", ".h1"
9776     };
9777 
9778     const char *lane0 = lane0_table[_BITS(bits, 7, 1)];
9779 
9780     fputs("+FATAN_ASSIST.f16", fp);
9781     fputs(" ", fp);
9782     bi_disasm_dest_add(fp, next_regs, last);
9783     fputs(", ", fp);
9784     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9785     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9786     fputs(lane0, fp);
9787     fputs(", ", fp);
9788     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9789     if (!(0xf7 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
9790     fputs(lane1, fp);
9791     fputs("\n", fp);
9792 }
9793 
9794 static void
bi_disasm_fma_frexpe_f32_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9795 bi_disasm_fma_frexpe_f32_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9796 {
9797     static const char *sqrt_table[] = {
9798         ""
9799     };
9800     const char *sqrt = sqrt_table[0];
9801     static const char *log_table[] = {
9802         ".log"
9803     };
9804     const char *log = log_table[0];
9805     static const char *neg_table[] = {
9806         ""
9807     };
9808     const char *neg = neg_table[0];
9809     static const char *widen0_table[] = {
9810         ".reserved", "", ".h0", ".h1"
9811     };
9812 
9813     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
9814 
9815     fputs("*FREXPE.f32", fp);
9816     fputs(neg, fp);
9817     fputs(sqrt, fp);
9818     fputs(log, fp);
9819     fputs(" ", fp);
9820     bi_disasm_dest_fma(fp, next_regs, last);
9821     fputs(", ", fp);
9822     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9823     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9824     fputs(widen0, fp);
9825     fputs("\n", fp);
9826 }
9827 
9828 static void
bi_disasm_add_icmp_v4s8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9829 bi_disasm_add_icmp_v4s8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9830 {
9831     static const char *cmpf_table[] = {
9832         ".gt", ".ge"
9833     };
9834     const char *cmpf = cmpf_table[(_BITS(bits, 6, 1) << 0)];
9835     static const char *result_type_table[] = {
9836         "", ".m1"
9837     };
9838 
9839     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
9840 
9841     fputs("+ICMP.v4s8", fp);
9842     fputs(result_type, fp);
9843     fputs(cmpf, fp);
9844     fputs(" ", fp);
9845     bi_disasm_dest_add(fp, next_regs, last);
9846     fputs(", ", fp);
9847     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9848     fputs(", ", fp);
9849     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9850     fputs("\n", fp);
9851 }
9852 
9853 static void
bi_disasm_add_iadd_v4s8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9854 bi_disasm_add_iadd_v4s8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9855 {
9856     static const char *lanes1_table[] = {
9857         ""
9858     };
9859     const char *lanes1 = lanes1_table[0];
9860     static const char *lanes0_table[] = {
9861         ""
9862     };
9863     const char *lanes0 = lanes0_table[0];
9864     static const char *saturate_table[] = {
9865         "", ".sat"
9866     };
9867 
9868     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
9869 
9870     fputs("+IADD.v4s8", fp);
9871     fputs(saturate, fp);
9872     fputs(" ", fp);
9873     bi_disasm_dest_add(fp, next_regs, last);
9874     fputs(", ", fp);
9875     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9876     fputs(lanes0, fp);
9877     fputs(", ", fp);
9878     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9879     fputs(lanes1, fp);
9880     fputs("\n", fp);
9881 }
9882 
9883 static void
bi_disasm_add_acmpxchg_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9884 bi_disasm_add_acmpxchg_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9885 {
9886     static const char *seg_table[] = {
9887         "", ".wgl"
9888     };
9889 
9890     const char *seg = seg_table[_BITS(bits, 9, 1)];
9891 
9892     fputs("+ACMPXCHG.i64", fp);
9893     fputs(seg, fp);
9894     fputs(" ", fp);
9895     bi_disasm_dest_add(fp, next_regs, last);
9896     fputs(", ", fp);
9897     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9898     fputs(", ", fp);
9899     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
9900     fprintf(fp, ", @r%u", staging_register);
9901     fputs("\n", fp);
9902 }
9903 
9904 static void
bi_disasm_add_frcp_approx_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9905 bi_disasm_add_frcp_approx_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9906 {
9907     static const char *widen0_table[] = {
9908         ""
9909     };
9910     const char *widen0 = widen0_table[0];
9911     static const char *neg_table[] = {
9912         "", ".neg"
9913     };
9914 
9915     const char *neg = neg_table[_BITS(bits, 3, 1)];
9916 
9917     static const char *abs0_table[] = {
9918         "", ".abs0"
9919     };
9920 
9921     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
9922 
9923     static const char *divzero_table[] = {
9924         "", ".divzero"
9925     };
9926 
9927     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
9928 
9929     fputs("+FRCP_APPROX.f32", fp);
9930     fputs(neg, fp);
9931     fputs(divzero, fp);
9932     fputs(" ", fp);
9933     bi_disasm_dest_add(fp, next_regs, last);
9934     fputs(", ", fp);
9935     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9936     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9937     fputs(widen0, fp);
9938     fputs(abs0, fp);
9939     fputs("\n", fp);
9940 }
9941 
9942 static void
bi_disasm_add_u32_to_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9943 bi_disasm_add_u32_to_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9944 {
9945     static const char *round_table[] = {
9946         "", ".rtp", ".rtn", ".rtz"
9947     };
9948     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
9949     fputs("+U32_TO_F32", fp);
9950     fputs(round, fp);
9951     fputs(" ", fp);
9952     bi_disasm_dest_add(fp, next_regs, last);
9953     fputs(", ", fp);
9954     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
9955     fputs("\n", fp);
9956 }
9957 
9958 static void
bi_disasm_fma_fround_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9959 bi_disasm_fma_fround_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9960 {
9961     static const char *round_table[] = {
9962         "", ".rtp", ".rtn", ".rtz"
9963     };
9964     const char *round = round_table[(_BITS(bits, 9, 2) << 0)];
9965     static const char *abs0_table[] = {
9966         "", ".abs0"
9967     };
9968 
9969     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
9970 
9971     static const char *neg0_table[] = {
9972         "", ".neg0"
9973     };
9974 
9975     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
9976 
9977     static const char *widen0_table[] = {
9978         ".reserved", "", ".h0", ".h1"
9979     };
9980 
9981     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
9982 
9983     fputs("*FROUND.f32", fp);
9984     fputs(round, fp);
9985     fputs(" ", fp);
9986     bi_disasm_dest_fma(fp, next_regs, last);
9987     fputs(", ", fp);
9988     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
9989     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
9990     fputs(abs0, fp);
9991     fputs(neg0, fp);
9992     fputs(widen0, fp);
9993     fputs("\n", fp);
9994 }
9995 
9996 static void
bi_disasm_add_load_i96(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)9997 bi_disasm_add_load_i96(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
9998 {
9999     static const char *seg_table[] = {
10000         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
10001     };
10002 
10003     const char *seg = seg_table[_BITS(bits, 6, 3)];
10004 
10005     fputs("+LOAD.i96", fp);
10006     fputs(seg, fp);
10007     fputs(" ", fp);
10008     bi_disasm_dest_add(fp, next_regs, last);
10009     fputs(", ", fp);
10010     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10011     fputs(", ", fp);
10012     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10013     fprintf(fp, ", @r%u", staging_register);
10014     fputs("\n", fp);
10015 }
10016 
10017 static void
bi_disasm_add_branchz_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10018 bi_disasm_add_branchz_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10019 {
10020     static const char *cmpf_table[] = {
10021         ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ne", ".eq", ".ge", ".gt", ".le", ".lt"
10022     };
10023     const char *cmpf = cmpf_table[(_BITS(bits, 3, 1) << 0) | (_BITS(bits, 9, 3) << 1)];
10024     fputs("+BRANCHZ.f32", fp);
10025     fputs(cmpf, fp);
10026     fputs(" ", fp);
10027     bi_disasm_dest_add(fp, next_regs, last);
10028     fputs(", ", fp);
10029     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10030     fputs(", ", fp);
10031     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
10032     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
10033     fputs("\n", fp);
10034 }
10035 
10036 static void
bi_disasm_fma_fma_rscale_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10037 bi_disasm_fma_fma_rscale_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10038 {
10039     static const char *neg0_table[] = {
10040         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
10041     };
10042     const char *neg0 = neg0_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
10043     static const char *neg1_table[] = {
10044         "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg", "", ".neg"
10045     };
10046     const char *neg1 = neg1_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
10047     static const char *clamp_table[] = {
10048         "", "", ".clamp_0_inf", ".clamp_0_inf", ".clamp_m1_1", ".clamp_m1_1", ".clamp_0_1", ".clamp_0_1", "", "", "", "", "", "", "", ""
10049     };
10050     const char *clamp = clamp_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
10051     static const char *round_table[] = {
10052         "", "", "", "", "", "", "", "", "", "", ".rtz", ".rtz", "", "", "", ""
10053     };
10054     const char *round = round_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
10055     static const char *special_table[] = {
10056         "", "", "", "", "", "", "", "", ".n", ".n", ".n", ".n", ".scale16", ".scale16", ".left", ".left"
10057     };
10058     const char *special = special_table[(_BITS(bits, 16, 1) << 0) | (_BITS(bits, 12, 3) << 1)];
10059     static const char *abs0_table[] = {
10060         "", ".abs"
10061     };
10062 
10063     const char *abs0 = abs0_table[_BITS(bits, 15, 1)];
10064 
10065     static const char *neg2_table[] = {
10066         "", ".neg"
10067     };
10068 
10069     const char *neg2 = neg2_table[_BITS(bits, 17, 1)];
10070 
10071     fputs("*FMA_RSCALE.f32", fp);
10072     fputs(round, fp);
10073     fputs(clamp, fp);
10074     fputs(special, fp);
10075     fputs(" ", fp);
10076     bi_disasm_dest_fma(fp, next_regs, last);
10077     fputs(", ", fp);
10078     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10079     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10080     fputs(neg0, fp);
10081     fputs(abs0, fp);
10082     fputs(", ", fp);
10083     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10084     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10085     fputs(neg1, fp);
10086     fputs(", ", fp);
10087     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
10088     fputs(neg2, fp);
10089     fputs(", ", fp);
10090     dump_src(fp, _BITS(bits, 9, 3), *srcs, consts, true);
10091     fputs("\n", fp);
10092 }
10093 
10094 static void
bi_disasm_add_icmp_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10095 bi_disasm_add_icmp_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10096 {
10097     static const char *result_type_table[] = {
10098         "", ".m1"
10099     };
10100 
10101     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
10102 
10103     static const char *cmpf_table[] = {
10104         ".eq", ".ne"
10105     };
10106 
10107     const char *cmpf = cmpf_table[_BITS(bits, 6, 1)];
10108 
10109     fputs("+ICMP.i32", fp);
10110     fputs(result_type, fp);
10111     fputs(cmpf, fp);
10112     fputs(" ", fp);
10113     bi_disasm_dest_add(fp, next_regs, last);
10114     fputs(", ", fp);
10115     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10116     fputs(", ", fp);
10117     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10118     fputs("\n", fp);
10119 }
10120 
10121 static void
bi_disasm_fma_fround_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10122 bi_disasm_fma_fround_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10123 {
10124     static const char *round_table[] = {
10125         "", ".rtp", ".rtn", ".rtz"
10126     };
10127     const char *round = round_table[(_BITS(bits, 9, 2) << 0)];
10128     static const char *abs0_table[] = {
10129         "", ".abs0"
10130     };
10131 
10132     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
10133 
10134     static const char *neg0_table[] = {
10135         "", ".neg0"
10136     };
10137 
10138     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
10139 
10140     static const char *swz0_table[] = {
10141         ".h00", ".h10", "", ".h11"
10142     };
10143 
10144     const char *swz0 = swz0_table[_BITS(bits, 3, 2)];
10145 
10146     fputs("*FROUND.v2f16", fp);
10147     fputs(round, fp);
10148     fputs(" ", fp);
10149     bi_disasm_dest_fma(fp, next_regs, last);
10150     fputs(", ", fp);
10151     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10152     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10153     fputs(abs0, fp);
10154     fputs(neg0, fp);
10155     fputs(swz0, fp);
10156     fputs("\n", fp);
10157 }
10158 
10159 static void
bi_disasm_fma_clz_v4u8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10160 bi_disasm_fma_clz_v4u8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10161 {
10162     static const char *mask_table[] = {
10163         "", ".mask"
10164     };
10165 
10166     const char *mask = mask_table[_BITS(bits, 3, 1)];
10167 
10168     fputs("*CLZ.v4u8", fp);
10169     fputs(mask, fp);
10170     fputs(" ", fp);
10171     bi_disasm_dest_fma(fp, next_regs, last);
10172     fputs(", ", fp);
10173     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10174     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10175     fputs("\n", fp);
10176 }
10177 
10178 static void
bi_disasm_add_load_i32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10179 bi_disasm_add_load_i32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10180 {
10181     static const char *extend_table[] = {
10182         ""
10183     };
10184     const char *extend = extend_table[0];
10185     static const char *lane_table[] = {
10186         ""
10187     };
10188     const char *lane = lane_table[0];
10189     static const char *seg_table[] = {
10190         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
10191     };
10192 
10193     const char *seg = seg_table[_BITS(bits, 6, 3)];
10194 
10195     fputs("+LOAD.i32", fp);
10196     fputs(seg, fp);
10197     fputs(lane, fp);
10198     fputs(extend, fp);
10199     fputs(" ", fp);
10200     bi_disasm_dest_add(fp, next_regs, last);
10201     fputs(", ", fp);
10202     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10203     fputs(", ", fp);
10204     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10205     fprintf(fp, ", @r%u", staging_register);
10206     fputs("\n", fp);
10207 }
10208 
10209 static void
bi_disasm_add_branch_s16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10210 bi_disasm_add_branch_s16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10211 {
10212     bool ordering = (_BITS(bits, 0, 3) > _BITS(bits, 3, 3));
10213     static const char *cmpf_0[] = {
10214         ".reserved", ".lt", ".lt", ".reserved", ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".le", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".ge", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".gt", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10215     };
10216     static const char *cmpf_1[] = {
10217         ".reserved", ".reserved", ".reserved", ".reserved", ".lt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".le", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".ge", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".gt", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10218     };
10219     const char *cmpf = ordering ? cmpf_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : cmpf_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
10220     static const char *widen0_0[] = {
10221         ".reserved", ".h0", ".h1", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10222     };
10223     static const char *widen0_1[] = {
10224         ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h1", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10225     };
10226     const char *widen0 = ordering ? widen0_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen0_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
10227     static const char *widen1_0[] = {
10228         ".reserved", ".h0", ".h1", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".h1", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10229     };
10230     static const char *widen1_1[] = {
10231         ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".h0", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved", ".reserved"
10232     };
10233     const char *widen1 = ordering ? widen1_1[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)] : widen1_0[(_BITS(bits, 12, 3) << 0) | (_BITS(bits, 9, 3) << 3)];
10234     fputs("+BRANCH.s16", fp);
10235     fputs(cmpf, fp);
10236     fputs(" ", fp);
10237     bi_disasm_dest_add(fp, next_regs, last);
10238     fputs(", ", fp);
10239     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10240     fputs(widen0, fp);
10241     fputs(", ", fp);
10242     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10243     fputs(widen1, fp);
10244     fputs(", ", fp);
10245     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
10246     if (!(0xf7 & (1 << _BITS(bits, 6, 3)))) fputs("(INVALID)", fp);
10247     fputs("\n", fp);
10248 }
10249 
10250 static void
bi_disasm_add_mux_v2i16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10251 bi_disasm_add_mux_v2i16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10252 {
10253     static const char *mux_table[] = {
10254         ".neg", "", ".fp_zero", ".bit"
10255     };
10256 
10257     const char *mux = mux_table[_BITS(bits, 9, 2)];
10258 
10259     static const char *swap2_table[] = {
10260         "", ".h10"
10261     };
10262 
10263     const char *swap2 = swap2_table[_BITS(bits, 11, 1)];
10264 
10265     static const char *swap1_table[] = {
10266         "", ".h10"
10267     };
10268 
10269     const char *swap1 = swap1_table[_BITS(bits, 12, 1)];
10270 
10271     static const char *swap0_table[] = {
10272         "", ".h10"
10273     };
10274 
10275     const char *swap0 = swap0_table[_BITS(bits, 13, 1)];
10276 
10277     fputs("+MUX.v2i16", fp);
10278     fputs(mux, fp);
10279     fputs(" ", fp);
10280     bi_disasm_dest_add(fp, next_regs, last);
10281     fputs(", ", fp);
10282     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10283     fputs(swap0, fp);
10284     fputs(", ", fp);
10285     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10286     fputs(swap1, fp);
10287     fputs(", ", fp);
10288     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
10289     fputs(swap2, fp);
10290     fputs("\n", fp);
10291 }
10292 
10293 static void
bi_disasm_add_atom_cx(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10294 bi_disasm_add_atom_cx(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10295 {
10296     fputs("+ATOM_CX", fp);
10297     fputs(" ", fp);
10298     bi_disasm_dest_add(fp, next_regs, last);
10299     fputs(", ", fp);
10300     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10301     fputs(", ", fp);
10302     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10303     fputs(", ", fp);
10304     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
10305     fprintf(fp, ", @r%u", staging_register);
10306     fputs("\n", fp);
10307 }
10308 
10309 static void
bi_disasm_fma_imuld(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10310 bi_disasm_fma_imuld(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10311 {
10312     static const char *threads_table[] = {
10313         ".even", ""
10314     };
10315 
10316     const char *threads = threads_table[_BITS(bits, 6, 1)];
10317 
10318     fputs("*IMULD", fp);
10319     fputs(threads, fp);
10320     fputs(" ", fp);
10321     bi_disasm_dest_fma(fp, next_regs, last);
10322     fputs(", ", fp);
10323     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10324     if (!(0x33 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10325     fputs(", ", fp);
10326     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10327     if (!(0x33 & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10328     fputs("\n", fp);
10329 }
10330 
10331 static void
bi_disasm_fma_shaddxl_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10332 bi_disasm_fma_shaddxl_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10333 {
10334     fputs("*SHADDXL.i64", fp);
10335     fputs(" ", fp);
10336     bi_disasm_dest_fma(fp, next_regs, last);
10337     fputs(", ", fp);
10338     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10339     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10340     fputs(", ", fp);
10341     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10342     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10343     fprintf(fp, ", shift:%u", _BITS(bits, 6, 3));
10344     fputs("\n", fp);
10345 }
10346 
10347 static void
bi_disasm_add_acmpstore_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10348 bi_disasm_add_acmpstore_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10349 {
10350     static const char *seg_table[] = {
10351         "", ".wgl"
10352     };
10353 
10354     const char *seg = seg_table[_BITS(bits, 9, 1)];
10355 
10356     fputs("+ACMPSTORE.i32", fp);
10357     fputs(seg, fp);
10358     fputs(" ", fp);
10359     bi_disasm_dest_add(fp, next_regs, last);
10360     fputs(", ", fp);
10361     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10362     fputs(", ", fp);
10363     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10364     fprintf(fp, ", @r%u", staging_register);
10365     fputs("\n", fp);
10366 }
10367 
10368 static void
bi_disasm_add_u16_to_u32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10369 bi_disasm_add_u16_to_u32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10370 {
10371     static const char *lane0_table[] = {
10372         "", ".h1"
10373     };
10374 
10375     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
10376 
10377     fputs("+U16_TO_U32", fp);
10378     fputs(" ", fp);
10379     bi_disasm_dest_add(fp, next_regs, last);
10380     fputs(", ", fp);
10381     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10382     fputs(lane0, fp);
10383     fputs("\n", fp);
10384 }
10385 
10386 static void
bi_disasm_add_s16_to_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10387 bi_disasm_add_s16_to_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10388 {
10389     static const char *lane0_table[] = {
10390         "", ".h1"
10391     };
10392 
10393     const char *lane0 = lane0_table[_BITS(bits, 4, 1)];
10394 
10395     fputs("+S16_TO_S32", fp);
10396     fputs(" ", fp);
10397     bi_disasm_dest_add(fp, next_regs, last);
10398     fputs(", ", fp);
10399     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10400     fputs(lane0, fp);
10401     fputs("\n", fp);
10402 }
10403 
10404 static void
bi_disasm_fma_lshift_or_v2i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10405 bi_disasm_fma_lshift_or_v2i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10406 {
10407     static const char *lanes2_table[] = {
10408         ".b00", ".b11", ".b22", ".b33"
10409     };
10410     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
10411     static const char *not1_table[] = {
10412         ".not", ""
10413     };
10414 
10415     const char *not1 = not1_table[_BITS(bits, 14, 1)];
10416 
10417     static const char *not_result_table[] = {
10418         "", ".not"
10419     };
10420 
10421     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
10422 
10423     fputs("*LSHIFT_OR.v2i16", fp);
10424     fputs(not_result, fp);
10425     fputs(" ", fp);
10426     bi_disasm_dest_fma(fp, next_regs, last);
10427     fputs(", ", fp);
10428     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10429     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10430     fputs(", ", fp);
10431     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10432     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10433     fputs(not1, fp);
10434     fputs(", ", fp);
10435     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
10436     fputs(lanes2, fp);
10437     fputs("\n", fp);
10438 }
10439 
10440 static void
bi_disasm_fma_rshift_and_v4i8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10441 bi_disasm_fma_rshift_and_v4i8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10442 {
10443     static const char *lanes2_table[] = {
10444         ".b0000", ".b1111", ".b2222", ".b3333"
10445     };
10446     const char *lanes2 = lanes2_table[(_BITS(bits, 9, 2) << 0)];
10447     static const char *not1_table[] = {
10448         "", ".not"
10449     };
10450 
10451     const char *not1 = not1_table[_BITS(bits, 14, 1)];
10452 
10453     static const char *not_result_table[] = {
10454         ".not", ""
10455     };
10456 
10457     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
10458 
10459     fputs("*RSHIFT_AND.v4i8", fp);
10460     fputs(not_result, fp);
10461     fputs(" ", fp);
10462     bi_disasm_dest_fma(fp, next_regs, last);
10463     fputs(", ", fp);
10464     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10465     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10466     fputs(", ", fp);
10467     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10468     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10469     fputs(not1, fp);
10470     fputs(", ", fp);
10471     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
10472     fputs(lanes2, fp);
10473     fputs("\n", fp);
10474 }
10475 
10476 static void
bi_disasm_add_isub_v4s8_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10477 bi_disasm_add_isub_v4s8_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10478 {
10479     static const char *lanes1_table[] = {
10480         ""
10481     };
10482     const char *lanes1 = lanes1_table[0];
10483     static const char *lanes0_table[] = {
10484         ""
10485     };
10486     const char *lanes0 = lanes0_table[0];
10487     static const char *saturate_table[] = {
10488         "", ".sat"
10489     };
10490 
10491     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
10492 
10493     fputs("+ISUB.v4s8", fp);
10494     fputs(saturate, fp);
10495     fputs(" ", fp);
10496     bi_disasm_dest_add(fp, next_regs, last);
10497     fputs(", ", fp);
10498     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10499     fputs(lanes0, fp);
10500     fputs(", ", fp);
10501     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10502     fputs(lanes1, fp);
10503     fputs("\n", fp);
10504 }
10505 
10506 static void
bi_disasm_fma_frexpe_f32_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10507 bi_disasm_fma_frexpe_f32_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10508 {
10509     static const char *log_table[] = {
10510         ""
10511     };
10512     const char *log = log_table[0];
10513     static const char *neg_table[] = {
10514         "", ".neg"
10515     };
10516 
10517     const char *neg = neg_table[_BITS(bits, 6, 1)];
10518 
10519     static const char *sqrt_table[] = {
10520         "", ".sqrt"
10521     };
10522 
10523     const char *sqrt = sqrt_table[_BITS(bits, 8, 1)];
10524 
10525     static const char *widen0_table[] = {
10526         ".reserved", "", ".h0", ".h1"
10527     };
10528 
10529     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
10530 
10531     fputs("*FREXPE.f32", fp);
10532     fputs(neg, fp);
10533     fputs(sqrt, fp);
10534     fputs(log, fp);
10535     fputs(" ", fp);
10536     bi_disasm_dest_fma(fp, next_regs, last);
10537     fputs(", ", fp);
10538     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10539     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10540     fputs(widen0, fp);
10541     fputs("\n", fp);
10542 }
10543 
10544 static void
bi_disasm_add_v2s16_to_v2f16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10545 bi_disasm_add_v2s16_to_v2f16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10546 {
10547     static const char *round_table[] = {
10548         "", ".rtp", ".rtn", ".rtz"
10549     };
10550     const char *round = round_table[(_BITS(bits, 4, 2) << 0)];
10551     static const char *swz0_table[] = {
10552         ".h00", ".h10", "", ".h11"
10553     };
10554 
10555     const char *swz0 = swz0_table[_BITS(bits, 6, 2)];
10556 
10557     fputs("+V2S16_TO_V2F16", fp);
10558     fputs(round, fp);
10559     fputs(" ", fp);
10560     bi_disasm_dest_add(fp, next_regs, last);
10561     fputs(", ", fp);
10562     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10563     fputs(swz0, fp);
10564     fputs("\n", fp);
10565 }
10566 
10567 static void
bi_disasm_add_mov_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10568 bi_disasm_add_mov_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10569 {
10570     fputs("+MOV.i32", fp);
10571     fputs(" ", fp);
10572     bi_disasm_dest_add(fp, next_regs, last);
10573     fputs(", ", fp);
10574     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10575     fputs("\n", fp);
10576 }
10577 
10578 static void
bi_disasm_add_fround_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10579 bi_disasm_add_fround_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10580 {
10581     static const char *abs0_table[] = {
10582         "", ".abs0"
10583     };
10584 
10585     const char *abs0 = abs0_table[_BITS(bits, 7, 1)];
10586 
10587     static const char *neg0_table[] = {
10588         "", ".neg0"
10589     };
10590 
10591     const char *neg0 = neg0_table[_BITS(bits, 8, 1)];
10592 
10593     static const char *widen0_table[] = {
10594         ".reserved", "", ".h0", ".h1"
10595     };
10596 
10597     const char *widen0 = widen0_table[_BITS(bits, 3, 2)];
10598 
10599     static const char *round_table[] = {
10600         "", ".rtp", ".rtn", ".rtz"
10601     };
10602 
10603     const char *round = round_table[_BITS(bits, 9, 2)];
10604 
10605     fputs("+FROUND.f32", fp);
10606     fputs(round, fp);
10607     fputs(" ", fp);
10608     bi_disasm_dest_add(fp, next_regs, last);
10609     fputs(", ", fp);
10610     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10611     fputs(abs0, fp);
10612     fputs(neg0, fp);
10613     fputs(widen0, fp);
10614     fputs("\n", fp);
10615 }
10616 
10617 static void
bi_disasm_add_acmpstore_i64(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10618 bi_disasm_add_acmpstore_i64(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10619 {
10620     static const char *seg_table[] = {
10621         "", ".wgl"
10622     };
10623 
10624     const char *seg = seg_table[_BITS(bits, 9, 1)];
10625 
10626     fputs("+ACMPSTORE.i64", fp);
10627     fputs(seg, fp);
10628     fputs(" ", fp);
10629     bi_disasm_dest_add(fp, next_regs, last);
10630     fputs(", ", fp);
10631     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10632     fputs(", ", fp);
10633     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10634     fprintf(fp, ", @r%u", staging_register);
10635     fputs("\n", fp);
10636 }
10637 
10638 static void
bi_disasm_add_v2u8_to_v2f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10639 bi_disasm_add_v2u8_to_v2f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10640 {
10641     static const char *swz0_table[] = {
10642         ".b00", ".b10", ".b20", ".b30", "", ".b11", ".b21", ".b31", ".b02", ".b12", ".b22", ".b32", ".b03", ".b13", ".b23", ".b33"
10643     };
10644 
10645     const char *swz0 = swz0_table[_BITS(bits, 4, 4)];
10646 
10647     fputs("+V2U8_TO_V2F16", fp);
10648     fputs(" ", fp);
10649     bi_disasm_dest_add(fp, next_regs, last);
10650     fputs(", ", fp);
10651     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10652     fputs(swz0, fp);
10653     fputs("\n", fp);
10654 }
10655 
10656 static void
bi_disasm_add_icmpi_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10657 bi_disasm_add_icmpi_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10658 {
10659     static const char *result_type_table[] = {
10660         "", ".m1"
10661     };
10662 
10663     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
10664 
10665     static const char *cmpf_table[] = {
10666         ".gt", ".ge"
10667     };
10668 
10669     const char *cmpf = cmpf_table[_BITS(bits, 6, 1)];
10670 
10671     fputs("+ICMPI.s32", fp);
10672     fputs(result_type, fp);
10673     fputs(cmpf, fp);
10674     fputs(" ", fp);
10675     bi_disasm_dest_add(fp, next_regs, last);
10676     fputs(", ", fp);
10677     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10678     fputs(", ", fp);
10679     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10680     fputs("\n", fp);
10681 }
10682 
10683 static void
bi_disasm_fma_arshift_double_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10684 bi_disasm_fma_arshift_double_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10685 {
10686     static const char *bytes2_table[] = {
10687         "", ".bytes2"
10688     };
10689 
10690     const char *bytes2 = bytes2_table[_BITS(bits, 9, 1)];
10691 
10692     static const char *lane2_table[] = {
10693         "", ".b2"
10694     };
10695 
10696     const char *lane2 = lane2_table[_BITS(bits, 10, 1)];
10697 
10698     static const char *result_word_table[] = {
10699         "", ".w1"
10700     };
10701 
10702     const char *result_word = result_word_table[_BITS(bits, 11, 1)];
10703 
10704     fputs("*ARSHIFT_DOUBLE.i32", fp);
10705     fputs(result_word, fp);
10706     fputs(" ", fp);
10707     bi_disasm_dest_fma(fp, next_regs, last);
10708     fputs(", ", fp);
10709     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10710     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10711     fputs(", ", fp);
10712     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10713     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10714     fputs(", ", fp);
10715     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
10716     fputs(bytes2, fp);
10717     fputs(lane2, fp);
10718     fputs("\n", fp);
10719 }
10720 
10721 static void
bi_disasm_add_icmpi_i32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10722 bi_disasm_add_icmpi_i32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10723 {
10724     static const char *result_type_table[] = {
10725         "", ".m1"
10726     };
10727 
10728     const char *result_type = result_type_table[_BITS(bits, 10, 1)];
10729 
10730     static const char *cmpf_table[] = {
10731         ".eq", ".ne"
10732     };
10733 
10734     const char *cmpf = cmpf_table[_BITS(bits, 6, 1)];
10735 
10736     fputs("+ICMPI.i32", fp);
10737     fputs(result_type, fp);
10738     fputs(cmpf, fp);
10739     fputs(" ", fp);
10740     bi_disasm_dest_add(fp, next_regs, last);
10741     fputs(", ", fp);
10742     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10743     fputs(", ", fp);
10744     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10745     fputs("\n", fp);
10746 }
10747 
10748 static void
bi_disasm_add_ld_attr_imm_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10749 bi_disasm_add_ld_attr_imm_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10750 {
10751     static const char *register_format_table[] = {
10752         ".f16", ".f32", ".s32", ".u32", ".s16", ".u16", ".f64", ".i64"
10753     };
10754     const char *register_format = register_format_table[(_BITS(bits, 13, 3) << 0)];
10755     static const char *vecsize_table[] = {
10756         "", ".v2", ".v3", ".v4"
10757     };
10758 
10759     const char *vecsize = vecsize_table[_BITS(bits, 11, 2)];
10760 
10761     fputs("+LD_ATTR_IMM", fp);
10762     fputs(register_format, fp);
10763     fputs(vecsize, fp);
10764     fputs(" ", fp);
10765     bi_disasm_dest_add(fp, next_regs, last);
10766     fputs(", ", fp);
10767     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10768     fputs(", ", fp);
10769     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10770     fprintf(fp, ", attribute_index:%u", _BITS(bits, 6, 4));
10771     fprintf(fp, ", @r%u", staging_register);
10772     fputs("\n", fp);
10773 }
10774 
10775 static void
bi_disasm_fma_shaddxl_s32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10776 bi_disasm_fma_shaddxl_s32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10777 {
10778     static const char *lane1_table[] = {
10779         ".h0", ".h1", "", ".reserved"
10780     };
10781 
10782     const char *lane1 = lane1_table[_BITS(bits, 9, 2)];
10783 
10784     fputs("*SHADDXL.s32", fp);
10785     fputs(" ", fp);
10786     bi_disasm_dest_fma(fp, next_regs, last);
10787     fputs(", ", fp);
10788     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10789     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10790     fputs(", ", fp);
10791     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10792     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10793     fputs(lane1, fp);
10794     fprintf(fp, ", shift:%u", _BITS(bits, 6, 3));
10795     fputs("\n", fp);
10796 }
10797 
10798 static void
bi_disasm_add_mux_v4i8(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10799 bi_disasm_add_mux_v4i8(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10800 {
10801     static const char *mux_table[] = {
10802         ".neg", ""
10803     };
10804 
10805     const char *mux = mux_table[_BITS(bits, 9, 1)];
10806 
10807     fputs("+MUX.v4i8", fp);
10808     fputs(mux, fp);
10809     fputs(" ", fp);
10810     bi_disasm_dest_add(fp, next_regs, last);
10811     fputs(", ", fp);
10812     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10813     fputs(", ", fp);
10814     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10815     fputs(", ", fp);
10816     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, false);
10817     fputs("\n", fp);
10818 }
10819 
10820 static void
bi_disasm_fma_lshift_or_v4i8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10821 bi_disasm_fma_lshift_or_v4i8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10822 {
10823     static const char *lanes2_table[] = {
10824         ""
10825     };
10826     const char *lanes2 = lanes2_table[0];
10827     static const char *not1_table[] = {
10828         ".not", ""
10829     };
10830 
10831     const char *not1 = not1_table[_BITS(bits, 14, 1)];
10832 
10833     static const char *not_result_table[] = {
10834         "", ".not"
10835     };
10836 
10837     const char *not_result = not_result_table[_BITS(bits, 15, 1)];
10838 
10839     fputs("*LSHIFT_OR.v4i8", fp);
10840     fputs(not_result, fp);
10841     fputs(" ", fp);
10842     bi_disasm_dest_fma(fp, next_regs, last);
10843     fputs(", ", fp);
10844     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10845     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10846     fputs(", ", fp);
10847     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10848     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10849     fputs(not1, fp);
10850     fputs(", ", fp);
10851     dump_src(fp, _BITS(bits, 6, 3), *srcs, consts, true);
10852     fputs(lanes2, fp);
10853     fputs("\n", fp);
10854 }
10855 
10856 static void
bi_disasm_fma_fadd_lscale_f32(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10857 bi_disasm_fma_fadd_lscale_f32(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10858 {
10859     static const char *abs0_table[] = {
10860         "", ".abs"
10861     };
10862 
10863     const char *abs0 = abs0_table[_BITS(bits, 6, 1)];
10864 
10865     static const char *neg0_table[] = {
10866         "", ".neg"
10867     };
10868 
10869     const char *neg0 = neg0_table[_BITS(bits, 7, 1)];
10870 
10871     static const char *abs1_table[] = {
10872         "", ".abs"
10873     };
10874 
10875     const char *abs1 = abs1_table[_BITS(bits, 8, 1)];
10876 
10877     static const char *neg1_table[] = {
10878         "", ".neg"
10879     };
10880 
10881     const char *neg1 = neg1_table[_BITS(bits, 9, 1)];
10882 
10883     fputs("*FADD_LSCALE.f32", fp);
10884     fputs(" ", fp);
10885     bi_disasm_dest_fma(fp, next_regs, last);
10886     fputs(", ", fp);
10887     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, true);
10888     if (!(0xfb & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10889     fputs(abs0, fp);
10890     fputs(neg0, fp);
10891     fputs(", ", fp);
10892     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, true);
10893     if (!(0xfb & (1 << _BITS(bits, 3, 3)))) fputs("(INVALID)", fp);
10894     fputs(abs1, fp);
10895     fputs(neg1, fp);
10896     fputs("\n", fp);
10897 }
10898 
10899 static void
bi_disasm_add_load_i16_0(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10900 bi_disasm_add_load_i16_0(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10901 {
10902     static const char *extend_table[] = {
10903         "", ""
10904     };
10905     const char *extend = extend_table[(_BITS(bits, 9, 1) << 0)];
10906     static const char *lane_table[] = {
10907         "", ".h1"
10908     };
10909     const char *lane = lane_table[(_BITS(bits, 9, 1) << 0)];
10910     static const char *seg_table[] = {
10911         ".reserved", "", ".wgl", ".stream", ".ubo", ".reserved", ".reserved", ".tl"
10912     };
10913 
10914     const char *seg = seg_table[_BITS(bits, 6, 3)];
10915 
10916     fputs("+LOAD.i16", fp);
10917     fputs(seg, fp);
10918     fputs(lane, fp);
10919     fputs(extend, fp);
10920     fputs(" ", fp);
10921     bi_disasm_dest_add(fp, next_regs, last);
10922     fputs(", ", fp);
10923     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10924     fputs(", ", fp);
10925     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10926     fprintf(fp, ", @r%u", staging_register);
10927     fputs("\n", fp);
10928 }
10929 
10930 static void
bi_disasm_add_isub_v4s8_1(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10931 bi_disasm_add_isub_v4s8_1(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10932 {
10933     static const char *lanes1_table[] = {
10934         ".b0000", ".b1111", ".b2222", ".b3333"
10935     };
10936     const char *lanes1 = lanes1_table[(_BITS(bits, 9, 2) << 0)];
10937     static const char *lanes0_table[] = {
10938         "", "", "", ""
10939     };
10940     const char *lanes0 = lanes0_table[(_BITS(bits, 9, 2) << 0)];
10941     static const char *saturate_table[] = {
10942         "", ".sat"
10943     };
10944 
10945     const char *saturate = saturate_table[_BITS(bits, 8, 1)];
10946 
10947     fputs("+ISUB.v4s8", fp);
10948     fputs(saturate, fp);
10949     fputs(" ", fp);
10950     bi_disasm_dest_add(fp, next_regs, last);
10951     fputs(", ", fp);
10952     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10953     fputs(lanes0, fp);
10954     fputs(", ", fp);
10955     dump_src(fp, _BITS(bits, 3, 3), *srcs, consts, false);
10956     fputs(lanes1, fp);
10957     fputs("\n", fp);
10958 }
10959 
10960 static void
bi_disasm_add_frsq_f16(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)10961 bi_disasm_add_frsq_f16(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
10962 {
10963     static const char *neg_table[] = {
10964         "", ".neg"
10965     };
10966 
10967     const char *neg = neg_table[_BITS(bits, 3, 1)];
10968 
10969     static const char *abs0_table[] = {
10970         "", ".abs0"
10971     };
10972 
10973     const char *abs0 = abs0_table[_BITS(bits, 4, 1)];
10974 
10975     static const char *divzero_table[] = {
10976         "", ".divzero"
10977     };
10978 
10979     const char *divzero = divzero_table[_BITS(bits, 5, 1)];
10980 
10981     static const char *lane0_table[] = {
10982         "", ".h1"
10983     };
10984 
10985     const char *lane0 = lane0_table[_BITS(bits, 8, 1)];
10986 
10987     fputs("+FRSQ.f16", fp);
10988     fputs(neg, fp);
10989     fputs(divzero, fp);
10990     fputs(" ", fp);
10991     bi_disasm_dest_add(fp, next_regs, last);
10992     fputs(", ", fp);
10993     dump_src(fp, _BITS(bits, 0, 3), *srcs, consts, false);
10994     if (!(0xf7 & (1 << _BITS(bits, 0, 3)))) fputs("(INVALID)", fp);
10995     fputs(abs0, fp);
10996     fputs(lane0, fp);
10997     fputs("\n", fp);
10998 }
10999 
11000 void
bi_disasm_fma(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)11001 bi_disasm_fma(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
11002 {
11003     if (unlikely(((bits & 0x7fffff) == 0x701963)))
11004         bi_disasm_fma_nop_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11005     else if (unlikely(((bits & 0x7ffff8) == 0x701968)))
11006         bi_disasm_fma_mov_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11007     else if (unlikely(((bits & 0x7ffff8) == 0x701fc0)))
11008         bi_disasm_fma_bitrev_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11009     else if (unlikely(((bits & 0x7ffff8) == 0x73c6d8)))
11010         bi_disasm_fma_popcount_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11011     else if (unlikely(((bits & 0x7ffff8) == 0x701970)))
11012         bi_disasm_fma_quiet_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11013     else if (unlikely(((bits & 0x7ffff0) == 0x701fd0)))
11014         bi_disasm_fma_clz_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11015     else if (unlikely(((bits & 0x7ffff0) == 0x700d10)))
11016         bi_disasm_fma_f16_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11017     else if (unlikely(((bits & 0x7ffff0) == 0x701f90)))
11018         bi_disasm_fma_clz_v4u8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11019     else if (unlikely(((bits & 0x7fffe8) == 0x700cc8)))
11020         bi_disasm_fma_u16_to_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11021     else if (unlikely(((bits & 0x7fffe8) == 0x700cc0)))
11022         bi_disasm_fma_s16_to_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11023     else if (unlikely(((bits & 0x7fffe0) == 0x701e00)))
11024         bi_disasm_fma_frexpe_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11025     else if (unlikely(((bits & 0x7fffe0) == 0x701e20)))
11026         bi_disasm_fma_frexpe_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11027     else if (unlikely(((bits & 0x7fffc8) == 0x700b48)))
11028         bi_disasm_fma_u8_to_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11029     else if (unlikely(((bits & 0x7fffc8) == 0x701900)))
11030         bi_disasm_fma_quiet_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11031     else if (unlikely(((bits & 0x7fffc8) == 0x700b40)))
11032         bi_disasm_fma_s8_to_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11033     else if (unlikely(((bits & 0x7fffc0) == 0x73c0c0)))
11034         bi_disasm_fma_imul_i32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11035     else if (unlikely(((bits & 0x7fffc0) == 0x701ec0)))
11036         bi_disasm_fma_clz_v2u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11037     else if (unlikely(((bits & 0x7fffc0) == 0x73e0c0)))
11038         bi_disasm_fma_imul_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11039     else if (unlikely(((bits & 0x7fffc0) == 0x70cb40)))
11040         bi_disasm_fma_fmul_slice_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11041     else if (unlikely(((bits & 0x7fff80) == 0x70f100)))
11042         bi_disasm_fma_imuld(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11043     else if (unlikely(((bits & 0x7fff40) == 0x701500)))
11044         bi_disasm_fma_seg_add(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11045     else if (unlikely(((bits & 0x7fff40) == 0x701540)))
11046         bi_disasm_fma_seg_sub(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11047     else if (unlikely(((bits & 0x7fff20) == 0x701a00)))
11048         bi_disasm_fma_frexpm_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11049     else if (unlikely(((bits & 0x7fff20) == 0x701b00)))
11050         bi_disasm_fma_frexpm_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11051     else if (unlikely(((bits & 0x7fff20) == 0x701b20)))
11052         bi_disasm_fma_frexpm_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11053     else if (unlikely(((bits & 0x7fff20) == 0x701a20)))
11054         bi_disasm_fma_frexpm_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11055     else if (unlikely(((bits & 0x7fff00) == 0x70f000)))
11056         bi_disasm_fma_mkvec_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11057     else if (unlikely(((bits & 0x7ffea0) == 0x701c00)))
11058         bi_disasm_fma_frexpe_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11059     else if (unlikely(((bits & 0x7ffea0) == 0x701c20)))
11060         bi_disasm_fma_frexpe_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11061     else if (unlikely(((bits & 0x7ffe60) == 0x707620)))
11062         bi_disasm_fma_fround_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11063     else if (unlikely(((bits & 0x7ffe60) == 0x707600)))
11064         bi_disasm_fma_fround_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11065     else if (unlikely(((bits & 0x7ffe38) == 0x335818)))
11066         bi_disasm_fma_arshift_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11067     else if (unlikely(((bits & 0x7ffe00) == 0x27fe00)))
11068         bi_disasm_fma_isubb_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11069     else if (unlikely(((bits & 0x7ffe00) == 0x70f200)))
11070         bi_disasm_fma_dtsel_imm(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11071     else if (unlikely(((bits & 0x7ffe00) == 0x27fc00)))
11072         bi_disasm_fma_iaddc_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11073     else if (unlikely(((bits & 0x7ffe00) == 0x2f1e00)))
11074         bi_disasm_fma_atom_c1_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11075     else if (unlikely(((bits & 0x7ffe00) == 0x2f7e00)))
11076         bi_disasm_fma_atom_c1_return_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11077     else if (unlikely(((bits & 0x7ffe00) == 0x2f5e00)))
11078         bi_disasm_fma_atom_c1_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11079     else if (unlikely(((bits & 0x7ffe00) == 0x70d000)))
11080         bi_disasm_fma_fmul_cslice(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11081     else if (unlikely(((bits & 0x7ffe00) == 0x2f3e00)))
11082         bi_disasm_fma_atom_c1_return_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11083     else if (unlikely(((bits & 0x7ffe00) == 0x70e600)))
11084         bi_disasm_fma_shaddxl_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11085     else if (unlikely(((bits & 0x7ffc00) == 0x6ee400)))
11086         bi_disasm_fma_atom_post_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11087     else if (unlikely(((bits & 0x7ffc00) == 0x6ee000)))
11088         bi_disasm_fma_atom_post_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11089     else if (unlikely(((bits & 0x7ffc00) == 0x706800)))
11090         bi_disasm_fma_cubeface1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11091     else if (unlikely(((bits & 0x7ffc00) == 0x70f400)))
11092         bi_disasm_fma_fadd_lscale_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11093     else if (unlikely(((bits & 0x7ff9c0) == 0x7380c0)))
11094         bi_disasm_fma_imul_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11095     else if (unlikely(((bits & 0x7ff9c0) == 0x73c8c0)))
11096         bi_disasm_fma_imul_i32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11097     else if (unlikely(((bits & 0x7ff9c0) == 0x73e8c0)))
11098         bi_disasm_fma_idp_v4i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11099     else if (unlikely(((bits & 0x7ff860) == 0x70c020)))
11100         bi_disasm_fma_fround_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11101     else if (unlikely(((bits & 0x7ff860) == 0x70c000)))
11102         bi_disasm_fma_fround_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11103     else if (unlikely(((bits & 0x7ff838) == 0x335818)
11104         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11105     ))
11106         bi_disasm_fma_arshift_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11107     else if (unlikely(((bits & 0x7ff838) == 0x334818)))
11108         bi_disasm_fma_arshift_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11109     else if (unlikely(((bits & 0x7ff838) == 0x334018)))
11110         bi_disasm_fma_arshift_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11111     else if (unlikely(((bits & 0x7ff838) == 0x335018)))
11112         bi_disasm_fma_arshift_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11113     else if (unlikely(((bits & 0x7ff800) == 0x33f000)))
11114         bi_disasm_fma_frshift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11115     else if (unlikely(((bits & 0x7ff800) == 0x70e000)))
11116         bi_disasm_fma_shaddxl_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11117     else if (unlikely(((bits & 0x7ff800) == 0x33f800)))
11118         bi_disasm_fma_flshift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11119     else if (unlikely(((bits & 0x7ff800) == 0x70e800)))
11120         bi_disasm_fma_shaddxl_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11121     else if (unlikely(((bits & 0x7ff1c0) == 0x73b0c0)))
11122         bi_disasm_fma_imul_i32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11123     else if (unlikely(((bits & 0x7ff000) == 0x33a000)))
11124         bi_disasm_fma_rrot_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11125     else if (unlikely(((bits & 0x7ff000) == 0x33c000)))
11126         bi_disasm_fma_lshift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11127     else if (unlikely(((bits & 0x7ff000) == 0x6eb000)))
11128         bi_disasm_fma_vn_asst1_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11129     else if (unlikely(((bits & 0x7ff000) == 0x33b000)))
11130         bi_disasm_fma_lrot_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11131     else if (unlikely(((bits & 0x7ff000) == 0x33d000)))
11132         bi_disasm_fma_rshift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11133     else if (unlikely(((bits & 0x7ff000) == 0x2eb000)))
11134         bi_disasm_fma_jump_ex(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11135     else if (unlikely(((bits & 0x7ff000) == 0x33e000)))
11136         bi_disasm_fma_arshift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11137     else if (unlikely(((bits & 0x7fe1c0) == 0x7240c0)))
11138         bi_disasm_fma_imul_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11139     else if (unlikely(((bits & 0x7fe000) == 0x2f6000)))
11140         bi_disasm_fma_atom_c_return_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11141     else if (unlikely(((bits & 0x7fe000) == 0x6ec000)))
11142         bi_disasm_fma_atom_pre_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11143     else if (unlikely(((bits & 0x7fe000) == 0x2e6000)))
11144         bi_disasm_fma_csel_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11145     else if (unlikely(((bits & 0x7fe000) == 0x27c000)))
11146         bi_disasm_fma_vn_asst1_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11147     else if (unlikely(((bits & 0x7fe000) == 0x2e4000)))
11148         bi_disasm_fma_csel_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11149     else if (unlikely(((bits & 0x7fe000) == 0x6e6000)))
11150         bi_disasm_fma_csel_v2u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11151     else if (unlikely(((bits & 0x7fe000) == 0x6e8000)))
11152         bi_disasm_fma_v2f32_to_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11153     else if (unlikely(((bits & 0x7fe000) == 0x2f2000)))
11154         bi_disasm_fma_atom_c_return_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11155     else if (unlikely(((bits & 0x7fe000) == 0x2f0000)))
11156         bi_disasm_fma_atom_c_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11157     else if (unlikely(((bits & 0x7fe000) == 0x6e4000)))
11158         bi_disasm_fma_csel_v2s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11159     else if (unlikely(((bits & 0x7fe000) == 0x2f4000)))
11160         bi_disasm_fma_atom_c_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11161     else if (unlikely(((bits & 0x7fde00) == 0x321800)))
11162         bi_disasm_fma_rshift_xor_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11163     else if (unlikely(((bits & 0x7fde00) == 0x325800)))
11164         bi_disasm_fma_lshift_xor_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11165     else if (unlikely(((bits & 0x7fd800) == 0x324800)))
11166         bi_disasm_fma_lshift_xor_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11167     else if (unlikely(((bits & 0x7fd800) == 0x321800)
11168         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11169     ))
11170         bi_disasm_fma_rshift_xor_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11171     else if (unlikely(((bits & 0x7fd800) == 0x325000)))
11172         bi_disasm_fma_lshift_xor_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11173     else if (unlikely(((bits & 0x7fd800) == 0x320000)))
11174         bi_disasm_fma_rshift_xor_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11175     else if (unlikely(((bits & 0x7fd800) == 0x320800)))
11176         bi_disasm_fma_rshift_xor_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11177     else if (unlikely(((bits & 0x7fd800) == 0x325800)
11178         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11179     ))
11180         bi_disasm_fma_lshift_xor_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11181     else if (unlikely(((bits & 0x7fd800) == 0x321000)))
11182         bi_disasm_fma_rshift_xor_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11183     else if (unlikely(((bits & 0x7fd800) == 0x324000)))
11184         bi_disasm_fma_lshift_xor_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11185     else if (unlikely(((bits & 0x7fc000) == 0x2e0000)
11186         && !(0x8 & (1 << _BITS(bits, 12, 2)))
11187     ))
11188         bi_disasm_fma_csel_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11189     else if (unlikely(((bits & 0x7fc000) == 0x6e0000)
11190         && !(0x8 & (1 << _BITS(bits, 12, 2)))
11191     ))
11192         bi_disasm_fma_csel_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11193     else if (unlikely(((bits & 0x7f8000) == 0x6e0000)
11194         && !(0xf7 & (1 << _BITS(bits, 12, 3)))
11195     ))
11196         bi_disasm_fma_csel_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11197     else if (unlikely(((bits & 0x7f8000) == 0x2e0000)
11198         && !(0xf7 & (1 << _BITS(bits, 12, 3)))
11199     ))
11200         bi_disasm_fma_csel_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11201     else if (unlikely(((bits & 0x7f3e00) == 0x303800)))
11202         bi_disasm_fma_rshift_or_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11203     else if (unlikely(((bits & 0x7f3e00) == 0x301800)))
11204         bi_disasm_fma_rshift_and_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11205     else if (unlikely(((bits & 0x7f3e00) == 0x311800)))
11206         bi_disasm_fma_lshift_and_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11207     else if (unlikely(((bits & 0x7f3e00) == 0x313800)))
11208         bi_disasm_fma_lshift_or_v4i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11209     else if (unlikely(((bits & 0x7f3800) == 0x303000)))
11210         bi_disasm_fma_rshift_or_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11211     else if (unlikely(((bits & 0x7f3800) == 0x312000)))
11212         bi_disasm_fma_lshift_or_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11213     else if (unlikely(((bits & 0x7f3800) == 0x310000)))
11214         bi_disasm_fma_lshift_and_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11215     else if (unlikely(((bits & 0x7f3800) == 0x300800)))
11216         bi_disasm_fma_rshift_and_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11217     else if (unlikely(((bits & 0x7f3800) == 0x303800)
11218         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11219     ))
11220         bi_disasm_fma_rshift_or_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11221     else if (unlikely(((bits & 0x7f3800) == 0x301000)))
11222         bi_disasm_fma_rshift_and_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11223     else if (unlikely(((bits & 0x7f3800) == 0x313000)))
11224         bi_disasm_fma_lshift_or_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11225     else if (unlikely(((bits & 0x7f3800) == 0x302800)))
11226         bi_disasm_fma_rshift_or_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11227     else if (unlikely(((bits & 0x7f3800) == 0x301800)
11228         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11229     ))
11230         bi_disasm_fma_rshift_and_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11231     else if (unlikely(((bits & 0x7f3800) == 0x302000)))
11232         bi_disasm_fma_rshift_or_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11233     else if (unlikely(((bits & 0x7f3800) == 0x311800)
11234         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11235     ))
11236         bi_disasm_fma_lshift_and_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11237     else if (unlikely(((bits & 0x7f3800) == 0x313800)
11238         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11239     ))
11240         bi_disasm_fma_lshift_or_v2i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11241     else if (unlikely(((bits & 0x7f3800) == 0x311000)))
11242         bi_disasm_fma_lshift_and_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11243     else if (unlikely(((bits & 0x7f3800) == 0x310800)))
11244         bi_disasm_fma_lshift_and_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11245     else if (unlikely(((bits & 0x7f3800) == 0x312800)))
11246         bi_disasm_fma_lshift_or_v2i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11247     else if (unlikely(((bits & 0x7f3800) == 0x300000)))
11248         bi_disasm_fma_rshift_and_v4i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11249     else if (unlikely(((bits & 0x7f0000) == 0x710000)))
11250         bi_disasm_fma_mkvec_v4i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11251     else if (unlikely(((bits & 0x7e0000) == 0x2c0000)))
11252         bi_disasm_fma_fadd_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11253     else if (unlikely(((bits & 0x7e0000) == 0x6c0000)))
11254         bi_disasm_fma_fadd_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11255     else if (unlikely(((bits & 0x7c0000) == 0x680000)
11256         && !(0x40 & (1 << _BITS(bits, 12, 3)))
11257     ))
11258         bi_disasm_fma_fma_rscale_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11259     else if (unlikely(((bits & 0x7c0000) == 0x640000)))
11260         bi_disasm_fma_fcmp_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11261     else if (unlikely(((bits & 0x7c0000) == 0x240000)))
11262         bi_disasm_fma_fcmp_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11263     else if (unlikely(((bits & 0x7c0000) == 0x280000)))
11264         bi_disasm_fma_fma_rscale_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11265     else if (unlikely(((bits & 0x600000) == 0x0)))
11266         bi_disasm_fma_fma_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11267     else if (unlikely(((bits & 0x600000) == 0x400000)))
11268         bi_disasm_fma_fma_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11269     else
11270         fprintf(fp, "INSTR_INVALID_ENC fma %X\n", bits);
11271 }
11272 void
bi_disasm_add(FILE * fp,unsigned bits,struct bifrost_regs * srcs,struct bifrost_regs * next_regs,unsigned staging_register,unsigned branch_offset,struct bi_constants * consts,bool last)11273 bi_disasm_add(FILE *fp, unsigned bits, struct bifrost_regs *srcs, struct bifrost_regs *next_regs, unsigned staging_register, unsigned branch_offset, struct bi_constants *consts, bool last)
11274 {
11275     if (unlikely(((bits & 0xfffff) == 0xd7874)))
11276         bi_disasm_add_barrier(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11277     else if (unlikely(((bits & 0xfffff) == 0x3d964)))
11278         bi_disasm_add_nop_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11279     else if (unlikely(((bits & 0xffff8) == 0xd7800)))
11280         bi_disasm_add_ld_gclk_u64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11281     else if (unlikely(((bits & 0xffff8) == 0x67c50)))
11282         bi_disasm_add_fpclass_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11283     else if (unlikely(((bits & 0xffff8) == 0x3d970)))
11284         bi_disasm_add_quiet_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11285     else if (unlikely(((bits & 0xffff8) == 0xd7860)))
11286         bi_disasm_add_doorbell(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11287     else if (unlikely(((bits & 0xffff8) == 0xd7850)))
11288         bi_disasm_add_eureka(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11289     else if (unlikely(((bits & 0xffff8) == 0x3cd00)))
11290         bi_disasm_add_s32_to_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11291     else if (unlikely(((bits & 0xffff8) == 0x3cca0)))
11292         bi_disasm_add_f32_to_s32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11293     else if (unlikely(((bits & 0xffff8) == 0x67ab0)))
11294         bi_disasm_add_frcbrt_approx_b_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11295     else if (unlikely(((bits & 0xffff8) == 0x3dea0)))
11296         bi_disasm_add_iabs_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11297     else if (unlikely(((bits & 0xffff8) == 0x3de58)))
11298         bi_disasm_add_cubeface2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11299     else if (unlikely(((bits & 0xffff8) == 0x3cca8)))
11300         bi_disasm_add_f32_to_u32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11301     else if (unlikely(((bits & 0xffff8) == 0x66340)))
11302         bi_disasm_add_flogd_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11303     else if (unlikely(((bits & 0xffff8) == 0x3cd08)))
11304         bi_disasm_add_u32_to_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11305     else if (unlikely(((bits & 0xffff8) == 0x67ab8)))
11306         bi_disasm_add_frcbrt_approx_c_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11307     else if (unlikely(((bits & 0xffff8) == 0xd7858)))
11308         bi_disasm_add_kaboom(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11309     else if (unlikely(((bits & 0xffff8) == 0x3deb0)))
11310         bi_disasm_add_iabs_v4s8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11311     else if (unlikely(((bits & 0xffff8) == 0x3d968)))
11312         bi_disasm_add_mov_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11313     else if (unlikely(((bits & 0xffff7) == 0xd7820)))
11314         bi_disasm_add_imov_fma(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11315     else if (unlikely(((bits & 0xffff0) == 0x3df80)))
11316         bi_disasm_add_vn_asst2_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11317     else if (unlikely(((bits & 0xffff0) == 0x3dfa0)))
11318         bi_disasm_add_vn_asst2_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11319     else if (unlikely(((bits & 0xffff0) == 0x3cd10)))
11320         bi_disasm_add_f16_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11321     else if (unlikely(((bits & 0xffff0) == 0x67c40)))
11322         bi_disasm_add_fpclass_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11323     else if (unlikely(((bits & 0xffff0) == 0x67aa0)))
11324         bi_disasm_add_fsincos_offset_u6(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11325     else if (unlikely(((bits & 0xfffe8) == 0x3de80)))
11326         bi_disasm_add_vn_asst2_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11327     else if (unlikely(((bits & 0xfffe8) == 0x3cce8)))
11328         bi_disasm_add_u16_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11329     else if (unlikely(((bits & 0xfffe8) == 0x3cce0)))
11330         bi_disasm_add_s16_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11331     else if (unlikely(((bits & 0xfffe8) == 0x67a88)))
11332         bi_disasm_add_fcos_table_u6(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11333     else if (unlikely(((bits & 0xfffe8) == 0x67a80)))
11334         bi_disasm_add_fsin_table_u6(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11335     else if (unlikely(((bits & 0xfffe8) == 0x3ccc8)))
11336         bi_disasm_add_u16_to_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11337     else if (unlikely(((bits & 0xfffe8) == 0x3ccc0)))
11338         bi_disasm_add_s16_to_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11339     else if (unlikely(((bits & 0xfffe0) == 0x3de00)))
11340         bi_disasm_add_frexpe_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11341     else if (unlikely(((bits & 0xfffe0) == 0x3d9a0)))
11342         bi_disasm_add_logb_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11343     else if (unlikely(((bits & 0xfffe0) == 0x67ac0)))
11344         bi_disasm_add_fexp_table_u4(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11345     else if (unlikely(((bits & 0xfffe0) == 0x3d9e0)))
11346         bi_disasm_add_ilogb_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11347     else if (unlikely(((bits & 0xfffe0) == 0x3de20)))
11348         bi_disasm_add_frexpe_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11349     else if (unlikely(((bits & 0xfffe0) == 0x67ae0)))
11350         bi_disasm_add_flog_table_f32_4(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11351     else if (unlikely(((bits & 0xfffe0) == 0x3d980)))
11352         bi_disasm_add_logb_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11353     else if (unlikely(((bits & 0xfffe0) == 0x3d9c0)))
11354         bi_disasm_add_ilogb_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11355     else if (unlikely(((bits & 0xfffd8) == 0x3cc40)))
11356         bi_disasm_add_f16_to_s32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11357     else if (unlikely(((bits & 0xfffd8) == 0x3cc48)))
11358         bi_disasm_add_f16_to_u32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11359     else if (unlikely(((bits & 0xfffc8) == 0x3c988)))
11360         bi_disasm_add_f32_to_u32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11361     else if (unlikely(((bits & 0xfffc8) == 0x3cb48)))
11362         bi_disasm_add_u8_to_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11363     else if (unlikely(((bits & 0xfffc8) == 0x3d900)))
11364         bi_disasm_add_quiet_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11365     else if (unlikely(((bits & 0xfffc8) == 0x3cb80)))
11366         bi_disasm_add_s8_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11367     else if (unlikely(((bits & 0xfffc8) == 0x3cb00)))
11368         bi_disasm_add_v2s16_to_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11369     else if (unlikely(((bits & 0xfffc8) == 0x3cb08)))
11370         bi_disasm_add_v2u16_to_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11371     else if (unlikely(((bits & 0xfffc8) == 0x3cbc0)))
11372         bi_disasm_add_s32_to_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11373     else if (unlikely(((bits & 0xfffc8) == 0x3d948)))
11374         bi_disasm_add_swz_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11375     else if (unlikely(((bits & 0xfffc8) == 0x3c980)))
11376         bi_disasm_add_f32_to_s32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11377     else if (unlikely(((bits & 0xfffc8) == 0x3cb40)))
11378         bi_disasm_add_s8_to_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11379     else if (unlikely(((bits & 0xfffc8) == 0x3cb88)))
11380         bi_disasm_add_u8_to_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11381     else if (unlikely(((bits & 0xfffc8) == 0x3de88)))
11382         bi_disasm_add_iabs_v2s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11383     else if (unlikely(((bits & 0xfffc8) == 0x3ca80)))
11384         bi_disasm_add_v2f16_to_v2s16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11385     else if (unlikely(((bits & 0xfffc8) == 0x3ca88)))
11386         bi_disasm_add_v2f16_to_v2u16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11387     else if (unlikely(((bits & 0xfffc8) == 0x3cbc8)))
11388         bi_disasm_add_u32_to_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11389     else if (unlikely(((bits & 0xfffc0) == 0x75200)))
11390         bi_disasm_add_fadd_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11391     else if (unlikely(((bits & 0xfffc0) == 0x67a00)))
11392         bi_disasm_add_fatan_assist_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11393     else if (unlikely(((bits & 0xfffc0) == 0x3df40)))
11394         bi_disasm_add_swz_v4i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11395     else if (unlikely(((bits & 0xfffc0) == 0x67a40)))
11396         bi_disasm_add_fatan_table_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11397     else if (unlikely(((bits & 0xfffc0) == 0x75080)))
11398         bi_disasm_add_fpow_sc_apply(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11399     else if (unlikely(((bits & 0xfffc0) == 0x67300)))
11400         bi_disasm_add_flog_table_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11401     else if (unlikely(((bits & 0xfffc0) == 0x67b00)))
11402         bi_disasm_add_flog_table_f32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11403     else if (unlikely(((bits & 0xfffc0) == 0x67100)))
11404         bi_disasm_add_frsq_approx_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11405     else if (unlikely(((bits & 0xfffc0) == 0x3f8c0)))
11406         bi_disasm_add_shaddxh_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11407     else if (unlikely(((bits & 0xfffc0) == 0x3d700)))
11408         bi_disasm_add_wmask(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11409     else if (unlikely(((bits & 0xfffc0) == 0x67200)))
11410         bi_disasm_add_frcbrt_approx_a_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11411     else if (unlikely(((bits & 0xfffc0) == 0x66ac0)))
11412         bi_disasm_add_fexp_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11413     else if (unlikely(((bits & 0xfffc0) == 0x67000)))
11414         bi_disasm_add_frcp_approx_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11415     else if (unlikely(((bits & 0xfffa0) == 0x66100)
11416         && !(0x2 & (1 << _BITS(bits, 6, 1)))
11417     ))
11418         bi_disasm_add_frsq_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11419     else if (unlikely(((bits & 0xfffa0) == 0x66000)
11420         && !(0x2 & (1 << _BITS(bits, 6, 1)))
11421     ))
11422         bi_disasm_add_frcp_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11423     else if (unlikely(((bits & 0xfff48) == 0x3c500)))
11424         bi_disasm_add_f16_to_s32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11425     else if (unlikely(((bits & 0xfff48) == 0x3c508)))
11426         bi_disasm_add_f16_to_u32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11427     else if (unlikely(((bits & 0xfff40) == 0x67140)))
11428         bi_disasm_add_frsq_approx_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11429     else if (unlikely(((bits & 0xfff40) == 0x3d540)))
11430         bi_disasm_add_seg_sub(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11431     else if (unlikely(((bits & 0xfff40) == 0x67040)))
11432         bi_disasm_add_frcp_approx_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11433     else if (unlikely(((bits & 0xfff40) == 0x3d500)))
11434         bi_disasm_add_seg_add(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11435     else if (unlikely(((bits & 0xfff40) == 0x67b40)))
11436         bi_disasm_add_flog_table_f32_3(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11437     else if (unlikely(((bits & 0xfff40) == 0x67340)))
11438         bi_disasm_add_flog_table_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11439     else if (unlikely(((bits & 0xfff40) == 0x67240)))
11440         bi_disasm_add_frcbrt_approx_a_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11441     else if (unlikely(((bits & 0xfff20) == 0x3da00)))
11442         bi_disasm_add_frexpm_v2f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11443     else if (unlikely(((bits & 0xfff20) == 0x3db20)))
11444         bi_disasm_add_frexpm_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11445     else if (unlikely(((bits & 0xfff20) == 0x3db00)))
11446         bi_disasm_add_frexpm_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11447     else if (unlikely(((bits & 0xfff20) == 0x3da20)))
11448         bi_disasm_add_frexpm_f32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11449     else if (unlikely(((bits & 0xfff08) == 0x3c200)))
11450         bi_disasm_add_v2f16_to_v2s16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11451     else if (unlikely(((bits & 0xfff08) == 0x3c608)))
11452         bi_disasm_add_v2u16_to_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11453     else if (unlikely(((bits & 0xfff08) == 0x3c208)))
11454         bi_disasm_add_v2f16_to_v2u16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11455     else if (unlikely(((bits & 0xfff08) == 0x3c700)))
11456         bi_disasm_add_v2s8_to_v2s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11457     else if (unlikely(((bits & 0xfff08) == 0x3c708)))
11458         bi_disasm_add_v2u8_to_v2u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11459     else if (unlikely(((bits & 0xfff08) == 0x3c800)))
11460         bi_disasm_add_v2s8_to_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11461     else if (unlikely(((bits & 0xfff08) == 0x3c600)))
11462         bi_disasm_add_v2s16_to_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11463     else if (unlikely(((bits & 0xfff08) == 0x3c808)))
11464         bi_disasm_add_v2u8_to_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11465     else if (unlikely(((bits & 0xfff00) == 0xc8f00)))
11466         bi_disasm_add_atest(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11467     else if (unlikely(((bits & 0xfff00) == 0x75300)))
11468         bi_disasm_add_mkvec_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11469     else if (unlikely(((bits & 0xfff00) == 0x67900)))
11470         bi_disasm_add_fatan_table_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11471     else if (unlikely(((bits & 0xfff00) == 0x67800)))
11472         bi_disasm_add_fatan_assist_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11473     else if (unlikely(((bits & 0xffec0) == 0x67080)))
11474         bi_disasm_add_frcp_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11475     else if (unlikely(((bits & 0xffec0) == 0xbc600)))
11476         bi_disasm_add_iadd_s32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11477     else if (unlikely(((bits & 0xffec0) == 0xbd600)))
11478         bi_disasm_add_isub_s32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11479     else if (unlikely(((bits & 0xffec0) == 0xbc400)))
11480         bi_disasm_add_iadd_v4s8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11481     else if (unlikely(((bits & 0xffec0) == 0xbd400)))
11482         bi_disasm_add_isub_v4s8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11483     else if (unlikely(((bits & 0xffec0) == 0x67280)))
11484         bi_disasm_add_frsq_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11485     else if (unlikely(((bits & 0xffea0) == 0x3dc20)))
11486         bi_disasm_add_frexpe_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11487     else if (unlikely(((bits & 0xffea0) == 0x3dc00)))
11488         bi_disasm_add_frexpe_v2f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11489     else if (unlikely(((bits & 0xffe40) == 0xbc400)))
11490         bi_disasm_add_iadd_v4u8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11491     else if (unlikely(((bits & 0xffe40) == 0xbd400)))
11492         bi_disasm_add_isub_v4u8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11493     else if (unlikely(((bits & 0xffe40) == 0xbc600)))
11494         bi_disasm_add_iadd_u32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11495     else if (unlikely(((bits & 0xffe40) == 0xbd600)))
11496         bi_disasm_add_isub_u32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11497     else if (unlikely(((bits & 0xffe40) == 0x67640)))
11498         bi_disasm_add_fpow_sc_det_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11499     else if (unlikely(((bits & 0xffe40) == 0x67600)))
11500         bi_disasm_add_fpow_sc_det_f16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11501     else if (unlikely(((bits & 0xffe3f) == 0x6f83c)))
11502         bi_disasm_add_branch_diverg(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11503     else if (unlikely(((bits & 0xffe3f) == 0x6fe34)))
11504         bi_disasm_add_jump(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11505     else if (unlikely(((bits & 0xffe3f) == 0x6fa34)))
11506         bi_disasm_add_branch_no_diverg(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11507     else if (unlikely(((bits & 0xffe38) == 0x6fa38)))
11508         bi_disasm_add_branch_lowbits_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11509     else if (unlikely(((bits & 0xffe30) == 0x6f800)))
11510         bi_disasm_add_branchz_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11511     else if (unlikely(((bits & 0xffe00) == 0x61200)))
11512         bi_disasm_add_store_i128(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11513     else if (unlikely(((bits & 0xffe00) == 0x62800)))
11514         bi_disasm_add_store_i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11515     else if (unlikely(((bits & 0xffe00) == 0x65c00)))
11516         bi_disasm_add_store_i96(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11517     else if (unlikely(((bits & 0xffe00) == 0x7be00)))
11518         bi_disasm_add_icmpf_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11519     else if (unlikely(((bits & 0xffe00) == 0xca800)))
11520         bi_disasm_add_blend(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11521     else if (unlikely(((bits & 0xffe00) == 0x62000)))
11522         bi_disasm_add_store_i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11523     else if (unlikely(((bits & 0xffe00) == 0x65200)))
11524         bi_disasm_add_load_i48(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11525     else if (unlikely(((bits & 0xffe00) == 0xc8400)))
11526         bi_disasm_add_lea_attr_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11527     else if (unlikely(((bits & 0xffe00) == 0x65800)))
11528         bi_disasm_add_store_i24(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11529     else if (unlikely(((bits & 0xffe00) == 0x65a00)))
11530         bi_disasm_add_store_i48(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11531     else if (unlikely(((bits & 0xffe00) == 0x6f800)
11532         && !(0x9 & (1 << _BITS(bits, 4, 2)))
11533     ))
11534         bi_disasm_add_branchz_i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11535     else if (unlikely(((bits & 0xffe00) == 0x60e00)))
11536         bi_disasm_add_load_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11537     else if (unlikely(((bits & 0xffe00) == 0x62c00)))
11538         bi_disasm_add_store_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11539     else if (unlikely(((bits & 0xffe00) == 0x74c00)))
11540         bi_disasm_add_ldexp_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11541     else if (unlikely(((bits & 0xffe00) == 0x65000)))
11542         bi_disasm_add_load_i24(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11543     else if (unlikely(((bits & 0xffe00) == 0x7ba00)))
11544         bi_disasm_add_icmpm_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11545     else if (unlikely(((bits & 0xffe00) == 0x74e00)))
11546         bi_disasm_add_ldexp_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11547     else if (unlikely(((bits & 0xffe00) == 0xc8600)))
11548         bi_disasm_add_lea_attr_tex_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11549     else if (unlikely(((bits & 0xffe00) == 0x67400)))
11550         bi_disasm_add_fpow_sc_det_f16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11551     else if (unlikely(((bits & 0xffe00) == 0x62e00)))
11552         bi_disasm_add_store_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11553     else if (unlikely(((bits & 0xffe00) == 0x61000)))
11554         bi_disasm_add_load_i128(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11555     else if (unlikely(((bits & 0xffe00) == 0xefe00)))
11556         bi_disasm_add_shift_double_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11557     else if (unlikely(((bits & 0xffe00) == 0x65400)))
11558         bi_disasm_add_load_i96(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11559     else if (unlikely(((bits & 0xffe00) == 0x60c00)))
11560         bi_disasm_add_load_i32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11561     else if (unlikely(((bits & 0xffe00) == 0xd7400)))
11562         bi_disasm_add_atom_cx(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11563     else if (unlikely(((bits & 0xffdc0) == 0x644c0)))
11564         bi_disasm_add_acmpxchg_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11565     else if (unlikely(((bits & 0xffdc0) == 0x64100)))
11566         bi_disasm_add_axchg_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11567     else if (unlikely(((bits & 0xffdc0) == 0x640c0)))
11568         bi_disasm_add_axchg_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11569     else if (unlikely(((bits & 0xffdc0) == 0x64500)))
11570         bi_disasm_add_acmpxchg_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11571     else if (unlikely(((bits & 0xffdc0) == 0x648c0)))
11572         bi_disasm_add_acmpstore_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11573     else if (unlikely(((bits & 0xffdc0) == 0x64900)))
11574         bi_disasm_add_acmpstore_i64(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11575     else if (unlikely(((bits & 0xffd00) == 0xca100)
11576         && !(0xc & (1 << _BITS(bits, 5, 2)))
11577     ))
11578         bi_disasm_add_var_tex_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11579     else if (unlikely(((bits & 0xffd00) == 0xca000)
11580         && !(0xc & (1 << _BITS(bits, 5, 2)))
11581     ))
11582         bi_disasm_add_var_tex_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11583     else if (unlikely(((bits & 0xffcc0) == 0xbe840)))
11584         bi_disasm_add_iadd_v4s8_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11585     else if (unlikely(((bits & 0xffcc0) == 0xbf800)))
11586         bi_disasm_add_isub_v2s16_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11587     else if (unlikely(((bits & 0xffcc0) == 0xbfc40)))
11588         bi_disasm_add_isub_v2s16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11589     else if (unlikely(((bits & 0xffcc0) == 0xbec40)))
11590         bi_disasm_add_iadd_v2s16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11591     else if (unlikely(((bits & 0xffcc0) == 0xbec00)))
11592         bi_disasm_add_iadd_s32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11593     else if (unlikely(((bits & 0xffcc0) == 0xbe800)))
11594         bi_disasm_add_iadd_v2s16_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11595     else if (unlikely(((bits & 0xffcc0) == 0xbf840)))
11596         bi_disasm_add_isub_v4s8_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11597     else if (unlikely(((bits & 0xffcc0) == 0xcf8c0)))
11598         bi_disasm_add_ld_var_flat_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11599     else if (unlikely(((bits & 0xffcc0) == 0xbfc00)))
11600         bi_disasm_add_isub_s32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11601     else if (unlikely(((bits & 0xffc40) == 0xbf840)))
11602         bi_disasm_add_isub_v4u8_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11603     else if (unlikely(((bits & 0xffc40) == 0xbec40)))
11604         bi_disasm_add_iadd_v2u16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11605     else if (unlikely(((bits & 0xffc40) == 0xbfc00)))
11606         bi_disasm_add_isub_u32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11607     else if (unlikely(((bits & 0xffc40) == 0xbf800)))
11608         bi_disasm_add_isub_v2u16_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11609     else if (unlikely(((bits & 0xffc40) == 0xbe800)))
11610         bi_disasm_add_iadd_v2u16_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11611     else if (unlikely(((bits & 0xffc40) == 0xbec00)))
11612         bi_disasm_add_iadd_u32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11613     else if (unlikely(((bits & 0xffc40) == 0xbfc40)))
11614         bi_disasm_add_isub_v2u16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11615     else if (unlikely(((bits & 0xffc40) == 0xbe840)))
11616         bi_disasm_add_iadd_v4u8_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11617     else if (unlikely(((bits & 0xffc00) == 0x3e400)))
11618         bi_disasm_add_cube_tsel(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11619     else if (unlikely(((bits & 0xffc00) == 0x63000)))
11620         bi_disasm_add_load_i16_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11621     else if (unlikely(((bits & 0xffc00) == 0x63400)))
11622         bi_disasm_add_load_i8_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11623     else if (unlikely(((bits & 0xffc00) == 0xcf800)))
11624         bi_disasm_add_ld_var_flat_imm_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11625     else if (unlikely(((bits & 0xffc00) == 0x61400)))
11626         bi_disasm_add_load_i8_3(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11627     else if (unlikely(((bits & 0xffc00) == 0x61800)))
11628         bi_disasm_add_load_i16_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11629     else if (unlikely(((bits & 0xffc00) == 0xc8000)))
11630         bi_disasm_add_lea_attr_imm_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11631     else if (unlikely(((bits & 0xffc00) == 0xd7000)))
11632         bi_disasm_add_texc(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11633     else if (unlikely(((bits & 0xffc00) == 0x61c00)))
11634         bi_disasm_add_load_i32_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11635     else if (unlikely(((bits & 0xffc00) == 0x3e000)))
11636         bi_disasm_add_cube_ssel(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11637     else if (unlikely(((bits & 0xffc00) == 0x74800)))
11638         bi_disasm_add_mux_v4i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11639     else if (unlikely(((bits & 0xffc00) == 0x60800)))
11640         bi_disasm_add_load_i16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11641     else if (unlikely(((bits & 0xffb80) == 0x7b100)))
11642         bi_disasm_add_icmp_v4i8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11643     else if (unlikely(((bits & 0xffb80) == 0x7b200)))
11644         bi_disasm_add_icmp_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11645     else if (unlikely(((bits & 0xffb80) == 0x7b080)))
11646         bi_disasm_add_icmp_v4u8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11647     else if (unlikely(((bits & 0xffb80) == 0x7b880)))
11648         bi_disasm_add_icmpi_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11649     else if (unlikely(((bits & 0xffb80) == 0x7b280)))
11650         bi_disasm_add_icmp_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11651     else if (unlikely(((bits & 0xffb80) == 0x7b000)))
11652         bi_disasm_add_icmp_v4s8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11653     else if (unlikely(((bits & 0xffb80) == 0x7b300)))
11654         bi_disasm_add_icmp_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11655     else if (unlikely(((bits & 0xffb80) == 0x7b800)))
11656         bi_disasm_add_icmpi_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11657     else if (unlikely(((bits & 0xffb80) == 0x7b900)))
11658         bi_disasm_add_icmpi_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11659     else if (unlikely(((bits & 0xffa38) == 0x6f238)))
11660         bi_disasm_add_branchc_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11661     else if (unlikely(((bits & 0xff8c0) == 0xbd800)))
11662         bi_disasm_add_isub_v2s16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11663     else if (unlikely(((bits & 0xff8c0) == 0xbf000)))
11664         bi_disasm_add_isub_s32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11665     else if (unlikely(((bits & 0xff8c0) == 0xbe000)))
11666         bi_disasm_add_iadd_s32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11667     else if (unlikely(((bits & 0xff8c0) == 0xbe040)))
11668         bi_disasm_add_iadd_v4s8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11669     else if (unlikely(((bits & 0xff8c0) == 0xbc800)))
11670         bi_disasm_add_iadd_v2s16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11671     else if (unlikely(((bits & 0xff8c0) == 0xbf040)))
11672         bi_disasm_add_isub_v4s8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11673     else if (unlikely(((bits & 0xff860) == 0x3e800)))
11674         bi_disasm_add_fround_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11675     else if (unlikely(((bits & 0xff860) == 0x3e820)))
11676         bi_disasm_add_fround_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11677     else if (unlikely(((bits & 0xff840) == 0xbe000)))
11678         bi_disasm_add_iadd_u32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11679     else if (unlikely(((bits & 0xff840) == 0xbc800)))
11680         bi_disasm_add_iadd_v2u16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11681     else if (unlikely(((bits & 0xff840) == 0xbf000)))
11682         bi_disasm_add_isub_u32_2(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11683     else if (unlikely(((bits & 0xff840) == 0xbe040)))
11684         bi_disasm_add_iadd_v4u8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11685     else if (unlikely(((bits & 0xff840) == 0xbd800)))
11686         bi_disasm_add_isub_v2u16_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11687     else if (unlikely(((bits & 0xff840) == 0xbf040)))
11688         bi_disasm_add_isub_v4u8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11689     else if (unlikely(((bits & 0xff830) == 0x6f030)))
11690         bi_disasm_add_branchc_i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11691     else if (unlikely(((bits & 0xff800) == 0x60000)))
11692         bi_disasm_add_load_i8_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11693     else if (unlikely(((bits & 0xff800) == 0xd7800)
11694         && !(0x1 & (1 << _BITS(bits, 9, 2)))
11695     ))
11696         bi_disasm_add_zs_emit(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11697     else if (unlikely(((bits & 0xff800) == 0xc8800)
11698         && !(0xe0 & (1 << _BITS(bits, 8, 3)))
11699     ))
11700         bi_disasm_add_discard_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11701     else if (unlikely(((bits & 0xff800) == 0xc9000)))
11702         bi_disasm_add_ld_cvt(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11703     else if (unlikely(((bits & 0xff800) == 0xc9800)))
11704         bi_disasm_add_st_cvt(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11705     else if (unlikely(((bits & 0xff800) == 0xcb800)))
11706         bi_disasm_add_st_tile(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11707     else if (unlikely(((bits & 0xff800) == 0xcb000)))
11708         bi_disasm_add_ld_tile(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11709     else if (unlikely(((bits & 0xff800) == 0x63800)))
11710         bi_disasm_add_load_i8_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11711     else if (unlikely(((bits & 0xff800) == 0x74000)))
11712         bi_disasm_add_mux_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11713     else if (unlikely(((bits & 0xff600) == 0xd6600)))
11714         bi_disasm_add_lea_tex(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11715     else if (unlikely(((bits & 0xff038) == 0x6f000)
11716         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11717     ))
11718         bi_disasm_add_branchz_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11719     else if (unlikely(((bits & 0xff038) == 0x6f008)
11720         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11721     ))
11722         bi_disasm_add_branchz_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11723     else if (unlikely(((bits & 0xff030) == 0x6f000)
11724         && !(0x1f & (1 << _BITS(bits, 9, 3)))
11725     ))
11726         bi_disasm_add_branchz_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11727     else if (unlikely(((bits & 0xff008) == 0x6f008)
11728         && !(0x9 & (1 << _BITS(bits, 4, 2)))
11729         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11730     ))
11731         bi_disasm_add_branchz_s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11732     else if (unlikely(((bits & 0xff008) == 0x6f000)
11733         && !(0x9 & (1 << _BITS(bits, 4, 2)))
11734         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11735     ))
11736         bi_disasm_add_branchz_u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11737     else if (unlikely(((bits & 0xff000) == 0x7a000)))
11738         bi_disasm_add_icmp_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11739     else if (unlikely(((bits & 0xff000) == 0x6f000)
11740         && !(0x9 & (1 << _BITS(bits, 4, 2)))
11741         && !(0x1f & (1 << _BITS(bits, 9, 3)))
11742     ))
11743         bi_disasm_add_branchz_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11744     else if (unlikely(((bits & 0xff000) == 0xd6000)))
11745         bi_disasm_add_lea_tex_imm(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11746     else if (unlikely(((bits & 0xfefc0) == 0xbc440)))
11747         bi_disasm_add_hadd_v4s8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11748     else if (unlikely(((bits & 0xfefc0) == 0xbc640)))
11749         bi_disasm_add_hadd_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11750     else if (unlikely(((bits & 0xfefc0) == 0xbc6c0)))
11751         bi_disasm_add_hadd_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11752     else if (unlikely(((bits & 0xfefc0) == 0xbc4c0)))
11753         bi_disasm_add_hadd_v4u8(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11754     else if (unlikely(((bits & 0xfe9c0) == 0xbc840)))
11755         bi_disasm_add_hadd_v2s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11756     else if (unlikely(((bits & 0xfe9c0) == 0xbc8c0)))
11757         bi_disasm_add_hadd_v2u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11758     else if (unlikely(((bits & 0xfe800) == 0x78000)))
11759         bi_disasm_add_icmp_v2s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11760     else if (unlikely(((bits & 0xfe800) == 0x78800)))
11761         bi_disasm_add_icmp_v2u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11762     else if (unlikely(((bits & 0xfe600) == 0xc4400)))
11763         bi_disasm_add_ld_attr_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11764     else if (unlikely(((bits & 0xfe600) == 0xc4600)))
11765         bi_disasm_add_ld_attr_tex_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11766     else if (unlikely(((bits & 0xfe400) == 0xc4000)))
11767         bi_disasm_add_ld_attr_imm_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11768     else if (unlikely(((bits & 0xfe000) == 0x76000)))
11769         bi_disasm_add_v2f32_to_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11770     else if (unlikely(((bits & 0xfc600) == 0xc0400)))
11771         bi_disasm_add_lea_attr_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11772     else if (unlikely(((bits & 0xfc600) == 0xc0600)))
11773         bi_disasm_add_lea_attr_tex_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11774     else if (unlikely(((bits & 0xfc400) == 0xc0000)))
11775         bi_disasm_add_lea_attr_imm_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11776     else if (unlikely(((bits & 0xfc3e0) == 0xcc0a0)
11777         && !(0x2 & (1 << _BITS(bits, 3, 2)))
11778         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11779     ))
11780         bi_disasm_add_ld_var_special_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11781     else if (unlikely(((bits & 0xfc0c0) == 0xcc0c0)
11782         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11783     ))
11784         bi_disasm_add_ld_var_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11785     else if (unlikely(((bits & 0xfc000) == 0xcc000)
11786         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11787     ))
11788         bi_disasm_add_ld_var_imm_1(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11789     else if (unlikely(((bits & 0xfc000) == 0x7c000)))
11790         bi_disasm_add_clper_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11791     else if (unlikely(((bits & 0xfc000) == 0xd8000)))
11792         bi_disasm_add_texs_2d_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11793     else if (unlikely(((bits & 0xfc000) == 0x5c000)))
11794         bi_disasm_add_texs_cube_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11795     else if (unlikely(((bits & 0xfc000) == 0x58000)))
11796         bi_disasm_add_texs_2d_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11797     else if (unlikely(((bits & 0xfc000) == 0xdc000)))
11798         bi_disasm_add_texs_cube_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11799     else if (unlikely(((bits & 0xfc000) == 0x70000)))
11800         bi_disasm_add_mux_v2i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11801     else if (unlikely(((bits & 0xf8000) == 0x68000)
11802         && !(0xe1 & (1 << _BITS(bits, 12, 3)))
11803         && !(0xf & (1 << _BITS(bits, 9, 3)))
11804     ))
11805         bi_disasm_add_branch_f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11806     else if (unlikely(((bits & 0xf8000) == 0x68000)
11807         && !(0xfe & (1 << _BITS(bits, 12, 3)))
11808         && !(0xe0 & (1 << _BITS(bits, 9, 3)))
11809     ))
11810         bi_disasm_add_branch_s32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11811     else if (unlikely(((bits & 0xf8000) == 0x68000)
11812         && !(0xf1 & (1 << _BITS(bits, 12, 3)))
11813         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11814     ))
11815         bi_disasm_add_branch_u16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11816     else if (unlikely(((bits & 0xf8000) == 0x68000)
11817         && !(0xfe & (1 << _BITS(bits, 12, 3)))
11818         && !(0xed & (1 << _BITS(bits, 9, 3)))
11819     ))
11820         bi_disasm_add_branch_i32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11821     else if (unlikely(((bits & 0xf8000) == 0x68000)
11822         && !(0xfe & (1 << _BITS(bits, 12, 3)))
11823         && !(0xf0 & (1 << _BITS(bits, 9, 3)))
11824     ))
11825         bi_disasm_add_branch_u32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11826     else if (unlikely(((bits & 0xf8000) == 0x90000)))
11827         bi_disasm_add_fmin_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11828     else if (unlikely(((bits & 0xf8000) == 0x68000)
11829         && !(0xe1 & (1 << _BITS(bits, 12, 3)))
11830         && !(0xed & (1 << _BITS(bits, 9, 3)))
11831     ))
11832         bi_disasm_add_branch_i16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11833     else if (unlikely(((bits & 0xf8000) == 0x80000)))
11834         bi_disasm_add_fmax_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11835     else if (unlikely(((bits & 0xf8000) == 0x68000)
11836         && !(0x9e & (1 << _BITS(bits, 12, 3)))
11837         && !(0x1 & (1 << _BITS(bits, 9, 3)))
11838     ))
11839         bi_disasm_add_branch_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11840     else if (unlikely(((bits & 0xf8000) == 0x68000)
11841         && !(0xe9 & (1 << _BITS(bits, 12, 3)))
11842         && !(0xe0 & (1 << _BITS(bits, 9, 3)))
11843     ))
11844         bi_disasm_add_branch_s16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11845     else if (unlikely(((bits & 0xf0600) == 0x10000)))
11846         bi_disasm_add_fmin_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11847     else if (unlikely(((bits & 0xf0600) == 0x40600)))
11848         bi_disasm_add_ld_attr_tex_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11849     else if (unlikely(((bits & 0xf0600) == 0x0)))
11850         bi_disasm_add_fmax_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11851     else if (unlikely(((bits & 0xf0600) == 0x40400)))
11852         bi_disasm_add_ld_attr_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11853     else if (unlikely(((bits & 0xf0400) == 0x40000)))
11854         bi_disasm_add_ld_attr_imm_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11855     else if (unlikely(((bits & 0xf0000) == 0x20000)))
11856         bi_disasm_add_fadd_f32_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11857     else if (unlikely(((bits & 0xf0000) == 0xa0000)))
11858         bi_disasm_add_fadd_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11859     else if (unlikely(((bits & 0xf0000) == 0x30000)))
11860         bi_disasm_add_fcmp_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11861     else if (unlikely(((bits & 0xf0000) == 0xb0000)))
11862         bi_disasm_add_fcmp_v2f16(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11863     else if (unlikely(((bits & 0xe8000) == 0x88000)
11864         && !(0x2 & (1 << _BITS(bits, 9, 3)))
11865     ))
11866         bi_disasm_add_fadd_rscale_f32(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11867     else if (unlikely(((bits & 0x7f8c0) == 0x538c0)))
11868         bi_disasm_add_ld_var_flat_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11869     else if (unlikely(((bits & 0x7f800) == 0x53800)))
11870         bi_disasm_add_ld_var_flat_imm_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11871     else if (unlikely(((bits & 0x7c3e0) == 0x500a0)
11872         && !(0x2 & (1 << _BITS(bits, 3, 2)))
11873         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11874     ))
11875         bi_disasm_add_ld_var_special_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11876     else if (unlikely(((bits & 0x7c0c0) == 0x500c0)
11877         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11878     ))
11879         bi_disasm_add_ld_var_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11880     else if (unlikely(((bits & 0x7c000) == 0x50000)
11881         && !(0xc0e0 & (1 << _BITS(bits, 10, 4)))
11882     ))
11883         bi_disasm_add_ld_var_imm_0(fp, bits, srcs, next_regs, staging_register, branch_offset, consts, last);
11884     else
11885         fprintf(fp, "INSTR_INVALID_ENC add %X\n", bits);
11886 }
11887