gem5  v22.0.0.1
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 #include "config/the_isa.hh"
36 
37 namespace gem5
38 {
39 
40 namespace branch_prediction
41 {
42 
44 {
45  private:
46  struct BTBEntry
47  {
49  Addr tag = 0;
50 
52  std::unique_ptr<PCStateBase> target;
53 
56 
58  bool valid = false;
59  };
60 
61  public:
68  DefaultBTB(unsigned numEntries, unsigned tagBits,
69  unsigned instShiftAmt, unsigned numThreads);
70 
71  void reset();
72 
78  const PCStateBase *lookup(Addr instPC, ThreadID tid);
79 
85  bool valid(Addr instPC, ThreadID tid);
86 
92  void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid);
93 
94  private:
99  inline unsigned getIndex(Addr instPC, ThreadID tid);
100 
105  inline Addr getTag(Addr instPC);
106 
109 
111  unsigned numEntries;
112 
114  unsigned idxMask;
115 
117  unsigned tagBits;
118 
120  unsigned tagMask;
121 
123  unsigned instShiftAmt;
124 
126  unsigned tagShiftAmt;
127 
129  unsigned log2NumThreads;
130 };
131 
132 } // namespace branch_prediction
133 } // namespace gem5
134 
135 #endif // __CPU_PRED_BTB_HH__
gem5::branch_prediction::DefaultBTB
Definition: btb.hh:43
gem5::branch_prediction::DefaultBTB::lookup
const PCStateBase * lookup(Addr instPC, ThreadID tid)
Looks up an address in the BTB.
Definition: btb.cc:116
gem5::branch_prediction::DefaultBTB::BTBEntry::valid
bool valid
Whether or not the entry is valid.
Definition: btb.hh:58
gem5::branch_prediction::DefaultBTB::BTBEntry::tag
Addr tag
The entry's tag.
Definition: btb.hh:49
gem5::branch_prediction::DefaultBTB::BTBEntry::tid
ThreadID tid
The entry's thread id.
Definition: btb.hh:55
gem5::branch_prediction::DefaultBTB::tagBits
unsigned tagBits
The number of tag bits per entry.
Definition: btb.hh:117
std::vector
STL vector class.
Definition: stl.hh:37
gem5::branch_prediction::DefaultBTB::tagMask
unsigned tagMask
The tag mask.
Definition: btb.hh:120
gem5::branch_prediction::DefaultBTB::instShiftAmt
unsigned instShiftAmt
Number of bits to shift PC when calculating index.
Definition: btb.hh:123
gem5::branch_prediction::DefaultBTB::DefaultBTB
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
gem5::branch_prediction::DefaultBTB::BTBEntry
Definition: btb.hh:46
gem5::branch_prediction::DefaultBTB::log2NumThreads
unsigned log2NumThreads
Log2 NumThreads used for hashing threadid.
Definition: btb.hh:129
gem5::branch_prediction::DefaultBTB::reset
void reset()
Definition: btb.cc:70
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::branch_prediction::DefaultBTB::getTag
Addr getTag(Addr instPC)
Returns the tag bits of a given address.
Definition: btb.cc:89
pcstate.hh
types.hh
gem5::branch_prediction::DefaultBTB::getIndex
unsigned getIndex(Addr instPC, ThreadID tid)
Returns the index into the BTB, based on the branch's PC.
Definition: btb.cc:79
gem5::branch_prediction::DefaultBTB::BTBEntry::target
std::unique_ptr< PCStateBase > target
The entry's target.
Definition: btb.hh:52
logging.hh
gem5::PCStateBase
Definition: pcstate.hh:57
gem5::branch_prediction::DefaultBTB::numEntries
unsigned numEntries
The number of entries in the BTB.
Definition: btb.hh:111
gem5::branch_prediction::DefaultBTB::btb
std::vector< BTBEntry > btb
The actual BTB.
Definition: btb.hh:108
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::branch_prediction::DefaultBTB::tagShiftAmt
unsigned tagShiftAmt
Number of bits to shift PC when calculating tag.
Definition: btb.hh:126
gem5::branch_prediction::DefaultBTB::valid
bool valid(Addr instPC, ThreadID tid)
Checks if a branch is in the BTB.
Definition: btb.cc:95
gem5::branch_prediction::DefaultBTB::update
void update(Addr inst_pc, const PCStateBase &target_pc, ThreadID tid)
Updates the BTB with the target of a branch.
Definition: btb.cc:134
gem5::ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:235
gem5::branch_prediction::DefaultBTB::idxMask
unsigned idxMask
The index mask.
Definition: btb.hh:114

Generated on Sat Jun 18 2022 08:12:21 for gem5 by doxygen 1.8.17