30#ifndef __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
31#define __BASE_CACHE_ASSOCIATIVE_CACHE_HH__
48template <
typename Entry>
51 static_assert(std::is_base_of_v<CacheEntry, Entry>,
52 "Entry should be derived from CacheEntry");
75 fatal_if((_num_entries % _assoc) != 0,
"The number of entries of an "
76 "AssociativeCache<> must be a multiple of its associativity");
77 for (
auto entry_idx = 0; entry_idx < _num_entries; entry_idx++) {
78 Entry *entry = &
entries[entry_idx];
101 const size_t associativity_,
104 Entry
const &init_val = Entry())
138 const size_t associativity_,
141 Entry
const &init_val = Entry())
146 entries.resize(num_entries, init_val);
203 for (
auto candidate : candidates) {
204 Entry *entry =
static_cast<Entry*
>(candidate);
205 if (entry->matchTag(tag)) {
268 std::transform(selected_entries.begin(), selected_entries.end(),
269 std::back_inserter(
entries), [](
auto &entry) {
270 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.
virtual void insertEntry(const Addr addr, Entry *entry)
Indicate that an entry has just been inserted.
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.
virtual Entry * accessEntryByAddr(const Addr addr)
Do an access to the entry if it exists.
iterator begin()
Returns an iterator to the first entry of the dictionary.
BaseReplacementPolicy * replPolicy
The replacement policy of the cache.
AssociativeCache(const char *name, const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *repl_policy, BaseIndexingPolicy *indexing_policy, Entry const &init_val=Entry())
Public constructor.
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.
const_iterator end() const
Returns an iterator pointing to the end of the the dictionary (placeholder element,...
virtual Entry * findVictim(const Addr addr)
Find a victim to be replaced.
BaseIndexingPolicy * indexingPolicy
Indexing policy of the cache.
AssociativeCache & operator=(const AssociativeCache &)=delete
AssociativeCache(const AssociativeCache &)=delete
Disable copy and assignment.
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.
virtual Entry * findEntry(const Addr addr) const
Find an entry within the set.
std::vector< Entry * > getPossibleEntries(const Addr addr) const
Find the set of entries that could be replaced given that we want to add a new entry with the provide...
virtual Addr getTag(const Addr addr) const
Get the tag for the addr.
void init(const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *_repl_policy, BaseIndexingPolicy *_indexing_policy, Entry const &init_val=Entry())
A common base class for indexing table locations.
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
virtual std::vector< ReplaceableEntry * > getPossibleEntries(const Addr addr) const =0
Find all possible entries for insertion and replacement of an address.
virtual Addr extractTag(const Addr addr) const
Generate the tag from the given address.
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.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Overload hash function for BasicBlockRange type.