LRUPolicy.hh revision 6145
1
2#ifndef LRUPOLICY_H
3#define LRUPOLICY_H
4
5#include "AbstractReplacementPolicy.hh"
6
7/* Simple true LRU replacement policy */
8
9class LRUPolicy : public AbstractReplacementPolicy {
10 public:
11
12  LRUPolicy(Index num_sets, Index assoc);
13  ~LRUPolicy();
14
15  void touch(Index set, Index way, Time time);
16  Index getVictim(Index set) const;
17};
18
19inline
20LRUPolicy::LRUPolicy(Index num_sets, Index assoc)
21  : AbstractReplacementPolicy(num_sets, assoc)
22{
23}
24
25inline
26LRUPolicy::~LRUPolicy()
27{
28}
29
30inline
31void LRUPolicy::touch(Index set, Index index, Time time){
32  assert(index >= 0 && index < m_assoc);
33  assert(set >= 0 && set < m_num_sets);
34
35  m_last_ref_ptr[set][index] = time;
36}
37
38inline
39Index LRUPolicy::getVictim(Index set) const {
40  //  assert(m_assoc != 0);
41  Time time, smallest_time;
42  Index smallest_index;
43
44  smallest_index = 0;
45  smallest_time = m_last_ref_ptr[set][0];
46
47  for (unsigned int i=0; i < m_assoc; i++) {
48    time = m_last_ref_ptr[set][i];
49    //assert(m_cache[cacheSet][i].m_Permission != AccessPermission_NotPresent);
50
51    if (time < smallest_time){
52      smallest_index = i;
53      smallest_time = time;
54    }
55  }
56
57  //  DEBUG_EXPR(CACHE_COMP, MedPrio, cacheSet);
58  //  DEBUG_EXPR(CACHE_COMP, MedPrio, smallest_index);
59  //  DEBUG_EXPR(CACHE_COMP, MedPrio, m_cache[cacheSet][smallest_index]);
60  //  DEBUG_EXPR(CACHE_COMP, MedPrio, *this);
61
62  return smallest_index;
63}
64
65#endif // PSEUDOLRUBITS_H
66