From 031ad0ecc2d585c109cbb5a757d07bcae344b8be Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 14 Apr 2020 19:50:24 -0400 Subject: [PATCH] pan/bi: Implement flog2 Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_special.c | 87 ++++++++++++++++++++++++++ src/panfrost/bifrost/bifrost_compile.c | 3 + src/panfrost/bifrost/compiler.h | 1 + 3 files changed, 91 insertions(+) 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 */ -- 2.30.2