AbstractReplacementPolicy.hh revision 6145
1
2#ifndef ABSTRACTREPLACEMENTPOLICY_H
3#define ABSTRACTREPLACEMENTPOLICY_H
4
5#include "Global.hh"
6
7class AbstractReplacementPolicy {
8
9public:
10
11  AbstractReplacementPolicy(Index num_sets, Index assoc);
12  virtual ~AbstractReplacementPolicy();
13
14  /* touch a block. a.k.a. update timestamp */
15  virtual void touch(Index set, Index way, Time time) = 0;
16
17  /* returns the way to replace */
18  virtual Index getVictim(Index set) const = 0;
19
20  /* get the time of the last access */
21  Time getLastAccess(Index set, Index way);
22
23 protected:
24  unsigned int m_num_sets;       /** total number of sets */
25  unsigned int m_assoc;          /** set associativity */
26  Time **m_last_ref_ptr;         /** timestamp of last reference */
27};
28
29inline
30AbstractReplacementPolicy::AbstractReplacementPolicy(Index num_sets, Index assoc)
31{
32  m_num_sets = num_sets;
33  m_assoc = assoc;
34  m_last_ref_ptr = new Time*[m_num_sets];
35  for(unsigned int i = 0; i < m_num_sets; i++){
36    m_last_ref_ptr[i] = new Time[m_assoc];
37    for(unsigned int j = 0; j < m_assoc; j++){
38      m_last_ref_ptr[i][j] = 0;
39    }
40  }
41}
42
43inline
44AbstractReplacementPolicy::~AbstractReplacementPolicy()
45{
46  if(m_last_ref_ptr != NULL){
47    for(unsigned int i = 0; i < m_num_sets; i++){
48      if(m_last_ref_ptr[i] != NULL){
49        delete[] m_last_ref_ptr[i];
50      }
51    }
52    delete[] m_last_ref_ptr;
53  }
54}
55
56inline
57Time AbstractReplacementPolicy::getLastAccess(Index set, Index way)
58{
59  return m_last_ref_ptr[set][way];
60}
61
62#endif // ABSTRACTREPLACEMENTPOLICY_H
63