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.
29 //==========================================================================
31 // This predictor takes the AND of a "local" and a "global" predictor
32 // in order to determine its prediction.
38 #ifndef __HYBRID_PRED_HH__
39 #define __HYBRID_PRED_HH__
43 #include "sat_counter.hh"
45 #include "statistics.hh"
46 #include "sim_stats.hh"
48 class HybridPredictor : public GenericPredictor
51 std::string pred_name;
53 std::string zero_name;
54 bool reg_individual_stats;
56 SaturatingCounterPred *local;
57 SaturatingCounterPred *global;
59 unsigned long max_index;
64 Statistics::Scalar<> pred_one; //num_one_preds
65 Statistics::Scalar<> pred_zero; //num_zero_preds
66 Statistics::Scalar<> correct_pred_one; //num_one_correct
67 Statistics::Scalar<> correct_pred_zero; //num_zero_correct
68 Statistics::Scalar<> record_one; //num_one_updates
69 Statistics::Scalar<> record_zero; //num_zero_updates
71 Statistics::Formula total_preds;
72 Statistics::Formula frac_preds_zero;
73 Statistics::Formula frac_preds_one;
74 Statistics::Formula total_correct;
75 Statistics::Formula total_accuracy;
76 Statistics::Formula zero_accuracy;
77 Statistics::Formula one_accuracy;
78 Statistics::Formula zero_coverage;
79 Statistics::Formula one_coverage;
82 HybridPredictor(const char *_p_name, const char *_z_name,
84 unsigned _index_bits, unsigned _counter_bits,
85 unsigned _zero_change, unsigned _one_change,
87 unsigned _global_bits, unsigned _global_thresh,
88 bool _reg_individual_stats = false);
95 unsigned peek(unsigned long _index) {
96 unsigned l = local->peek(_index);
97 unsigned g = global->peek(_index);
105 unsigned value(unsigned long _index) {
106 unsigned l = local->peek(_index);
107 unsigned g = global->peek(_index);
112 return (l << 16) | g;
116 unsigned predict(unsigned long _index) {
117 unsigned l = local->predict(_index);
118 unsigned g = global->predict(_index);
131 // This version need only be used if local/global statistics
132 // will be maintained
134 unsigned predict(unsigned long _index, unsigned &_pdata) {
135 unsigned l = local->predict(_index);
136 unsigned g = global->predict(_index);
139 // bit 0 => local predictor result
140 // bit 1 => global predictor result
156 void record(unsigned long _index, unsigned _val, unsigned _predicted) {
159 local->record(_index, _val, 0);
160 global->record(_index, _val, 0);
163 if (_val == _predicted) {
167 local->record(_index, _val, 0);
168 global->record(_index, _val, 0);
171 if (_val == _predicted)
176 void record(unsigned long _index, unsigned _val, unsigned _predicted,
180 local->record(_index, _val, (_pdata & 1));
181 global->record(_index, _val, ((_pdata & 2) ? 1 : 0));
187 if (_val == _predicted)
192 if (_val == _predicted)
202 #endif // _HYBRID_PRED_HH__