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 * Copyright (C) 2019-2020 Collabora, Ltd.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 bi_output_mod_name(enum bifrost_outmod mod
)
33 case BIFROST_NONE
: return "";
34 case BIFROST_POS
: return ".pos";
35 case BIFROST_SAT_SIGNED
: return ".sat_signed";
36 case BIFROST_SAT
: return ".sat";
37 default: return "invalid";
42 bi_minmax_mode_name(enum bifrost_minmax_mode mod
)
45 case BIFROST_MINMAX_NONE
: return "";
46 case BIFROST_NAN_WINS
: return ".nan_wins";
47 case BIFROST_SRC1_WINS
: return ".src1_wins";
48 case BIFROST_SRC0_WINS
: return ".src0_wins";
49 default: return "invalid";
54 bi_round_mode_name(enum bifrost_roundmode mod
)
57 case BIFROST_RTE
: return "";
58 case BIFROST_RTP
: return ".rtp";
59 case BIFROST_RTN
: return ".rtn";
60 case BIFROST_RTZ
: return ".rtz";
61 default: return "invalid";
66 bi_csel_cond_name(enum bifrost_csel_cond cond
)
69 case BIFROST_FEQ_F
: return "feq.f";
70 case BIFROST_FGT_F
: return "fgt.f";
71 case BIFROST_FGE_F
: return "fge.f";
72 case BIFROST_IEQ_F
: return "ieq.f";
73 case BIFROST_IGT_I
: return "igt.i";
74 case BIFROST_IGE_I
: return "uge.i";
75 case BIFROST_UGT_I
: return "ugt.i";
76 case BIFROST_UGE_I
: return "uge.i";
77 default: return "invalid";
82 bi_interp_mode_name(enum bifrost_interp_mode mode
)
85 case BIFROST_INTERP_PER_FRAG
: return ".per_frag";
86 case BIFROST_INTERP_CENTROID
: return ".centroid";
87 case BIFROST_INTERP_DEFAULT
: return "";
88 case BIFROST_INTERP_EXPLICIT
: return ".explicit";
89 default: return ".unknown";
94 bi_ldst_type_name(enum bifrost_ldst_type type
)
97 case BIFROST_LDST_F16
: return "f16";
98 case BIFROST_LDST_F32
: return "f32";
99 case BIFROST_LDST_I32
: return "i32";
100 case BIFROST_LDST_U32
: return "u32";
101 default: return "invalid";
105 /* The remaining functions in this file are for IR-internal
106 * structures; the disassembler doesn't use them */
109 bi_class_name(enum bi_class cl
)
112 case BI_ADD
: return "add";
113 case BI_ATEST
: return "atest";
114 case BI_BRANCH
: return "branch";
115 case BI_CMP
: return "cmp";
116 case BI_BLEND
: return "blend";
117 case BI_BITWISE
: return "bitwise";
118 case BI_CONVERT
: return "convert";
119 case BI_CSEL
: return "csel";
120 case BI_DISCARD
: return "discard";
121 case BI_EXTRACT
: return "extract";
122 case BI_FMA
: return "fma";
123 case BI_FREXP
: return "frexp";
124 case BI_LOAD
: return "load";
125 case BI_LOAD_ATTR
: return "load_attr";
126 case BI_LOAD_VAR
: return "load_var";
127 case BI_LOAD_VAR_ADDRESS
: return "load_var_address";
128 case BI_MAKE_VEC
: return "make_vec";
129 case BI_MINMAX
: return "minmax";
130 case BI_MOV
: return "mov";
131 case BI_SHIFT
: return "shift";
132 case BI_STORE
: return "store";
133 case BI_STORE_VAR
: return "store_var";
134 case BI_SPECIAL
: return "special";
135 case BI_SWIZZLE
: return "swizzle";
136 case BI_TEX
: return "tex";
137 case BI_ROUND
: return "round";
138 default: return "unknown_class";
143 bi_print_src(FILE *fp
, bi_instruction
*ins
, unsigned s
)
145 unsigned src
= ins
->src
[s
];
146 bool mods
= bi_has_source_mods(ins
);
147 bool abs
= ins
->src_abs
[s
] && mods
;
148 bool neg
= ins
->src_neg
[s
] && mods
;
158 else if (src
& BIR_INDEX_REGISTER
)
159 fprintf(fp
, "br%u", src
& ~BIR_INDEX_REGISTER
);
160 else if (src
& BIR_INDEX_UNIFORM
)
161 fprintf(fp
, "u%u", src
& ~BIR_INDEX_UNIFORM
);
162 else if (src
& BIR_INDEX_CONSTANT
)
163 fprintf(fp
, "#0x%" PRIx64
, ins
->constant
.u64
);
164 else if (src
& BIR_INDEX_ZERO
)
166 else if (src
& BIR_IS_REG
)
167 fprintf(fp
, "r%u", src
>> 1);
169 fprintf(fp
, "%u", (src
>> 1) - 1);
175 /* Prints a NIR ALU type in Bifrost-style ".f32" ".i8" etc */
178 bi_print_alu_type(nir_alu_type t
, FILE *fp
)
180 unsigned size
= nir_alu_type_get_type_size(t
);
181 nir_alu_type base
= nir_alu_type_get_base_type(t
);
197 fprintf(fp
, ".unknown");
201 fprintf(fp
, "%u", size
);
205 bi_print_swizzle(bi_instruction
*ins
, FILE *fp
)
207 unsigned size
= nir_alu_type_get_type_size(ins
->dest_type
);
208 unsigned count
= 32 / size
;
209 assert(size
== 8 || size
== 16);
213 for (unsigned u
= 0; u
< count
; ++u
) {
214 assert(ins
->swizzle
[u
] < size
);
215 fputc("xyzw"[ins
->swizzle
[u
]], fp
);
220 bi_bitwise_op_name(enum bi_bitwise_op op
)
223 case BI_BITWISE_AND
: return "and";
224 case BI_BITWISE_OR
: return "or";
225 case BI_BITWISE_XOR
: return "xor";
226 default: return "invalid";
231 bi_print_load(struct bi_load
*load
, FILE *fp
)
233 fprintf(fp
, ".loc%u", load
->location
);
235 if (load
->channels
!= 1)
236 fprintf(fp
, ".v%u", load
->channels
);
240 bi_print_load_vary(struct bi_load_vary
*load
, FILE *fp
)
242 bi_print_load(&load
->load
, fp
);
243 fprintf(fp
, "%s", bi_interp_mode_name(load
->interp_mode
));
246 fprintf(fp
, ".reuse");
249 fprintf(fp
, ".flat");
253 bi_cond_name(enum bi_cond cond
)
256 case BI_COND_ALWAYS
: return ".always";
257 case BI_COND_LT
: return ".lt";
258 case BI_COND_LE
: return ".le";
259 case BI_COND_GE
: return ".ge";
260 case BI_COND_GT
: return ".gt";
261 case BI_COND_EQ
: return ".eq";
262 case BI_COND_NE
: return ".ne";
263 default: return "invalid";
268 bi_print_branch(struct bi_branch
*branch
, FILE *fp
)
270 fprintf(fp
, "%s", bi_cond_name(branch
->cond
));
274 bi_print_instruction(bi_instruction
*ins
, FILE *fp
)
276 if (ins
->type
== BI_MINMAX
)
277 fprintf(fp
, "%s", ins
->op
.minmax
== BI_MINMAX_MIN
? "min" : "max");
278 else if (ins
->type
== BI_BITWISE
)
279 fprintf(fp
, "%s", bi_bitwise_op_name(ins
->op
.bitwise
));
280 else if (ins
->type
== BI_ROUND
)
281 fprintf(fp
, ins
->op
.round
== BI_ROUND_MODE
? "roundMode": "round");
283 fprintf(fp
, "%s", bi_class_name(ins
->type
));
285 if (ins
->type
== BI_MINMAX
)
286 fprintf(fp
, "%s", bi_minmax_mode_name(ins
->minmax
));
287 else if (ins
->type
== BI_LOAD_ATTR
|| ins
->type
== BI_LOAD_VAR_ADDRESS
)
288 bi_print_load(&ins
->load
, fp
);
289 else if (ins
->type
== BI_LOAD_VAR
)
290 bi_print_load_vary(&ins
->load_vary
, fp
);
291 else if (ins
->type
== BI_BRANCH
)
292 bi_print_branch(&ins
->branch
, fp
);
293 else if (ins
->type
== BI_CSEL
)
294 fprintf(fp
, "%s", bi_cond_name(ins
->csel_cond
));
297 bi_print_alu_type(ins
->dest_type
, fp
);
299 if (bi_has_outmod(ins
))
300 fprintf(fp
, "%s", bi_output_mod_name(ins
->outmod
));
302 if (bi_class_props
[ins
->type
] & BI_ROUNDMODE
)
303 fprintf(fp
, "%s", bi_round_mode_name(ins
->roundmode
));
308 fprintf(fp
, "%d", ins
->dest
);
314 bi_foreach_src(ins
, s
) {
315 bi_print_src(fp
, ins
, s
);
317 if (bi_is_src_swizzled(ins
, s
))
318 bi_print_swizzle(ins
, fp
);
320 if (ins
->type
== BI_CONVERT
&& s
== 0)
321 bi_print_alu_type(ins
->src_types
[s
], fp
);
322 else if ((ins
->type
== BI_BRANCH
|| ins
->type
== BI_CSEL
) && s
< 2)
323 bi_print_alu_type(ins
->src_types
[s
], fp
);
325 if (s
< BIR_SRC_COUNT
)