Mesa (master): aco: refactor get_reg_simple() to return early on exact matches
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Apr 22 18:36:13 UTC 2020
Module: Mesa
Branch: master
Commit: 2796cb4c2481c35b9510c03dad3a5ebe65a82d51
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2796cb4c2481c35b9510c03dad3a5ebe65a82d51
Author: Daniel Schürmann <daniel at schuermann.dev>
Date: Tue Apr 14 11:43:39 2020 +0100
aco: refactor get_reg_simple() to return early on exact matches
in the best fit algorithm
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4573>
---
src/amd/compiler/aco_register_allocation.cpp | 47 +++++++++++++---------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp
index a3e01b11c68..11b54ba8339 100644
--- a/src/amd/compiler/aco_register_allocation.cpp
+++ b/src/amd/compiler/aco_register_allocation.cpp
@@ -393,7 +393,6 @@ std::pair<PhysReg, bool> get_reg_simple(ra_ctx& ctx,
stride = 1; /* stride in full registers */
}
- /* best fit algorithm: find the smallest gap to fit in the variable */
if (stride == 1) {
if (rc.type() == RegType::vgpr && (size == 4 || size == 8)) {
@@ -403,41 +402,39 @@ std::pair<PhysReg, bool> get_reg_simple(ra_ctx& ctx,
return res;
}
+ /* best fit algorithm: find the smallest gap to fit in the variable */
unsigned best_pos = 0xFFFF;
unsigned gap_size = 0xFFFF;
- unsigned next_pos = 0xFFFF;
+ unsigned last_pos = 0xFFFF;
for (unsigned current_reg = lb; current_reg < ub; current_reg++) {
- if (reg_file[current_reg] != 0 || ctx.war_hint[current_reg]) {
- if (next_pos == 0xFFFF)
- continue;
-
- /* check if the variable fits */
- if (next_pos + size > current_reg) {
- next_pos = 0xFFFF;
- continue;
- }
+ if (reg_file[current_reg] == 0 && !ctx.war_hint[current_reg]) {
+ if (last_pos == 0xFFFF)
+ last_pos = current_reg;
+ continue;
+ }
- /* check if the tested gap is smaller */
- if (current_reg - next_pos < gap_size) {
- best_pos = next_pos;
- gap_size = current_reg - next_pos;
- }
- next_pos = 0xFFFF;
+ if (last_pos == 0xFFFF)
continue;
+
+ /* early return on exact matches */
+ if (last_pos + size == current_reg) {
+ adjust_max_used_regs(ctx, rc, last_pos);
+ return {PhysReg{last_pos}, true};
}
- if (next_pos == 0xFFFF)
- next_pos = current_reg;
+ /* check if it fits and the gap size is smaller */
+ if (last_pos + size < current_reg && current_reg - last_pos < gap_size) {
+ best_pos = last_pos;
+ gap_size = current_reg - last_pos;
+ }
+ last_pos = 0xFFFF;
}
/* final check */
- if (next_pos != 0xFFFF &&
- next_pos + size <= ub &&
- ub - next_pos < gap_size) {
- best_pos = next_pos;
- gap_size = ub - next_pos;
- }
+ if (last_pos + size <= ub && ub - last_pos < gap_size)
+ best_pos = last_pos;
+
if (best_pos != 0xFFFF) {
adjust_max_used_regs(ctx, rc, best_pos);
return {PhysReg{best_pos}, true};
More information about the mesa-commit
mailing list