summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorWilliam Wang <William.Wang@arm.com>2012-06-05 01:23:11 -0400
committerWilliam Wang <William.Wang@arm.com>2012-06-05 01:23:11 -0400
commite5f0d6016ba768c06b36d8b3d54f3ea700a4aa58 (patch)
tree1d0b7512f7eabaabbc04d3752134b61c9cd8a806 /src/base
parent14539ccae19098a26a7048f475f3ffd44b711f5d (diff)
downloadgem5-e5f0d6016ba768c06b36d8b3d54f3ea700a4aa58.tar.xz
stats: when applying an operation to two vectors sum the components first.
Previously writing X/Y in a formula would result in: x[0]/y[0] + x[1]/y[1] In reality you want: (x[0] +x[1])/(y[0] + y[1])
Diffstat (limited to 'src/base')
-rw-r--r--src/base/statistics.hh24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index c36f8f461..723c8bd9c 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -2289,9 +2289,31 @@ class BinaryNode : public Node
total() const
{
const VResult &vec = this->result();
+ const VResult &lvec = l->result();
+ const VResult &rvec = r->result();
Result total = 0.0;
- for (off_type i = 0; i < size(); i++)
+ Result lsum = 0.0;
+ Result rsum = 0.0;
+ Op op;
+
+ assert(lvec.size() > 0 && rvec.size() > 0);
+ assert(lvec.size() == rvec.size() ||
+ lvec.size() == 1 || rvec.size() == 1);
+
+ /** If vectors are the same divide their sums (x0+x1)/(y0+y1) */
+ if (lvec.size() == rvec.size() && lvec.size() > 1) {
+ for (off_type i = 0; i < size(); ++i) {
+ lsum += lvec[i];
+ rsum += rvec[i];
+ }
+ return op(lsum, rsum);
+ }
+
+ /** Otherwise divide each item by the divisor */
+ for (off_type i = 0; i < size(); ++i) {
total += vec[i];
+ }
+
return total;
}