2 * Copyright (c) 2001-2004 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 "base/sat_counter.hh"
44 #include "base/statistics.hh"
46 class HybridPredictor : public GenericPredictor
49 std::string pred_name;
51 std::string zero_name;
52 bool reg_individual_stats;
54 SaturatingCounterPred *local;
55 SaturatingCounterPred *global;
57 unsigned long max_index;
62 Stats::Scalar<> pred_one; //num_one_preds
63 Stats::Scalar<> pred_zero; //num_zero_preds
64 Stats::Scalar<> correct_pred_one; //num_one_correct
65 Stats::Scalar<> correct_pred_zero; //num_zero_correct
66 Stats::Scalar<> record_one; //num_one_updates
67 Stats::Scalar<> record_zero; //num_zero_updates
69 Stats::Formula total_preds;
70 Stats::Formula frac_preds_zero;
71 Stats::Formula frac_preds_one;
72 Stats::Formula total_correct;
73 Stats::Formula total_accuracy;
74 Stats::Formula zero_accuracy;
75 Stats::Formula one_accuracy;
76 Stats::Formula zero_coverage;
77 Stats::Formula one_coverage;
80 HybridPredictor(const char *_p_name, const char *_z_name,
82 unsigned _index_bits, unsigned _counter_bits,
83 unsigned _zero_change, unsigned _one_change,
85 unsigned _global_bits, unsigned _global_thresh,
86 bool _reg_individual_stats = false);
93 unsigned peek(unsigned long _index) {
94 unsigned l = local->peek(_index);
95 unsigned g = global->peek(_index);
103 unsigned value(unsigned long _index) {
104 unsigned l = local->peek(_index);
105 unsigned g = global->peek(_index);
110 return (l << 16) | g;
114 unsigned predict(unsigned long _index) {
115 unsigned l = local->predict(_index);
116 unsigned g = global->predict(_index);
129 // This version need only be used if local/global statistics
130 // will be maintained
132 unsigned predict(unsigned long _index, unsigned &_pdata) {
133 unsigned l = local->predict(_index);
134 unsigned g = global->predict(_index);
137 // bit 0 => local predictor result
138 // bit 1 => global predictor result
154 void record(unsigned long _index, unsigned _val, unsigned _predicted) {
157 local->record(_index, _val, 0);
158 global->record(_index, _val, 0);
161 if (_val == _predicted) {
165 local->record(_index, _val, 0);
166 global->record(_index, _val, 0);
169 if (_val == _predicted)
174 void record(unsigned long _index, unsigned _val, unsigned _predicted,
178 local->record(_index, _val, (_pdata & 1));
179 global->record(_index, _val, ((_pdata & 2) ? 1 : 0));
185 if (_val == _predicted)
190 if (_val == _predicted)
200 #endif // _HYBRID_PRED_HH__