From 4a2e015ff8dfe6199f048889cf1993683e171c97 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 8 Aug 2024 17:26:19 +0100 Subject: [PATCH] base: Extract IP type in the AssociativeCache from Entry This commit is making the AssociativeCache indexing policy a type extracted from the Entry template parameter Change-Id: Ic9fb6ccb1b3549aaa250901e91ae3c300b92103e Signed-off-by: Giacomo Travaglini --- src/base/cache/associative_cache.hh | 11 ++++++----- src/base/cache/cache_entry.hh | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/base/cache/associative_cache.hh b/src/base/cache/associative_cache.hh index 63bd6dbad7..6aa91d2414 100644 --- a/src/base/cache/associative_cache.hh +++ b/src/base/cache/associative_cache.hh @@ -60,12 +60,13 @@ namespace gem5 template class AssociativeCache : public Named { + protected: + static_assert(std::is_base_of_v, "Entry should be derived from CacheEntry"); typedef replacement_policy::Base BaseReplacementPolicy; - - protected: + typedef typename Entry::IndexingPolicy IndexingPolicy; /** Associativity of the cache. */ size_t associativity; @@ -74,7 +75,7 @@ class AssociativeCache : public Named BaseReplacementPolicy *replPolicy; /** Indexing policy of the cache */ - BaseIndexingPolicy *indexingPolicy; + IndexingPolicy *indexingPolicy; /** The entries */ std::vector entries; @@ -112,7 +113,7 @@ class AssociativeCache : public Named AssociativeCache(const char *name, const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *repl_policy, - BaseIndexingPolicy *indexing_policy, + IndexingPolicy *indexing_policy, Entry const &init_val = Entry()) : Named(std::string(name)), associativity(associativity_), @@ -149,7 +150,7 @@ class AssociativeCache : public Named init(const size_t num_entries, const size_t associativity_, BaseReplacementPolicy *_repl_policy, - BaseIndexingPolicy *_indexing_policy, + IndexingPolicy *_indexing_policy, Entry const &init_val = Entry()) { associativity = associativity_; diff --git a/src/base/cache/cache_entry.hh b/src/base/cache/cache_entry.hh index 5af7be17ed..7a3756bceb 100644 --- a/src/base/cache/cache_entry.hh +++ b/src/base/cache/cache_entry.hh @@ -59,6 +59,8 @@ namespace gem5 class CacheEntry : public ReplaceableEntry { public: + using IndexingPolicy = BaseIndexingPolicy; + CacheEntry(BaseIndexingPolicy *ip) : indexingPolicy(ip) {} ~CacheEntry() = default; CacheEntry(const CacheEntry &rhs)