gem5  v20.1.0.0
2bit_local.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2006 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 #include "cpu/pred/2bit_local.hh"
30 
31 #include "base/intmath.hh"
32 #include "base/logging.hh"
33 #include "base/trace.hh"
34 #include "debug/Fetch.hh"
35 
36 LocalBP::LocalBP(const LocalBPParams *params)
37  : BPredUnit(params),
38  localPredictorSize(params->localPredictorSize),
39  localCtrBits(params->localCtrBits),
40  localPredictorSets(localPredictorSize / localCtrBits),
41  localCtrs(localPredictorSets, SatCounter(localCtrBits)),
42  indexMask(localPredictorSets - 1)
43 {
45  fatal("Invalid local predictor size!\n");
46  }
47 
49  fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
50  }
51 
52  DPRINTF(Fetch, "index mask: %#x\n", indexMask);
53 
54  DPRINTF(Fetch, "local predictor size: %i\n",
56 
57  DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
58 
59  DPRINTF(Fetch, "instruction shift amount: %i\n",
60  instShiftAmt);
61 }
62 
63 void
64 LocalBP::btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history)
65 {
66 // Place holder for a function that is called to update predictor history when
67 // a BTB entry is invalid or not found.
68 }
69 
70 
71 bool
72 LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
73 {
74  bool taken;
75  unsigned local_predictor_idx = getLocalIndex(branch_addr);
76 
77  DPRINTF(Fetch, "Looking up index %#x\n",
78  local_predictor_idx);
79 
80  uint8_t counter_val = localCtrs[local_predictor_idx];
81 
82  DPRINTF(Fetch, "prediction is %i.\n",
83  (int)counter_val);
84 
85  taken = getPrediction(counter_val);
86 
87  return taken;
88 }
89 
90 void
91 LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
92  bool squashed, const StaticInstPtr & inst, Addr corrTarget)
93 {
94  assert(bp_history == NULL);
95  unsigned local_predictor_idx;
96 
97  // No state to restore, and we do not update on the wrong
98  // path.
99  if (squashed) {
100  return;
101  }
102 
103  // Update the local predictor.
104  local_predictor_idx = getLocalIndex(branch_addr);
105 
106  DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
107 
108  if (taken) {
109  DPRINTF(Fetch, "Branch updated as taken.\n");
110  localCtrs[local_predictor_idx]++;
111  } else {
112  DPRINTF(Fetch, "Branch updated as not taken.\n");
113  localCtrs[local_predictor_idx]--;
114  }
115 }
116 
117 inline
118 bool
120 {
121  // Get the MSB of the count
122  return (count >> (localCtrBits - 1));
123 }
124 
125 inline
126 unsigned
128 {
129  return (branch_addr >> instShiftAmt) & indexMask;
130 }
131 
132 void
133 LocalBP::uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
134 {
135 }
136 
137 LocalBP*
138 LocalBPParams::create()
139 {
140  return new LocalBP(this);
141 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
LocalBP::uncondBranch
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
Definition: 2bit_local.cc:133
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
LocalBP::localCtrs
std::vector< SatCounter > localCtrs
Array of counters that make up the local predictor.
Definition: 2bit_local.hh:119
LocalBP::update
void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget)
Updates the branch predictor with the actual result of a branch.
Definition: 2bit_local.cc:91
LocalBP::indexMask
const unsigned indexMask
Mask to get index bits.
Definition: 2bit_local.hh:122
2bit_local.hh
X86ISA::count
count
Definition: misc.hh:703
LocalBP::localPredictorSize
const unsigned localPredictorSize
Size of the local predictor.
Definition: 2bit_local.hh:110
BPredUnit::instShiftAmt
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:312
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
LocalBP::btbUpdate
void btbUpdate(ThreadID tid, Addr branch_addr, void *&bp_history)
Updates the branch predictor to Not Taken if a BTB entry is invalid or not found.
Definition: 2bit_local.cc:64
BPredUnit
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:62
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
LocalBP::getLocalIndex
unsigned getLocalIndex(Addr &PC)
Calculates the local index based on the PC.
Definition: 2bit_local.cc:127
LocalBP::getPrediction
bool getPrediction(uint8_t &count)
Returns the taken/not taken prediction given the value of the counter.
Definition: 2bit_local.cc:119
SatCounter
Implements an n bit saturating counter and provides methods to increment, decrement,...
Definition: sat_counter.hh:54
LocalBP::localPredictorSets
const unsigned localPredictorSets
Number of sets.
Definition: 2bit_local.hh:116
logging.hh
RefCountingPtr< StaticInst >
trace.hh
LocalBP::localCtrBits
const unsigned localCtrBits
Number of bits of the local predictor's counters.
Definition: 2bit_local.hh:113
intmath.hh
LocalBP
Implements a local predictor that uses the PC to index into a table of counters.
Definition: 2bit_local.hh:58
LocalBP::LocalBP
LocalBP(const LocalBPParams *params)
Default branch predictor constructor.
Definition: 2bit_local.cc:36
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
LocalBP::lookup
bool lookup(ThreadID tid, Addr branch_addr, void *&bp_history)
Looks up the given address in the branch predictor and returns a true/false value as to whether it is...
Definition: 2bit_local.cc:72

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17