From 5b974a922aaf0de3596b887173d1ee109b0e5723 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Wed, 25 Feb 2026 14:56:51 +0100 Subject: [PATCH] nir: print all fp_math_ctrl bits Examples: div 32 %338 = ffma %89, %328.z, %335 // exact, preserve:sz,inf,nan con 32 %28 = fmul %17.y, %27 (2.000000) // preserve:sz,inf,nan Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_print.c | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index f967a1afe15..cb38dd285d6 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -481,6 +481,41 @@ print_alu_src(nir_alu_instr *instr, unsigned src, print_state *state) } } +static void +print_fp_math_ctrl(unsigned fp_math_ctrl, print_state *state) +{ + FILE *fp = state->fp; + + if (fp_math_ctrl & nir_fp_exact) { + fprintf(fp, "exact"); + if (fp_math_ctrl & ~nir_fp_exact) + fprintf(fp, ", "); + } + + if (fp_math_ctrl & nir_fp_preserve_sz_inf_nan) { + fprintf(fp, "preserve:"); + + static const struct { + nir_fp_math_control bit; + const char *name; + } preserve_bits[] = { + { nir_fp_preserve_signed_zero, "sz" }, + { nir_fp_preserve_inf, "inf" }, + { nir_fp_preserve_nan, "nan" }, + }; + + bool first = true; + for (unsigned i = 0; i < ARRAY_SIZE(preserve_bits); i++) { + if (fp_math_ctrl & preserve_bits[i].bit) { + if (!first) + fprintf(fp, ","); + first = false; + fprintf(fp, "%s", preserve_bits[i].name); + } + } + } +} + static void print_alu_instr(nir_alu_instr *instr, print_state *state) { @@ -489,8 +524,6 @@ print_alu_instr(nir_alu_instr *instr, print_state *state) print_def(&instr->def, state); fprintf(fp, " = %s", nir_op_infos[instr->op].name); - if (nir_alu_instr_is_exact(instr)) - fprintf(fp, "!"); if (instr->no_signed_wrap) fprintf(fp, ".nsw"); if (instr->no_unsigned_wrap) @@ -503,6 +536,11 @@ print_alu_instr(nir_alu_instr *instr, print_state *state) print_alu_src(instr, i, state); } + + if (instr->fp_math_ctrl) { + fprintf(fp, " // "); + print_fp_math_ctrl(instr->fp_math_ctrl, state); + } } static const char *