gem5  v22.1.0.0
btb.hh
Go to the documentation of this file.
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/generic/pcstate.hh"
33 #include "base/logging.hh"
34 #include "base/types.hh"
35 
36 namespace gem5
37 {
38 
39 namespace branch_prediction
40 {
41 
43 {
44  private:
45  struct BTBEntry
46  {
48  Addr tag = 0;
49 
51  std::unique_ptr<PCStateBase> target;
52 
55 
57  bool valid = false;
58  };
59 
60  public:
67  DefaultBTB(unsigned numEntries, unsigned tagBits,
68  unsigned instShiftAmt, unsigned numThreads);
69 
70  void reset();
71 
77  const PCStateBase *lookup(Addr instPC, ThreadID tid);
78 
84  bool valid(Addr instPC, ThreadID tid);
85 
91  void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid);
92 
93  private:
98  inline unsigned getIndex(Addr instPC, ThreadID tid);
99 
104  inline Addr getTag(Addr instPC);
105 
108 
110  unsigned numEntries;
111 
113  unsigned idxMask;
114 
116  unsigned tagBits;
117 
119  unsigned tagMask;
120 
122  unsigned instShiftAmt;
123 
125  unsigned tagShiftAmt;
126 
128  unsigned log2NumThreads;
129 };
130 
131 } // namespace branch_prediction
132 } // namespace gem5
133 
134 #endif // __CPU_PRED_BTB_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:95
Addr getTag(Addr instPC)
Returns the tag bits of a given address.
Definition: btb.cc:89
std::vector< BTBEntry > btb
The actual BTB.
Definition: btb.hh:107
unsigned tagBits
The number of tag bits per entry.
Definition: btb.hh:116
unsigned instShiftAmt
Number of bits to shift PC when calculating index.
Definition: btb.hh:122
void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:134
unsigned log2NumThreads
Log2 NumThreads used for hashing threadid.
Definition: btb.hh:128
unsigned idxMask
The index mask.
Definition: btb.hh:113
unsigned tagShiftAmt
Number of bits to shift PC when calculating tag.
Definition: btb.hh:125
const PCStateBase * lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:116
unsigned numEntries
The number of entries in the BTB.
Definition: btb.hh:110
unsigned getIndex(Addr instPC, ThreadID tid)
Returns the index into the BTB, based on the branch's PC.
Definition: btb.cc:79
unsigned tagMask
The tag mask.
Definition: btb.hh:119
DefaultBTB(unsigned numEntries, unsigned tagBits, unsigned instShiftAmt, unsigned numThreads)
Creates a BTB with the given number of entries, number of bits per tag, and instruction offset amount...
Definition: btb.cc:41
STL vector class.
Definition: stl.hh:37
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:235
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
ThreadID tid
The entry's thread id.
Definition: btb.hh:54
bool valid
Whether or not the entry is valid.
Definition: btb.hh:57
std::unique_ptr< PCStateBase > target
The entry's target.
Definition: btb.hh:51

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1