gem5 v23.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
30
31#include "base/intmath.hh"
32#include "base/logging.hh"
33#include "base/trace.hh"
34#include "debug/Fetch.hh"
35
36namespace gem5
37{
38
39namespace branch_prediction
40{
41
42LocalBP::LocalBP(const LocalBPParams &params)
43 : BPredUnit(params),
44 localPredictorSize(params.localPredictorSize),
45 localCtrBits(params.localCtrBits),
46 localPredictorSets(localPredictorSize / localCtrBits),
47 localCtrs(localPredictorSets, SatCounter8(localCtrBits)),
48 indexMask(localPredictorSets - 1)
49{
51 fatal("Invalid local predictor size!\n");
52 }
53
55 fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
56 }
57
58 DPRINTF(Fetch, "index mask: %#x\n", indexMask);
59
60 DPRINTF(Fetch, "local predictor size: %i\n",
62
63 DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
64
65 DPRINTF(Fetch, "instruction shift amount: %i\n",
67}
68
69void
70LocalBP::btbUpdate(ThreadID tid, Addr branch_addr, void * &bp_history)
71{
72// Place holder for a function that is called to update predictor history when
73// a BTB entry is invalid or not found.
74}
75
76
77bool
78LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
79{
80 bool taken;
81 unsigned local_predictor_idx = getLocalIndex(branch_addr);
82
83 DPRINTF(Fetch, "Looking up index %#x\n",
84 local_predictor_idx);
85
86 uint8_t counter_val = localCtrs[local_predictor_idx];
87
88 DPRINTF(Fetch, "prediction is %i.\n",
89 (int)counter_val);
90
91 taken = getPrediction(counter_val);
92
93 return taken;
94}
95
96void
97LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history,
98 bool squashed, const StaticInstPtr & inst, Addr corrTarget)
99{
100 assert(bp_history == NULL);
101 unsigned local_predictor_idx;
102
103 // No state to restore, and we do not update on the wrong
104 // path.
105 if (squashed) {
106 return;
107 }
108
109 // Update the local predictor.
110 local_predictor_idx = getLocalIndex(branch_addr);
111
112 DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
113
114 if (taken) {
115 DPRINTF(Fetch, "Branch updated as taken.\n");
116 localCtrs[local_predictor_idx]++;
117 } else {
118 DPRINTF(Fetch, "Branch updated as not taken.\n");
119 localCtrs[local_predictor_idx]--;
120 }
121}
122
123inline
124bool
126{
127 // Get the MSB of the count
128 return (count >> (localCtrBits - 1));
129}
130
131inline
132unsigned
134{
135 return (branch_addr >> instShiftAmt) & indexMask;
136}
137
138void
139LocalBP::uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
140{
141}
142
143} // namespace branch_prediction
144} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition bpred_unit.hh:69
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
virtual void uncondBranch(ThreadID tid, Addr pc, void *&bp_history)
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:97
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:78
const unsigned localPredictorSize
Size of the local predictor.
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:70
bool getPrediction(uint8_t &count)
Returns the taken/not taken prediction given the value of the counter.
const unsigned localCtrBits
Number of bits of the local predictor's counters.
const unsigned localPredictorSets
Number of sets.
LocalBP(const LocalBPParams &params)
Default branch predictor constructor.
Definition 2bit_local.cc:42
const unsigned indexMask
Mask to get index bits.
std::vector< SatCounter8 > localCtrs
Array of counters that make up the local predictor.
unsigned getLocalIndex(Addr &PC)
Calculates the local index based on the PC.
static constexpr bool isPowerOf2(const T &n)
Definition intmath.hh:98
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Bitfield< 4 > pc
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

Generated on Mon Jul 10 2023 14:24:29 for gem5 by doxygen 1.9.7