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.
29 #ifndef __CPU_O3_TOURNAMENT_PRED_HH__
30 #define __CPU_O3_TOURNAMENT_PRED_HH__
33 #include "arch/isa_traits.hh"
34 #include "cpu/o3/sat_counter.hh"
41 * Default branch predictor constructor.
43 TournamentBP(unsigned localPredictorSize,
44 unsigned localCtrBits,
45 unsigned localHistoryTableSize,
46 unsigned localHistoryBits,
47 unsigned globalPredictorSize,
48 unsigned globalHistoryBits,
49 unsigned globalCtrBits,
50 unsigned choicePredictorSize,
51 unsigned choiceCtrBits,
52 unsigned instShiftAmt);
55 * Looks up the given address in the branch predictor and returns
56 * a true/false value as to whether it is taken.
57 * @param branch_addr The address of the branch to look up.
58 * @return Whether or not the branch is taken.
60 bool lookup(Addr &branch_addr);
63 * Updates the branch predictor with the actual result of a branch.
64 * @param branch_addr The address of the branch to update.
65 * @param taken Whether or not the branch was taken.
67 void update(Addr &branch_addr, unsigned global_history, bool taken);
69 inline unsigned readGlobalHist() { return globalHistory; }
73 inline bool getPrediction(uint8_t &count);
75 inline unsigned calcLocHistIdx(Addr &branch_addr);
77 inline void updateHistoriesTaken(unsigned local_history_idx);
79 inline void updateHistoriesNotTaken(unsigned local_history_idx);
81 /** Local counters. */
82 std::vector<SatCounter> localCtrs;
84 /** Size of the local predictor. */
85 unsigned localPredictorSize;
87 /** Number of bits of the local predictor's counters. */
88 unsigned localCtrBits;
90 /** Array of local history table entries. */
91 std::vector<unsigned> localHistoryTable;
93 /** Size of the local history table. */
94 unsigned localHistoryTableSize;
96 /** Number of bits for each entry of the local history table.
97 * @todo Doesn't this come from the size of the local predictor?
99 unsigned localHistoryBits;
101 /** Mask to get the proper local history. */
102 unsigned localHistoryMask;
105 /** Array of counters that make up the global predictor. */
106 std::vector<SatCounter> globalCtrs;
108 /** Size of the global predictor. */
109 unsigned globalPredictorSize;
111 /** Number of bits of the global predictor's counters. */
112 unsigned globalCtrBits;
114 /** Global history register. */
115 unsigned globalHistory;
117 /** Number of bits for the global history. */
118 unsigned globalHistoryBits;
120 /** Mask to get the proper global history. */
121 unsigned globalHistoryMask;
124 /** Array of counters that make up the choice predictor. */
125 std::vector<SatCounter> choiceCtrs;
127 /** Size of the choice predictor (identical to the global predictor). */
128 unsigned choicePredictorSize;
130 /** Number of bits of the choice predictor's counters. */
131 unsigned choiceCtrBits;
133 /** Number of bits to shift the instruction over to get rid of the word
136 unsigned instShiftAmt;
138 /** Threshold for the counter value; above the threshold is taken,
139 * equal to or below the threshold is not taken.
144 #endif // __CPU_O3_TOURNAMENT_PRED_HH__