changeset 5bad83cddb8c in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=5bad83cddb8c
description:
        stats: use properly signed types for looping and comparison

diffstat:

4 files changed, 3 insertions(+), 3 deletions(-)
src/base/statistics.cc  |    1 -
src/base/stats/mysql.hh |    2 +-
src/base/stats/text.cc  |    2 +-
src/base/stats/types.hh |    1 +

diffs (truncated from 1247 to 300 lines):

diff -r 345ef3bda3d2 -r 5bad83cddb8c src/base/statistics.cc
--- a/src/base/statistics.cc    Thu Oct 09 04:58:23 2008 -0700
+++ b/src/base/statistics.cc    Thu Oct 09 04:58:23 2008 -0700
@@ -117,8 +117,8 @@
     tokenize(v1, name1, '.');
     tokenize(v2, name2, '.');
 
-    int last = min(v1.size(), v2.size()) - 1;
-    for (int i = 0; i < last; ++i)
+    size_type last = min(v1.size(), v2.size()) - 1;
+    for (off_type i = 0; i < last; ++i)
         if (v1[i] != v2[i])
             return v1[i] < v2[i];
 
@@ -164,7 +164,7 @@
     return root ? root->total() : 0.0;
 }
 
-size_t
+size_type
 FormulaBase::size() const
 {
     if (!root)
@@ -183,7 +183,7 @@
 {
     VResult vec;
     result(vec);
-    for (int i = 0; i < vec.size(); ++i)
+    for (off_t i = 0; i < vec.size(); ++i)
         if (vec[i] != 0.0)
             return false;
     return true;
@@ -244,7 +244,7 @@
             panic("stat check failed for %s\n", data->name);
     }
 
-    int j = 0;
+    off_t j = 0;
     for (i = Database::stats().begin(); i != end; ++i) {
         StatData *data = *i;
         if (!(data->flags & print))
diff -r 345ef3bda3d2 -r 5bad83cddb8c src/base/statistics.hh
--- a/src/base/statistics.hh    Thu Oct 09 04:58:23 2008 -0700
+++ b/src/base/statistics.hh    Thu Oct 09 04:58:23 2008 -0700
@@ -173,7 +173,7 @@
     mutable std::vector<std::string> subnames;
     mutable std::vector<std::string> subdescs;
 
-    virtual size_t size() const  = 0;
+    virtual size_type size() const  = 0;
     virtual const VCounter &value() const = 0;
     virtual const VResult &result() const = 0;
     virtual Result total() const  = 0;
@@ -182,7 +182,7 @@
     update()
     {
         if (!subnames.empty()) {
-            int s = size();
+            size_type s = size();
             if (subnames.size() < s)
                 subnames.resize(s);
 
@@ -207,7 +207,7 @@
     virtual bool zero() const { return s.zero(); }
     virtual void reset() { s.reset(); }
 
-    virtual size_t size() const { return s.size(); }
+    virtual size_type size() const { return s.size(); }
 
     virtual VCounter &
     value() const
@@ -248,7 +248,7 @@
     Counter min;
     Counter max;
     Counter bucket_size;
-    int size;
+    size_type size;
     bool fancy;
 };
 
@@ -290,12 +290,12 @@
     /** Local storage for the entry values, used for printing. */
     mutable VResult rvec;
 
-    virtual size_t size() const = 0;
+    virtual size_type size() const = 0;
 
     void
     update()
     {
-        int s = size();
+        size_type s = size();
         if (subnames.size() < s)
             subnames.resize(s);
 
@@ -315,7 +315,7 @@
 
     virtual bool check() const { return s.check(); }
     virtual void reset() { s.reset(); }
-    virtual size_t size() const { return s.size(); }
+    virtual size_type size() const { return s.size(); }
     virtual bool zero() const { return s.zero(); }
 
     virtual void
@@ -336,8 +336,8 @@
 
     /** Local storage for the entry values, used for printing. */
     mutable VCounter cvec;
-    mutable int x;
-    mutable int y;
+    mutable size_type x;
+    mutable size_type y;
 
     void
     update()
@@ -506,7 +506,7 @@
      * @return A reference to this stat.
      */
     Parent &
-    subname(int index, const std::string &name)
+    subname(off_type index, const std::string &name)
     {
         std::vector<std::string> &subn = this->statData()->subnames;
         if (subn.size() <= index)
@@ -523,7 +523,7 @@
      * @return A reference to this stat.
      */
     Parent &
-    subdesc(int index, const std::string &desc)
+    subdesc(off_type index, const std::string &desc)
     {
         std::vector<std::string> &subd = this->statData()->subdescs;
         if (subd.size() <= index)
@@ -548,13 +548,13 @@
     {
         Data<Child> *data = this->statData();
         data->y_subnames.resize(this->y);
-        for (int i = 0; i < this->y; ++i)
+        for (off_type i = 0; i < this->y; ++i)
             data->y_subnames[i] = names[i];
         return this->self();
     }
 
     Parent &
-    ysubname(int index, const std::string subname)
+    ysubname(off_type index, const std::string subname)
     {
         Data<Child> *data = this->statData();
         assert(index < this->y);
@@ -832,7 +832,7 @@
      * Return the number of elements, always 1 for a scalar.
      * @return 1.
      */
-    size_t size() const { return 1; }
+    size_type size() const { return 1; }
 
     bool check() const { return true; }
 
@@ -856,7 +856,7 @@
   public:
     virtual void visit(Visit &visitor) { visitor.visit(*this); }
     virtual std::string str() const { return to_string(value()); }
-    virtual size_t size() const { return 1; }
+    virtual size_type size() const { return 1; }
     virtual bool zero() const { return value() == 0; }
     virtual bool check() const { return true; }
     virtual void reset() { }
@@ -916,7 +916,7 @@
     Counter value() { return proxy->value(); }
     Result result() const { return proxy->result(); }
     Result total() const { return proxy->total(); };
-    size_t size() const { return proxy->size(); }
+    size_type size() const { return proxy->size(); }
 
     std::string str() const { return proxy->str(); }
     bool zero() const { return proxy->zero(); }
@@ -942,7 +942,7 @@
     Stat *stat;
 
     /** The index to access in the parent VectorBase. */
-    int index;
+    off_type index;
 
   public:
     /**
@@ -963,7 +963,7 @@
      * @param p The params to use.
      * @param i The index to access.
      */
-    ScalarProxy(Stat *s, int i)
+    ScalarProxy(Stat *s, off_type i)
         : stat(s), index(i)
     {
         assert(stat);
@@ -1047,7 +1047,7 @@
      * Return the number of elements, always 1 for a scalar.
      * @return 1.
      */
-    size_t size() const { return 1; }
+    size_type size() const { return 1; }
 
     /**
      * This stat has no state.  Nothing to reset
@@ -1083,7 +1083,7 @@
   protected:
     /** The storage of this stat. */
     Storage *storage;
-    size_t _size;
+    size_type _size;
 
     /** The parameters for this stat. */
     Params params;
@@ -1094,17 +1094,17 @@
      * @param index The vector index to access.
      * @return The storage object at the given index.
      */
-    Storage *data(int index) { return &storage[index]; }
+    Storage *data(off_type index) { return &storage[index]; }
 
     /**
      * Retrieve a const pointer to the storage.
      * @param index The vector index to access.
      * @return A const pointer to the storage object at the given index.
      */
-    const Storage *data(int index) const { return &storage[index]; }
+    const Storage *data(off_type index) const { return &storage[index]; }
 
     void
-    doInit(int s)
+    doInit(size_type s)
     {
         assert(s > 0 && "size must be positive!");
         assert(!storage && "already initialized");
@@ -1113,7 +1113,7 @@
         char *ptr = new char[_size * sizeof(Storage)];
         storage = reinterpret_cast<Storage *>(ptr);
 
-        for (int i = 0; i < _size; ++i)
+        for (off_type i = 0; i < _size; ++i)
             new (&storage[i]) Storage(params);
 
         setInit();
@@ -1124,7 +1124,7 @@
     value(VCounter &vec) const
     {
         vec.resize(size());
-        for (int i = 0; i < size(); ++i)
+        for (off_type i = 0; i < size(); ++i)
             vec[i] = data(i)->value(params);
     }
 
@@ -1136,7 +1136,7 @@
     result(VResult &vec) const
     {
         vec.resize(size());
-        for (int i = 0; i < size(); ++i)
+        for (off_type i = 0; i < size(); ++i)
             vec[i] = data(i)->result(params);
     }
 
@@ -1148,7 +1148,7 @@
     total() const
     {
         Result total = 0.0;
-        for (int i = 0; i < size(); ++i)
+        for (off_type i = 0; i < size(); ++i)
             total += data(i)->result(params);
         return total;
     }
@@ -1156,12 +1156,12 @@
     /**
      * @return the number of elements in this vector.
      */
-    size_t size() const { return _size; }
+    size_type size() const { return _size; }
 
     bool
     zero() const
     {
-        for (int i = 0; i < size(); ++i)
+        for (off_type i = 0; i < size(); ++i)
             if (data(i)->zero())
                 return false;
         return true;
@@ -1176,7 +1176,7 @@
     void
     reset()
     {
-        for (int i = 0; i < size(); ++i)
+        for (off_type i = 0; i < size(); ++i)
             data(i)->reset();
     }
 
@@ -1190,7 +1190,7 @@
         if (!storage)
             return;
 
-        for (int i = 0; i < _size; ++i)
+        for (off_type i = 0; i < _size; ++i)
             data(i)->~Storage();
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to