Mesa (master): aco/ra: Use std::all_of to simplify a loop

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 13 18:31:39 UTC 2021


Module: Mesa
Branch: master
Commit: 46c9d761347bf94001a14c5a2f0758f1ec7d6b87
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=46c9d761347bf94001a14c5a2f0758f1ec7d6b87

Author: Tony Wasserka <tony.wasserka at gmx.de>
Date:   Wed Oct 28 23:40:39 2020 +0100

aco/ra: Use std::all_of to simplify a loop

Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7799>

---

 src/amd/compiler/aco_register_allocation.cpp | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/amd/compiler/aco_register_allocation.cpp b/src/amd/compiler/aco_register_allocation.cpp
index e54369749e6..a9050ddb197 100644
--- a/src/amd/compiler/aco_register_allocation.cpp
+++ b/src/amd/compiler/aco_register_allocation.cpp
@@ -726,6 +726,8 @@ std::pair<PhysReg, bool> get_reg_simple(ra_ctx& ctx,
          return res;
    }
 
+   auto is_free = [&](unsigned reg_index) { return reg_file[reg_index] == 0 && !ctx.war_hint[reg_index]; };
+
    if (stride == 1) {
       /* best fit algorithm: find the smallest gap to fit in the variable */
       PhysRegInterval best_gap { 0xFFFF, 0xFFFF };
@@ -733,8 +735,6 @@ std::pair<PhysReg, bool> get_reg_simple(ra_ctx& ctx,
 
       PhysRegIterator reg_it = bounds.begin();
       const PhysRegIterator end_it = std::min(bounds.end(), std::max(PhysRegIterator { max_gpr + 1 }, reg_it));
-
-      auto is_free = [&](unsigned reg_index) { return reg_file[reg_index] == 0 && !ctx.war_hint[reg_index]; };
       while (reg_it != bounds.end()) {
          /* Find the next chunk of available register slots */
          reg_it = std::find_if(reg_it, end_it, is_free);
@@ -781,24 +781,16 @@ std::pair<PhysReg, bool> get_reg_simple(ra_ctx& ctx,
       return {PhysReg{best_gap.lo()}, true};
    }
 
-   bool found = false;
-   PhysRegInterval reg_win = { bounds.lo(), size };
-   while (reg_win.hi() <= bounds.hi()) {
+   for (PhysRegInterval reg_win = { bounds.lo(), size }; reg_win.hi() <= bounds.hi(); reg_win += stride) {
       if (reg_file[reg_win.lo()] != 0) {
-         reg_win += stride;
          continue;
       }
-      found = true;
-      for (unsigned reg = reg_win.lo() + 1; found && reg < reg_win.hi(); reg++) {
-         if (reg_file[reg] != 0 || ctx.war_hint[reg])
-            found = false;
-      }
-      if (found) {
+
+      bool is_valid = std::all_of(std::next(reg_win.begin()), reg_win.end(), is_free);
+      if (is_valid) {
          adjust_max_used_regs(ctx, rc, reg_win.lo());
          return {PhysReg{reg_win.lo()}, true};
       }
-
-      reg_win += stride;
    }
 
    /* do this late because using the upper bytes of a register can require



More information about the mesa-commit mailing list