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.
32 #include "sat_counter.hh"
34 #include "statistics.hh"
35 #include "sim_stats.hh"
41 SaturatingCounterPred::SaturatingCounterPred(string p_name
,
45 unsigned _counter_bits
,
46 unsigned _zero_change
,
55 index_bits
= _index_bits
;
56 counter_bits
= _counter_bits
;
57 zero_change
= _zero_change
;
58 one_change
= _one_change
;
60 init_value
= _init_value
;
62 max_index
= (1 << index_bits
) - 1;
63 max_value
= (1 << counter_bits
) - 1;
65 table
= new unsigned[max_index
+ 1];
67 // Initialize with the right parameters & clear the counter
68 for (int i
= 0; i
<= max_index
; ++i
)
69 table
[i
] = init_value
;
72 void SaturatingCounterPred::regStats()
74 using namespace Statistics
;
75 stringstream name
, description
;
78 // Number of predictions
80 name
<< pred_name
<< ":" << zero_name
<< ":preds";
81 description
<< "number of predictions of " << zero_name
;
84 .desc(description
.str())
89 name
<< pred_name
<< ":" << one_name
<< ":preds";
90 description
<< "number of predictions of " << one_name
;
93 .desc(description
.str())
99 // Count the number of correct predictions
101 name
<< pred_name
<< ":" << zero_name
<< ":corr_preds";
102 description
<< "number of correct " << zero_name
<< " preds";
105 .desc(description
.str())
110 name
<< pred_name
<< ":" << one_name
<< ":corr_preds";
111 description
<< "number of correct " << one_name
<< " preds";
114 .desc(description
.str())
120 // Number of predictor updates
122 name
<< pred_name
<< ":" << zero_name
<< ":updates";
123 description
<< "number of actual " << zero_name
<< "s";
126 .desc(description
.str())
131 name
<< pred_name
<< ":" << one_name
<< ":updates";
132 description
<< "number of actual " << one_name
<< "s";
135 .desc(description
.str())
141 void SaturatingCounterPred::regFormulas()
143 using namespace Statistics
;
144 stringstream name
, description
;
147 // Number of predictions
149 name
<< pred_name
<< ":predictions";
152 .desc("total number of predictions made")
154 preds_total
= predicted_zero
+ predicted_one
;
158 // Fraction of all predictions that are one or zero
160 name
<< pred_name
<< ":" << zero_name
<< ":pred_frac";
161 description
<< "fraction of all preds that were " << zero_name
;
164 .desc(description
.str())
166 pred_frac_zero
= 100 * predicted_zero
/ preds_total
;
170 name
<< pred_name
<< ":" << one_name
<< ":pred_frac";
171 description
<< "fraction of all preds that were " << one_name
;
174 .desc(description
.str())
176 pred_frac_one
= 100 * predicted_one
/ preds_total
;
182 // Count the number of correct predictions
184 name
<< pred_name
<< ":correct_preds";
187 .desc("total correct predictions made")
189 correct_total
= correct_pred_one
+ correct_pred_zero
;
193 // Number of predictor updates
195 name
<< pred_name
<< ":updates";
198 .desc("total number of updates")
200 updates_total
= record_zero
+ record_one
;
204 // Prediction accuracy rates
206 name
<< pred_name
<< ":pred_rate";
209 .desc("correct fraction of all preds")
211 pred_rate
= correct_total
/ updates_total
;
214 name
<< pred_name
<< ":" << zero_name
<< ":pred_rate";
215 description
<< "fraction of " << zero_name
<< " preds that were correct";
218 .desc(description
.str())
220 frac_correct_zero
= 100 * correct_pred_zero
/
221 (correct_pred_zero
+ record_one
- correct_pred_one
);
225 name
<< pred_name
<< ":" << one_name
<< ":pred_rate";
226 description
<< "fraction of " << one_name
<< " preds that were correct";
229 .desc(description
.str())
231 frac_correct_one
= 100 * correct_pred_one
/
232 (correct_pred_one
+ record_zero
- correct_pred_zero
);
239 name
<< pred_name
<< ":" << zero_name
<< ":coverage";
240 description
<< "fraction of " << zero_name
241 << "s that were predicted correctly";
244 .desc(description
.str())
246 coverage_zero
= 100 * correct_pred_zero
/ record_zero
;
250 name
<< pred_name
<< ":" << one_name
<< ":coverage";
251 description
<< "fraction of " << one_name
252 << "s that were predicted correctly";
255 .desc(description
.str())
257 coverage_one
= 100 * correct_pred_one
/ record_one
;