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