tournament.hh revision 2292
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
29#ifndef __CPU_O3_TOURNAMENT_PRED_HH__
30#define __CPU_O3_TOURNAMENT_PRED_HH__
31
32// For Addr type.
33#include "arch/isa_traits.hh"
34#include "cpu/o3/sat_counter.hh"
35#include <vector>
36
37class TournamentBP
38{
39  public:
40    /**
41     * Default branch predictor constructor.
42     */
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);
53
54    /**
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.
59     */
60    bool lookup(Addr &branch_addr);
61
62    /**
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.
66     */
67    void update(Addr &branch_addr, unsigned global_history, bool taken);
68
69    inline unsigned readGlobalHist() { return globalHistory; }
70
71  private:
72
73    inline bool getPrediction(uint8_t &count);
74
75    inline unsigned calcLocHistIdx(Addr &branch_addr);
76
77    inline void updateHistoriesTaken(unsigned local_history_idx);
78
79    inline void updateHistoriesNotTaken(unsigned local_history_idx);
80
81    /** Local counters. */
82    std::vector<SatCounter> localCtrs;
83
84    /** Size of the local predictor. */
85    unsigned localPredictorSize;
86
87    /** Number of bits of the local predictor's counters. */
88    unsigned localCtrBits;
89
90    /** Array of local history table entries. */
91    std::vector<unsigned> localHistoryTable;
92
93    /** Size of the local history table. */
94    unsigned localHistoryTableSize;
95
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?
98     */
99    unsigned localHistoryBits;
100
101    /** Mask to get the proper local history. */
102    unsigned localHistoryMask;
103
104
105    /** Array of counters that make up the global predictor. */
106    std::vector<SatCounter> globalCtrs;
107
108    /** Size of the global predictor. */
109    unsigned globalPredictorSize;
110
111    /** Number of bits of the global predictor's counters. */
112    unsigned globalCtrBits;
113
114    /** Global history register. */
115    unsigned globalHistory;
116
117    /** Number of bits for the global history. */
118    unsigned globalHistoryBits;
119
120    /** Mask to get the proper global history. */
121    unsigned globalHistoryMask;
122
123
124    /** Array of counters that make up the choice predictor. */
125    std::vector<SatCounter> choiceCtrs;
126
127    /** Size of the choice predictor (identical to the global predictor). */
128    unsigned choicePredictorSize;
129
130    /** Number of bits of the choice predictor's counters. */
131    unsigned choiceCtrBits;
132
133    /** Number of bits to shift the instruction over to get rid of the word
134     *  offset.
135     */
136    unsigned instShiftAmt;
137
138    /** Threshold for the counter value; above the threshold is taken,
139     *  equal to or below the threshold is not taken.
140     */
141    unsigned threshold;
142};
143
144#endif // __CPU_O3_TOURNAMENT_PRED_HH__
145