summaryrefslogtreecommitdiff
path: root/src/base/addr_range.hh
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:38 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:38 -0500
commit01c55983737273c70e44e0181e75453e01c5da34 (patch)
tree2a1c68d06c39a1cf1554d589df8961a313cb9c25 /src/base/addr_range.hh
parente6c57786a43b6e21e11dec95d2fcb2c965d84abb (diff)
downloadgem5-01c55983737273c70e44e0181e75453e01c5da34.tar.xz
mem: Add interleaving bits to the address ranges
This patch adds support for interleaving bits for the address ranges. What was previously just a start and end address, now has an additional three fields, for the high bit, and number of bits to use for interleaving, and a match value to compare against. If the number of interleaving bits is set to zero it is effectively disabled. A number of convenience functions are added to the range to enquire about the interleaving, its granularity and the number of stripes it is part of.
Diffstat (limited to 'src/base/addr_range.hh')
-rw-r--r--src/base/addr_range.hh117
1 files changed, 106 insertions, 11 deletions
diff --git a/src/base/addr_range.hh b/src/base/addr_range.hh
index 1e86aa859..edcc0bf2f 100644
--- a/src/base/addr_range.hh
+++ b/src/base/addr_range.hh
@@ -45,7 +45,9 @@
#ifndef __BASE_ADDR_RANGE_HH__
#define __BASE_ADDR_RANGE_HH__
+#include "base/bitfield.hh"
#include "base/cprintf.hh"
+#include "base/misc.hh"
#include "base/types.hh"
class AddrRange
@@ -53,27 +55,68 @@ class AddrRange
private:
- /// Private fields for the start and end of the range. In the
- /// future, these will be extended with interleaving functionality
- /// and hence should never be manipulated directly.
+ /// Private fields for the start and end of the range
Addr _start;
Addr _end;
+ /// The high bit of the slice that is used for interleaving
+ uint8_t intlvHighBit;
+
+ /// The number of bits used for interleaving, set to 0 to disable
+ uint8_t intlvBits;
+
+ /// The value to compare the slice addr[high:(high - bits + 1)]
+ /// with.
+ uint8_t intlvMatch;
+
public:
AddrRange()
- : _start(1), _end(0)
+ : _start(1), _end(0), intlvHighBit(0), intlvBits(0), intlvMatch(0)
+ {}
+
+ AddrRange(Addr _start, Addr _end, uint8_t _intlv_high_bit,
+ uint8_t _intlv_bits, uint8_t _intlv_match)
+ : _start(_start), _end(_end), intlvHighBit(_intlv_high_bit),
+ intlvBits(_intlv_bits), intlvMatch(_intlv_match)
{}
AddrRange(Addr _start, Addr _end)
- : _start(_start), _end(_end)
+ : _start(_start), _end(_end), intlvHighBit(0), intlvBits(0),
+ intlvMatch(0)
{}
/**
+ * Determine if the range is interleaved or not.
+ *
+ * @return true if interleaved
+ */
+ bool interleaved() const { return intlvBits != 0; }
+
+ /**
+ * Determing the interleaving granularity of the range.
+ *
+ * @return The size of the regions created by the interleaving bits
+ */
+ uint64_t granularity() const { return ULL(1) << intlvHighBit; }
+
+ /**
+ * Determine the number of interleaved address stripes this range
+ * is part of.
+ *
+ * @return The number of stripes spanned by the interleaving bits
+ */
+ uint32_t stripes() const { return ULL(1) << intlvBits; }
+
+ /**
* Get the size of the address range. For a case where
- * interleaving is used this should probably cause a panic.
+ * interleaving is used we make the simplifying assumption that
+ * the size is a divisible by the size of the interleaving slice.
*/
- Addr size() const { return _end - _start + 1; }
+ Addr size() const
+ {
+ return (_end - _start + 1) >> intlvBits;
+ }
/**
* Determine if the range is valid.
@@ -92,7 +135,27 @@ class AddrRange
*/
std::string to_string() const
{
- return csprintf("[%#llx : %#llx]", _start, _end);
+ if (interleaved())
+ return csprintf("[%#llx : %#llx], [%d : %d] = %d", _start, _end,
+ intlvHighBit, intlvHighBit - intlvBits + 1,
+ intlvMatch);
+ else
+ return csprintf("[%#llx : %#llx]", _start, _end);
+ }
+
+ /**
+ * Determine if another range merges with the current one, i.e. if
+ * they are part of the same contigous range and have the same
+ * interleaving bits.
+ *
+ * @param r Range to evaluate merging with
+ * @return true if the two ranges would merge
+ */
+ bool mergesWith(const AddrRange& r) const
+ {
+ return r._start == _start && r._end == _end &&
+ r.intlvHighBit == intlvHighBit &&
+ r.intlvBits == intlvBits;
}
/**
@@ -105,7 +168,26 @@ class AddrRange
*/
bool intersects(const AddrRange& r) const
{
- return _start <= r._end && _end >= r._start;
+ if (!interleaved()) {
+ return _start <= r._end && _end >= r._start;
+ }
+
+ // the current range is interleaved, split the check up in
+ // three cases
+ if (r.size() == 1)
+ // keep it simple and check if the address is within
+ // this range
+ return contains(r.start());
+ else if (!r.interleaved())
+ // be conservative and ignore the interleaving
+ return _start <= r._end && _end >= r._start;
+ else if (mergesWith(r))
+ // restrict the check to ranges that belong to the
+ // same chunk
+ return intlvMatch == r.intlvMatch;
+ else
+ panic("Cannot test intersection of interleaved range %s\n",
+ to_string());
}
/**
@@ -118,6 +200,8 @@ class AddrRange
*/
bool isSubset(const AddrRange& r) const
{
+ if (interleaved())
+ panic("Cannot test subset of interleaved range %s\n", to_string());
return _start >= r._start && _end <= r._end;
}
@@ -129,7 +213,13 @@ class AddrRange
*/
bool contains(const Addr& a) const
{
- return a >= _start && a <= _end;
+ // check if the address is in the range and if there is either
+ // no interleaving, or with interleaving also if the selected
+ // bits from the address match the interleaving value
+ return a >= _start && a <= _end &&
+ (interleaved() ||
+ (bits(a, intlvHighBit, intlvHighBit - intlvBits + 1) ==
+ intlvMatch));
}
/**
@@ -146,7 +236,12 @@ class AddrRange
*/
bool operator<(const AddrRange& r) const
{
- return _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;
}
#endif // SWIG