From af9c5e05f73f6899a405230e66dfa75a5b39822a Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 19 Sep 2008 09:11:43 -0700 Subject: [PATCH] Use C++ limits where applicable for portability --- src/base/statistics.hh | 11 +++++++---- src/base/str.cc | 15 +++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 3a859d364..17aef14b9 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -76,6 +77,8 @@ extern Tick curTick; /* A namespace for all of the Statistics */ namespace Stats { +typedef std::numeric_limits CounterLimits; + /* Contains the statistic implementation details */ ////////////////////////////////////////////////////////////////////// // @@ -1454,8 +1457,8 @@ struct DistStor data->bucket_size = params.bucket_size; data->size = params.size; - data->min_val = (min_val == INT_MAX) ? 0 : min_val; - data->max_val = (max_val == INT_MIN) ? 0 : max_val; + data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val; + data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val; data->underflow = underflow; data->overflow = overflow; data->cvec.resize(params.size); @@ -1472,8 +1475,8 @@ struct DistStor */ void reset() { - min_val = INT_MAX; - max_val = INT_MIN; + min_val = CounterLimits::max(); + max_val = CounterLimits::min(); underflow = 0; overflow = 0; diff --git a/src/base/str.cc b/src/base/str.cc index 0a517dff5..2df1c103c 100644 --- a/src/base/str.cc +++ b/src/base/str.cc @@ -28,10 +28,10 @@ * Authors: Nathan Binkert */ -#include - +#include #include #include +#include #include #include @@ -117,12 +117,11 @@ inline bool __to_number(string value, T &retval) { static const T maxnum = ((T)-1); - static const bool sign = maxnum < 0; - static const int bits = sizeof(T) * 8; - static const T hexmax = maxnum & (((T)1 << (bits - 4 - sign)) - 1); - static const T octmax = maxnum & (((T)1 << (bits - 3 - sign)) - 1); - static const T signmax = - (sign) ? maxnum & (((T)1 << (bits - 1)) - 1) : maxnum; + static const bool sign = numeric_limits::is_signed; + static const int bits = numeric_limits::digits; + static const T hexmax = maxnum & (((T)1 << (bits - 4)) - 1); + static const T octmax = maxnum & (((T)1 << (bits - 3)) - 1); + static const T signmax = numeric_limits::max(); static const T decmax = signmax / 10; #if 0