diff options
author | Daniel R. Carvalho <odanrc@yahoo.com.br> | 2019-05-29 21:15:06 +0200 |
---|---|---|
committer | Daniel Carvalho <odanrc@yahoo.com.br> | 2019-08-29 20:19:05 +0000 |
commit | fc528bb0c0d2c6fe1ae55e9aa5be8652cc3fd456 (patch) | |
tree | 559dca56c6f3fde1035f16298a165e72e97b75ac /src/base/sat_counter.test.cc | |
parent | 51d38a4b79d54a97d438ecdba5ce94d6e9172eef (diff) | |
download | gem5-fc528bb0c0d2c6fe1ae55e9aa5be8652cc3fd456.tar.xz |
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>
Diffstat (limited to 'src/base/sat_counter.test.cc')
-rw-r--r-- | src/base/sat_counter.test.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/base/sat_counter.test.cc b/src/base/sat_counter.test.cc index dbdaf0ae6..817f2c7ac 100644 --- a/src/base/sat_counter.test.cc +++ b/src/base/sat_counter.test.cc @@ -97,6 +97,23 @@ TEST(SatCounterTest, SaturationPercentile) } /** + * 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. */ TEST(SatCounterTest, IntComparison) |