45#include "debug/RAS.hh"
50namespace branch_prediction
75 return addrStack[tos].get();
85 set(addrStack[tos], return_addr);
95 if (usedEntries > 0) {
108 set(addrStack[tos], restored);
118 std::stringstream
ss;
119 for (
int i = 0;
i <
n;
i++) {
120 int idx = int(tos)-
i;
121 if (idx < 0 || addrStack[idx] ==
nullptr) {
124 ss << std::dec << idx <<
":0x" << std::setfill(
'0') << std::setw(16)
125 << std::hex << addrStack[idx]->instAddr() <<
";";
140 DPRINTF(RAS,
"Create RAS stacks.\n");
161 history->
poped =
false;
162 ras_history =
static_cast<void*
>(history);
171 if (ras_history ==
nullptr) {
180 DPRINTF(RAS,
"%s: RAS[%i] <= %#x. Entries used: %i, tid:%i\n", __func__,
192 if (ras_history ==
nullptr) {
198 history->
poped =
true;
206 DPRINTF(RAS,
"%s: RAS[%i] => %#x. Entries used: %i, tid:%i\n", __func__,
218 if (ras_history ==
nullptr) {
231 DPRINTF(RAS,
"RAS::%s Incorrect push. Pop RAS[%i]. "
232 "Entries used: %i, tid:%i\n", __func__,
236 if (history->
poped) {
239 DPRINTF(RAS,
"RAS::%s Incorrect pop. Restore to: RAS[%i]:%#x. "
240 "Entries used: %i, tid:%i\n", __func__,
247 ras_history =
nullptr;
255 if (!(brType == BranchType::Return ||
256 brType == BranchType::CallDirect ||
257 brType == BranchType::CallIndirect)) {
259 assert(ras_history ==
nullptr);
263 DPRINTF(RAS,
"RAS::%s Commit Branch inst: %s, tid:%i\n",
267 if (ras_history ==
nullptr) {
289 if (history->
poped) {
297 DPRINTF(RAS,
"RAS::%s Commit Return PC %#x, correct:%i, tid:%i\n",
298 __func__, !misp, (history->
ras_entry.get() !=
nullptr)
299 ? history->
ras_entry->instAddr() : 0, tid);
302 ras_history =
nullptr;
309 : statistics::
Group(parent),
310 ADD_STAT(pushes, statistics::units::Count::get(),
311 "Number of times a PC was pushed onto the RAS"),
312 ADD_STAT(pops, statistics::units::Count::get(),
313 "Number of times a PC was poped from the RAS"),
314 ADD_STAT(squashes, statistics::units::Count::get(),
315 "Number of times the stack operation was squashed due to "
316 "wrong speculation."),
317 ADD_STAT(used, statistics::units::Count::get(),
318 "Number of times the RAS is the provider"),
319 ADD_STAT(correct, statistics::units::Count::get(),
320 "Number of times the RAS is the provider and the "
321 "prediction is correct"),
322 ADD_STAT(incorrect, statistics::units::Count::get(),
323 "Number of times the RAS is the provider and the "
324 "prediction is wrong")
Abstract superclass for simulation objects.
const PCStateBase * top()
Returns the top address on the RAS.
void pop()
Pops the top address from the RAS.
std::string toString(int n)
Returns the top n entries of the stack as string.
unsigned numEntries
The number of entries in the RAS.
void push(const PCStateBase &return_addr)
Pushes an address onto the RAS.
std::vector< std::unique_ptr< PCStateBase > > addrStack
The Stack itself.
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.
void init(unsigned numEntries)
Initializes RAS with a specified number of entries.
std::unique_ptr< PCStateBase > ras_entry
The entry that poped from the RAS (only valid if a return).
unsigned tos
The RAS index (top of stack pointer) of the instruction.
unsigned numThreads
The number of threads.
ReturnAddrStack(const Params &p)
const PCStateBase * pop(ThreadID tid, void *&ras_history)
Pops the top address from the RAS.
void makeRASHistory(void *&ras_history)
ReturnAddrStackParams Params
std::vector< AddrStack > addrStacks
The RAS itself.
void squash(ThreadID tid, void *&ras_history)
The branch (call/return) got squashed.
gem5::branch_prediction::ReturnAddrStack::ReturnAddrStackStats stats
unsigned numEntries
The number of entries in the RAS.
void commit(ThreadID tid, bool misp, const BranchType brType, void *&ras_history)
A branch got finally got finally commited.
void push(ThreadID tid, const PCStateBase &pc, void *&ras_history)
Pushes an address onto the RAS.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
std::string toString(BranchType type)
enums::BranchType BranchType
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
int16_t ThreadID
Thread index/ID type.
statistics::Scalar squashes
statistics::Scalar pushes
ReturnAddrStackStats(statistics::Group *parent)
statistics::Scalar incorrect
statistics::Scalar correct