misc: Updated the RELEASE-NOTES and version number
[gem5.git] / src / cpu / pred / btb.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
29 #ifndef __CPU_PRED_BTB_HH__
30 #define __CPU_PRED_BTB_HH__
31
32 #include "arch/types.hh"
33 #include "base/logging.hh"
34 #include "base/types.hh"
35 #include "config/the_isa.hh"
36
37 class DefaultBTB
38 {
39 private:
40 struct BTBEntry
41 {
42 BTBEntry()
43 : tag(0), target(0), valid(false)
44 {}
45
46 /** The entry's tag. */
47 Addr tag;
48
49 /** The entry's target. */
50 TheISA::PCState target;
51
52 /** The entry's thread id. */
53 ThreadID tid;
54
55 /** Whether or not the entry is valid. */
56 bool valid;
57 };
58
59 public:
60 /** Creates a BTB with the given number of entries, number of bits per
61 * tag, and instruction offset amount.
62 * @param numEntries Number of entries for the BTB.
63 * @param tagBits Number of bits for each tag in the BTB.
64 * @param instShiftAmt Offset amount for instructions to ignore alignment.
65 */
66 DefaultBTB(unsigned numEntries, unsigned tagBits,
67 unsigned instShiftAmt, unsigned numThreads);
68
69 void reset();
70
71 /** Looks up an address in the BTB. Must call valid() first on the address.
72 * @param inst_PC The address of the branch to look up.
73 * @param tid The thread id.
74 * @return Returns the target of the branch.
75 */
76 TheISA::PCState lookup(Addr instPC, ThreadID tid);
77
78 /** Checks if a branch is in the BTB.
79 * @param inst_PC The address of the branch to look up.
80 * @param tid The thread id.
81 * @return Whether or not the branch exists in the BTB.
82 */
83 bool valid(Addr instPC, ThreadID tid);
84
85 /** Updates the BTB with the target of a branch.
86 * @param inst_PC The address of the branch being updated.
87 * @param target_PC The target address of the branch.
88 * @param tid The thread id.
89 */
90 void update(Addr instPC, const TheISA::PCState &targetPC,
91 ThreadID tid);
92
93 private:
94 /** Returns the index into the BTB, based on the branch's PC.
95 * @param inst_PC The branch to look up.
96 * @return Returns the index into the BTB.
97 */
98 inline unsigned getIndex(Addr instPC, ThreadID tid);
99
100 /** Returns the tag bits of a given address.
101 * @param inst_PC The branch's address.
102 * @return Returns the tag bits.
103 */
104 inline Addr getTag(Addr instPC);
105
106 /** The actual BTB. */
107 std::vector<BTBEntry> btb;
108
109 /** The number of entries in the BTB. */
110 unsigned numEntries;
111
112 /** The index mask. */
113 unsigned idxMask;
114
115 /** The number of tag bits per entry. */
116 unsigned tagBits;
117
118 /** The tag mask. */
119 unsigned tagMask;
120
121 /** Number of bits to shift PC when calculating index. */
122 unsigned instShiftAmt;
123
124 /** Number of bits to shift PC when calculating tag. */
125 unsigned tagShiftAmt;
126
127 /** Log2 NumThreads used for hashing threadid */
128 unsigned log2NumThreads;
129 };
130
131 #endif // __CPU_PRED_BTB_HH__