pan/midgard: Switch constants to uint32
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 23 Aug 2019 23:02:49 +0000 (16:02 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 26 Aug 2019 18:42:32 +0000 (11:42 -0700)
Storing constants as float doesn't make sense when we have integer
instructions; better to switch to be integer natively and coerce to/from
float rather than the opposite.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_compile.c
src/panfrost/midgard/midgard_print.c

index 75f9e4a93fc625143d385917d3a5b4f9c0dd3656..a64bb55203db6a007a4fc1513fe809c62c2499d9 100644 (file)
@@ -109,7 +109,7 @@ typedef struct midgard_instruction {
         bool precede_break;
 
         bool has_constants;
-        float constants[4];
+        uint32_t constants[4];
         uint16_t inline_constant;
         bool has_blend_constant;
 
index 8000f72c9cf6f36cdbb37644e24c96c5f281d57a..be4318d371af27e1d8f45bddb74169ec04d9954d 100644 (file)
@@ -1096,11 +1096,10 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
                 ins.has_constants = true;
 
                 if (instr->op == nir_op_b2f32) {
-                        ins.constants[0] = 1.0f;
+                        float f = 1.0f;
+                        memcpy(&ins.constants, &f, sizeof(float));
                 } else {
-                        /* Type pun it into place */
-                        uint32_t one = 0x1;
-                        memcpy(&ins.constants[0], &one, sizeof(uint32_t));
+                        ins.constants[0] = 1;
                 }
 
                 ins.alu.src2 = vector_alu_srco_unsigned(blank_alu_src_xxxx);
@@ -1109,7 +1108,7 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
                 ins.ssa_args.inline_constant = false;
                 ins.ssa_args.src[1] = SSA_FIXED_REGISTER(REGISTER_CONSTANT);
                 ins.has_constants = true;
-                ins.constants[0] = 0.0f;
+                ins.constants[0] = 0;
                 ins.alu.src2 = vector_alu_srco_unsigned(blank_alu_src_xxxx);
         } else if (instr->op == nir_op_inot) {
                 ins.invert = true;
@@ -2108,7 +2107,8 @@ embedded_to_inline_constant(compiler_context *ctx)
                                 if (scaled_constant != iconstants[component])
                                         continue;
                         } else {
-                                float original = (float) ins->constants[component];
+                                float *f = (float *) ins->constants;
+                                float original = f[component];
                                 scaled_constant = _mesa_float_to_half(original);
 
                                 /* Check for loss of precision. If this is
@@ -2135,7 +2135,7 @@ embedded_to_inline_constant(compiler_context *ctx)
                          * vector by checking if all accessed values
                          * (by the swizzle) are the same. */
 
-                        uint32_t *cons = (uint32_t *) ins->constants;
+                        uint32_t *cons = ins->constants;
                         uint32_t value = cons[component];
 
                         bool is_vector = false;
index add40511d2f398de8e8441be83102b5a3e982bef..871d1c5a6de54b28e424b4d43c3baace09bdd6e1 100644 (file)
@@ -148,8 +148,15 @@ mir_print_instruction(midgard_instruction *ins)
         printf(", ");
         mir_print_index(args->src[2]);
 
-        if (ins->has_constants)
-                printf(" <%f, %f, %f, %f>", ins->constants[0], ins->constants[1], ins->constants[2], ins->constants[3]);
+        if (ins->has_constants) {
+                uint32_t *uc = ins->constants;
+                float *fc = (float *) uc;
+
+                if (midgard_is_integer_op(ins->alu.op))
+                        printf(" <0x%X, 0x%X, 0x%X, 0x%x>", uc[0], uc[1], uc[2], uc[3]);
+                else
+                        printf(" <%f, %f, %f, %f>", fc[0], fc[1], fc[2], fc[3]);
+        }
 
         if (ins->no_spill)
                 printf(" /* no spill */");