From: Daniel R. Carvalho Date: Sat, 8 Feb 2020 11:38:02 +0000 (+0100) Subject: base: Fix squares of stats X-Git-Tag: v19.0.0.0~16 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f5e84a5fb989cc6dff0ec063578447a32dad6d5c;p=gem5.git 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 --- 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; } /**