From 8c81479193f59c2f05616d744e74973e64464955 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Sat, 13 Apr 2024 08:55:15 +0100 Subject: [PATCH] base: Extract KeyType type in the AssociativeCache from Entry The KeyType data type is the type of the lookup and the cache extracts it from the Entry template parameter Change-Id: I147d7c2503abc11becfeebe6336e7f90989ad4e8 Signed-off-by: Giacomo Travaglini --- src/base/cache/associative_cache.hh | 31 ++++++++++++----------- src/base/cache/cache_entry.hh | 1 + src/mem/cache/prefetch/associative_set.hh | 1 - 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/base/cache/associative_cache.hh b/src/base/cache/associative_cache.hh index 6aa91d2414..73bb9afdf5 100644 --- a/src/base/cache/associative_cache.hh +++ b/src/base/cache/associative_cache.hh @@ -67,6 +67,7 @@ class AssociativeCache : public Named typedef replacement_policy::Base BaseReplacementPolicy; typedef typename Entry::IndexingPolicy IndexingPolicy; + typedef typename Entry::KeyType KeyType; /** Associativity of the cache. */ size_t associativity; @@ -164,13 +165,13 @@ class AssociativeCache : public Named /** * Do an access to the entry if it exists. * This is required to update the replacement information data. - * @param addr key to the entry + * @param key key to the entry * @return The entry if it exists */ virtual Entry* - accessEntryByAddr(const Addr addr) + accessEntry(const KeyType &key) { - auto entry = findEntry(addr); + auto entry = findEntry(key); if (entry) { accessEntry(entry); @@ -191,18 +192,18 @@ class AssociativeCache : public Named /** * Find an entry within the set - * @param addr key element + * @param key key element * @return returns a pointer to the wanted entry or nullptr if it does not * exist. */ virtual Entry* - findEntry(const Addr addr) const + findEntry(const KeyType &key) const { - auto candidates = indexingPolicy->getPossibleEntries(addr); + auto candidates = indexingPolicy->getPossibleEntries(key); for (auto candidate : candidates) { Entry *entry = static_cast(candidate); - if (entry->match(addr)) { + if (entry->match(key)) { return entry; } } @@ -212,13 +213,13 @@ class AssociativeCache : public Named /** * Find a victim to be replaced - * @param addr key to select the possible victim + * @param key key to select the possible victim * @result entry to be victimized */ virtual Entry* - findVictim(const Addr addr) + findVictim(const KeyType &key) { - auto candidates = indexingPolicy->getPossibleEntries(addr); + auto candidates = indexingPolicy->getPossibleEntries(key); auto victim = static_cast(replPolicy->getVictim(candidates)); @@ -241,13 +242,13 @@ class AssociativeCache : public Named /** * Indicate that an entry has just been inserted - * @param addr key of the container + * @param key key of the container * @param entry pointer to the container entry to be inserted */ virtual void - insertEntry(const Addr addr, Entry *entry) + insertEntry(const KeyType &key, Entry *entry) { - entry->insert(addr); + entry->insert(key); replPolicy->reset(entry->replacementData); } @@ -258,10 +259,10 @@ class AssociativeCache : public Named * @result vector of candidates matching with the provided key */ std::vector - getPossibleEntries(const Addr addr) const + getPossibleEntries(const KeyType &key) const { std::vector selected_entries = - indexingPolicy->getPossibleEntries(addr); + indexingPolicy->getPossibleEntries(key); std::vector entries; diff --git a/src/base/cache/cache_entry.hh b/src/base/cache/cache_entry.hh index 7a3756bceb..dc0a347142 100644 --- a/src/base/cache/cache_entry.hh +++ b/src/base/cache/cache_entry.hh @@ -60,6 +60,7 @@ class CacheEntry : public ReplaceableEntry { public: using IndexingPolicy = BaseIndexingPolicy; + using KeyType = Addr; CacheEntry(BaseIndexingPolicy *ip) : indexingPolicy(ip) {} ~CacheEntry() = default; diff --git a/src/mem/cache/prefetch/associative_set.hh b/src/mem/cache/prefetch/associative_set.hh index dcac4a7b8c..70794704c7 100644 --- a/src/mem/cache/prefetch/associative_set.hh +++ b/src/mem/cache/prefetch/associative_set.hh @@ -86,7 +86,6 @@ class AssociativeSet : public AssociativeCache private: // The following APIs are excluded since they lack the secure bit - using AssociativeCache::accessEntryByAddr; using AssociativeCache::findEntry; using AssociativeCache::insertEntry; using AssociativeCache::replPolicy;