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

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13