summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Bardsley <Andrew.Bardsley@arm.com>2014-05-09 18:58:47 -0400
committerAndrew Bardsley <Andrew.Bardsley@arm.com>2014-05-09 18:58:47 -0400
commit8087d2622d4c7c55def5a0f2daec4be951f1929b (patch)
tree08fe037e2ab36352439ba095699508286ccdb007 /src
parentf7d80348fa6c764da5ec75fb6ed4796d4e88aa0a (diff)
downloadgem5-8087d2622d4c7c55def5a0f2daec4be951f1929b.tar.xz
cpu: Timebuf const accessors
Add const accessors for timebuf elements.
Diffstat (limited to 'src')
-rw-r--r--src/cpu/timebuf.hh32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/cpu/timebuf.hh b/src/cpu/timebuf.hh
index b6f709d71..e93fe0e79 100644
--- a/src/cpu/timebuf.hh
+++ b/src/cpu/timebuf.hh
@@ -49,7 +49,7 @@ class TimeBuffer
std::vector<char *> index;
unsigned base;
- void valid(int idx)
+ void valid(int idx) const
{
assert (idx >= -past && idx <= future);
}
@@ -189,7 +189,10 @@ class TimeBuffer
new (index[ptr]) T;
}
- T *access(int idx)
+ protected:
+ //Calculate the index into this->index for element at position idx
+ //relative to now
+ inline int calculateVectorIndex(int idx) const
{
//Need more complex math here to calculate index.
valid(idx);
@@ -201,24 +204,31 @@ class TimeBuffer
vector_index += size;
}
+ return vector_index;
+ }
+
+ public:
+ T *access(int idx)
+ {
+ int vector_index = calculateVectorIndex(idx);
+
return reinterpret_cast<T *>(index[vector_index]);
}
T &operator[](int idx)
{
- //Need more complex math here to calculate index.
- valid(idx);
-
- int vector_index = idx + base;
- if (vector_index >= (int)size) {
- vector_index -= size;
- } else if (vector_index < 0) {
- vector_index += size;
- }
+ int vector_index = calculateVectorIndex(idx);
return reinterpret_cast<T &>(*index[vector_index]);
}
+ const T &operator[] (int idx) const
+ {
+ int vector_index = calculateVectorIndex(idx);
+
+ return reinterpret_cast<const T &>(*index[vector_index]);
+ }
+
wire getWire(int idx)
{
valid(idx);