base: Add function to saturate SatCounter
Create a saturation function for the SatCounter that makes its internal counter reach its maximum value. Change-Id: Ibd30fa27c4ae2714dd48e3eba85addd035fb737c Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20451 Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
51d38a4b79
commit
fc528bb0c0
@@ -235,6 +235,18 @@ class SatCounter
|
||||
*/
|
||||
bool isSaturated() const { return counter == maxVal; }
|
||||
|
||||
/**
|
||||
* Saturate the counter.
|
||||
*
|
||||
* @return The value added to the counter to reach saturation.
|
||||
*/
|
||||
uint8_t saturate()
|
||||
{
|
||||
const uint8_t diff = maxVal - counter;
|
||||
counter = maxVal;
|
||||
return diff;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t initialVal;
|
||||
uint8_t maxVal;
|
||||
|
||||
@@ -96,6 +96,23 @@ TEST(SatCounterTest, SaturationPercentile)
|
||||
ASSERT_TRUE(counter.isSaturated());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test abrupt saturation.
|
||||
*/
|
||||
TEST(SatCounterTest, Saturate)
|
||||
{
|
||||
const unsigned bits = 3;
|
||||
const unsigned max_value = (1 << bits) - 1;
|
||||
SatCounter counter(bits);
|
||||
counter++;
|
||||
ASSERT_FALSE(counter.isSaturated());
|
||||
|
||||
// Make sure the value added is what was missing to saturate
|
||||
const unsigned diff = counter.saturate();
|
||||
ASSERT_EQ(diff, max_value - 1);
|
||||
ASSERT_TRUE(counter.isSaturated());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test back and forth against an int.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user