From f5e84a5fb989cc6dff0ec063578447a32dad6d5c Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Sat, 8 Feb 2020 12:38:02 +0100 Subject: [PATCH] base: Fix squares of stats If a sample V, which has a square(V) = V * V, was seen N times, then its sum of squares is given by N * square(V). Change-Id: Ie3fe0e4afe6e79ba4c8a5a56532f9346f79b4029 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25184 Reviewed-by: Bobby R. Bruce Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/base/statistics.hh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 07f295995..fd16c3a36 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -1724,9 +1724,8 @@ class SampleStor void sample(Counter val, int number) { - Counter value = val * number; - sum += value; - squares += value * value; + sum += val * number; + squares += val * val * number; samples += number; } @@ -1801,9 +1800,8 @@ class AvgSampleStor void sample(Counter val, int number) { - Counter value = val * number; - sum += value; - squares += value * value; + sum += val * number; + squares += val * val * number; } /** -- 2.30.2