2 * Copyright (c) 2003-2005 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.
28 * Authors: Steve Reinhardt
34 #include "base/sat_counter.hh"
35 #include "base/statistics.hh"
36 #include "sim/stats.hh"
42 SaturatingCounterPred::SaturatingCounterPred(string p_name
,
46 unsigned _counter_bits
,
47 unsigned _zero_change
,
56 index_bits
= _index_bits
;
57 counter_bits
= _counter_bits
;
58 zero_change
= _zero_change
;
59 one_change
= _one_change
;
61 init_value
= _init_value
;
63 max_index
= (1 << index_bits
) - 1;
64 max_value
= (1 << counter_bits
) - 1;
66 table
= new unsigned[max_index
+ 1];
68 // Initialize with the right parameters & clear the counter
69 for (int i
= 0; i
<= max_index
; ++i
)
70 table
[i
] = init_value
;
73 void SaturatingCounterPred::regStats()
75 using namespace Stats
;
76 stringstream name
, description
;
79 // Number of predictions
81 name
<< pred_name
<< ":" << zero_name
<< ":preds";
82 description
<< "number of predictions of " << zero_name
;
85 .desc(description
.str())
90 name
<< pred_name
<< ":" << one_name
<< ":preds";
91 description
<< "number of predictions of " << one_name
;
94 .desc(description
.str())
100 // Count the number of correct predictions
102 name
<< pred_name
<< ":" << zero_name
<< ":corr_preds";
103 description
<< "number of correct " << zero_name
<< " preds";
106 .desc(description
.str())
111 name
<< pred_name
<< ":" << one_name
<< ":corr_preds";
112 description
<< "number of correct " << one_name
<< " preds";
115 .desc(description
.str())
121 // Number of predictor updates
123 name
<< pred_name
<< ":" << zero_name
<< ":updates";
124 description
<< "number of actual " << zero_name
<< "s";
127 .desc(description
.str())
132 name
<< pred_name
<< ":" << one_name
<< ":updates";
133 description
<< "number of actual " << one_name
<< "s";
136 .desc(description
.str())
142 void SaturatingCounterPred::regFormulas()
144 using namespace Stats
;
145 stringstream name
, description
;
148 // Number of predictions
150 name
<< pred_name
<< ":predictions";
153 .desc("total number of predictions made")
155 preds_total
= predicted_zero
+ predicted_one
;
159 // Fraction of all predictions that are one or zero
161 name
<< pred_name
<< ":" << zero_name
<< ":pred_frac";
162 description
<< "fraction of all preds that were " << zero_name
;
165 .desc(description
.str())
167 pred_frac_zero
= 100 * predicted_zero
/ preds_total
;
171 name
<< pred_name
<< ":" << one_name
<< ":pred_frac";
172 description
<< "fraction of all preds that were " << one_name
;
175 .desc(description
.str())
177 pred_frac_one
= 100 * predicted_one
/ preds_total
;
183 // Count the number of correct predictions
185 name
<< pred_name
<< ":correct_preds";
188 .desc("total correct predictions made")
190 correct_total
= correct_pred_one
+ correct_pred_zero
;
194 // Number of predictor updates
196 name
<< pred_name
<< ":updates";
199 .desc("total number of updates")
201 updates_total
= record_zero
+ record_one
;
205 // Prediction accuracy rates
207 name
<< pred_name
<< ":pred_rate";
210 .desc("correct fraction of all preds")
212 pred_rate
= correct_total
/ updates_total
;
215 name
<< pred_name
<< ":" << zero_name
<< ":pred_rate";
216 description
<< "fraction of " << zero_name
<< " preds that were correct";
219 .desc(description
.str())
221 frac_correct_zero
= 100 * correct_pred_zero
/
222 (correct_pred_zero
+ record_one
- correct_pred_one
);
226 name
<< pred_name
<< ":" << one_name
<< ":pred_rate";
227 description
<< "fraction of " << one_name
<< " preds that were correct";
230 .desc(description
.str())
232 frac_correct_one
= 100 * correct_pred_one
/
233 (correct_pred_one
+ record_zero
- correct_pred_zero
);
240 name
<< pred_name
<< ":" << zero_name
<< ":coverage";
241 description
<< "fraction of " << zero_name
242 << "s that were predicted correctly";
245 .desc(description
.str())
247 coverage_zero
= 100 * correct_pred_zero
/ record_zero
;
251 name
<< pred_name
<< ":" << one_name
<< ":coverage";
252 description
<< "fraction of " << one_name
253 << "s that were predicted correctly";
256 .desc(description
.str())
258 coverage_one
= 100 * correct_pred_one
/ record_one
;