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.
32 #include "base/hybrid_pred.hh"
33 #include "base/statistics.hh"
34 #include "sim/stats.hh"
38 HybridPredictor::HybridPredictor(const char *_p_name
, const char *_z_name
,
40 unsigned _index_bits
, unsigned _counter_bits
,
41 unsigned _zero_change
, unsigned _one_change
,
43 unsigned _global_bits
,
44 unsigned _global_thresh
,
45 bool _reg_individual_stats
)
47 stringstream local_name
, global_name
;
52 reg_individual_stats
= _reg_individual_stats
;
54 local_name
<< pred_name
.c_str() << ":L";
55 local
= new SaturatingCounterPred(local_name
.str(), zero_name
, one_name
,
56 _index_bits
, _counter_bits
,
57 _zero_change
, _one_change
, _thresh
);
59 global_name
<< pred_name
.c_str() << ":G";
60 global
= new SaturatingCounterPred(global_name
.str(), zero_name
, one_name
,
61 0, _global_bits
, 1, 1, _global_thresh
);
64 void HybridPredictor::regStats()
66 using namespace Stats
;
69 stringstream description
;
71 if (reg_individual_stats
)
72 p_name
= pred_name
+ ":A";
78 // Number of predictions
80 stringstream num_zero_preds
;
81 num_zero_preds
<< p_name
<< ":" << zero_name
<< ":preds";
82 description
<< "number of predictions of " << zero_name
;
84 .name(num_zero_preds
.str())
85 .desc(description
.str());
88 stringstream num_one_preds
;
89 num_one_preds
<< p_name
<< ":" << one_name
<< ":preds";
90 description
<< "number of predictions of " << one_name
;
92 .name(num_one_preds
.str())
93 .desc(description
.str())
98 // Count the number of correct predictions
100 stringstream num_zero_correct
;
101 num_zero_correct
<< p_name
<< ":" << zero_name
<< ":corr_preds";
102 description
<< "number of correct " << zero_name
<< " preds" ;
104 .name(num_zero_correct
.str())
105 .desc(description
.str())
109 stringstream num_one_correct
;
110 num_one_correct
<< p_name
<< ":" << one_name
<< ":corr_preds";
111 description
<< "number of correct " << one_name
<< " preds" ;
113 .name(num_one_correct
.str())
114 .desc(description
.str())
120 // Number of predictor updates
122 stringstream num_zero_updates
;
123 num_zero_updates
<< p_name
<< ":" << zero_name
<< ":updates" ;
124 description
<< "number of actual " << zero_name
<< "s" ;
126 .name(num_zero_updates
.str())
127 .desc(description
.str())
131 stringstream num_one_updates
;
132 num_one_updates
<< p_name
<< ":" << one_name
<< ":updates" ;
133 description
<< "number of actual " << one_name
<< "s" ;
135 .name(num_one_updates
.str())
136 .desc(description
.str())
141 // Local & Global predictor stats
143 if (reg_individual_stats
) {
149 void HybridPredictor::regFormulas()
151 using namespace Stats
;
154 stringstream description
;
157 if (reg_individual_stats
)
158 p_name
= pred_name
+ ":A";
163 // Number of predictions
165 name
<< p_name
<< ":predictions" ;
168 .desc("total number of predictions made")
170 total_preds
= pred_one
+ pred_zero
;
174 // Fraction of all predictions that are one or zero
176 name
<< p_name
<< ":" << zero_name
<< ":pred_frac";
177 description
<< "fraction of all preds that were " << zero_name
;
180 .desc(description
.str())
182 frac_preds_zero
= 100 * record_zero
/ total_preds
;
186 name
<< p_name
<< ":" << one_name
<< ":pred_frac";
187 description
<< "fraction of all preds that were " << one_name
;
190 .desc(description
.str())
192 frac_preds_one
= 100 * record_one
/ total_preds
;
197 // Count the number of correct predictions
199 name
<< p_name
<< ":correct_preds" ;
202 .desc("total number of correct predictions made")
204 total_correct
= correct_pred_one
+ correct_pred_zero
;
209 // Prediction accuracy rates
211 name
<< p_name
<< ":pred_rate";
214 .desc("fraction of all preds that were correct")
216 total_accuracy
= 100 * total_correct
/ total_preds
;
219 name
<< p_name
<< ":" << zero_name
<< ":pred_rate" ;
220 description
<< "fraction of "<< zero_name
<<" preds that were correct";
223 .desc(description
.str())
225 zero_accuracy
= 100 * correct_pred_zero
/ pred_zero
;
229 name
<< p_name
<< ":" << one_name
<< ":pred_rate" ;
230 description
<< "fraction of "<< one_name
<<" preds that were correct";
233 .desc(description
.str())
235 one_accuracy
= 100 * correct_pred_one
/ pred_one
;
242 name
<< p_name
<< ":" << zero_name
<< ":coverage";
243 description
<< "fraction of " << zero_name
244 << "s that were predicted correctly";
247 .desc(description
.str())
249 zero_coverage
= 100 * correct_pred_zero
/ record_zero
;
253 name
<< p_name
<< ":" << one_name
<< ":coverage";
254 description
<< "fraction of " << one_name
255 << "s that were predicted correctly";
258 .desc(description
.str())
260 one_coverage
= 100 * correct_pred_one
/ record_one
;
265 // Local & Global predictor stats
267 if (reg_individual_stats
) {
268 local
->regFormulas();
269 global
->regFormulas();