source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Victim/Victim_Pseudo_LRU/include/Types.h

Last change on this file was 128, checked in by rosiere, 15 years ago

1) Correct bug in link two signal
2) Fix error detected with valgrind
3) modif distexe script

  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#ifndef morpheo_behavioural_generic_victim_victim_pseudo_lru_Type_h
2#define morpheo_behavioural_generic_victim_victim_pseudo_lru_Type_h
3
4/*
5 * $Id: Types.h 128 2009-06-26 08:43:23Z rosiere $
6 *
7 * [ Description ]
8 *
9 */
10
11#include "Behavioural/Generic/Victim/include/Types.h"
12
13namespace morpheo {
14namespace behavioural {
15namespace generic {
16namespace victim {
17namespace victim_pseudo_lru {
18
19  class entry_t
20  {
21    // Numerotation of victim_pseudo_lru's tree
22    // Tree of Pseudo-LRU
23    //
24    // | d2              [3]                 |
25    // |          0_______|_______1          |
26    // |          |               |          |
27    // | d1      [1]             [5]         |
28    // |      0___|___1       0___|___1      |
29    // |      |       |       |       |      |
30    // | d0  [0]     [2]     [4]     [6]     |
31    // |    0_|_1   0_|_1   0_|_1   0_|_1    |
32    // |    |   |   |   |   |   |   |   |    |
33    // |   Way Way Way Way Way Way Way Way   |
34    // |    0   1   2   3   4   5   6   7    |
35    //
36    // Access :  Way N with N=2*n   -> bit 2*n = 0
37    //                 with N=2*n+1 -> bit 2*n = 1
38    //
39    // if bit = B, depth = D, next_B = B+D if B==1
40    //                               = B-D if B==0
41    //
42    // Update :
43
44  private : bool    * _entry;
45  private : uint32_t  _size;
46   
47  public  : entry_t () 
48    {
49      _entry = NULL;
50    };
51  public  : entry_t (uint32_t size) : _size (size)
52    {
53      _entry = new bool [size];
54     
55      // initialisation
56      reset ();
57    }
58   
59  public : ~entry_t ()
60    {
61      if (_entry != NULL)
62        delete [] _entry;
63    }
64
65  public : void reset ()
66    {
67      // initialisation
68      for (uint32_t i=0; i<_size; i++)
69        _entry [i] = false;
70    }
71   
72  private : uint32_t one_access (uint32_t index, uint32_t offset)
73    {
74      bool val = _entry[index];
75     
76      // Compute next slot
77      if (val == true)
78        return index + offset;
79      else
80        return index - offset;
81    }
82
83  public : uint32_t access ()
84    {
85      uint32_t index = (_size>>1)-1; // middle
86
87      for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>= 1; i--)
88        {
89          index = one_access (index,(1<<(i-1)));
90        }
91      index = one_access (index,0);
92     
93      // reverse by one_access make always a reverse
94      uint32_t offset = (_entry[index]==true)?1:0; 
95
96      return index+offset;
97    }
98
99  private : uint32_t one_update (uint32_t index, uint32_t offset, uint32_t value)
100    {
101      uint32_t mask = (offset==0)?1:(offset<<1);
102      bool     val  = ((value & mask) != 0);
103
104      // reverse
105      _entry[index] = not val;
106
107      if (val == true)
108      // Compute next slot
109        return index + offset;
110      else
111        return index - offset;
112    }
113  public : void update (uint32_t value)
114    {
115      uint32_t index = (_size>>1)-1; // middle
116
117      for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>=1; i--)
118        {
119          index = one_update (index,1<<(i-1),value);
120        }
121      index = one_update (index,0,value);
122    }
123
124  public : std::string print ()
125    {
126      std::string res = "";
127
128      for (int32_t i=static_cast<int32_t>(_size)-1; i>=0; i--)
129        res += toString(_entry[i]) + " ";
130
131      return res;
132    }
133  };
134
135}; // end namespace victim_pseudo_lru
136}; // end namespace victim
137}; // end namespace generic
138}; // end namespace behavioural
139}; // end namespace morpheo             
140
141#endif
Note: See TracBrowser for help on using the repository browser.