gem5 v24.0.0.0
Loading...
Searching...
No Matches
ras.hh
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-2005 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
41#ifndef __CPU_PRED_RAS_HH__
42#define __CPU_PRED_RAS_HH__
43
44#include <vector>
45
47#include "base/statistics.hh"
48#include "base/types.hh"
50#include "cpu/static_inst.hh"
51#include "params/ReturnAddrStack.hh"
52#include "sim/sim_object.hh"
53
54namespace gem5
55{
56
57namespace branch_prediction
58{
59
62{
63 public:
64
68 {
69 public:
71 : parent(_parent)
72 {}
73
74
78 void init(unsigned numEntries);
79
80 void reset();
81
83 const PCStateBase *top();
84
86 unsigned topIdx() { return tos; }
87
89 void push(const PCStateBase &return_addr);
90
92 void pop();
93
99 void restore(unsigned top_of_stack, const PCStateBase *restored);
100
101 bool empty() { return usedEntries == 0; }
102
103 bool full() { return usedEntries >= numEntries; }
104
106 std::string toString(int n);
107
109 inline void
111 {
112 if (++tos == numEntries)
113 tos = 0;
114 }
115
117 inline void
119 {
120 tos = (tos == 0 ? numEntries - 1 : tos - 1);
121 }
122
125
127 unsigned numEntries;
128
130 unsigned usedEntries;
131
133 unsigned tos;
134
135 protected:
137 };
138
139
140
141 public:
142 // typedef RASParams Params;
143 typedef ReturnAddrStackParams Params;
144
145 // ReturnAddrStack(BPredUnit &_parent, const RASParams);
146 ReturnAddrStack(const Params &p);
147
148 void reset();
149
156 void push(ThreadID tid, const PCStateBase &pc, void * &ras_history);
157
164 const PCStateBase* pop(ThreadID tid, void * &ras_history);
165
171 void squash(ThreadID tid, void * &ras_history);
172
179 void commit(ThreadID tid, bool misp,
180 const BranchType brType, void * &ras_history);
181
182 private:
183
185 {
186 public:
187 /* Was the RAS pushed or poped for this branch. */
188 bool pushed = false;
189 bool poped = false;
190 /* Was it a call */
191 bool wasReturn = false;
192 bool wasCall = false;
194 std::unique_ptr<PCStateBase> ras_entry;
196 unsigned tos = 0;
197 };
198
199 void makeRASHistory(void* &ras_history);
200
203
205 unsigned numEntries;
207 unsigned numThreads;
208
219};
220
221} // namespace branch_prediction
222} // namespace gem5
223
224#endif // __CPU_PRED_RAS_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Abstract superclass for simulation objects.
Subclass that implements the actual address stack.
Definition ras.hh:68
void decrTos()
Decrements the top of stack index.
Definition ras.hh:118
const PCStateBase * top()
Returns the top address on the RAS.
Definition ras.cc:73
unsigned topIdx()
Returns the index of the top of the RAS.
Definition ras.hh:86
void pop()
Pops the top address from the RAS.
Definition ras.cc:93
std::string toString(int n)
Returns the top n entries of the stack as string.
Definition ras.cc:116
unsigned usedEntries
The number of used entries in the RAS.
Definition ras.hh:130
unsigned numEntries
The number of entries in the RAS.
Definition ras.hh:127
unsigned tos
The top of stack index.
Definition ras.hh:133
void push(const PCStateBase &return_addr)
Pushes an address onto the RAS.
Definition ras.cc:80
std::vector< std::unique_ptr< PCStateBase > > addrStack
The Stack itself.
Definition ras.hh:124
void restore(unsigned top_of_stack, const PCStateBase *restored)
Changes index to the top of the RAS, and replaces the top address with a new target.
Definition ras.cc:103
void incrTos()
Increments the top of stack index.
Definition ras.hh:110
std::unique_ptr< PCStateBase > ras_entry
The entry that poped from the RAS (only valid if a return).
Definition ras.hh:194
unsigned tos
The RAS index (top of stack pointer) of the instruction.
Definition ras.hh:196
Return address stack class, implements a simple RAS.
Definition ras.hh:62
unsigned numThreads
The number of threads.
Definition ras.hh:207
const PCStateBase * pop(ThreadID tid, void *&ras_history)
Pops the top address from the RAS.
Definition ras.cc:188
void makeRASHistory(void *&ras_history)
Definition ras.cc:157
ReturnAddrStackParams Params
Definition ras.hh:143
std::vector< AddrStack > addrStacks
The RAS itself.
Definition ras.hh:202
void squash(ThreadID tid, void *&ras_history)
The branch (call/return) got squashed.
Definition ras.cc:216
gem5::branch_prediction::ReturnAddrStack::ReturnAddrStackStats stats
unsigned numEntries
The number of entries in the RAS.
Definition ras.hh:205
void commit(ThreadID tid, bool misp, const BranchType brType, void *&ras_history)
A branch got finally got finally commited.
Definition ras.cc:251
void push(ThreadID tid, const PCStateBase &pc, void *&ras_history)
Pushes an address onto the RAS.
Definition ras.cc:166
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL vector class.
Definition stl.hh:37
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition sim_object.cc:73
Bitfield< 31 > n
Bitfield< 4 > pc
Bitfield< 0 > p
enums::BranchType BranchType
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
Declaration of Statistics objects.

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0