From f921b42c8c9dd250e18c6e1a3315294d24f53af3 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Sat, 8 Feb 2025 18:38:55 +0100 Subject: [PATCH] nir/print: print large floats as mantissa + exponent This is silly: con 64 %18698 = load_const (0xf0f0f0f0f0f0f0f0 = -107730874267432137203343331820822035577514310242782965586097631855966576162301880634213986293205127792322062538351156704152182839736964151026851280176102232488321269248467172131803507875122376996725092200401040958124190100858265776685056.000000 = -1085102592571150096 = 17361641481138401520) This is better: con 64 %18698 = load_const (0xf0f0f0f0f0f0f0f0 = -1.077309e+236 = -1085102592571150096 = 17361641481138401520) Reviewed-by: Konstantin Seurer Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir_print.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 8030199bf2f..200009e7476 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -210,19 +210,12 @@ print_hex_terse_const_value(const nir_const_value *value, unsigned bit_size, FIL static void print_float_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp) { - switch (bit_size) { - case 64: - fprintf(fp, "%f", value->f64); - break; - case 32: - fprintf(fp, "%f", value->f32); - break; - case 16: - fprintf(fp, "%f", _mesa_half_to_float(value->u16)); - break; - default: - unreachable("unhandled bit size"); - } + double dval = nir_const_value_as_float(*value, bit_size); + + if (fabs(dval) >= 1000000.0) + fprintf(fp, "%e", dval); + else + fprintf(fp, "%f", dval); } static void