Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/66791?usp=email )

Change subject: base: Fix signature of SatCounter::saturate()
......................................................................

base: Fix signature of SatCounter::saturate()

The variants that use more than 8 bits were broken,
since the size of the difference in those cases
could be larger than 8 bits, and the return value
was only 8-bits long.

Change-Id: I8b75be48f924cc33ebf5e5aeff6d4045fac66bcc
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/66791
Maintainer: Matt Sinclair <mattdsincl...@gmail.com>
Reviewed-by: Matt Sinclair <mattdsincl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/sat_counter.hh
M src/base/sat_counter.test.cc
2 files changed, 35 insertions(+), 2 deletions(-)

Approvals:
  Matt Sinclair: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/base/sat_counter.hh b/src/base/sat_counter.hh
index a607c4c..ecb8df8 100644
--- a/src/base/sat_counter.hh
+++ b/src/base/sat_counter.hh
@@ -318,9 +318,9 @@
      *
      * @ingroup api_sat_counter
      */
-    uint8_t saturate()
+    T saturate()
     {
-        const uint8_t diff = maxVal - counter;
+        const T diff = maxVal - counter;
         counter = maxVal;
         return diff;
     }
diff --git a/src/base/sat_counter.test.cc b/src/base/sat_counter.test.cc
index 07a01c7..0a6459c 100644
--- a/src/base/sat_counter.test.cc
+++ b/src/base/sat_counter.test.cc
@@ -149,6 +149,20 @@
     ASSERT_TRUE(counter.isSaturated());
 }

+TEST(SatCounterTest, Saturate16)
+{
+    const unsigned bits = 14;
+    const unsigned max_value = (1 << bits) - 1;
+    SatCounter16 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.
  */

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/66791?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I8b75be48f924cc33ebf5e5aeff6d4045fac66bcc
Gerrit-Change-Number: 66791
Gerrit-PatchSet: 2
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Matt Sinclair <mattdsincl...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to