42#ifndef __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
43#define __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
60template <
typename Entry>
65 static_assert(std::is_base_of_v<ReplaceableEntry, Entry>,
66 "Entry should be derived from ReplaceableEntry");
84 const ::gem5::debug::SimpleFlag*
debugFlag =
nullptr;
91 fatal_if((_num_entries % _assoc) != 0,
"The number of entries of an "
92 "AssociativeCache<> must be a multiple of its associativity");
93 for (
auto entry_idx = 0; entry_idx < _num_entries; entry_idx++) {
94 Entry *entry = &
entries[entry_idx];
117 const size_t associativity_,
120 Entry
const &init_val = Entry())
125 entries(num_entries, init_val),
155 const size_t associativity_,
158 Entry
const &init_val = Entry())
163 entries.resize(num_entries, init_val);
213 for (
auto candidate : candidates) {
214 Entry *entry =
static_cast<Entry*
>(candidate);
215 if (entry->match(key)) {
238 "Replacing entry: %s\n", victim->print());
269 "Inserting entry: %s\n", entry->print());
290 std::transform(selected_entries.begin(), selected_entries.end(),
291 std::back_inserter(
entries), [](
auto &entry) {
292 return static_cast<Entry *>(entry);
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
void clear()
Clear the entries in the cache.
AssociativeCache(const char *name)
Empty constructor - need to call init() later with all args.
replacement_policy::Base BaseReplacementPolicy
typename std::vector< Entry >::iterator iterator
typename std::vector< Entry >::const_iterator const_iterator
Iterator types.
size_t associativity
Associativity of the cache.
const ::gem5::debug::SimpleFlag * debugFlag
Entry::IndexingPolicy IndexingPolicy
IndexingPolicy * indexingPolicy
Indexing policy of the cache.
iterator begin()
Returns an iterator to the first entry of the dictionary.
virtual Entry * findVictim(const KeyType &key)
Find a victim to be replaced.
BaseReplacementPolicy * replPolicy
The replacement policy of the cache.
virtual Entry * findEntry(const KeyType &key) const
Find an entry within the set.
iterator end()
Returns an iterator pointing to the end of the the dictionary (placeholder element,...
~AssociativeCache()=default
Default destructor.
void initParams(size_t _num_entries, size_t _assoc)
std::vector< Entry > entries
The entries.
AssociativeCache(const char *name, const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *repl_policy, IndexingPolicy *indexing_policy, Entry const &init_val=Entry())
Public constructor.
const_iterator end() const
Returns an iterator pointing to the end of the the dictionary (placeholder element,...
AssociativeCache & operator=(const AssociativeCache &)=delete
virtual void insertEntry(const KeyType &key, Entry *entry)
Indicate that an entry has just been inserted.
void init(const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *_repl_policy, IndexingPolicy *_indexing_policy, Entry const &init_val=Entry())
std::vector< Entry * > getPossibleEntries(const KeyType &key) const
Find the set of entries that could be replaced given that we want to add a new entry with the provide...
AssociativeCache(const AssociativeCache &)=delete
Disable copy and assignment.
virtual Entry * accessEntry(const KeyType &key)
Do an access to the entry if it exists.
virtual void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
virtual void accessEntry(Entry *entry)
Update the replacement information for an entry.
const_iterator begin() const
Returns an iterator to the first entry of the dictionary.
void setDebugFlag(const ::gem5::debug::SimpleFlag &flag)
Interface for things with names.
virtual std::string name() const
A common base class of cache replacement policy objects.
virtual void invalidate(const std::shared_ptr< ReplacementData > &replacement_data)=0
Invalidate replacement data to set it as the next probable victim.
virtual void reset(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Reset replacement data.
virtual void touch(const std::shared_ptr< ReplacementData > &replacement_data, const PacketPtr pkt)
Update replacement data.
virtual ReplaceableEntry * getVictim(const ReplacementCandidates &candidates) const =0
Find replacement victim among candidates.
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
void dprintf_flag(Tick when, const std::string &name, const std::string &flag, const char *fmt, const Args &...args)
Log a single message with a flag prefix.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Logger * getDebugLogger()
Get the current global debug logger.
Copyright (c) 2024 Arm Limited All rights reserved.
Tick curTick()
The universal simulation clock.
Overload hash function for BasicBlockRange type.