base: Fix squares of stats
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Sat, 8 Feb 2020 11:38:02 +0000 (12:38 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 10 Feb 2020 22:35:24 +0000 (22:35 +0000)
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 <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25184
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/statistics.hh

index 07f29599541c80d1e4f309a3d7f91a1f903c7d7c..fd16c3a36b0a6564d68331eff67fc81bc10454ed 100644 (file)
@@ -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;
     }
 
     /**