2 * Copyright (c) 2003 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "base/sat_counter.hh"
33 #include "base/statistics.hh"
34 #include "sim/sim_stats.hh"
40 SaturatingCounterPred::SaturatingCounterPred(string p_name
,
44 unsigned _counter_bits
,
45 unsigned _zero_change
,
54 index_bits
= _index_bits
;
55 counter_bits
= _counter_bits
;
56 zero_change
= _zero_change
;
57 one_change
= _one_change
;
59 init_value
= _init_value
;
61 max_index
= (1 << index_bits
) - 1;
62 max_value
= (1 << counter_bits
) - 1;
64 table
= new unsigned[max_index
+ 1];
66 // Initialize with the right parameters & clear the counter
67 for (int i
= 0; i
<= max_index
; ++i
)
68 table
[i
] = init_value
;
71 void SaturatingCounterPred::regStats()
73 using namespace Statistics
;
74 stringstream name
, description
;
77 // Number of predictions
79 name
<< pred_name
<< ":" << zero_name
<< ":preds";
80 description
<< "number of predictions of " << zero_name
;
83 .desc(description
.str())
88 name
<< pred_name
<< ":" << one_name
<< ":preds";
89 description
<< "number of predictions of " << one_name
;
92 .desc(description
.str())
98 // Count the number of correct predictions
100 name
<< pred_name
<< ":" << zero_name
<< ":corr_preds";
101 description
<< "number of correct " << zero_name
<< " preds";
104 .desc(description
.str())
109 name
<< pred_name
<< ":" << one_name
<< ":corr_preds";
110 description
<< "number of correct " << one_name
<< " preds";
113 .desc(description
.str())
119 // Number of predictor updates
121 name
<< pred_name
<< ":" << zero_name
<< ":updates";
122 description
<< "number of actual " << zero_name
<< "s";
125 .desc(description
.str())
130 name
<< pred_name
<< ":" << one_name
<< ":updates";
131 description
<< "number of actual " << one_name
<< "s";
134 .desc(description
.str())
140 void SaturatingCounterPred::regFormulas()
142 using namespace Statistics
;
143 stringstream name
, description
;
146 // Number of predictions
148 name
<< pred_name
<< ":predictions";
151 .desc("total number of predictions made")
153 preds_total
= predicted_zero
+ predicted_one
;
157 // Fraction of all predictions that are one or zero
159 name
<< pred_name
<< ":" << zero_name
<< ":pred_frac";
160 description
<< "fraction of all preds that were " << zero_name
;
163 .desc(description
.str())
165 pred_frac_zero
= 100 * predicted_zero
/ preds_total
;
169 name
<< pred_name
<< ":" << one_name
<< ":pred_frac";
170 description
<< "fraction of all preds that were " << one_name
;
173 .desc(description
.str())
175 pred_frac_one
= 100 * predicted_one
/ preds_total
;
181 // Count the number of correct predictions
183 name
<< pred_name
<< ":correct_preds";
186 .desc("total correct predictions made")
188 correct_total
= correct_pred_one
+ correct_pred_zero
;
192 // Number of predictor updates
194 name
<< pred_name
<< ":updates";
197 .desc("total number of updates")
199 updates_total
= record_zero
+ record_one
;
203 // Prediction accuracy rates
205 name
<< pred_name
<< ":pred_rate";
208 .desc("correct fraction of all preds")
210 pred_rate
= correct_total
/ updates_total
;
213 name
<< pred_name
<< ":" << zero_name
<< ":pred_rate";
214 description
<< "fraction of " << zero_name
<< " preds that were correct";
217 .desc(description
.str())
219 frac_correct_zero
= 100 * correct_pred_zero
/
220 (correct_pred_zero
+ record_one
- correct_pred_one
);
224 name
<< pred_name
<< ":" << one_name
<< ":pred_rate";
225 description
<< "fraction of " << one_name
<< " preds that were correct";
228 .desc(description
.str())
230 frac_correct_one
= 100 * correct_pred_one
/
231 (correct_pred_one
+ record_zero
- correct_pred_zero
);
238 name
<< pred_name
<< ":" << zero_name
<< ":coverage";
239 description
<< "fraction of " << zero_name
240 << "s that were predicted correctly";
243 .desc(description
.str())
245 coverage_zero
= 100 * correct_pred_zero
/ record_zero
;
249 name
<< pred_name
<< ":" << one_name
<< ":coverage";
250 description
<< "fraction of " << one_name
251 << "s that were predicted correctly";
254 .desc(description
.str())
256 coverage_one
= 100 * correct_pred_one
/ record_one
;