Mesa (staging/21.0): aco: Fix constant address offset calculation for ds_read2 instructions.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 18 16:39:24 UTC 2021


Module: Mesa
Branch: staging/21.0
Commit: a9536794c33ee7c721f54e46f29b86484c651aed
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a9536794c33ee7c721f54e46f29b86484c651aed

Author: Timur Kristóf <timur.kristof at gmail.com>
Date:   Thu Mar 18 10:15:14 2021 +0100

aco: Fix constant address offset calculation for ds_read2 instructions.

Cc: mesa-stable
Signed-off-by: Timur Kristóf <timur.kristof at gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9678>
(cherry picked from commit 89c8e22cc65bae26160134145b6c3ef313174713)

---

 .pick_status.json                              |  2 +-
 src/amd/compiler/aco_instruction_selection.cpp | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 761dffe48e2..77099a222ce 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -58,7 +58,7 @@
         "description": "aco: Fix constant address offset calculation for ds_read2 instructions.",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": null
     },
diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp
index bb19a961f7c..7cf21a1a3dc 100644
--- a/src/amd/compiler/aco_instruction_selection.cpp
+++ b/src/amd/compiler/aco_instruction_selection.cpp
@@ -3506,14 +3506,16 @@ Temp lds_load_callback(Builder& bld, const LoadEmitInfo &info,
       op = aco_opcode::ds_read_u8;
    }
 
-   unsigned max_offset_plus_one = read2 ? 254 * (size / 2u) + 1 : 65536;
-   if (const_offset >= max_offset_plus_one) {
-      offset = bld.vadd32(bld.def(v1), offset, Operand(const_offset / max_offset_plus_one));
-      const_offset %= max_offset_plus_one;
+   unsigned const_offset_unit = read2 ? size / 2u : 1u;
+   unsigned const_offset_range = read2 ? 255 * const_offset_unit : 65536;
+
+   if (const_offset > (const_offset_range - const_offset_unit)) {
+      unsigned excess = const_offset - (const_offset % const_offset_range);
+      offset = bld.vadd32(bld.def(v1), offset, Operand(excess));
+      const_offset -= excess;
    }
 
-   if (read2)
-      const_offset /= (size / 2u);
+   const_offset /= const_offset_unit;
 
    RegClass rc = RegClass(RegType::vgpr, DIV_ROUND_UP(size, 4));
    Temp val = rc == info.dst.regClass() && dst_hint.id() ? dst_hint : bld.tmp(rc);



More information about the mesa-commit mailing list