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