Andreas Sandberg has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/21599 )
Change subject: base: Add addIntlvBits to AddrRange
..
base: Add addIntlvBits to AddrRange
This method performs the opposite operation of removeIntlvBits and can
be used to transform a channel-local address to a global PA.
Change-Id: I2fab587d7c094597e52422305775ac7f31efba34
Signed-off-by: Andreas Sandberg
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21599
Reviewed-by: Nikos Nikoleris
Reviewed-by: Daniel Carvalho
Tested-by: kokoro
---
M src/base/addr_range.hh
M src/base/addr_range.test.cc
2 files changed, 62 insertions(+), 0 deletions(-)
Approvals:
Nikos Nikoleris: Looks good to me, approved
Daniel Carvalho: Looks good to me, approved
Andreas Sandberg: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh
index cda6ccf..84a3d4d 100644
--- a/src/base/addr_range.hh
+++ b/src/base/addr_range.hh
@@ -471,6 +471,44 @@
}
/**
+ * This method adds the interleaving bits removed by
+ * removeIntlvBits.
+ */
+inline Addr addIntlvBits(Addr a) const
+{
+// Get the LSB set from each mask
+int masks_lsb[masks.size()];
+for (int i = 0; i < masks.size(); i++) {
+masks_lsb[i] = ctz64(masks[i]);
+}
+
+// Add bits one-by-one from the LSB side.
+std::sort(masks_lsb, masks_lsb + masks.size());
+for (int i = 0; i < masks.size(); i++) {
+const int intlv_bit = masks_lsb[i];
+if (intlv_bit > 0) {
+// on every iteration we add one bit from the input
+// address, and therefore the lowest invtl_bit has
+// also shifted to the left by i positions.
+a = insertBits(a << 1, intlv_bit + i - 1, 0, a);
+} else {
+a <<= 1;
+}
+}
+
+for (int i = 0; i < masks.size(); i++) {
+const int lsb = ctz64(masks[i]);
+const Addr intlv_bit = bits(intlvMatch, i);
+// Calculate the mask ignoring the LSB
+const Addr masked = a & masks[i] & ~(1 << lsb);
+// Set the LSB of the mask to whatever satisfies the selector
bit
+a = insertBits(a, lsb, intlv_bit ^ popCount(masked));
+}
+
+return a;
+}
+
+/**
* Determine the offset of an address within the range.
*
* This function returns the offset of the given address from the
diff --git a/src/base/addr_range.test.cc b/src/base/addr_range.test.cc
index 54eb198..93afbb0 100644
--- a/src/base/addr_range.test.cc
+++ b/src/base/addr_range.test.cc
@@ -121,6 +121,16 @@
}
}
+void testAddRemoveIntlvBits()
+{
+for (Addr addr = start; addr <= end; addr++) {
+AddrRange = range[getIndex(addr)];
+Addr ch_addr = r.removeIntlvBits(addr);
+Addr pa = r.addIntlvBits(ch_addr);
+ASSERT_EQ(addr, pa);
+}
+}
+
static const Addr end = 0x1;
static const Addr start = 0x0;
static const int intlvSize = 4;
@@ -162,6 +172,11 @@
testGetOffset();
}
+TEST_F(AddrRangeCont, AddrRangeAddRemoveIntlvBits)
+{
+testAddRemoveIntlvBits();
+}
+
class AddrRangeContLegacy : public AddrRangeCont {
protected:
@@ -185,6 +200,10 @@
testGetOffset();
}
+TEST_F(AddrRangeContLegacy, AddrRangeAddRemoveIntlvBits)
+{
+testAddRemoveIntlvBits();
+}
class AddrRangeArb : public AddrRangeBase {
protected:
@@ -218,3 +237,8 @@
{
testGetOffset();
}
+
+TEST_F(AddrRangeArb, AddrRangeAddRemoveIntlvBits)
+{
+testAddRemoveIntlvBits();
+}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/21599
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I2fab587d7c094597e52422305775ac7f31efba34
Gerrit-Change-Number: 21599
Gerrit-PatchSet: 2
Gerrit-Owner: Andreas Sandberg
Gerrit-Assignee: Nikos Nikoleris
Gerrit-Reviewer: Andreas Sandberg
Gerrit-Reviewer: Daniel Carvalho
Gerrit-Reviewer: Jason Lowe-Power
Gerrit-Reviewer: Nikos Nikoleris
Gerrit-Reviewer: kokoro
Gerrit-MessageType: merged
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev