base: Add a check for edge case

- Now check for the condition where the bigger address range wraps but smaller does not.

Change-Id: Icc7a549afaf82a277dc2845255aa1702a1d662e0
This commit is contained in:
Harshil Patel
2024-01-23 11:35:54 -08:00
parent 7372097376
commit 78613e2307
2 changed files with 25 additions and 1 deletions

View File

@@ -459,9 +459,16 @@ class AddrRange
if (_end <= _start){
// Special case: if our range wraps around that is
// _end is 2^64 so it wraps to 0.
// In this case r will be a subset only if its _end
// In this case we will be a subset only if r._end
// also wraps around.
return _start >= r._start && r._end == 0;
} else if (r._end <= r._start){
// Special case: if r wraps around that is
// r._end is 2^64 so it wraps to 0.
// In this case we will be a subset only if our _start
// is within r._start/ _end does not matter
// because r wraps around.
return _start >= r._start;
} else {
// Normal case: Check if our range is completely within 'r'.
return _start >= r._start && _end <= r._end;

View File

@@ -1557,6 +1557,23 @@ TEST(AddrRangeTest, isNotSubsetLastByte)
EXPECT_FALSE(last_four_bytes.isSubset(first_four_bytes));
}
TEST(AddrRangeTest, isSubsetLastByte)
{
/* An issue raised in https://github.com/gem5/gem5/issues/240 where if an
* address range ends at the last byte of a 64 bit address space, it will
* be considered a subset of any other address range that starts at the
* first byte of the range.
*
* This test checks it subset works correctly when the range is the last
* byte of the address space.
*/
AddrRange last_four_bytes = RangeSize(0xfffffffffffffffc, 4);
AddrRange not_wrapped_last_bytes = RangeSize(0xfffffffffffffffc, 3);
EXPECT_TRUE(not_wrapped_last_bytes.isSubset(last_four_bytes));
}
/*
* InterleavingRanges:
* The exclude method does not support interleaving ranges