gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
2bit_local.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023 The University of Edinburgh
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
42
43#include "base/intmath.hh"
44#include "base/logging.hh"
45#include "base/trace.hh"
46#include "debug/Fetch.hh"
47
48namespace gem5
49{
50
52{
53
54LocalBP::LocalBP(const LocalBPParams &params)
61{
63 fatal("Invalid local predictor size!\n");
64 }
65
67 fatal("Invalid number of local predictor sets! Check localCtrBits.\n");
68 }
69
70 DPRINTF(Fetch, "index mask: %#x\n", indexMask);
71
72 DPRINTF(Fetch, "local predictor size: %i\n",
74
75 DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits);
76
77 DPRINTF(Fetch, "instruction shift amount: %i\n",
79}
80
81void
82LocalBP::updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken,
83 Addr target, const StaticInstPtr &inst,
84 void * &bp_history)
85{
86// Place holder for a function that is called to update predictor history
87}
88
89
90bool
91LocalBP::lookup(ThreadID tid, Addr branch_addr, void * &bp_history)
92{
93 bool taken;
94 unsigned local_predictor_idx = getLocalIndex(branch_addr);
95
96 DPRINTF(Fetch, "Looking up index %#x\n",
97 local_predictor_idx);
98
99 uint8_t counter_val = localCtrs[local_predictor_idx];
100
101 DPRINTF(Fetch, "prediction is %i.\n",
102 (int)counter_val);
103
104 taken = getPrediction(counter_val);
105
106 return taken;
107}
108
109void
110LocalBP::update(ThreadID tid, Addr branch_addr, bool taken, void *&bp_history,
111 bool squashed, const StaticInstPtr & inst, Addr target)
112{
113 assert(bp_history == NULL);
114 unsigned local_predictor_idx;
115
116 // No state to restore, and we do not update on the wrong
117 // path.
118 if (squashed) {
119 return;
120 }
121
122 // Update the local predictor.
123 local_predictor_idx = getLocalIndex(branch_addr);
124
125 DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx);
126
127 if (taken) {
128 DPRINTF(Fetch, "Branch updated as taken.\n");
129 localCtrs[local_predictor_idx]++;
130 } else {
131 DPRINTF(Fetch, "Branch updated as not taken.\n");
132 localCtrs[local_predictor_idx]--;
133 }
134}
135
136inline
137bool
139{
140 // Get the MSB of the count
141 return (count >> (localCtrBits - 1));
142}
143
144inline
145unsigned
147{
148 return (branch_addr >> instShiftAmt) & indexMask;
149}
150
151
152} // namespace branch_prediction
153} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
BPredUnit(const Params &p)
Branch Predictor Unit (BPU) interface functions.
Definition bpred_unit.cc:58
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
const unsigned localPredictorSize
Size of the local predictor.
bool getPrediction(uint8_t &count)
Returns the taken/not taken prediction given the value of the counter.
void updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken, Addr target, const StaticInstPtr &inst, void *&bp_history) override
Ones done with the prediction this function updates the path and global history.
Definition 2bit_local.cc:82
const unsigned localCtrBits
Number of bits of the local predictor's counters.
const unsigned localPredictorSets
Number of sets.
void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target) override
Updates the BP with taken/not taken information.
LocalBP(const LocalBPParams &params)
Default branch predictor constructor.
Definition 2bit_local.cc:54
bool lookup(ThreadID tid, Addr pc, void *&bp_history) override
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
Definition 2bit_local.cc:91
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:232
GenericSatCounter< uint8_t > SatCounter8
const Params & params() const
Bitfield< 4 > pc
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
RefCountingPtr< StaticInst > StaticInstPtr

Generated on Mon May 26 2025 09:19:08 for gem5 by doxygen 1.13.2