diff options
author | Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> | 2020-05-28 13:49:59 -0400 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2020-05-29 20:34:55 +0000 |
commit | 682b63cdc2631de48d6d5e8ce739e272ae373c10 (patch) | |
tree | a33f452d2f67699ddbe7f6ba1cfca2962e33373b | |
parent | 64c49ab1fc48e9a82c06f1e9fc92c3cf093ef3ce (diff) |
pan/bi: Measure distance between blocks
For branch offset calculation.
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5260>
-rw-r--r-- | src/panfrost/bifrost/bi_layout.c | 46 | ||||
-rw-r--r-- | src/panfrost/bifrost/compiler.h | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/panfrost/bifrost/bi_layout.c b/src/panfrost/bifrost/bi_layout.c index 1c700b13840..77e97e85ee9 100644 --- a/src/panfrost/bifrost/bi_layout.c +++ b/src/panfrost/bifrost/bi_layout.c @@ -89,3 +89,49 @@ bi_clause_quadwords(bi_clause *clause) return Y + DIV_ROUND_UP(constants, 2); } + +/* Measures the number of quadwords a branch jumps. Bifrost relative offsets + * are from the beginning of a clause so to jump forward we count the current + * clause length, but to jump backwards we do not. */ + +signed +bi_block_offset(bi_context *ctx, bi_clause *start, bi_block *target) +{ + /* Signed since we might jump backwards */ + signed ret = 0; + + /* Determine if the block we're branching to is strictly greater in + * source order */ + bool forwards = target->base.name > start->block->base.name; + + if (forwards) { + /* We have to jump through this block from the start of this + * clause to the end */ + bi_foreach_clause_in_block_from(start->block, clause, start) { + ret += bi_clause_quadwords(clause); + } + + /* We then need to jump through every clause of every following + * block until the target */ + bi_foreach_block_from(ctx, start->block, _blk) { + bi_block *blk = (bi_block *) _blk; + + /* Don't double-count the first block */ + if (blk == start->block) + continue; + + /* End just before the target */ + if (blk == target) + break; + + /* Count every clause in the block */ + bi_foreach_clause_in_block(blk, clause) { + ret += bi_clause_quadwords(clause); + } + } + } else { + unreachable("Backwards branching is to-do"); + } + + return ret; +} diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index bfa8ab81fe0..ad02a46a2d0 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -602,6 +602,7 @@ bool bi_is_live_after(bi_context *ctx, bi_block *block, bi_instruction *start, i bool bi_can_insert_bundle(bi_clause *clause, bool constant); unsigned bi_clause_quadwords(bi_clause *clause); +signed bi_block_offset(bi_context *ctx, bi_clause *start, bi_block *target); /* Code emit */ |