pan/bi: Fix source mod testing for CMP
[mesa.git] / src / panfrost / bifrost / bifrost.h
1 /*
2 * Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
3 * Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
4 * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #ifndef __bifrost_h__
27 #define __bifrost_h__
28
29 #include <stdint.h>
30 #include <stdbool.h>
31
32 enum bifrost_clause_type {
33 BIFROST_CLAUSE_NONE = 0,
34 BIFROST_CLAUSE_LOAD_VARY = 1,
35 BIFROST_CLAUSE_UBO = 2,
36 BIFROST_CLAUSE_TEX = 3,
37 BIFROST_CLAUSE_SSBO_LOAD = 5,
38 BIFROST_CLAUSE_SSBO_STORE = 6,
39 BIFROST_CLAUSE_BLEND = 9,
40 BIFROST_CLAUSE_ATEST = 13,
41 BIFROST_CLAUSE_64BIT = 15
42 };
43
44 struct bifrost_header {
45 unsigned unk0 : 7;
46 // If true, convert any infinite result of any floating-point operation to
47 // the biggest representable number.
48 unsigned suppress_inf: 1;
49 // Convert any NaN results to 0.
50 unsigned suppress_nan : 1;
51 unsigned unk1 : 2;
52 // true if the execution mask of the next clause is the same as the mask of
53 // the current clause.
54 unsigned back_to_back : 1;
55 unsigned no_end_of_shader: 1;
56 unsigned unk2 : 2;
57 // Set to true for fragment shaders, to implement this bit of spec text
58 // from section 7.1.5 of the GLSL ES spec:
59 //
60 // "Stores to image and buffer variables performed by helper invocations
61 // have no effect on the underlying image or buffer memory."
62 //
63 // Helper invocations are threads (invocations) corresponding to pixels in
64 // a quad that aren't actually part of the triangle, but are included to
65 // make derivatives work correctly. They're usually turned on, but they
66 // need to be masked off for GLSL-level stores. This bit seems to be the
67 // only bit that's actually different between fragment shaders and other
68 // shaders, so this is probably what it's doing.
69 unsigned elide_writes : 1;
70 // If backToBack is off:
71 // - true for conditional branches and fallthrough
72 // - false for unconditional branches
73 // The blob seems to always set it to true if back-to-back is on.
74 unsigned branch_cond : 1;
75 // This bit is set when the next clause writes to the data register of some
76 // previous clause.
77 unsigned datareg_writebarrier: 1;
78 unsigned datareg : 6;
79 unsigned scoreboard_deps: 8;
80 unsigned scoreboard_index: 3;
81 enum bifrost_clause_type clause_type: 4;
82 unsigned unk3 : 1; // part of clauseType?
83 enum bifrost_clause_type next_clause_type: 4;
84 unsigned unk4 : 1; // part of nextClauseType?
85 } __attribute__((packed));
86
87 enum bifrost_packed_src {
88 BIFROST_SRC_PORT0 = 0,
89 BIFROST_SRC_PORT1 = 1,
90 BIFROST_SRC_PORT3 = 2,
91 BIFROST_SRC_STAGE = 3,
92 BIFROST_SRC_CONST_LO = 4,
93 BIFROST_SRC_CONST_HI = 5,
94 BIFROST_SRC_PASS_FMA = 6,
95 BIFROST_SRC_PASS_ADD = 7,
96 };
97
98 #define BIFROST_FMA_EXT (0xe0000)
99 #define BIFROST_FMA_OP_MOV BIFROST_FMA_EXT | (0x32d)
100 #define BIFROST_FMA_OP_FREXPE_LOG BIFROST_FMA_EXT | 0x3c5
101 #define BIFROST_FMA_OP_ADD_FREXPM ((BIFROST_FMA_EXT | 0x1e80) >> 3)
102 #define BIFROST_FMA_SEL_16(swiz) (((BIFROST_FMA_EXT | 0x1e00) >> 3) | (swiz))
103
104 struct bifrost_fma_inst {
105 unsigned src0 : 3;
106 unsigned op : 20;
107 } __attribute__((packed));
108
109 struct bifrost_fma_2src {
110 unsigned src0 : 3;
111 unsigned src1 : 3;
112 unsigned op : 17;
113 } __attribute__((packed));
114
115 #define BIFROST_FMA_OP_SEL8 (0x71)
116
117 struct bifrost_fma_sel8 {
118 unsigned src0 : 3;
119 unsigned src1 : 3;
120 unsigned src2 : 3;
121 unsigned src3 : 3;
122 unsigned swizzle : 4;
123 unsigned op : 7;
124 } __attribute__((packed));
125
126 #define BIFROST_FMA_OP_MSCALE (0x50 >> 3)
127
128 struct bifrost_fma_mscale {
129 unsigned src0 : 3;
130 unsigned src1 : 3;
131 unsigned src2 : 3;
132 unsigned src3 : 3;
133
134 /* If mscale_mode is set - an MSCALE specific mode. If it is not set, a
135 * regular outmod */
136 unsigned mode : 2;
137 unsigned mscale_mode : 1;
138
139 unsigned src0_abs : 1;
140 unsigned src1_neg : 1;
141 unsigned src2_neg : 1;
142 unsigned op : 5;
143 } __attribute__((packed));
144
145 #define BIFROST_ADD_OP_BLEND (0x1952c)
146 #define BIFROST_ADD_OP_FRCP_FAST_F32 (0x0cc00)
147 #define BIFROST_ADD_OP_FRCP_FAST_F16_X (0x0ce10)
148 #define BIFROST_ADD_OP_FRCP_FAST_F16_Y (0x0ce30)
149 #define BIFROST_ADD_OP_FRSQ_FAST_F32 (0x0cc20)
150 #define BIFROST_ADD_OP_FRSQ_FAST_F16_X (0x0ce50)
151 #define BIFROST_ADD_OP_FRSQ_FAST_F16_Y (0x0ce70)
152 #define BIFROST_ADD_OP_LOG2_HELP (0x0cc68)
153 #define BIFROST_ADD_OP_FEXP2_FAST (0x0cd58)
154
155 struct bifrost_add_inst {
156 unsigned src0 : 3;
157 unsigned op : 17;
158 } __attribute__((packed));
159
160 #define BIFROST_ADD_OP_LD_UBO_1 (0x0c1a0 >> 3)
161 #define BIFROST_ADD_OP_LD_UBO_2 (0x0c1e0 >> 3)
162 #define BIFROST_ADD_OP_LD_UBO_3 (0x0caa0 >> 3)
163 #define BIFROST_ADD_OP_LD_UBO_4 (0x0c220 >> 3)
164 #define BIFROST_ADD_SEL_16(swiz) ((0xea60 >> 3) | (swiz))
165
166 struct bifrost_add_2src {
167 unsigned src0 : 3;
168 unsigned src1 : 3;
169 unsigned op : 14;
170 } __attribute__((packed));
171
172 #define BIFROST_ADD_OP_FMAX32 (0x00)
173 #define BIFROST_ADD_OP_FMIN32 (0x01)
174 #define BIFROST_ADD_OP_FADD32 (0x02)
175
176 #define BIFROST_ADD_OP_FADD16 (0x0A)
177
178 struct bifrost_add_faddmin {
179 unsigned src0 : 3;
180 unsigned src1 : 3;
181 unsigned src1_abs : 1;
182 unsigned src0_neg : 1;
183 unsigned src1_neg : 1;
184 unsigned select : 2; /* swizzle_0 for fp16 */
185 unsigned outmod : 2; /* swizzle_1 for fp16 */
186 unsigned mode : 2;
187 unsigned src0_abs : 1;
188 unsigned op : 4;
189 } __attribute__((packed));
190
191 #define BIFROST_ADD_OP_FMAX16 (0x10)
192 #define BIFROST_ADD_OP_FMIN16 (0x12)
193
194 struct bifrost_add_fmin16 {
195 unsigned src0 : 3;
196 unsigned src1 : 3;
197 /* abs2 inferred as with FMA */
198 unsigned abs1 : 1;
199 unsigned src0_neg : 1;
200 unsigned src1_neg : 1;
201 unsigned src0_swizzle : 2;
202 unsigned src1_swizzle : 2;
203 unsigned mode : 2;
204 unsigned op : 5;
205 } __attribute__((packed));
206
207 #define BIFROST_ADD_OP_ST_VAR (0x19300 >> 8)
208
209 struct bifrost_st_vary {
210 unsigned src0 : 3;
211 unsigned src1 : 3;
212 unsigned src2 : 3;
213 unsigned channels : 2;
214 unsigned op : 9;
215 } __attribute__((packed));
216
217 #define BIFROST_ADD_OP_ATEST (0xc8f)
218
219 struct bifrost_add_atest {
220 /* gl_SampleMask (R60) */
221 unsigned src0 : 3;
222
223 /* Alpha value */
224 unsigned src1 : 3;
225
226 /* If half, X/Y select. If !half, always set */
227 unsigned component : 1;
228 unsigned half : 1;
229
230 unsigned op : 12;
231 } __attribute__((packed));
232
233 enum bifrost_outmod {
234 BIFROST_NONE = 0x0,
235 BIFROST_POS = 0x1,
236 BIFROST_SAT_SIGNED = 0x2,
237 BIFROST_SAT = 0x3,
238 };
239
240 enum bifrost_roundmode {
241 BIFROST_RTE = 0x0, /* round to even */
242 BIFROST_RTP = 0x1, /* round to positive */
243 BIFROST_RTN = 0x2, /* round to negative */
244 BIFROST_RTZ = 0x3 /* round to zero */
245 };
246
247 /* NONE: Same as fmax() and fmin() -- return the other
248 * number if any number is NaN. Also always return +0 if
249 * one argument is +0 and the other is -0.
250 *
251 * NAN_WINS: Instead of never returning a NaN, always return
252 * one. The "greater"/"lesser" NaN is always returned, first
253 * by checking the sign and then the mantissa bits.
254 *
255 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
256 * For min, implement src0 < src1 ? src0 : src1. This
257 * includes handling NaN's and signedness of 0 differently
258 * from above, since +0 and -0 compare equal and comparisons
259 * always return false for NaN's. As a result, this mode is
260 * *not* commutative.
261 *
262 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
263 * For min, implement src0 > src1 ? src1 : src0
264 */
265
266
267 enum bifrost_minmax_mode {
268 BIFROST_MINMAX_NONE = 0x0,
269 BIFROST_NAN_WINS = 0x1,
270 BIFROST_SRC1_WINS = 0x2,
271 BIFROST_SRC0_WINS = 0x3,
272 };
273
274 #define BIFROST_FMA_OP_FADD32 (0x58 >> 2)
275 #define BIFROST_FMA_OP_FMAX32 (0x40 >> 2)
276 #define BIFROST_FMA_OP_FMIN32 (0x44 >> 2)
277
278 struct bifrost_fma_add {
279 unsigned src0 : 3;
280 unsigned src1 : 3;
281 unsigned src1_abs : 1;
282 unsigned src0_neg : 1;
283 unsigned src1_neg : 1;
284 unsigned unk : 3;
285 unsigned src0_abs : 1;
286 enum bifrost_roundmode roundmode : 2;
287 enum bifrost_outmod outmod : 2;
288 unsigned op : 6;
289 } __attribute__((packed));
290
291 #define BIFROST_FMA_OP_FMAX16 (0xC0 >> 2)
292 #define BIFROST_FMA_OP_FMIN16 (0xCC >> 2)
293 #define BIFROST_FMA_OP_FADD16 (0xD8 >> 2)
294
295 struct bifrost_fma_add_minmax16 {
296 unsigned src0 : 3;
297 unsigned src1 : 3;
298 /* abs2 inferred as (src1 < src0) */
299 unsigned abs1 : 1;
300 unsigned src0_neg : 1;
301 unsigned src1_neg : 1;
302 unsigned src0_swizzle : 2;
303 unsigned src1_swizzle : 2;
304 unsigned mode : 2;
305 enum bifrost_outmod outmod : 2;
306 /* roundmode for add, min/max mode for min/max */
307 unsigned op : 6;
308 } __attribute__((packed));
309
310 #define BIFROST_FMA_OP_FMA (0x00)
311
312 struct bifrost_fma_fma {
313 unsigned src0 : 3;
314 unsigned src1 : 3;
315 unsigned src2 : 3;
316 unsigned src_expand : 3;
317 unsigned src0_abs : 1;
318 enum bifrost_roundmode roundmode : 2;
319 enum bifrost_outmod outmod : 2;
320 unsigned src0_neg : 1; /* 14 */
321 unsigned src2_neg : 1;
322 unsigned src1_abs : 1;
323 unsigned src2_abs : 1; /* 17 */
324 unsigned op : 2;
325 } __attribute__((packed));
326
327 #define BIFROST_FMA_OP_FMA16 (0x2)
328
329 struct bifrost_fma_fma16 {
330 unsigned src0 : 3;
331 unsigned src1 : 3;
332 unsigned src2 : 3;
333 unsigned swizzle_0 : 2;
334 unsigned swizzle_1 : 2;
335 enum bifrost_roundmode roundmode : 2;
336 enum bifrost_outmod outmod : 2;
337 unsigned src0_neg : 1;
338 unsigned src2_neg : 1;
339 unsigned swizzle_2 : 2;
340 unsigned op : 2;
341 } __attribute__((packed));
342
343 enum bifrost_csel_cond {
344 BIFROST_FEQ_F = 0x0,
345 BIFROST_FGT_F = 0x1,
346 BIFROST_FGE_F = 0x2,
347 BIFROST_IEQ_F = 0x3,
348 BIFROST_IGT_I = 0x4,
349 BIFROST_IGE_I = 0x5,
350 BIFROST_UGT_I = 0x6,
351 BIFROST_UGE_I = 0x7
352 };
353
354 #define BIFROST_FMA_OP_CSEL4 (0x5c)
355 #define BIFROST_FMA_OP_CSEL4_V16 (0xdc)
356
357 struct bifrost_csel4 {
358 unsigned src0 : 3;
359 unsigned src1 : 3;
360 unsigned src2 : 3;
361 unsigned src3 : 3;
362 enum bifrost_csel_cond cond : 3;
363 unsigned op : 8;
364 } __attribute__((packed));
365
366 struct bifrost_shift_fma {
367 unsigned src0 : 3;
368 unsigned src1 : 3;
369 unsigned src2 : 3;
370 unsigned half : 3; /* 000 for i32, 100 for i8, 111 for v2i16 */
371 unsigned unk : 1; /* always set? */
372 unsigned invert_1 : 1; /* Inverts sources to combining op */
373 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
374 unsigned invert_2 : 1;
375 unsigned op : 8;
376 } __attribute__((packed));
377
378 struct bifrost_shift_add {
379 unsigned src0 : 3;
380 unsigned src1 : 3;
381 unsigned src2 : 3;
382 unsigned zero : 2;
383
384 unsigned invert_1 : 1;
385 unsigned invert_2 : 1;
386
387 unsigned op : 7;
388 } __attribute__((packed));
389
390 enum bifrost_fcmp_cond {
391 BIFROST_OEQ = 0,
392 BIFROST_OGT = 1,
393 BIFROST_OGE = 2,
394 BIFROST_UNE = 3,
395 BIFROST_OLT = 4,
396 BIFROST_OLE = 5,
397 };
398
399 struct bifrost_fma_fcmp {
400 unsigned src0 : 3;
401 unsigned src1 : 3;
402 unsigned src1_abs : 1;
403 unsigned unk1 : 1;
404 unsigned src1_neg : 1;
405 unsigned src_expand : 3;
406 unsigned src0_abs : 1;
407 enum bifrost_fcmp_cond cond : 3;
408 unsigned op : 7;
409 } __attribute__((packed));
410
411 struct bifrost_add_fcmp {
412 unsigned src0 : 3;
413 unsigned src1 : 3;
414 enum bifrost_fcmp_cond cond : 3;
415 unsigned src_expand : 2;
416 unsigned src0_abs : 1;
417 unsigned src1_abs : 1;
418 unsigned src1_neg : 1;
419 unsigned op : 6;
420 } __attribute__((packed));
421
422 struct bifrost_fma_fcmp16 {
423 unsigned src0 : 3;
424 unsigned src1 : 3;
425
426 /* abs2 inferred */
427 unsigned abs1 : 1;
428 unsigned unk : 2;
429
430 unsigned src0_swizzle : 2;
431 unsigned src1_swizzle : 2;
432
433 enum bifrost_fcmp_cond cond : 3;
434 unsigned op : 7;
435 } __attribute__((packed));
436
437 struct bifrost_add_fcmp16 {
438 unsigned src0 : 3;
439 unsigned src1 : 3;
440 enum bifrost_fcmp_cond cond : 3;
441
442 unsigned src0_swizzle : 2;
443 unsigned src1_swizzle : 2;
444
445 /* No abs mods */
446 unsigned src0_neg : 1;
447
448 unsigned op : 6;
449 } __attribute__((packed));
450
451 enum bifrost_icmp_cond {
452 BIFROST_ICMP_IGT = 0,
453 BIFROST_ICMP_IGE = 1,
454 BIFROST_ICMP_UGT = 2,
455 BIFROST_ICMP_UGE = 3,
456 BIFROST_ICMP_EQ = 4,
457 BIFROST_ICMP_NEQ = 5,
458 };
459
460 struct bifrost_fma_icmp32 {
461 unsigned src0 : 3;
462 unsigned src1 : 3;
463 enum bifrost_icmp_cond cond : 3;
464 unsigned unk1 : 1; /* set */
465 unsigned d3d : 1;
466 unsigned op : 12;
467 } __attribute__((packed));
468
469 struct bifrost_fma_icmp16 {
470 unsigned src0 : 3;
471 unsigned src1 : 3;
472 unsigned unk : 5; /* 11010 */
473 enum bifrost_icmp_cond cond : 3;
474 unsigned op : 9;
475 } __attribute__((packed));
476
477 struct bifrost_add_icmp {
478 unsigned src0 : 3;
479 unsigned src1 : 3;
480 enum bifrost_icmp_cond cond : 3;
481 unsigned sz : 1; /* 1 for 32, 0 for 8 */
482 unsigned d3d : 1;
483 unsigned op : 9;
484 } __attribute__((packed));
485
486 /* Two sources for vectorization */
487 #define BIFROST_FMA_FLOAT32_TO_16 (0xdd000 >> 3)
488 #define BIFROST_ADD_FLOAT32_TO_16 (0x0EC00 >> 3)
489
490 enum bifrost_convert_mode {
491 BIFROST_CONV_UNK0 = 0,
492 BIFROST_CONV_F32_TO_I32 = 1,
493 BIFROST_CONV_F16_TO_I16 = 2,
494 BIFROST_CONV_I32_TO_F32 = 3,
495 BIFROST_CONV_I16_TO_X32 = 4,
496 BIFROST_CONV_F16_TO_F32 = 5,
497 BIFROST_CONV_I16_TO_F16 = 6,
498 BIFROST_CONV_UNK7 = 7
499 };
500
501 /* i16 to x32 */
502 #define BIFROST_CONVERT_4(is_unsigned, component, to_float) \
503 ((is_unsigned & 1) | ((component & 1) << 1) | ((to_float & 1) << 2) | \
504 ((0x3) << 3) | ((4) << 5) | 0x100)
505
506 /* f16 to f32 */
507 #define BIFROST_CONVERT_5(component) \
508 ((component & 1) | ((1) << 1) | ((5) << 5) | 0x100)
509
510 /* Other conversions */
511 #define BIFROST_CONVERT(is_unsigned, roundmode, swizzle, mode) \
512 ((is_unsigned & 1) | ((roundmode & 3) << 1) | ((swizzle & 3) << 3) | ((mode & 7) << 5))
513
514 #define BIFROST_FMA_CONVERT (0xe0000)
515 #define BIFROST_ADD_CONVERT (0x07800)
516
517 enum bifrost_ldst_type {
518 BIFROST_LDST_F16 = 0,
519 BIFROST_LDST_F32 = 1,
520 BIFROST_LDST_I32 = 2,
521 BIFROST_LDST_U32 = 3
522 };
523
524 #define BIFROST_ADD_OP_LD_VAR_ADDR (0x18000 >> 10)
525
526 struct bifrost_ld_var_addr {
527 unsigned src0 : 3;
528 unsigned src1 : 3;
529 unsigned location : 5;
530 enum bifrost_ldst_type type : 2;
531 unsigned op : 7;
532 } __attribute__((packed));
533
534 #define BIFROST_ADD_OP_LD_ATTR (0x08000 >> 12)
535
536 struct bifrost_ld_attr {
537 unsigned src0 : 3;
538 unsigned src1 : 3;
539 unsigned location : 5;
540 unsigned channels : 2; /* MALI_POSITIVE */
541 enum bifrost_ldst_type type : 2;
542 unsigned op : 5;
543 } __attribute__((packed));
544
545 enum bifrost_interp_mode {
546 BIFROST_INTERP_PER_FRAG = 0x0,
547 BIFROST_INTERP_CENTROID = 0x1,
548 BIFROST_INTERP_DEFAULT = 0x2,
549 BIFROST_INTERP_EXPLICIT = 0x3
550 };
551
552 #define BIFROST_ADD_OP_LD_VAR_16 (0x1a << 1)
553 #define BIFROST_ADD_OP_LD_VAR_32 (0x0a << 1)
554
555 struct bifrost_ld_var {
556 unsigned src0 : 3;
557
558 /* If top two bits set, indirect with src in bottom three */
559 unsigned addr : 5;
560
561 unsigned channels : 2; /* MALI_POSITIVE */
562 enum bifrost_interp_mode interp_mode : 2;
563 unsigned reuse : 1;
564 unsigned flat : 1;
565 unsigned op : 6;
566 } __attribute__((packed));
567
568 struct bifrost_tex_ctrl {
569 unsigned sampler_index : 4; // also used to signal indirects
570 unsigned tex_index : 7;
571 bool no_merge_index : 1; // whether to merge (direct) sampler & texture indices
572 bool filter : 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
573 unsigned unk0 : 2;
574 bool texel_offset : 1; // *Offset()
575 bool is_shadow : 1;
576 bool is_array : 1;
577 unsigned tex_type : 2; // 2D, 3D, Cube, Buffer
578 bool compute_lod : 1; // 0 for *Lod()
579 bool not_supply_lod : 1; // 0 for *Lod() or when a bias is applied
580 bool calc_gradients : 1; // 0 for *Grad()
581 unsigned unk1 : 1;
582 unsigned result_type : 4; // integer, unsigned, float TODO: why is this 4 bits?
583 unsigned unk2 : 4;
584 } __attribute__((packed));
585
586 struct bifrost_dual_tex_ctrl {
587 unsigned sampler_index0 : 2;
588 unsigned unk0 : 2;
589 unsigned tex_index0 : 2;
590 unsigned sampler_index1 : 2;
591 unsigned tex_index1 : 2;
592 unsigned unk1 : 22;
593 } __attribute__((packed));
594
595 #define BIFROST_ADD_OP_TEX_COMPACT_F32 (0x0b000 >> 10)
596 #define BIFROST_ADD_OP_TEX_COMPACT_F16 (0x1b000 >> 10)
597
598 struct bifrost_tex_compact {
599 unsigned src0 : 3;
600 unsigned src1 : 3;
601 unsigned tex_index : 3;
602 unsigned unknown : 1;
603 unsigned sampler_index : 3;
604 unsigned op : 7;
605 } __attribute__((packed));
606
607 enum branch_bit_size {
608 BR_SIZE_32 = 0,
609 BR_SIZE_16XX = 1,
610 BR_SIZE_16YY = 2,
611 // For the above combinations of bitsize and location, an extra bit is
612 // encoded via comparing the sources. The only possible source of ambiguity
613 // would be if the sources were the same, but then the branch condition
614 // would be always true or always false anyways, so we can ignore it. But
615 // this no longer works when comparing the y component to the x component,
616 // since it's valid to compare the y component of a source against its own
617 // x component. Instead, the extra bit is encoded via an extra bitsize.
618 BR_SIZE_16YX0 = 3,
619 BR_SIZE_16YX1 = 4,
620 BR_SIZE_32_AND_16X = 5,
621 BR_SIZE_32_AND_16Y = 6,
622 // Used for comparisons with zero and always-true, see below. I think this
623 // only works for integer comparisons.
624 BR_SIZE_ZERO = 7,
625 };
626
627 enum bifrost_reg_write_unit {
628 REG_WRITE_NONE = 0, // don't write
629 REG_WRITE_TWO, // write using reg2
630 REG_WRITE_THREE, // write using reg3
631 };
632
633 struct bifrost_regs {
634 unsigned uniform_const : 8;
635 unsigned reg2 : 6;
636 unsigned reg3 : 6;
637 unsigned reg0 : 5;
638 unsigned reg1 : 6;
639 unsigned ctrl : 4;
640 } __attribute__((packed));
641
642 enum bifrost_branch_cond {
643 BR_COND_LT = 0,
644 BR_COND_LE = 1,
645 BR_COND_GE = 2,
646 BR_COND_GT = 3,
647 // Equal vs. not-equal determined by src0/src1 comparison
648 BR_COND_EQ = 4,
649 // floating-point comparisons
650 // Becomes UNE when you flip the arguments
651 BR_COND_OEQ = 5,
652 // TODO what happens when you flip the arguments?
653 BR_COND_OGT = 6,
654 BR_COND_OLT = 7,
655 };
656
657 enum bifrost_branch_code {
658 BR_ALWAYS = 63,
659 };
660
661 struct bifrost_branch {
662 unsigned src0 : 3;
663
664 /* For BR_SIZE_ZERO, upper two bits become ctrl */
665 unsigned src1 : 3;
666
667 /* Offset source -- always uniform/const but
668 * theoretically could support indirect jumps? */
669 unsigned src2 : 3;
670
671 enum bifrost_branch_cond cond : 3;
672 enum branch_bit_size size : 3;
673
674 unsigned op : 5;
675 };
676
677 /* Clause packing */
678
679 #define BIFROST_FMA_NOP (0x701960 | BIFROST_SRC_STAGE)
680 #define BIFROST_ADD_NOP (0x3D960 | BIFROST_SRC_STAGE)
681
682 struct bifrost_fmt1 {
683 unsigned ins_0 : 3;
684 unsigned tag : 5;
685 uint64_t ins_1 : 64;
686 unsigned ins_2 : 11;
687 uint64_t header : 45;
688 } __attribute__((packed));
689
690 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
691 #define BIFROST_FMT1_FINAL 0b01001
692 #define BIFROST_FMT1_CONSTANTS 0b00001
693
694 #define BIFROST_FMTC_CONSTANTS 0b0011
695 #define BIFROST_FMTC_FINAL 0b0111
696
697 struct bifrost_fmt_constant {
698 unsigned pos : 4;
699 unsigned tag : 4;
700 uint64_t imm_1 : 60;
701 uint64_t imm_2 : 60;
702 } __attribute__((packed));
703
704 enum bifrost_reg_control {
705 BIFROST_WRITE_FMA_P2 = 1,
706 BIFROST_WRITE_FMA_P2_READ_P3 = 2,
707 BIFROST_FIRST_WRITE_FMA_P2_READ_P3 = 3,
708 BIFROST_READ_P3 = 4,
709 BIFROST_WRITE_ADD_P2 = 5,
710 BIFROST_WRITE_ADD_P2_READ_P3 = 6,
711 BIFROST_WRITE_ADD_P2_FMA_P3 = 7,
712
713 BIFROST_FIRST_NONE = 8,
714 BIFROST_FIRST_WRITE_FMA_P2 = 9,
715 /* INSTR_INVALID_ENC */
716 BIFROST_REG_NONE = 11,
717 BIFROST_FIRST_READ_P3 = 12,
718 BIFROST_FIRST_WRITE_ADD_P2 = 13,
719 BIFROST_FIRST_WRITE_ADD_P2_READ_P3 = 14,
720 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3 = 15
721 };
722
723 #endif