Carlos Falquez has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/47279 )

Change subject: base: Improved less-than operator for AddrRange
......................................................................

base: Improved less-than operator for AddrRange

The current implementation of the less-than operator
for AddrRange compares intlvMatch values without first
checking that both ranges are interleaved.

This commit modifies the less-than operator to compare
intlvMatch values only if both regions are interleaved.
Otherwise, the operator returns whether the left
address range is interleaved.

This commit also adds AddrRangeMap unit tests
for interleaved address ranges.

JIRA: https://gem5.atlassian.net/browse/GEM5-1010

Change-Id: Id9f14d75d465d472c046995754bdccd441b9470c
Signed-off-by: Carlos Falquez <c.falq...@fz-juelich.de>
---
M src/base/addr_range.hh
M src/base/addr_range_map.test.cc
2 files changed, 49 insertions(+), 5 deletions(-)



diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh
index 12186fa..405d8ba 100644
--- a/src/base/addr_range.hh
+++ b/src/base/addr_range.hh
@@ -593,12 +593,19 @@
      */
     bool operator<(const AddrRange& r) const
     {
-        if (_start != r._start)
+        if (_start != r._start) {
             return _start < r._start;
-        else
-            // for now assume that the end is also the same, and that
-            // we are looking at the same interleaving bits
-            return intlvMatch < r.intlvMatch;
+        } else {
+            // For now assume that the end is also the same.
+            // If both regions are interleaved, assume same interleaving,
+            // and compare intlvMatch values.
+            // Otherwise, return true if this address range is interleaved.
+            if (interleaved() && r.interleaved()) {
+                return intlvMatch < r.intlvMatch;
+            } else {
+                return interleaved();
+            }
+        }
     }

     /**
diff --git a/src/base/addr_range_map.test.cc b/src/base/addr_range_map.test.cc
index fef3a89..7fc3888 100644
--- a/src/base/addr_range_map.test.cc
+++ b/src/base/addr_range_map.test.cc
@@ -66,3 +66,40 @@

     EXPECT_NE(r.contains(RangeIn(20, 30)), r.end());
 }
+
+TEST(AddrRangeMapTest, InterleavedTest1)
+{
+    AddrRangeMap<int> r;
+    AddrRangeMap<int>::const_iterator i;
+
+    const auto masks = std::vector<Addr>{64, 128, 256, 512};
+    const Addr start = 2147483648;
+    const Addr end   = 3221225472;
+
+    // insert interleaved address list
+    for (int n=0; n <16; n++) {
+        i = r.insert(AddrRange(start, end, masks, n ), n);
+    }
+    EXPECT_NE(r.contains(AddrRange(start, start + 1)), r.end());
+}
+
+TEST(AddrRangeMapTest, InterleavedTest2)
+{
+    AddrRangeMap<int> r;
+    AddrRangeMap<int>::const_iterator i;
+
+    const auto masks = std::vector<Addr>{
+        1200959900632128,
+        2401919801264256,
+        300239975158016,
+        600479950316032
+    };
+    const Addr start = 2147483648;
+    const Addr end   = 3221225472;
+
+    // insert interleaved address list
+    for (int n=0; n <16; n++) {
+        i = r.insert(AddrRange(start, end, masks, n ), n);
+    }
+    EXPECT_NE(r.contains(AddrRange(start, start + 1)), r.end());
+}

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/47279
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Id9f14d75d465d472c046995754bdccd441b9470c
Gerrit-Change-Number: 47279
Gerrit-PatchSet: 1
Gerrit-Owner: Carlos Falquez <c.falq...@fz-juelich.de>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to