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>
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:
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
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
32 #define BIFROST_DBG_MSGS 0x0001
33 #define BIFROST_DBG_SHADERS 0x0002
35 extern int bifrost_debug
;
37 enum bifrost_clause_type
{
38 BIFROST_CLAUSE_NONE
= 0,
39 BIFROST_CLAUSE_LOAD_VARY
= 1,
40 BIFROST_CLAUSE_UBO
= 2,
41 BIFROST_CLAUSE_TEX
= 3,
42 BIFROST_CLAUSE_SSBO_LOAD
= 5,
43 BIFROST_CLAUSE_SSBO_STORE
= 6,
44 BIFROST_CLAUSE_BLEND
= 9,
45 BIFROST_CLAUSE_FRAGZ
= 12,
46 BIFROST_CLAUSE_ATEST
= 13,
47 BIFROST_CLAUSE_64BIT
= 15
50 struct bifrost_header
{
52 // If true, convert any infinite result of any floating-point operation to
53 // the biggest representable number.
54 unsigned suppress_inf
: 1;
55 // Convert any NaN results to 0.
56 unsigned suppress_nan
: 1;
58 // true if the execution mask of the next clause is the same as the mask of
59 // the current clause.
60 unsigned back_to_back
: 1;
61 unsigned no_end_of_shader
: 1;
63 // Set to true for fragment shaders, to implement this bit of spec text
64 // from section 7.1.5 of the GLSL ES spec:
66 // "Stores to image and buffer variables performed by helper invocations
67 // have no effect on the underlying image or buffer memory."
69 // Helper invocations are threads (invocations) corresponding to pixels in
70 // a quad that aren't actually part of the triangle, but are included to
71 // make derivatives work correctly. They're usually turned on, but they
72 // need to be masked off for GLSL-level stores. This bit seems to be the
73 // only bit that's actually different between fragment shaders and other
74 // shaders, so this is probably what it's doing.
75 unsigned elide_writes
: 1;
76 // If backToBack is off:
77 // - true for conditional branches and fallthrough
78 // - false for unconditional branches
79 // The blob seems to always set it to true if back-to-back is on.
80 unsigned branch_cond
: 1;
81 // This bit is set when the next clause writes to the data register of some
83 unsigned datareg_writebarrier
: 1;
85 unsigned scoreboard_deps
: 8;
86 unsigned scoreboard_index
: 3;
87 enum bifrost_clause_type clause_type
: 4;
88 unsigned unk3
: 1; // part of clauseType?
89 enum bifrost_clause_type next_clause_type
: 4;
90 unsigned unk4
: 1; // part of nextClauseType?
91 } __attribute__((packed
));
93 enum bifrost_packed_src
{
94 BIFROST_SRC_PORT0
= 0,
95 BIFROST_SRC_PORT1
= 1,
96 BIFROST_SRC_PORT3
= 2,
97 BIFROST_SRC_STAGE
= 3,
98 BIFROST_SRC_CONST_LO
= 4,
99 BIFROST_SRC_CONST_HI
= 5,
100 BIFROST_SRC_PASS_FMA
= 6,
101 BIFROST_SRC_PASS_ADD
= 7,
104 #define BIFROST_FMA_EXT (0xe0000)
105 #define BIFROST_FMA_OP_MOV BIFROST_FMA_EXT | (0x32d)
106 #define BIFROST_FMA_OP_FREXPE_LOG BIFROST_FMA_EXT | 0x3c5
107 #define BIFROST_FMA_OP_ADD_FREXPM ((BIFROST_FMA_EXT | 0x1e80) >> 3)
108 #define BIFROST_FMA_SEL_16(swiz) (((BIFROST_FMA_EXT | 0x1e00) >> 3) | (swiz))
110 #define BIFROST_FMA_ROUND_16(mode, swiz) (BIFROST_FMA_EXT | 0x1800 | (swiz) | ((mode) << 6))
111 #define BIFROST_FMA_ROUND_32(mode) (BIFROST_FMA_EXT | 0x1805 | ((mode) << 6))
113 struct bifrost_fma_inst
{
116 } __attribute__((packed
));
118 #define BIFROST_FMA_IADD_32 (0x4ff98 >> 3)
119 #define BIFROST_FMA_ISUB_32 (0x4ffd8 >> 3)
120 #define BIFROST_FMA_IMUL_32 ((BIFROST_FMA_EXT | 0x7818) >> 3)
122 struct bifrost_fma_2src
{
126 } __attribute__((packed
));
128 #define BIFROST_FMA_OP_SEL8 (0x71)
130 struct bifrost_fma_sel8
{
135 unsigned swizzle
: 4;
137 } __attribute__((packed
));
139 #define BIFROST_FMA_OP_MSCALE (0x50 >> 3)
141 struct bifrost_fma_mscale
{
147 /* If mscale_mode is set - an MSCALE specific mode. If it is not set, a
150 unsigned mscale_mode
: 1;
152 unsigned src0_abs
: 1;
153 unsigned src1_neg
: 1;
154 unsigned src2_neg
: 1;
156 } __attribute__((packed
));
158 #define BIFROST_ADD_OP_BLEND (0x1952c)
159 #define BIFROST_ADD_OP_FRCP_FAST_F32 (0x0cc00)
160 #define BIFROST_ADD_OP_FRCP_FAST_F16_X (0x0ce10)
161 #define BIFROST_ADD_OP_FRCP_FAST_F16_Y (0x0ce30)
162 #define BIFROST_ADD_OP_FRSQ_FAST_F32 (0x0cc20)
163 #define BIFROST_ADD_OP_FRSQ_FAST_F16_X (0x0ce50)
164 #define BIFROST_ADD_OP_FRSQ_FAST_F16_Y (0x0ce70)
165 #define BIFROST_ADD_OP_LOG2_HELP (0x0cc68)
166 #define BIFROST_ADD_OP_IABS_32 (0x07bd4)
168 struct bifrost_add_inst
{
171 } __attribute__((packed
));
173 #define BIFROST_ADD_OP_DISCARD (0x19100 >> 8)
175 enum bifrost_discard_cond
{
176 BIFROST_DISCARD_FEQ
= 0,
177 BIFROST_DISCARD_FNE
= 1,
178 BIFROST_DISCARD_FLE
= 2,
179 BIFROST_DISCARD_FLT
= 3,
182 struct bifrost_add_discard
{
185 enum bifrost_discard_cond cond
: 2;
187 unsigned src0_select
: 1;
188 unsigned src1_select
: 1;
191 } __attribute__((packed
));
193 #define BIFROST_ADD_OP_LD_UBO_1 (0x0c1a0 >> 3)
194 #define BIFROST_ADD_OP_LD_UBO_2 (0x0c1e0 >> 3)
195 #define BIFROST_ADD_OP_LD_UBO_3 (0x0caa0 >> 3)
196 #define BIFROST_ADD_OP_LD_UBO_4 (0x0c220 >> 3)
197 #define BIFROST_ADD_SEL_16(swiz) ((0xea60 >> 3) | (swiz))
199 #define BIFROST_ADD_IADD_8 (0x17880 >> 3)
200 #define BIFROST_ADD_IADD_16 (0x17900 >> 3)
201 #define BIFROST_ADD_IADD_32 (0x178c0 >> 3)
202 #define BIFROST_ADD_ISUB_8 (0x17a80 >> 3)
203 #define BIFROST_ADD_ISUB_16 (0x17b00 >> 3)
204 #define BIFROST_ADD_ISUB_32 (0x17ac0 >> 3)
205 #define BIFROST_ADD_OP_FEXP2_FAST (0x0cd58 >> 3)
207 struct bifrost_add_2src
{
211 } __attribute__((packed
));
213 #define BIFROST_ADD_OP_FMAX32 (0x00)
214 #define BIFROST_ADD_OP_FMIN32 (0x01)
215 #define BIFROST_ADD_OP_FADD32 (0x02)
217 #define BIFROST_ADD_OP_FADD16 (0x0A)
219 struct bifrost_add_faddmin
{
222 unsigned src1_abs
: 1;
223 unsigned src0_neg
: 1;
224 unsigned src1_neg
: 1;
225 unsigned select
: 2; /* swizzle_0 for fp16 */
226 unsigned outmod
: 2; /* swizzle_1 for fp16 */
228 unsigned src0_abs
: 1;
230 } __attribute__((packed
));
232 #define BIFROST_ADD_OP_FMAX16 (0x10)
233 #define BIFROST_ADD_OP_FMIN16 (0x12)
235 struct bifrost_add_fmin16
{
238 /* abs2 inferred as with FMA */
240 unsigned src0_neg
: 1;
241 unsigned src1_neg
: 1;
242 unsigned src0_swizzle
: 2;
243 unsigned src1_swizzle
: 2;
246 } __attribute__((packed
));
248 #define BIFROST_ADD_OP_ST_VAR (0x19300 >> 8)
250 struct bifrost_st_vary
{
254 unsigned channels
: 2;
256 } __attribute__((packed
));
258 #define BIFROST_ADD_OP_ATEST (0xc8f)
260 struct bifrost_add_atest
{
261 /* gl_SampleMask (R60) */
267 /* If half, X/Y select. If !half, always set */
268 unsigned component
: 1;
272 } __attribute__((packed
));
274 enum bifrost_outmod
{
277 BIFROST_SAT_SIGNED
= 0x2,
281 enum bifrost_roundmode
{
282 BIFROST_RTE
= 0x0, /* round to even */
283 BIFROST_RTP
= 0x1, /* round to positive */
284 BIFROST_RTN
= 0x2, /* round to negative */
285 BIFROST_RTZ
= 0x3 /* round to zero */
288 /* NONE: Same as fmax() and fmin() -- return the other
289 * number if any number is NaN. Also always return +0 if
290 * one argument is +0 and the other is -0.
292 * NAN_WINS: Instead of never returning a NaN, always return
293 * one. The "greater"/"lesser" NaN is always returned, first
294 * by checking the sign and then the mantissa bits.
296 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
297 * For min, implement src0 < src1 ? src0 : src1. This
298 * includes handling NaN's and signedness of 0 differently
299 * from above, since +0 and -0 compare equal and comparisons
300 * always return false for NaN's. As a result, this mode is
303 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
304 * For min, implement src0 > src1 ? src1 : src0
308 enum bifrost_minmax_mode
{
309 BIFROST_MINMAX_NONE
= 0x0,
310 BIFROST_NAN_WINS
= 0x1,
311 BIFROST_SRC1_WINS
= 0x2,
312 BIFROST_SRC0_WINS
= 0x3,
315 #define BIFROST_FMA_OP_FADD32 (0x58 >> 2)
316 #define BIFROST_FMA_OP_FMAX32 (0x40 >> 2)
317 #define BIFROST_FMA_OP_FMIN32 (0x44 >> 2)
319 struct bifrost_fma_add
{
322 unsigned src1_abs
: 1;
323 unsigned src0_neg
: 1;
324 unsigned src1_neg
: 1;
326 unsigned src0_abs
: 1;
327 enum bifrost_roundmode roundmode
: 2;
328 enum bifrost_outmod outmod
: 2;
330 } __attribute__((packed
));
332 #define BIFROST_FMA_OP_FMAX16 (0xC0 >> 2)
333 #define BIFROST_FMA_OP_FMIN16 (0xCC >> 2)
334 #define BIFROST_FMA_OP_FADD16 (0xD8 >> 2)
336 struct bifrost_fma_add_minmax16
{
339 /* abs2 inferred as (src1 < src0) */
341 unsigned src0_neg
: 1;
342 unsigned src1_neg
: 1;
343 unsigned src0_swizzle
: 2;
344 unsigned src1_swizzle
: 2;
346 enum bifrost_outmod outmod
: 2;
347 /* roundmode for add, min/max mode for min/max */
349 } __attribute__((packed
));
351 #define BIFROST_FMA_OP_FMA (0x00)
353 struct bifrost_fma_fma
{
357 unsigned src_expand
: 3;
358 unsigned src0_abs
: 1;
359 enum bifrost_roundmode roundmode
: 2;
360 enum bifrost_outmod outmod
: 2;
361 unsigned src0_neg
: 1; /* 14 */
362 unsigned src2_neg
: 1;
363 unsigned src1_abs
: 1;
364 unsigned src2_abs
: 1; /* 17 */
366 } __attribute__((packed
));
368 #define BIFROST_FMA_OP_FMA16 (0x2)
370 struct bifrost_fma_fma16
{
374 unsigned swizzle_0
: 2;
375 unsigned swizzle_1
: 2;
376 enum bifrost_roundmode roundmode
: 2;
377 enum bifrost_outmod outmod
: 2;
378 unsigned src0_neg
: 1;
379 unsigned src2_neg
: 1;
380 unsigned swizzle_2
: 2;
382 } __attribute__((packed
));
384 enum bifrost_csel_cond
{
395 #define BIFROST_FMA_OP_CSEL4 (0x5c)
396 #define BIFROST_FMA_OP_CSEL4_V16 (0xdc)
398 struct bifrost_csel4
{
403 enum bifrost_csel_cond cond
: 3;
405 } __attribute__((packed
));
407 #define BIFROST_FMA_OP_RSHIFT_NAND (0x60000 >> 12)
408 #define BIFROST_FMA_OP_RSHIFT_AND (0x61000 >> 12)
409 #define BIFROST_FMA_OP_LSHIFT_NAND (0x62000 >> 12)
410 #define BIFROST_FMA_OP_LSHIFT_AND (0x63000 >> 12)
411 #define BIFROST_FMA_OP_RSHIFT_XOR (0x64000 >> 12)
412 #define BIFROST_FMA_OP_LSHIFT_ADD_32 (0x65200 >> 6)
413 #define BIFROST_FMA_OP_LSHIFT_SUB_32 (0x65600 >> 6)
414 #define BIFROST_FMA_OP_LSHIFT_RSUB_32 (0x65a00 >> 6)
415 #define BIFROST_FMA_OP_RSHIFT_ADD_32 (0x65e00 >> 6)
416 #define BIFROST_FMA_OP_RSHIFT_SUB_32 (0x66200 >> 6)
417 #define BIFROST_FMA_OP_RSHIFT_RSUB_32 (0x66600 >> 6)
419 struct bifrost_shift_fma
{
424 unsigned unk
: 1; /* always set? */
425 unsigned invert_1
: 1; /* Inverts sources to combining op */
426 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
427 unsigned invert_2
: 1;
429 } __attribute__((packed
));
431 struct bifrost_shift_add
{
437 unsigned invert_1
: 1;
438 unsigned invert_2
: 1;
441 } __attribute__((packed
));
443 enum bifrost_fcmp_cond
{
452 /* "gl" version produces 0/1. "d3d" version produces 0/~0 */
453 #define BIFROST_FMA_OP_FCMP_GL (0x48000 >> 13)
454 #define BIFROST_FMA_OP_FCMP_D3D (0x4c000 >> 13)
456 struct bifrost_fma_fcmp
{
459 unsigned src1_abs
: 1;
461 unsigned src1_neg
: 1;
462 unsigned src_expand
: 3;
463 unsigned src0_abs
: 1;
464 enum bifrost_fcmp_cond cond
: 3;
466 } __attribute__((packed
));
468 struct bifrost_add_fcmp
{
471 enum bifrost_fcmp_cond cond
: 3;
472 unsigned src_expand
: 2;
473 unsigned src0_abs
: 1;
474 unsigned src1_abs
: 1;
475 unsigned src1_neg
: 1;
477 } __attribute__((packed
));
479 /* "gl" version produces 0/1. "d3d" version produces 0/~0 */
480 #define BIFROST_FMA_OP_FCMP_GL_16 (0xc8000 >> 13)
481 #define BIFROST_FMA_OP_FCMP_D3D_16 (0xcc000 >> 13)
483 struct bifrost_fma_fcmp16
{
491 unsigned src0_swizzle
: 2;
492 unsigned src1_swizzle
: 2;
494 enum bifrost_fcmp_cond cond
: 3;
496 } __attribute__((packed
));
498 struct bifrost_add_fcmp16
{
501 enum bifrost_fcmp_cond cond
: 3;
503 unsigned src0_swizzle
: 2;
504 unsigned src1_swizzle
: 2;
507 unsigned src0_neg
: 1;
510 } __attribute__((packed
));
512 enum bifrost_icmp_cond
{
513 BIFROST_ICMP_IGT
= 0,
514 BIFROST_ICMP_IGE
= 1, /* swapped for 16-bit */
515 BIFROST_ICMP_UGT
= 2, /* swapped for 16-bit */
516 BIFROST_ICMP_UGE
= 3,
518 BIFROST_ICMP_NEQ
= 5,
519 BIFROST_ICMP_32_OR_8
= 6, /* nested */
520 BIFROST_ICMP_64
= 7, /* nested */
523 struct bifrost_fma_icmp32
{
526 enum bifrost_icmp_cond cond
: 3;
527 unsigned unk1
: 1; /* set */
528 unsigned d3d
: 1; /* if set, true is ~0. otherwise, true is 1 */
530 } __attribute__((packed
));
532 struct bifrost_fma_icmp16
{
535 unsigned unk
: 5; /* 11010 */
536 enum bifrost_icmp_cond cond
: 3;
538 } __attribute__((packed
));
540 #define BIFROST_ADD_OP_ICMP_32 (0x0f600 >> 8)
541 #define BIFROST_ADD_OP_ICMP_16 (0x0f000 >> 11)
543 struct bifrost_add_icmp
{
546 enum bifrost_icmp_cond cond
: 3;
547 unsigned sz
: 1; /* 1 for 32, 0 for 8 */
548 unsigned d3d
: 1; /* if set, true is ~0. otherwise, true is 1 */
550 } __attribute__((packed
));
552 struct bifrost_add_icmp16
{
555 unsigned src0_swizzle
: 2;
556 unsigned src1_swizzle
: 2;
557 unsigned d3d
: 1; /* if set, true is ~0. otherwise, true is 1 */
558 enum bifrost_icmp_cond cond
: 3;
560 } __attribute__((packed
));
562 /* Two sources for vectorization */
563 #define BIFROST_FMA_FLOAT32_TO_16 (0xdd000 >> 3)
564 #define BIFROST_ADD_FLOAT32_TO_16 (0x0EC00 >> 3)
566 enum bifrost_convert_mode
{
567 BIFROST_CONV_UNK0
= 0,
568 BIFROST_CONV_F32_TO_I32
= 1,
569 BIFROST_CONV_F16_TO_I16
= 2,
570 BIFROST_CONV_I32_TO_F32
= 3,
571 BIFROST_CONV_I16_TO_X32
= 4,
572 BIFROST_CONV_F16_TO_F32
= 5,
573 BIFROST_CONV_I16_TO_F16
= 6,
574 BIFROST_CONV_UNK7
= 7
578 #define BIFROST_CONVERT_4(is_unsigned, component, to_float) \
579 ((is_unsigned & 1) | ((component & 1) << 1) | ((to_float & 1) << 2) | \
580 ((0x3) << 3) | ((4) << 5) | 0x100)
583 #define BIFROST_CONVERT_5(component) \
584 ((component & 1) | ((1) << 1) | ((5) << 5) | 0x100)
586 /* Other conversions */
587 #define BIFROST_CONVERT(is_unsigned, roundmode, swizzle, mode) \
588 ((is_unsigned & 1) | ((roundmode & 3) << 1) | ((swizzle & 3) << 3) | ((mode & 7) << 5))
590 #define BIFROST_FMA_CONVERT (0xe0000)
591 #define BIFROST_ADD_CONVERT (0x07800)
593 enum bifrost_ldst_type
{
594 BIFROST_LDST_F16
= 0,
595 BIFROST_LDST_F32
= 1,
596 BIFROST_LDST_I32
= 2,
600 #define BIFROST_ADD_OP_LD_VAR_ADDR (0x18000 >> 10)
602 struct bifrost_ld_var_addr
{
605 unsigned location
: 5;
606 enum bifrost_ldst_type type
: 2;
608 } __attribute__((packed
));
610 #define BIFROST_ADD_OP_LD_ATTR (0x08000 >> 12)
612 struct bifrost_ld_attr
{
615 unsigned location
: 5;
616 unsigned channels
: 2; /* MALI_POSITIVE */
617 enum bifrost_ldst_type type
: 2;
619 } __attribute__((packed
));
621 enum bifrost_interp_mode
{
622 BIFROST_INTERP_PER_FRAG
= 0x0,
623 BIFROST_INTERP_CENTROID
= 0x1,
624 BIFROST_INTERP_DEFAULT
= 0x2,
625 BIFROST_INTERP_EXPLICIT
= 0x3
628 #define BIFROST_ADD_OP_LD_VAR_16 (0x1a << 1)
629 #define BIFROST_ADD_OP_LD_VAR_32 (0x0a << 1)
631 /* Fixed location for gl_FragCoord.zw */
632 #define BIFROST_FRAGZ (23)
633 #define BIFROST_FRAGW (22)
635 struct bifrost_ld_var
{
638 /* If top two bits set, indirect with src in bottom three */
641 unsigned channels
: 2; /* MALI_POSITIVE */
642 enum bifrost_interp_mode interp_mode
: 2;
646 } __attribute__((packed
));
648 struct bifrost_tex_ctrl
{
649 unsigned sampler_index
: 4; // also used to signal indirects
650 unsigned tex_index
: 7;
651 bool no_merge_index
: 1; // whether to merge (direct) sampler & texture indices
652 bool filter
: 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
654 bool texel_offset
: 1; // *Offset()
657 unsigned tex_type
: 2; // 2D, 3D, Cube, Buffer
658 bool compute_lod
: 1; // 0 for *Lod()
659 bool not_supply_lod
: 1; // 0 for *Lod() or when a bias is applied
660 bool calc_gradients
: 1; // 0 for *Grad()
662 unsigned result_type
: 4; // integer, unsigned, float TODO: why is this 4 bits?
664 } __attribute__((packed
));
666 struct bifrost_dual_tex_ctrl
{
667 unsigned sampler_index0
: 2;
669 unsigned tex_index0
: 2;
670 unsigned sampler_index1
: 2;
671 unsigned tex_index1
: 2;
673 } __attribute__((packed
));
675 #define BIFROST_ADD_OP_TEX_COMPACT_F32(vtx) ((0x0b000 | ((vtx) ? (0x400) : (0))) >> 10)
676 #define BIFROST_ADD_OP_TEX_COMPACT_F16(vtx) ((0x1b000 | ((vtx) ? (0x400) : (0))) >> 10)
678 struct bifrost_tex_compact
{
681 unsigned tex_index
: 3;
682 unsigned compute_lod
: 1;
683 unsigned sampler_index
: 3;
685 } __attribute__((packed
));
687 enum branch_bit_size
{
691 // For the above combinations of bitsize and location, an extra bit is
692 // encoded via comparing the sources. The only possible source of ambiguity
693 // would be if the sources were the same, but then the branch condition
694 // would be always true or always false anyways, so we can ignore it. But
695 // this no longer works when comparing the y component to the x component,
696 // since it's valid to compare the y component of a source against its own
697 // x component. Instead, the extra bit is encoded via an extra bitsize.
700 BR_SIZE_32_AND_16X
= 5,
701 BR_SIZE_32_AND_16Y
= 6,
702 // Used for comparisons with zero and always-true, see below. I think this
703 // only works for integer comparisons.
707 enum bifrost_reg_write_unit
{
708 REG_WRITE_NONE
= 0, // don't write
709 REG_WRITE_TWO
, // write using reg2
710 REG_WRITE_THREE
, // write using reg3
713 struct bifrost_regs
{
714 unsigned uniform_const
: 8;
720 } __attribute__((packed
));
722 enum bifrost_branch_cond
{
727 // Equal vs. not-equal determined by src0/src1 comparison
729 // floating-point comparisons
730 // Becomes UNE when you flip the arguments
732 // TODO what happens when you flip the arguments?
737 enum bifrost_branch_code
{
741 #define BIFROST_ADD_OP_BRANCH (0x0d000 >> 12)
743 struct bifrost_branch
{
746 /* For BR_SIZE_ZERO, upper two bits become ctrl */
749 /* Offset source -- always uniform/const but
750 * theoretically could support indirect jumps? */
753 enum bifrost_branch_cond cond
: 3;
754 enum branch_bit_size size
: 3;
761 #define BIFROST_FMA_NOP (0x701960 | BIFROST_SRC_STAGE)
762 #define BIFROST_ADD_NOP (0x3D960 | BIFROST_SRC_STAGE)
764 struct bifrost_fmt1
{
769 uint64_t header
: 45;
770 } __attribute__((packed
));
772 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
773 #define BIFROST_FMT1_FINAL 0b01001
774 #define BIFROST_FMT1_CONSTANTS 0b00001
776 #define BIFROST_FMTC_CONSTANTS 0b0011
777 #define BIFROST_FMTC_FINAL 0b0111
779 struct bifrost_fmt_constant
{
784 } __attribute__((packed
));
786 enum bifrost_reg_control
{
787 BIFROST_WRITE_FMA_P2
= 1,
788 BIFROST_WRITE_FMA_P2_READ_P3
= 2,
789 BIFROST_FIRST_WRITE_FMA_P2_READ_P3
= 3,
791 BIFROST_WRITE_ADD_P2
= 5,
792 BIFROST_WRITE_ADD_P2_READ_P3
= 6,
793 BIFROST_WRITE_ADD_P2_FMA_P3
= 7,
795 BIFROST_FIRST_NONE
= 8,
796 BIFROST_FIRST_WRITE_FMA_P2
= 9,
797 /* INSTR_INVALID_ENC */
798 BIFROST_REG_NONE
= 11,
799 BIFROST_FIRST_READ_P3
= 12,
800 BIFROST_FIRST_WRITE_ADD_P2
= 13,
801 BIFROST_FIRST_WRITE_ADD_P2_READ_P3
= 14,
802 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3
= 15