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
35 #include "base/hybrid_pred.hh"
36 #include "base/statistics.hh"
37 #include "sim/stats.hh"
41 HybridPredictor::HybridPredictor(const char *_p_name
, const char *_z_name
,
43 unsigned _index_bits
, unsigned _counter_bits
,
44 unsigned _zero_change
, unsigned _one_change
,
46 unsigned _global_bits
,
47 unsigned _global_thresh
,
48 bool _reg_individual_stats
)
50 stringstream local_name
, global_name
;
55 reg_individual_stats
= _reg_individual_stats
;
57 local_name
<< pred_name
.c_str() << ":L";
58 local
= new SaturatingCounterPred(local_name
.str(), zero_name
, one_name
,
59 _index_bits
, _counter_bits
,
60 _zero_change
, _one_change
, _thresh
);
62 global_name
<< pred_name
.c_str() << ":G";
63 global
= new SaturatingCounterPred(global_name
.str(), zero_name
, one_name
,
64 0, _global_bits
, 1, 1, _global_thresh
);
67 void HybridPredictor::regStats()
69 using namespace Stats
;
72 stringstream description
;
74 if (reg_individual_stats
)
75 p_name
= pred_name
+ ":A";
81 // Number of predictions
83 stringstream num_zero_preds
;
84 num_zero_preds
<< p_name
<< ":" << zero_name
<< ":preds";
85 description
<< "number of predictions of " << zero_name
;
87 .name(num_zero_preds
.str())
88 .desc(description
.str());
91 stringstream num_one_preds
;
92 num_one_preds
<< p_name
<< ":" << one_name
<< ":preds";
93 description
<< "number of predictions of " << one_name
;
95 .name(num_one_preds
.str())
96 .desc(description
.str())
101 // Count the number of correct predictions
103 stringstream num_zero_correct
;
104 num_zero_correct
<< p_name
<< ":" << zero_name
<< ":corr_preds";
105 description
<< "number of correct " << zero_name
<< " preds" ;
107 .name(num_zero_correct
.str())
108 .desc(description
.str())
112 stringstream num_one_correct
;
113 num_one_correct
<< p_name
<< ":" << one_name
<< ":corr_preds";
114 description
<< "number of correct " << one_name
<< " preds" ;
116 .name(num_one_correct
.str())
117 .desc(description
.str())
123 // Number of predictor updates
125 stringstream num_zero_updates
;
126 num_zero_updates
<< p_name
<< ":" << zero_name
<< ":updates" ;
127 description
<< "number of actual " << zero_name
<< "s" ;
129 .name(num_zero_updates
.str())
130 .desc(description
.str())
134 stringstream num_one_updates
;
135 num_one_updates
<< p_name
<< ":" << one_name
<< ":updates" ;
136 description
<< "number of actual " << one_name
<< "s" ;
138 .name(num_one_updates
.str())
139 .desc(description
.str())
144 // Local & Global predictor stats
146 if (reg_individual_stats
) {
152 void HybridPredictor::regFormulas()
154 using namespace Stats
;
157 stringstream description
;
160 if (reg_individual_stats
)
161 p_name
= pred_name
+ ":A";
166 // Number of predictions
168 name
<< p_name
<< ":predictions" ;
171 .desc("total number of predictions made")
173 total_preds
= pred_one
+ pred_zero
;
177 // Fraction of all predictions that are one or zero
179 name
<< p_name
<< ":" << zero_name
<< ":pred_frac";
180 description
<< "fraction of all preds that were " << zero_name
;
183 .desc(description
.str())
185 frac_preds_zero
= 100 * record_zero
/ total_preds
;
189 name
<< p_name
<< ":" << one_name
<< ":pred_frac";
190 description
<< "fraction of all preds that were " << one_name
;
193 .desc(description
.str())
195 frac_preds_one
= 100 * record_one
/ total_preds
;
200 // Count the number of correct predictions
202 name
<< p_name
<< ":correct_preds" ;
205 .desc("total number of correct predictions made")
207 total_correct
= correct_pred_one
+ correct_pred_zero
;
212 // Prediction accuracy rates
214 name
<< p_name
<< ":pred_rate";
217 .desc("fraction of all preds that were correct")
219 total_accuracy
= 100 * total_correct
/ total_preds
;
222 name
<< p_name
<< ":" << zero_name
<< ":pred_rate" ;
223 description
<< "fraction of "<< zero_name
<<" preds that were correct";
226 .desc(description
.str())
228 zero_accuracy
= 100 * correct_pred_zero
/ pred_zero
;
232 name
<< p_name
<< ":" << one_name
<< ":pred_rate" ;
233 description
<< "fraction of "<< one_name
<<" preds that were correct";
236 .desc(description
.str())
238 one_accuracy
= 100 * correct_pred_one
/ pred_one
;
245 name
<< p_name
<< ":" << zero_name
<< ":coverage";
246 description
<< "fraction of " << zero_name
247 << "s that were predicted correctly";
250 .desc(description
.str())
252 zero_coverage
= 100 * correct_pred_zero
/ record_zero
;
256 name
<< p_name
<< ":" << one_name
<< ":coverage";
257 description
<< "fraction of " << one_name
258 << "s that were predicted correctly";
261 .desc(description
.str())
263 one_coverage
= 100 * correct_pred_one
/ record_one
;
268 // Local & Global predictor stats
270 if (reg_individual_stats
) {
271 local
->regFormulas();
272 global
->regFormulas();