pan/bi: Implement flog2
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 14 Apr 2020 23:50:24 +0000 (19:50 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 17 Apr 2020 20:25:35 +0000 (16:25 -0400)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4615>

src/panfrost/bifrost/bi_special.c
src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/compiler.h

index 943f03380d89a8fe3d9f59265acb18945af5ed44..54909093d8fc485dd12cb83fe49be6412fa78909 100644 (file)
@@ -91,9 +91,96 @@ bi_emit_fexp2_new(bi_context *ctx, nir_alu_instr *instr)
         bi_emit(ctx, fexp);
 }
 
+/* Even on new Bifrost, there are a bunch of reductions to do */
+
+static void
+bi_emit_flog2_new(bi_context *ctx, nir_alu_instr *instr)
+{
+        /* LOG_FREXPE X */
+        bi_instruction frexpe = {
+                .type = BI_FREXP,
+                .op = { .frexp = BI_FREXPE_LOG },
+                .dest = bi_make_temp(ctx),
+                .dest_type = nir_type_int32,
+                .writemask = 0xF,
+                .src = { bir_src_index(&instr->src[0].src) },
+                .src_types = { nir_type_float32 }
+        };
+
+        /* I32_TO_F32 m */
+        bi_instruction i2f = {
+                .type = BI_CONVERT,
+                .dest = bi_make_temp(ctx),
+                .dest_type = nir_type_float32,
+                .writemask = 0xF,
+                .src = { frexpe.dest },
+                .src_types = { nir_type_int32 },
+                .roundmode = BIFROST_RTZ
+        };
+
+        /* ADD_FREXPM (x-1), -1.0, X */
+        bi_instruction x_minus_1 = {
+                .type = BI_REDUCE_FMA,
+                .op = { .reduce = BI_REDUCE_ADD_FREXPM },
+                .dest = bi_make_temp(ctx),
+                .dest_type = nir_type_float32,
+                .writemask = 0xF,
+                .src = {
+                        BIR_INDEX_CONSTANT,
+                        bir_src_index(&instr->src[0].src),
+                },
+                .src_types = { nir_type_float32, nir_type_float32 },
+                .constant = {
+                        .u64 = 0xBF800000 /* -1.0 */
+                }
+        };
+
+        /* FLOG2_HELP log2(x)/(x-1), x */
+        bi_instruction help = {
+                .type = BI_TABLE,
+                .op = { .table = BI_TABLE_LOG2_U_OVER_U_1_LOW },
+                .dest = bi_make_temp(ctx),
+                .dest_type = nir_type_float32,
+                .writemask = 0xF,
+                .src = { bir_src_index(&instr->src[0].src) },
+                .src_types = { nir_type_float32 },
+        };
+
+        /* FMA log2(x)/(x - 1), (x - 1), M */
+        bi_instruction fma = {
+                .type = BI_FMA,
+                .dest = bir_dest_index(&instr->dest.dest),
+                .dest_type = nir_type_float32,
+                .writemask = 0xF,
+                .src = {
+                        help.dest,
+                        x_minus_1.dest,
+                        i2f.dest
+                },
+                .src_types = {
+                        nir_type_float32,
+                        nir_type_float32,
+                        nir_type_float32
+                }
+        };
+
+        bi_emit(ctx, frexpe);
+        bi_emit(ctx, i2f);
+        bi_emit(ctx, x_minus_1);
+        bi_emit(ctx, help);
+        bi_emit(ctx, fma);
+}
+
 void
 bi_emit_fexp2(bi_context *ctx, nir_alu_instr *instr)
 {
         /* TODO: G71 */
         bi_emit_fexp2_new(ctx, instr);
 }
+
+void
+bi_emit_flog2(bi_context *ctx, nir_alu_instr *instr)
+{
+        /* TODO: G71 */
+        bi_emit_flog2_new(ctx, instr);
+}
index 1f67f44ce0108f1a6cb10cf372d7c5d375bf9029..aa3de9ec356315383657949cd954b86a4d0bf7e7 100644 (file)
@@ -531,6 +531,9 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         case nir_op_fexp2:
                 bi_emit_fexp2(ctx, instr);
                 return;
+        case nir_op_flog2:
+                bi_emit_flog2(ctx, instr);
+                return;
         default:
                 break;
         }
index ec9a4add065b4ef7e2ab01f8af5bcf914a152d34..96be391ca357136c4248c8017a3ed1cda9dfa028 100644 (file)
@@ -561,6 +561,7 @@ pan_next_block(pan_block *block)
 /* Special functions */
 
 void bi_emit_fexp2(bi_context *ctx, nir_alu_instr *instr);
+void bi_emit_flog2(bi_context *ctx, nir_alu_instr *instr);
 
 /* BIR manipulation */