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