2 * Copyright (c) 2003-2004 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"
32 #include "base/statistics.hh"
33 #include "sim/stats.hh"
39 SaturatingCounterPred::SaturatingCounterPred(string p_name
,
43 unsigned _counter_bits
,
44 unsigned _zero_change
,
53 index_bits
= _index_bits
;
54 counter_bits
= _counter_bits
;
55 zero_change
= _zero_change
;
56 one_change
= _one_change
;
58 init_value
= _init_value
;
60 max_index
= (1 << index_bits
) - 1;
61 max_value
= (1 << counter_bits
) - 1;
63 table
= new unsigned[max_index
+ 1];
65 // Initialize with the right parameters & clear the counter
66 for (int i
= 0; i
<= max_index
; ++i
)
67 table
[i
] = init_value
;
70 void SaturatingCounterPred::regStats()
72 using namespace Stats
;
73 stringstream name
, description
;
76 // Number of predictions
78 name
<< pred_name
<< ":" << zero_name
<< ":preds";
79 description
<< "number of predictions of " << zero_name
;
82 .desc(description
.str())
87 name
<< pred_name
<< ":" << one_name
<< ":preds";
88 description
<< "number of predictions of " << one_name
;
91 .desc(description
.str())
97 // Count the number of correct predictions
99 name
<< pred_name
<< ":" << zero_name
<< ":corr_preds";
100 description
<< "number of correct " << zero_name
<< " preds";
103 .desc(description
.str())
108 name
<< pred_name
<< ":" << one_name
<< ":corr_preds";
109 description
<< "number of correct " << one_name
<< " preds";
112 .desc(description
.str())
118 // Number of predictor updates
120 name
<< pred_name
<< ":" << zero_name
<< ":updates";
121 description
<< "number of actual " << zero_name
<< "s";
124 .desc(description
.str())
129 name
<< pred_name
<< ":" << one_name
<< ":updates";
130 description
<< "number of actual " << one_name
<< "s";
133 .desc(description
.str())
139 void SaturatingCounterPred::regFormulas()
141 using namespace Stats
;
142 stringstream name
, description
;
145 // Number of predictions
147 name
<< pred_name
<< ":predictions";
150 .desc("total number of predictions made")
152 preds_total
= predicted_zero
+ predicted_one
;
156 // Fraction of all predictions that are one or zero
158 name
<< pred_name
<< ":" << zero_name
<< ":pred_frac";
159 description
<< "fraction of all preds that were " << zero_name
;
162 .desc(description
.str())
164 pred_frac_zero
= 100 * predicted_zero
/ preds_total
;
168 name
<< pred_name
<< ":" << one_name
<< ":pred_frac";
169 description
<< "fraction of all preds that were " << one_name
;
172 .desc(description
.str())
174 pred_frac_one
= 100 * predicted_one
/ preds_total
;
180 // Count the number of correct predictions
182 name
<< pred_name
<< ":correct_preds";
185 .desc("total correct predictions made")
187 correct_total
= correct_pred_one
+ correct_pred_zero
;
191 // Number of predictor updates
193 name
<< pred_name
<< ":updates";
196 .desc("total number of updates")
198 updates_total
= record_zero
+ record_one
;
202 // Prediction accuracy rates
204 name
<< pred_name
<< ":pred_rate";
207 .desc("correct fraction of all preds")
209 pred_rate
= correct_total
/ updates_total
;
212 name
<< pred_name
<< ":" << zero_name
<< ":pred_rate";
213 description
<< "fraction of " << zero_name
<< " preds that were correct";
216 .desc(description
.str())
218 frac_correct_zero
= 100 * correct_pred_zero
/
219 (correct_pred_zero
+ record_one
- correct_pred_one
);
223 name
<< pred_name
<< ":" << one_name
<< ":pred_rate";
224 description
<< "fraction of " << one_name
<< " preds that were correct";
227 .desc(description
.str())
229 frac_correct_one
= 100 * correct_pred_one
/
230 (correct_pred_one
+ record_zero
- correct_pred_zero
);
237 name
<< pred_name
<< ":" << zero_name
<< ":coverage";
238 description
<< "fraction of " << zero_name
239 << "s that were predicted correctly";
242 .desc(description
.str())
244 coverage_zero
= 100 * correct_pred_zero
/ record_zero
;
248 name
<< pred_name
<< ":" << one_name
<< ":coverage";
249 description
<< "fraction of " << one_name
250 << "s that were predicted correctly";
253 .desc(description
.str())
255 coverage_one
= 100 * correct_pred_one
/ record_one
;