Giacomo Travaglini has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/17528
Change subject: base: Fix CircularQueue's operator-= when negative
subtraction
......................................................................
base: Fix CircularQueue's operator-= when negative subtraction
Using operator-= when the rhs is a negative value is equivalent
to using += on -rhs. This is fixing rounding in that scenario.
Change-Id: Ia22e51f81a6805d27fd6b2115d288bb23421d00f
Signed-off-by: Giacomo Travaglini <[email protected]>
---
M src/base/circular_queue.hh
M src/base/circular_queue.test.cc
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/base/circular_queue.hh b/src/base/circular_queue.hh
index f368ed0..da3da8b 100644
--- a/src/base/circular_queue.hh
+++ b/src/base/circular_queue.hh
@@ -323,12 +323,12 @@
assert(_cq);
/* C does not do euclidean division, so we have to adjust */
- if (t >= 0)
+ if (t >= 0) {
_round += (-t + _idx) / _cq->capacity();
- else
- _round += (-t + _idx - _cq->capacity() + 1) /
_cq->capacity();
-
- _idx = _cq->moduloSub(_idx, t);
+ _idx = _cq->moduloSub(_idx, t);
+ } else {
+ *this += -t;
+ }
return *this;
}
diff --git a/src/base/circular_queue.test.cc
b/src/base/circular_queue.test.cc
index cce6cb0..fd63f72 100644
--- a/src/base/circular_queue.test.cc
+++ b/src/base/circular_queue.test.cc
@@ -198,8 +198,10 @@
cq.push_back(first_value);
cq.push_back(second_value);
+ auto negative_offset = -(cq_size + 1);
auto it_1 = cq.begin();
auto it_2 = cq.begin() + 1;
+ auto it_3 = cq.begin() - negative_offset;
// Operators test
ASSERT_TRUE(it_1 != it_2);
@@ -213,6 +215,7 @@
ASSERT_EQ(it_1, it_2 - 1);
ASSERT_EQ(it_2 - it_1, 1);
ASSERT_EQ(it_1 - it_2, -1);
+ ASSERT_EQ(it_3._round, 1);
auto temp_it = it_1;
ASSERT_EQ(++temp_it, it_2);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/17528
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ia22e51f81a6805d27fd6b2115d288bb23421d00f
Gerrit-Change-Number: 17528
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev