43#ifndef __CPU_PRED_BTB_ENTRY_HH__
44#define __CPU_PRED_BTB_ENTRY_HH__
54#include "params/BTBIndexingPolicy.hh"
55#include "params/BTBSetAssociative.hh"
67 using Params = BTBIndexingPolicyParams;
81 tagMask(
mask(
p.tag_bits))
83 setNumThreads(
p.numThreads);
93 return ((key.
address >> setShift)
94 ^ (key.
tid << (tagShift - setShift - log2NumThreads)))
105 auto set_idx = extractSet(key);
107 assert(set_idx < sets.size());
109 return sets[set_idx];
118 log2NumThreads =
log2i(num_threads);
127 return (
addr >> tagShift) & tagMask;
133 panic(
"Not implemented!");
142namespace branch_prediction
154 : inst(nullptr), extractTag(
ext), valid(false), tag({
MaxAddr, -1})
164 set(target, _target);
174 return isValid() && (tag.address == extractTag(key.
address))
175 && (tag.tid == key.
tid);
238 return csprintf(
"tag: %#x tid: %d valid: %d | %s", tag.address, tag.tid,
283 return [ip] (
Addr addr) {
return ip->extractTag(
addr); };
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
std::vector< ReplaceableEntry * > getPossibleEntries(const KeyType &key) const override
Find all possible entries for insertion and replacement of an address.
uint32_t extractSet(const KeyType &key) const
Extract the set index for the instruction PC based on tid.
Addr extractTag(const Addr addr) const override
Generate the tag from the given address.
BTBSetAssociative(const Params &p)
Addr regenerateAddr(const KeyType &key, const ReplaceableEntry *entry) const override
PARAMS(BTBSetAssociative)
void setNumThreads(unsigned num_threads)
Set number of threads sharing the BTB.
BTBIndexingPolicyParams Params
A common base class for indexing table locations.
typename Types::Params Params
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
virtual std::string print() const
Prints relevant information about this entry.
KeyType getTag() const
Get tag associated to this block.
StaticInstPtr inst
Pointer to the static branch inst at this address.
std::function< Addr(Addr)> TagExtractor
BTBEntry & operator=(const BTBEntry &other)
Assignment operator.
TagExtractor extractTag
Callback used to extract the tag from the entry.
KeyType tag
The entry's tag.
void insert(const KeyType &key)
Insert the block by assigning it a tag and marking it valid.
BTBEntry(TagExtractor ext)
Default constructor.
std::string print() const override
Prints relevant information about this entry.
void setTag(KeyType _tag)
Set tag associated to this block.
bool isValid() const
Checks if the entry is valid.
std::unique_ptr< PCStateBase > target
The entry's target.
void setValid()
Set valid bit.
void update(const PCStateBase &_target, StaticInstPtr _inst)
Update the target and instruction in the BTB entry.
void invalidate()
Invalidate the block.
bool match(const KeyType &key) const
Checks if the given tag information corresponds to this entry's.
BTBEntry(const BTBEntry &other)
Copy constructor.
static constexpr int log2i(int value)
Calculate the log2 of a power of 2 integer.
#define panic(...)
This implements a cprintf based panic() function.
Copyright (c) 2024 Arm Limited All rights reserved.
int16_t ThreadID
Thread index/ID type.
IndexingPolicyTemplate< BTBTagType > BTBIndexingPolicy
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
static constexpr auto genTagExtractor(BTBIndexingPolicy *ip)
This helper generates a tag extractor function object which will be typically used by Replaceable ent...
std::string csprintf(const char *format, const Args &...args)