2 * Copyright (c) 2001-2005 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.
28 * Authors: Steve Raasch
32 //==========================================================================
34 // This predictor takes the AND of a "local" and a "global" predictor
35 // in order to determine its prediction.
41 #ifndef __HYBRID_PRED_HH__
42 #define __HYBRID_PRED_HH__
46 #include "base/sat_counter.hh"
47 #include "base/statistics.hh"
49 class HybridPredictor : public GenericPredictor
52 std::string pred_name;
54 std::string zero_name;
55 bool reg_individual_stats;
57 SaturatingCounterPred *local;
58 SaturatingCounterPred *global;
60 unsigned long max_index;
65 Stats::Scalar pred_one; //num_one_preds
66 Stats::Scalar pred_zero; //num_zero_preds
67 Stats::Scalar correct_pred_one; //num_one_correct
68 Stats::Scalar correct_pred_zero; //num_zero_correct
69 Stats::Scalar record_one; //num_one_updates
70 Stats::Scalar record_zero; //num_zero_updates
72 Stats::Formula total_preds;
73 Stats::Formula frac_preds_zero;
74 Stats::Formula frac_preds_one;
75 Stats::Formula total_correct;
76 Stats::Formula total_accuracy;
77 Stats::Formula zero_accuracy;
78 Stats::Formula one_accuracy;
79 Stats::Formula zero_coverage;
80 Stats::Formula one_coverage;
83 HybridPredictor(const char *_p_name, const char *_z_name,
85 unsigned _index_bits, unsigned _counter_bits,
86 unsigned _zero_change, unsigned _one_change,
88 unsigned _global_bits, unsigned _global_thresh,
89 bool _reg_individual_stats = false);
96 unsigned peek(unsigned long _index) {
97 unsigned l = local->peek(_index);
98 unsigned g = global->peek(_index);
106 unsigned value(unsigned long _index) {
107 unsigned l = local->peek(_index);
108 unsigned g = global->peek(_index);
113 return (l << 16) | g;
117 unsigned predict(unsigned long _index) {
118 unsigned l = local->predict(_index);
119 unsigned g = global->predict(_index);
132 // This version need only be used if local/global statistics
133 // will be maintained
135 unsigned predict(unsigned long _index, unsigned &_pdata) {
136 unsigned l = local->predict(_index);
137 unsigned g = global->predict(_index);
140 // bit 0 => local predictor result
141 // bit 1 => global predictor result
157 void record(unsigned long _index, unsigned _val, unsigned _predicted) {
160 local->record(_index, _val, 0);
161 global->record(_index, _val, 0);
164 if (_val == _predicted) {
168 local->record(_index, _val, 0);
169 global->record(_index, _val, 0);
172 if (_val == _predicted)
177 void record(unsigned long _index, unsigned _val, unsigned _predicted,
181 local->record(_index, _val, (_pdata & 1));
182 global->record(_index, _val, ((_pdata & 2) ? 1 : 0));
188 if (_val == _predicted)
193 if (_val == _predicted)
203 #endif // _HYBRID_PRED_HH__