2 * Copyright (c) 2004-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.
31 #ifndef __CPU_O3_TOURNAMENT_PRED_HH__
32 #define __CPU_O3_TOURNAMENT_PRED_HH__
35 #include "arch/isa_traits.hh"
36 #include "cpu/o3/sat_counter.hh"
43 * Default branch predictor constructor.
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);
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.
62 bool lookup(Addr &branch_addr);
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.
69 void update(Addr &branch_addr, unsigned global_history, bool taken);
71 inline unsigned readGlobalHist() { return globalHistory; }
75 inline bool getPrediction(uint8_t &count);
77 inline unsigned calcLocHistIdx(Addr &branch_addr);
79 inline void updateHistoriesTaken(unsigned local_history_idx);
81 inline void updateHistoriesNotTaken(unsigned local_history_idx);
83 /** Local counters. */
84 std::vector<SatCounter> localCtrs;
86 /** Size of the local predictor. */
87 unsigned localPredictorSize;
89 /** Number of bits of the local predictor's counters. */
90 unsigned localCtrBits;
92 /** Array of local history table entries. */
93 std::vector<unsigned> localHistoryTable;
95 /** Size of the local history table. */
96 unsigned localHistoryTableSize;
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?
101 unsigned localHistoryBits;
103 /** Mask to get the proper local history. */
104 unsigned localHistoryMask;
107 /** Array of counters that make up the global predictor. */
108 std::vector<SatCounter> globalCtrs;
110 /** Size of the global predictor. */
111 unsigned globalPredictorSize;
113 /** Number of bits of the global predictor's counters. */
114 unsigned globalCtrBits;
116 /** Global history register. */
117 unsigned globalHistory;
119 /** Number of bits for the global history. */
120 unsigned globalHistoryBits;
122 /** Mask to get the proper global history. */
123 unsigned globalHistoryMask;
126 /** Array of counters that make up the choice predictor. */
127 std::vector<SatCounter> choiceCtrs;
129 /** Size of the choice predictor (identical to the global predictor). */
130 unsigned choicePredictorSize;
132 /** Number of bits of the choice predictor's counters. */
133 unsigned choiceCtrBits;
135 /** Number of bits to shift the instruction over to get rid of the word
138 unsigned instShiftAmt;
140 /** Threshold for the counter value; above the threshold is taken,
141 * equal to or below the threshold is not taken.
146 #endif // __CPU_O3_TOURNAMENT_PRED_HH__