gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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/misc.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 {
44  fatal("Invalid local predictor size!\n");
45  }
46 
48 
50  fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
51  }
52 
53  // Setup the index mask.
55 
56  DPRINTF(Fetch, "index mask: %#x\n", indexMask);
57 
58  // Setup the array of counters for the local predictor.
60 
61  for (unsigned i = 0; i < localPredictorSets; ++i)
62  localCtrs[i].setBits(localCtrBits);
63 
64  DPRINTF(Fetch, "local predictor size: %i\n",
66 
67  DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
68 
69  DPRINTF(Fetch, "instruction shift amount: %i\n",
70  instShiftAmt);
71 }
72 
73 void
75 {
76  for (unsigned i = 0; i < localPredictorSets; ++i) {
77  localCtrs[i].reset();
78  }
79 }
80 
81 void
82 LocalBP::btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history)
83 {
84 // Place holder for a function that is called to update predictor history when
85 // a BTB entry is invalid or not found.
86 }
87 
88 
89 bool
90 LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
91 {
92  bool taken;
93  uint8_t counter_val;
94  unsigned local_predictor_idx = getLocalIndex(branch_addr);
95 
96  DPRINTF(Fetch, "Looking up index %#x\n",
97  local_predictor_idx);
98 
99  counter_val = localCtrs[local_predictor_idx].read();
100 
101  DPRINTF(Fetch, "prediction is %i.\n",
102  (int)counter_val);
103 
104  taken = getPrediction(counter_val);
105 
106 #if 0
107  // Speculative update.
108  if (taken) {
109  DPRINTF(Fetch, "Branch updated as taken.\n");
110  localCtrs[local_predictor_idx].increment();
111  } else {
112  DPRINTF(Fetch, "Branch updated as not taken.\n");
113  localCtrs[local_predictor_idx].decrement();
114  }
115 #endif
116 
117  return taken;
118 }
119 
120 void
121 LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
122  bool squashed)
123 {
124  assert(bp_history == NULL);
125  unsigned local_predictor_idx;
126 
127  // No state to restore, and we do not update on the wrong
128  // path.
129  if (squashed) {
130  return;
131  }
132 
133  // Update the local predictor.
134  local_predictor_idx = getLocalIndex(branch_addr);
135 
136  DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
137 
138  if (taken) {
139  DPRINTF(Fetch, "Branch updated as taken.\n");
140  localCtrs[local_predictor_idx].increment();
141  } else {
142  DPRINTF(Fetch, "Branch updated as not taken.\n");
143  localCtrs[local_predictor_idx].decrement();
144  }
145 }
146 
147 inline
148 bool
150 {
151  // Get the MSB of the count
152  return (count >> (localCtrBits - 1));
153 }
154 
155 inline
156 unsigned
158 {
159  return (branch_addr >> instShiftAmt) & indexMask;
160 }
161 
162 void
163 LocalBP::uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
164 {
165 }
166 
167 LocalBP*
168 LocalBPParams::create()
169 {
170  return new LocalBP(this);
171 }
count
Definition: misc.hh:704
#define DPRINTF(x,...)
Definition: trace.hh:212
Implements a local predictor that uses the PC to index into a table of counters.
Definition: 2bit_local.hh:61
unsigned localPredictorSize
Size of the local predictor.
Definition: 2bit_local.hh:118
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:82
Bitfield< 7 > i
Definition: miscregs.hh:1378
unsigned indexMask
Mask to get index bits.
Definition: 2bit_local.hh:127
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
Definition: 2bit_local.cc:163
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:90
unsigned getLocalIndex(Addr &PC)
Calculates the local index based on the PC.
Definition: 2bit_local.cc:157
unsigned localPredictorSets
Number of sets.
Definition: 2bit_local.hh:121
LocalBP(const LocalBPParams *params)
Default branch predictor constructor.
Definition: 2bit_local.cc:38
#define fatal(...)
Definition: misc.hh:163
bool isPowerOf2(const T &n)
Definition: intmath.hh:73
std::vector< SatCounter > localCtrs
Array of counters that make up the local predictor.
Definition: 2bit_local.hh:115
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
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:171
void reset()
Definition: 2bit_local.cc:74
unsigned localCtrBits
Number of bits of the local predictor's counters.
Definition: 2bit_local.hh:124
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:308
IntReg pc
Definition: remote_gdb.hh:91
void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, bool squashed)
Updates the branch predictor with the actual result of a branch.
Definition: 2bit_local.cc:121
bool getPrediction(uint8_t &count)
Returns the taken/not taken prediction given the value of the counter.
Definition: 2bit_local.cc:149

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6