aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2020-04-14 19:50:24 -0400
committerAlyssa Rosenzweig <[email protected]>2020-04-17 16:25:35 -0400
commit031ad0ecc2d585c109cbb5a757d07bcae344b8be (patch)
tree94d8717362415d53b9c4e0b898129b891e410b59
parent8e52206dbef63ffe91f5e58043228bb51e41192c (diff)
pan/bi: Implement flog2
Signed-off-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4615>
-rw-r--r--src/panfrost/bifrost/bi_special.c87
-rw-r--r--src/panfrost/bifrost/bifrost_compile.c3
-rw-r--r--src/panfrost/bifrost/compiler.h1
3 files changed, 91 insertions, 0 deletions
diff --git a/src/panfrost/bifrost/bi_special.c b/src/panfrost/bifrost/bi_special.c
index 943f03380d8..54909093d8f 100644
--- a/src/panfrost/bifrost/bi_special.c
+++ b/src/panfrost/bifrost/bi_special.c
@@ -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);
+}
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 1f67f44ce01..aa3de9ec356 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -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;
}
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index ec9a4add065..96be391ca35 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -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 */