From 219003c57565b836f5822daf2ab2082f811d77ab Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Sat, 13 Mar 2021 19:06:27 -0300 Subject: [PATCH] base-stats: Make Rate's compilation smarter A Rate should be supplied units of different types. Rates between units of the same type are Ratios, and should be declared as such. An exception is applied to Count and Unspecified, since those units represent unknown underlying units. Change-Id: I36ab7c73b239ccc86d866c5b38e14fd765bbbd0f Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43008 Tested-by: kokoro Maintainer: Giacomo Travaglini Reviewed-by: Hoa Nguyen --- src/base/stats/units.hh | 67 +++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/base/stats/units.hh b/src/base/stats/units.hh index b2dfefa19e..87e6025b69 100644 --- a/src/base/stats/units.hh +++ b/src/base/stats/units.hh @@ -272,38 +272,6 @@ class Count : public Base std::string getUnitString() const override { return Count::toString(); } }; -template -class Rate : public Base -{ - static_assert(std::is_base_of::value, - "Rate(T1,T2) must have T1 and T2 derived from" - "Stats::Units::Base"); - static_assert(std::is_base_of::value, - "Rate(T1,T2) must have T1 and T2 derived from" - "Stats::Units::Base"); - private: - Rate() {} - public: - Rate(Rate const&) = delete; - void operator=(Rate const&) = delete; - static Rate* - get() - { - static Rate instance; - return &instance; - } - static std::string - toString() - { - return csprintf("(%s/%s)", T1::toString(), T2::toString()); - } - std::string - getUnitString() const override - { - return Rate::toString(); - } -}; - class Ratio : public Base { private: @@ -342,6 +310,41 @@ class Unspecified : public Base } }; +template +class Rate : public Base +{ + static_assert(std::is_base_of::value, + "Rate(T1,T2) must have T1 and T2 derived from Stats::Units::Base"); + static_assert(std::is_base_of::value, + "Rate(T1,T2) must have T1 and T2 derived from Stats::Units::Base"); + static_assert(!std::is_same::value || + std::is_same::value || std::is_same::value, + "Rate(T1,T2) must have T1 and T2 of different types; " + "otherwise, it would be a Ratio"); + + private: + Rate() {} + public: + Rate(Rate const&) = delete; + void operator=(Rate const&) = delete; + static Rate* + get() + { + static Rate instance; + return &instance; + } + static std::string + toString() + { + return csprintf("(%s/%s)", T1::toString(), T2::toString()); + } + std::string + getUnitString() const override + { + return Rate::toString(); + } +}; + } // namespace Units } // namespace Stats