nir/print: group hex and float vectors together
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Fri, 19 Nov 2021 14:35:37 +0000 (15:35 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 17 Dec 2021 10:04:50 +0000 (10:04 +0000)
Vectors are much easier to follow in this format, because developer cares
either about hex or float values, never both.

Before/after:

-vec4 32 ssa_222 = load_const (0x00000000 /* 0.000000 */, 0x00000000 /* 0.000000 */, 0x3f800000 /* 1.000000 */, 0x3f800000 /* 1.000000 */)
+vec4 32 ssa_222 = load_const (0x00000000, 0x00000000, 0x3f800000, 0x3f800000) = (0.000000, 0.000000, 1.000000, 1.000000)

-vec1 32 ssa_174 = load_const (0xbf800000 /* -1.000000 */)
+vec1 32 ssa_174 = load_const (0xbf800000 = -1.000000)

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13880>

src/compiler/nir/nir_print.c

index 1573b60..f06ea2a 100644 (file)
@@ -119,27 +119,25 @@ print_load_const_instr(nir_load_const_instr *instr, print_state *state)
 
    fprintf(fp, " = load_const (");
 
+   /*
+    * we don't really know the type of the constant (if it will be used as a
+    * float or an int), so just print the raw constant in hex for fidelity
+    * and then print in float again for readability.
+    */
+
    for (unsigned i = 0; i < instr->def.num_components; i++) {
       if (i != 0)
          fprintf(fp, ", ");
 
-      /*
-       * we don't really know the type of the constant (if it will be used as a
-       * float or an int), so just print the raw constant in hex for fidelity
-       * and then print the float in a comment for readability.
-       */
-
       switch (instr->def.bit_size) {
       case 64:
-         fprintf(fp, "0x%016" PRIx64 " /* %f */", instr->value[i].u64,
-                 instr->value[i].f64);
+         fprintf(fp, "0x%016" PRIx64, instr->value[i].u64);
          break;
       case 32:
-         fprintf(fp, "0x%08x /* %f */", instr->value[i].u32, instr->value[i].f32);
+         fprintf(fp, "0x%08x", instr->value[i].u32);
          break;
       case 16:
-         fprintf(fp, "0x%04x /* %f */", instr->value[i].u16,
-                 _mesa_half_to_float(instr->value[i].u16));
+         fprintf(fp, "0x%04x", instr->value[i].u16);
          break;
       case 8:
          fprintf(fp, "0x%02x", instr->value[i].u8);
@@ -150,6 +148,32 @@ print_load_const_instr(nir_load_const_instr *instr, print_state *state)
       }
    }
 
+   if (instr->def.bit_size > 8) {
+      if (instr->def.num_components > 1)
+         fprintf(fp, ") = (");
+      else
+         fprintf(fp, " = ");
+
+      for (unsigned i = 0; i < instr->def.num_components; i++) {
+         if (i != 0)
+            fprintf(fp, ", ");
+
+         switch (instr->def.bit_size) {
+         case 64:
+            fprintf(fp, "%f", instr->value[i].f64);
+            break;
+         case 32:
+            fprintf(fp, "%f", instr->value[i].f32);
+            break;
+         case 16:
+            fprintf(fp, "%f", _mesa_half_to_float(instr->value[i].u16));
+            break;
+         default:
+            unreachable("unhandled bit size");
+         }
+      }
+   }
+
    fprintf(fp, ")");
 }