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

Last change on this file since 75 was 75, checked in by rosiere, 16 years ago

Update all component (except front_end) to :

  • new statistics model
  • no namespace std
File size: 7.1 KB
Line 
1#ifndef morpheo_behavioural_generic_victim_victim_pseudo_lru_Victim_Pseudo_LRU_h
2#define morpheo_behavioural_generic_victim_victim_pseudo_lru_Victim_Pseudo_LRU_h
3
4/*
5 * $Id$
6 *
7 * [ Description ]
8 *
9 */
10    // Tree of Pseudo-LRU
11    //
12    // |               4-5-6-7?              |
13    // |          0_______|_______1          |
14    // |          |               |          |
15    // |         2-3?            6-7?        |
16    // |      0___|___1       0___|___1      |
17    // |      |       |       |       |      |
18    // |      1?      3?      5?      7?     |
19    // |    0_|_1   0_|_1   0_|_1   0_|_1    |
20    // |    |   |   |   |   |   |   |   |    |
21    // |   Way Way Way Way Way Way Way Way   |
22    // |    0   1   2   3   4   5   6   7    |
23
24
25
26#ifdef SYSTEMC
27#include "systemc.h"
28#endif
29
30#include <iostream>
31#include "Common/include/ToString.h"
32#include "Common/include/Debug.h"
33
34#include "Behavioural/Generic/Victim/Victim_Pseudo_LRU/include/Parameters.h"
35#include "Behavioural/Generic/Victim/Victim_Pseudo_LRU/include/Types.h"
36#ifdef STATISTICS
37#include "Behavioural/include/Stat.h"
38#endif
39#ifdef VHDL
40#include "Behavioural/include/Vhdl.h"
41#endif
42#include "Behavioural/include/Component.h"
43
44namespace morpheo {
45namespace behavioural {
46namespace generic {
47namespace victim {
48namespace victim_pseudo_lru {
49
50  class Victim_Pseudo_LRU
51#if SYSTEMC
52    : public sc_module
53#endif
54  {
55    // -----[ internal class ]--------------------------------------------
56  protected : class entry_t
57  {
58    // Numerotation of victim_pseudo_lru's tree
59    // Tree of Pseudo-LRU
60    //
61    // | d2              [3]                 |
62    // |          0_______|_______1          |
63    // |          |               |          |
64    // | d1      [1]             [5]         |
65    // |      0___|___1       0___|___1      |
66    // |      |       |       |       |      |
67    // | d0  [0]     [2]     [4]     [6]     |
68    // |    0_|_1   0_|_1   0_|_1   0_|_1    |
69    // |    |   |   |   |   |   |   |   |    |
70    // |   Way Way Way Way Way Way Way Way   |
71    // |    0   1   2   3   4   5   6   7    |
72    //
73    // Access :  Way N with N=2*n   -> bit 2*n = 0
74    //                 with N=2*n+1 -> bit 2*n = 1
75    //
76    // if bit = B, depth = D, next_B = B+D if B==1
77    //                               = B-D if B==0
78    //
79    // Update :
80
81  private : bool    * _entry;
82  private : uint32_t  _size;
83
84  public  : entry_t () 
85    {
86    };
87  public  : entry_t (uint32_t size) : _size (size)
88    {
89      _entry = new bool [size];
90     
91      // initialisation
92      for (uint32_t i=0; i<size; i++)
93        _entry [i] = false;
94    }
95   
96  public : ~entry_t ()
97    {
98      delete _entry;
99    }
100   
101  private : uint32_t one_access (uint32_t index, uint32_t offset)
102    {
103      bool val = _entry[index];
104     
105      // Compute next slot
106      if (val == true)
107        return index + offset;
108      else
109        return index - offset;
110    }
111
112  public : uint32_t access ()
113    {
114      uint32_t index = (_size>>1)-1; // medium
115
116      for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>= 1; i--)
117        {
118          index = one_access (index,(1<<(i-1)));
119        }
120      index = one_access (index,0);
121     
122      // reverse by one_access make always a reverse
123      uint32_t offset = (_entry[index]==true)?1:0; 
124
125      return index+offset;
126    }
127
128  private : uint32_t one_update (uint32_t index, uint32_t offset, uint32_t value)
129    {
130      uint32_t mask = (offset==0)?1:(offset<<1);
131      bool     val  = ((value & mask) != 0);
132
133      // reverse
134      _entry[index] = not val;
135
136      if (val == true)
137      // Compute next slot
138        return index + offset;
139      else
140        return index - offset;
141    }
142  public : void update (uint32_t value)
143    {
144      uint32_t index = (_size>>1)-1; // medium
145
146      for (int32_t i=static_cast<uint32_t>(log2(_size)-1); i>=1; i--)
147        {
148          index = one_update (index,1<<(i-1),value);
149        }
150      index = one_update (index,0,value);
151    }
152
153  public : std::string print ()
154    {
155      std::string res = "";
156
157      for (int32_t i=static_cast<int32_t>(_size)-1; i>=0; i--)
158        res += toString(_entry[i]) + " ";
159
160      return res;
161    }
162
163  };
164    // -----[ fields ]----------------------------------------------------
165    // Parameters
166  protected : const std::string     _name;
167
168  protected : const Parameters _param;
169#ifdef STATISTICS
170  public    : Stat                           * _stat;
171#endif
172
173  public    : Component                      * _component;
174  private   : Interfaces                     * _interfaces;
175
176#ifdef SYSTEMC
177    // ~~~~~[ Interface ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178    // Interface
179  public    : SC_CLOCK                      *  in_CLOCK         ;
180  public    : SC_IN (Tcontrol_t)            *  in_NRESET        ;
181
182    // Interface access
183  public    : SC_IN (Tcontrol_t)           **  in_ACCESS_VAL    ;
184  public    : SC_OUT(Tcontrol_t)           ** out_ACCESS_ACK    ;
185  public    : SC_IN (Taddress_t)           **  in_ACCESS_ADDRESS;
186  public    : SC_OUT(Tentity_t )           ** out_ACCESS_ENTITY ;
187    // Interface update
188  public    : SC_IN (Tcontrol_t)           **  in_UPDATE_VAL    ;
189  public    : SC_OUT(Tcontrol_t)           ** out_UPDATE_ACK    ;
190  public    : SC_IN (Taddress_t)           **  in_UPDATE_ADDRESS;
191  public    : SC_IN (Tentity_t )           **  in_UPDATE_ENTITY ;
192
193    // Interface update
194    // ~~~~~[ Register ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
195  private   : entry_t                      ** reg_TABLE;
196
197    // ~~~~~[ Internal ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
198  private   : Tentity_t                     * internal_ACCESS_ENTITY;
199#endif
200
201    // -----[ methods ]---------------------------------------------------
202
203#ifdef SYSTEMC
204    SC_HAS_PROCESS (Victim_Pseudo_LRU);
205#endif
206
207  public  :          Victim_Pseudo_LRU              (
208#ifdef SYSTEMC
209                                              sc_module_name                                name,
210#else                                         
211                                              std::string                                   name,
212#endif                                         
213#ifdef STATISTICS
214                                              morpheo::behavioural::Parameters_Statistics * param_statistics,
215#endif
216                                              Parameters                                    param );
217                                               
218  public  :          Victim_Pseudo_LRU              (Parameters param );
219  public  :          ~Victim_Pseudo_LRU             (void);
220                                               
221#ifdef SYSTEMC                                 
222  private : void     allocation                (void);
223  private : void     deallocation              (void);
224                                               
225  public  : void     transition                (void);
226  public  : void     genMealy_access           (void);
227#endif
228                                               
229#if VHDL                                       
230  public  : void     vhdl                      (void);
231  private : void     vhdl_declaration          (Vhdl * & vhdl);
232  private : void     vhdl_body                 (Vhdl * & vhdl);
233#endif                                         
234                                               
235#ifdef STATISTICS
236  public  : void     statistics_declaration    (morpheo::behavioural::Parameters_Statistics * param_statistics);
237#endif
238
239#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
240  private : void     end_cycle                 (void);
241#endif
242  };
243
244}; // end namespace victim_pseudo_lru
245}; // end namespace victim
246}; // end namespace generic
247
248}; // end namespace behavioural
249}; // end namespace morpheo             
250
251#endif
Note: See TracBrowser for help on using the repository browser.