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.
33 #include "hybrid_pred.hh"
35 #include "statistics.hh"
36 #include "sim_stats.hh"
40 HybridPredictor::HybridPredictor(const char *_p_name
, const char *_z_name
,
42 unsigned _index_bits
, unsigned _counter_bits
,
43 unsigned _zero_change
, unsigned _one_change
,
45 unsigned _global_bits
,
46 unsigned _global_thresh
,
47 bool _reg_individual_stats
)
49 stringstream local_name
, global_name
;
54 reg_individual_stats
= _reg_individual_stats
;
56 local_name
<< pred_name
.c_str() << ":L";
57 local
= new SaturatingCounterPred(local_name
.str(), zero_name
, one_name
,
58 _index_bits
, _counter_bits
,
59 _zero_change
, _one_change
, _thresh
);
61 global_name
<< pred_name
.c_str() << ":G";
62 global
= new SaturatingCounterPred(global_name
.str(), zero_name
, one_name
,
63 0, _global_bits
, 1, 1, _global_thresh
);
66 void HybridPredictor::regStats()
68 using namespace Statistics
;
71 stringstream description
;
73 if (reg_individual_stats
)
74 p_name
= pred_name
+ ":A";
80 // Number of predictions
82 stringstream num_zero_preds
;
83 num_zero_preds
<< p_name
<< ":" << zero_name
<< ":preds";
84 description
<< "number of predictions of " << zero_name
;
86 .name(num_zero_preds
.str())
87 .desc(description
.str());
90 stringstream num_one_preds
;
91 num_one_preds
<< p_name
<< ":" << one_name
<< ":preds";
92 description
<< "number of predictions of " << one_name
;
94 .name(num_one_preds
.str())
95 .desc(description
.str())
100 // Count the number of correct predictions
102 stringstream num_zero_correct
;
103 num_zero_correct
<< p_name
<< ":" << zero_name
<< ":corr_preds";
104 description
<< "number of correct " << zero_name
<< " preds" ;
106 .name(num_zero_correct
.str())
107 .desc(description
.str())
111 stringstream num_one_correct
;
112 num_one_correct
<< p_name
<< ":" << one_name
<< ":corr_preds";
113 description
<< "number of correct " << one_name
<< " preds" ;
115 .name(num_one_correct
.str())
116 .desc(description
.str())
122 // Number of predictor updates
124 stringstream num_zero_updates
;
125 num_zero_updates
<< p_name
<< ":" << zero_name
<< ":updates" ;
126 description
<< "number of actual " << zero_name
<< "s" ;
128 .name(num_zero_updates
.str())
129 .desc(description
.str())
133 stringstream num_one_updates
;
134 num_one_updates
<< p_name
<< ":" << one_name
<< ":updates" ;
135 description
<< "number of actual " << one_name
<< "s" ;
137 .name(num_one_updates
.str())
138 .desc(description
.str())
143 // Local & Global predictor stats
145 if (reg_individual_stats
) {
151 void HybridPredictor::regFormulas()
153 using namespace Statistics
;
156 stringstream description
;
159 if (reg_individual_stats
)
160 p_name
= pred_name
+ ":A";
165 // Number of predictions
167 name
<< p_name
<< ":predictions" ;
170 .desc("total number of predictions made")
172 total_preds
= pred_one
+ pred_zero
;
176 // Fraction of all predictions that are one or zero
178 name
<< p_name
<< ":" << zero_name
<< ":pred_frac";
179 description
<< "fraction of all preds that were " << zero_name
;
182 .desc(description
.str())
184 frac_preds_zero
= 100 * record_zero
/ total_preds
;
188 name
<< p_name
<< ":" << one_name
<< ":pred_frac";
189 description
<< "fraction of all preds that were " << one_name
;
192 .desc(description
.str())
194 frac_preds_one
= 100 * record_one
/ total_preds
;
199 // Count the number of correct predictions
201 name
<< p_name
<< ":correct_preds" ;
204 .desc("total number of correct predictions made")
206 total_correct
= correct_pred_one
+ correct_pred_zero
;
211 // Prediction accuracy rates
213 name
<< p_name
<< ":pred_rate";
216 .desc("fraction of all preds that were correct")
218 total_accuracy
= 100 * total_correct
/ total_preds
;
221 name
<< p_name
<< ":" << zero_name
<< ":pred_rate" ;
222 description
<< "fraction of "<< zero_name
<<" preds that were correct";
225 .desc(description
.str())
227 zero_accuracy
= 100 * correct_pred_zero
/ pred_zero
;
231 name
<< p_name
<< ":" << one_name
<< ":pred_rate" ;
232 description
<< "fraction of "<< one_name
<<" preds that were correct";
235 .desc(description
.str())
237 one_accuracy
= 100 * correct_pred_one
/ pred_one
;
244 name
<< p_name
<< ":" << zero_name
<< ":coverage";
245 description
<< "fraction of " << zero_name
246 << "s that were predicted correctly";
249 .desc(description
.str())
251 zero_coverage
= 100 * correct_pred_zero
/ record_zero
;
255 name
<< p_name
<< ":" << one_name
<< ":coverage";
256 description
<< "fraction of " << one_name
257 << "s that were predicted correctly";
260 .desc(description
.str())
262 one_coverage
= 100 * correct_pred_one
/ record_one
;
267 // Local & Global predictor stats
269 if (reg_individual_stats
) {
270 local
->regFormulas();
271 global
->regFormulas();