Merge ktlim@zizzer:/bk/newmem
[gem5.git] / src / cpu / o3 / tournament_pred.hh
1 /*
2 * Copyright (c) 2004-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: Kevin Lim
29 */
30
31 #ifndef __CPU_O3_TOURNAMENT_PRED_HH__
32 #define __CPU_O3_TOURNAMENT_PRED_HH__
33
34 // For Addr type.
35 #include "arch/isa_traits.hh"
36 #include "cpu/o3/sat_counter.hh"
37 #include <vector>
38
39 class TournamentBP
40 {
41 public:
42 /**
43 * Default branch predictor constructor.
44 */
45 TournamentBP(unsigned localPredictorSize,
46 unsigned localCtrBits,
47 unsigned localHistoryTableSize,
48 unsigned localHistoryBits,
49 unsigned globalPredictorSize,
50 unsigned globalHistoryBits,
51 unsigned globalCtrBits,
52 unsigned choicePredictorSize,
53 unsigned choiceCtrBits,
54 unsigned instShiftAmt);
55
56 /**
57 * Looks up the given address in the branch predictor and returns
58 * a true/false value as to whether it is taken.
59 * @param branch_addr The address of the branch to look up.
60 * @return Whether or not the branch is taken.
61 */
62 bool lookup(Addr &branch_addr);
63
64 /**
65 * Updates the branch predictor with the actual result of a branch.
66 * @param branch_addr The address of the branch to update.
67 * @param taken Whether or not the branch was taken.
68 */
69 void update(Addr &branch_addr, unsigned global_history, bool taken);
70
71 inline unsigned readGlobalHist() { return globalHistory; }
72
73 private:
74
75 inline bool getPrediction(uint8_t &count);
76
77 inline unsigned calcLocHistIdx(Addr &branch_addr);
78
79 inline void updateHistoriesTaken(unsigned local_history_idx);
80
81 inline void updateHistoriesNotTaken(unsigned local_history_idx);
82
83 /** Local counters. */
84 std::vector<SatCounter> localCtrs;
85
86 /** Size of the local predictor. */
87 unsigned localPredictorSize;
88
89 /** Number of bits of the local predictor's counters. */
90 unsigned localCtrBits;
91
92 /** Array of local history table entries. */
93 std::vector<unsigned> localHistoryTable;
94
95 /** Size of the local history table. */
96 unsigned localHistoryTableSize;
97
98 /** Number of bits for each entry of the local history table.
99 * @todo Doesn't this come from the size of the local predictor?
100 */
101 unsigned localHistoryBits;
102
103 /** Mask to get the proper local history. */
104 unsigned localHistoryMask;
105
106
107 /** Array of counters that make up the global predictor. */
108 std::vector<SatCounter> globalCtrs;
109
110 /** Size of the global predictor. */
111 unsigned globalPredictorSize;
112
113 /** Number of bits of the global predictor's counters. */
114 unsigned globalCtrBits;
115
116 /** Global history register. */
117 unsigned globalHistory;
118
119 /** Number of bits for the global history. */
120 unsigned globalHistoryBits;
121
122 /** Mask to get the proper global history. */
123 unsigned globalHistoryMask;
124
125
126 /** Array of counters that make up the choice predictor. */
127 std::vector<SatCounter> choiceCtrs;
128
129 /** Size of the choice predictor (identical to the global predictor). */
130 unsigned choicePredictorSize;
131
132 /** Number of bits of the choice predictor's counters. */
133 unsigned choiceCtrBits;
134
135 /** Number of bits to shift the instruction over to get rid of the word
136 * offset.
137 */
138 unsigned instShiftAmt;
139
140 /** Threshold for the counter value; above the threshold is taken,
141 * equal to or below the threshold is not taken.
142 */
143 unsigned threshold;
144 };
145
146 #endif // __CPU_O3_TOURNAMENT_PRED_HH__