gem5  v21.0.1.0
associative_set_impl.hh
Go to the documentation of this file.
1 
29 #ifndef __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
30 #define __CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
31 
32 #include "base/intmath.hh"
34 
35 template<class Entry>
36 AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
37  BaseIndexingPolicy *idx_policy, ReplacementPolicy::Base *rpl_policy,
38  Entry const &init_value)
39  : associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
40  replacementPolicy(rpl_policy), entries(numEntries, init_value)
41 {
42  fatal_if(!isPowerOf2(num_entries), "The number of entries of an "
43  "AssociativeSet<> must be a power of 2");
44  fatal_if(!isPowerOf2(assoc), "The associativity of an AssociativeSet<> "
45  "must be a power of 2");
46  for (unsigned int entry_idx = 0; entry_idx < numEntries; entry_idx += 1) {
47  Entry* entry = &entries[entry_idx];
48  indexingPolicy->setEntry(entry, entry_idx);
49  entry->replacementData = replacementPolicy->instantiateEntry();
50  }
51 }
52 
53 template<class Entry>
54 Entry*
56 {
57  Addr tag = indexingPolicy->extractTag(addr);
58  const std::vector<ReplaceableEntry*> selected_entries =
59  indexingPolicy->getPossibleEntries(addr);
60 
61  for (const auto& location : selected_entries) {
62  Entry* entry = static_cast<Entry *>(location);
63  if ((entry->getTag() == tag) && entry->isValid() &&
64  entry->isSecure() == is_secure) {
65  return entry;
66  }
67  }
68  return nullptr;
69 }
70 
71 template<class Entry>
72 void
74 {
75  replacementPolicy->touch(entry->replacementData);
76 }
77 
78 template<class Entry>
79 Entry*
81 {
82  // Get possible entries to be victimized
83  const std::vector<ReplaceableEntry*> selected_entries =
84  indexingPolicy->getPossibleEntries(addr);
85  Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
86  selected_entries));
87  // There is only one eviction for this replacement
88  invalidate(victim);
89  return victim;
90 }
91 
92 
93 template<class Entry>
96 {
97  std::vector<ReplaceableEntry *> selected_entries =
98  indexingPolicy->getPossibleEntries(addr);
99  std::vector<Entry *> entries(selected_entries.size(), nullptr);
100 
101  unsigned int idx = 0;
102  for (auto &entry : selected_entries) {
103  entries[idx++] = static_cast<Entry *>(entry);
104  }
105  return entries;
106 }
107 
108 template<class Entry>
109 void
110 AssociativeSet<Entry>::insertEntry(Addr addr, bool is_secure, Entry* entry)
111 {
112  entry->insert(indexingPolicy->extractTag(addr), is_secure);
113  replacementPolicy->reset(entry->replacementData);
114 }
115 
116 template<class Entry>
117 void
119 {
120  entry->invalidate();
121  replacementPolicy->invalidate(entry->replacementData);
122 }
123 
124 #endif//__CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
AssociativeSet::AssociativeSet
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy, ReplacementPolicy::Base *rpl_policy, Entry const &init_val=Entry())
Public constructor.
Definition: associative_set_impl.hh:36
std::vector
STL vector class.
Definition: stl.hh:37
AssociativeSet::findEntry
Entry * findEntry(Addr addr, bool is_secure) const
Find an entry within the set.
Definition: associative_set_impl.hh:55
AssociativeSet::entries
std::vector< Entry > entries
Vector containing the entries of the container.
Definition: associative_set.hh:59
AssociativeSet::accessEntry
void accessEntry(Entry *entry)
Do an access to the entry, this is required to update the replacement information data.
Definition: associative_set_impl.hh:73
AssociativeSet::getPossibleEntries
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...
Definition: associative_set_impl.hh:95
BaseIndexingPolicy::setEntry
void setEntry(ReplaceableEntry *entry, const uint64_t index)
Associate a pointer to an entry to its physical counterpart.
Definition: base.cc:78
ReplacementPolicy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:48
AssociativeSet::insertEntry
void insertEntry(Addr addr, bool is_secure, Entry *entry)
Indicate that an entry has just been inserted.
Definition: associative_set_impl.hh:110
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
AssociativeSet::findVictim
Entry * findVictim(Addr addr)
Find a victim to be replaced.
Definition: associative_set_impl.hh:80
ReplacementPolicy::Base::instantiateEntry
virtual std::shared_ptr< ReplacementData > instantiateEntry()=0
Instantiate a replacement data entry.
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
AssociativeSet::numEntries
const int numEntries
Total number of entries, entries are organized in sets of the provided associativity.
Definition: associative_set.hh:53
AssociativeSet::invalidate
void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
Definition: associative_set_impl.hh:118
BaseIndexingPolicy
A common base class for indexing table locations.
Definition: base.hh:63
AssociativeSet::indexingPolicy
BaseIndexingPolicy *const indexingPolicy
Pointer to the indexing policy.
Definition: associative_set.hh:55
associative_set.hh
intmath.hh
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
AssociativeSet::replacementPolicy
ReplacementPolicy::Base *const replacementPolicy
Pointer to the replacement policy.
Definition: associative_set.hh:57

Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17