gem5  v21.1.0.2
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 namespace gem5
36 {
37 
38 template<class Entry>
39 AssociativeSet<Entry>::AssociativeSet(int assoc, int num_entries,
40  BaseIndexingPolicy *idx_policy, replacement_policy::Base *rpl_policy,
41  Entry const &init_value)
42  : associativity(assoc), numEntries(num_entries), indexingPolicy(idx_policy),
43  replacementPolicy(rpl_policy), entries(numEntries, init_value)
44 {
45  fatal_if(!isPowerOf2(num_entries), "The number of entries of an "
46  "AssociativeSet<> must be a power of 2");
47  fatal_if(!isPowerOf2(assoc), "The associativity of an AssociativeSet<> "
48  "must be a power of 2");
49  for (unsigned int entry_idx = 0; entry_idx < numEntries; entry_idx += 1) {
50  Entry* entry = &entries[entry_idx];
51  indexingPolicy->setEntry(entry, entry_idx);
52  entry->replacementData = replacementPolicy->instantiateEntry();
53  }
54 }
55 
56 template<class Entry>
57 Entry*
59 {
60  Addr tag = indexingPolicy->extractTag(addr);
61  const std::vector<ReplaceableEntry*> selected_entries =
62  indexingPolicy->getPossibleEntries(addr);
63 
64  for (const auto& location : selected_entries) {
65  Entry* entry = static_cast<Entry *>(location);
66  if ((entry->getTag() == tag) && entry->isValid() &&
67  entry->isSecure() == is_secure) {
68  return entry;
69  }
70  }
71  return nullptr;
72 }
73 
74 template<class Entry>
75 void
77 {
78  replacementPolicy->touch(entry->replacementData);
79 }
80 
81 template<class Entry>
82 Entry*
84 {
85  // Get possible entries to be victimized
86  const std::vector<ReplaceableEntry*> selected_entries =
87  indexingPolicy->getPossibleEntries(addr);
88  Entry* victim = static_cast<Entry*>(replacementPolicy->getVictim(
89  selected_entries));
90  // There is only one eviction for this replacement
91  invalidate(victim);
92  return victim;
93 }
94 
95 
96 template<class Entry>
99 {
100  std::vector<ReplaceableEntry *> selected_entries =
101  indexingPolicy->getPossibleEntries(addr);
102  std::vector<Entry *> entries(selected_entries.size(), nullptr);
103 
104  unsigned int idx = 0;
105  for (auto &entry : selected_entries) {
106  entries[idx++] = static_cast<Entry *>(entry);
107  }
108  return entries;
109 }
110 
111 template<class Entry>
112 void
114 {
115  entry->insert(indexingPolicy->extractTag(addr), is_secure);
116  replacementPolicy->reset(entry->replacementData);
117 }
118 
119 template<class Entry>
120 void
122 {
123  entry->invalidate();
124  replacementPolicy->invalidate(entry->replacementData);
125 }
126 
127 } // namespace gem5
128 
129 #endif//__CACHE_PREFETCH_ASSOCIATIVE_SET_IMPL_HH__
gem5::AssociativeSet::invalidate
void invalidate(Entry *entry)
Invalidate an entry and its respective replacement data.
Definition: associative_set_impl.hh:121
gem5::BaseIndexingPolicy
A common base class for indexing table locations.
Definition: base.hh:66
std::vector
STL vector class.
Definition: stl.hh:37
gem5::isPowerOf2
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
gem5::AssociativeSet::AssociativeSet
AssociativeSet(int assoc, int num_entries, BaseIndexingPolicy *idx_policy, replacement_policy::Base *rpl_policy, Entry const &init_val=Entry())
Public constructor.
Definition: associative_set_impl.hh:39
gem5::AssociativeSet
Associative container based on the previosuly defined Entry type Each element is indexed by a key of ...
Definition: associative_set.hh:45
gem5::replacement_policy::Base
A common base class of cache replacement policy objects.
Definition: base.hh:55
gem5::auxv::Entry
@ Entry
Definition: aux_vector.hh:78
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
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:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Tue Sep 21 2021 12:25:29 for gem5 by doxygen 1.8.17