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

Last change on this file since 44 was 44, checked in by rosiere, 17 years ago

Modification des classes d'encapsulation des interfaces.
Stable sur tous les composants actuels

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