Merge ehallnor@zizzer:/bk/m5
[gem5.git] / sim / sat_counter.cc
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 #include <sstream>
30
31 #include "stats.hh"
32 #include "sat_counter.hh"
33
34 #include "statistics.hh"
35 #include "sim_stats.hh"
36
37
38 using namespace std;
39
40
41 SaturatingCounterPred::SaturatingCounterPred(string p_name,
42 string z_name,
43 string o_name,
44 unsigned _index_bits,
45 unsigned _counter_bits,
46 unsigned _zero_change,
47 unsigned _one_change,
48 unsigned _thresh,
49 unsigned _init_value)
50 {
51 pred_name = p_name;
52 zero_name = z_name;
53 one_name = o_name;
54
55 index_bits = _index_bits;
56 counter_bits = _counter_bits;
57 zero_change = _zero_change;
58 one_change = _one_change;
59 thresh = _thresh;
60 init_value = _init_value;
61
62 max_index = (1 << index_bits) - 1;
63 max_value = (1 << counter_bits) - 1;
64
65 table = new unsigned[max_index + 1];
66
67 // Initialize with the right parameters & clear the counter
68 for (int i = 0; i <= max_index; ++i)
69 table[i] = init_value;
70 }
71
72 void SaturatingCounterPred::regStats()
73 {
74 using namespace Statistics;
75 stringstream name, description;
76
77 //
78 // Number of predictions
79 //
80 name << pred_name << ":" << zero_name << ":preds";
81 description << "number of predictions of " << zero_name;
82 predicted_zero
83 .name(name.str())
84 .desc(description.str())
85 ;
86 description.str("");
87 name.str("");
88
89 name << pred_name << ":" << one_name << ":preds";
90 description << "number of predictions of " << one_name;
91 predicted_one
92 .name(name.str())
93 .desc(description.str())
94 ;
95 description.str("");
96 name.str("");
97
98 //
99 // Count the number of correct predictions
100 //
101 name << pred_name << ":" << zero_name << ":corr_preds";
102 description << "number of correct " << zero_name << " preds";
103 correct_pred_zero
104 .name(name.str())
105 .desc(description.str())
106 ;
107 description.str("");
108 name.str("");
109
110 name << pred_name << ":" << one_name << ":corr_preds";
111 description << "number of correct " << one_name << " preds";
112 correct_pred_one
113 .name(name.str())
114 .desc(description.str())
115 ;
116 description.str("");
117 name.str("");
118
119 //
120 // Number of predictor updates
121 //
122 name << pred_name << ":" << zero_name << ":updates";
123 description << "number of actual " << zero_name << "s";
124 record_zero
125 .name(name.str())
126 .desc(description.str())
127 ;
128 description.str("");
129 name.str("");
130
131 name << pred_name << ":" << one_name << ":updates";
132 description << "number of actual " << one_name << "s";
133 record_one
134 .name(name.str())
135 .desc(description.str())
136 ;
137 description.str("");
138 name.str("");
139 }
140
141 void SaturatingCounterPred::regFormulas()
142 {
143 using namespace Statistics;
144 stringstream name, description;
145
146 //
147 // Number of predictions
148 //
149 name << pred_name << ":predictions";
150 preds_total
151 .name(name.str())
152 .desc("total number of predictions made")
153 ;
154 preds_total = predicted_zero + predicted_one;
155 name.str("");
156
157 //
158 // Fraction of all predictions that are one or zero
159 //
160 name << pred_name << ":" << zero_name << ":pred_frac";
161 description << "fraction of all preds that were " << zero_name;
162 pred_frac_zero
163 .name(name.str())
164 .desc(description.str())
165 ;
166 pred_frac_zero = 100 * predicted_zero / preds_total;
167 description.str("");
168 name.str("");
169
170 name << pred_name << ":" << one_name << ":pred_frac";
171 description << "fraction of all preds that were " << one_name;
172 pred_frac_one
173 .name(name.str())
174 .desc(description.str())
175 ;
176 pred_frac_one = 100 * predicted_one / preds_total;
177 description.str("");
178 name.str("");
179
180
181 //
182 // Count the number of correct predictions
183 //
184 name << pred_name << ":correct_preds";
185 correct_total
186 .name(name.str())
187 .desc("total correct predictions made")
188 ;
189 correct_total = correct_pred_one + correct_pred_zero;
190 name.str("");
191
192 //
193 // Number of predictor updates
194 //
195 name << pred_name << ":updates";
196 updates_total
197 .name(name.str())
198 .desc("total number of updates")
199 ;
200 updates_total = record_zero + record_one;
201 name.str("");
202
203 //
204 // Prediction accuracy rates
205 //
206 name << pred_name << ":pred_rate";
207 pred_rate
208 .name(name.str())
209 .desc("correct fraction of all preds")
210 ;
211 pred_rate = correct_total / updates_total;
212 name.str("");
213
214 name << pred_name << ":" << zero_name << ":pred_rate";
215 description << "fraction of " << zero_name << " preds that were correct";
216 frac_correct_zero
217 .name(name.str())
218 .desc(description.str())
219 ;
220 frac_correct_zero = 100 * correct_pred_zero /
221 (correct_pred_zero + record_one - correct_pred_one);
222 description.str("");
223 name.str("");
224
225 name << pred_name << ":" << one_name << ":pred_rate";
226 description << "fraction of " << one_name << " preds that were correct";
227 frac_correct_one
228 .name(name.str())
229 .desc(description.str())
230 ;
231 frac_correct_one = 100 * correct_pred_one /
232 (correct_pred_one + record_zero - correct_pred_zero);
233 description.str("");
234 name.str("");
235
236 //
237 // Coverage
238 //
239 name << pred_name << ":" << zero_name << ":coverage";
240 description << "fraction of " << zero_name
241 << "s that were predicted correctly";
242 coverage_zero
243 .name(name.str())
244 .desc(description.str())
245 ;
246 coverage_zero = 100 * correct_pred_zero / record_zero;
247 description.str("");
248 name.str("");
249
250 name << pred_name << ":" << one_name << ":coverage";
251 description << "fraction of " << one_name
252 << "s that were predicted correctly";
253 coverage_one
254 .name(name.str())
255 .desc(description.str())
256 ;
257 coverage_one = 100 * correct_pred_one / record_one;
258 description.str("");
259 name.str("");
260 }
261
262
263
264
265
266
267
268
269
270