42#ifndef __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
43#define __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
61template <
typename Entry>
66 static_assert(std::is_base_of_v<ReplaceableEntry, Entry>,
67 "Entry should be derived from ReplaceableEntry");
85 const ::gem5::debug::SimpleFlag*
debugFlag =
nullptr;
92 fatal_if((_num_entries % _assoc) != 0,
"The number of entries of an "
93 "AssociativeCache<> must be a multiple of its associativity");
94 for (
auto entry_idx = 0; entry_idx < _num_entries; entry_idx++) {
95 Entry *entry = &
entries[entry_idx];
97 entry->replacementData =
replPolicy->instantiateEntry();
118 const size_t associativity_,
121 Entry
const &init_val = Entry())
126 entries(num_entries, init_val),
156 const size_t associativity_,
159 Entry
const &init_val = Entry())
164 entries.resize(num_entries, init_val);
203 "Accessing entry: %s\n", entry->print());
221 for (
auto candidate : candidates) {
222 Entry *entry =
static_cast<Entry*
>(candidate);
223 if (entry->match(key)) {
241 auto victim =
static_cast<Entry*
>(
replPolicy->getVictim(candidates));
246 "Replacing entry: %s\n", victim->print());
263 replPolicy->invalidate(entry->replacementData);
277 "Inserting entry: %s\n", entry->print());
298 std::transform(selected_entries.begin(), selected_entries.end(),
299 std::back_inserter(
entries), [](
auto &entry) {
300 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.
replacement_policy::Base BaseReplacementPolicy
typename std::vector< Entry >::iterator iterator
typename std::vector< Entry >::const_iterator const_iterator
Iterator types.
const ::gem5::debug::SimpleFlag * debugFlag
Entry::IndexingPolicy IndexingPolicy
IndexingPolicy * indexingPolicy
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
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< StrideEntry > entries
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)
AssociativeCache(std::string_view name, const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *repl_policy, IndexingPolicy *indexing_policy, Entry const &init_val=Entry())
Public constructor.
AssociativeCache(std::string_view name)
Empty constructor - need to call init() later with all args.
Named(std::string_view name_)
virtual std::string name() const
A common base class of cache replacement policy objects.
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.