source: trunk/modules/vci_mem_cache/caba/source/include/update_tab.h @ 430

Last change on this file since 430 was 385, checked in by alain, 11 years ago

VCI port to XRAM switched to DATA == 64 bits
=> two template parameters vci_param_int & vci_param_ext
This has been validated in tsar_generic_xbar platform...

File size: 12.2 KB
Line 
1#ifndef UPDATE_TAB_H_
2#define UPDATE_TAB_H_
3
4#include <inttypes.h>
5#include <systemc>
6#include <cassert>
7#include "arithmetics.h"
8
9////////////////////////////////////////////////////////////////////////
10//                  An update tab entry   
11////////////////////////////////////////////////////////////////////////
12class UpdateTabEntry {
13  typedef uint32_t size_t;
14  typedef sc_dt::sc_uint<40> addr_t;
15
16  public:
17  bool      valid;      // It is a valid pending transaction
18  bool      update;     // It is an update transaction
19  bool      brdcast;    // It is a broadcast invalidate
20  bool      rsp;        // It needs a response to the initiator
21  size_t        srcid;      // The srcid of the initiator which wrote the data
22  size_t        trdid;      // The trdid of the initiator which wrote the data
23  size_t        pktid;      // The pktid of the initiator which wrote the data
24  addr_t        nline;      // The identifier of the cache line
25  size_t        count;      // The number of acknowledge responses to receive
26
27  UpdateTabEntry(){
28    valid       = false;
29    update  = false;
30    brdcast = false;
31    rsp     = false;
32    srcid       = 0;
33    trdid       = 0;
34    pktid       = 0;
35    nline       = 0;
36    count       = 0;
37  }
38
39  UpdateTabEntry(bool   i_valid, 
40      bool   i_update,
41      bool   i_brdcast,
42      bool   i_rsp,
43      size_t i_srcid, 
44      size_t i_trdid, 
45      size_t i_pktid, 
46      addr_t i_nline,
47      size_t i_count) 
48  {
49    valid       = i_valid;
50    update      = i_update;
51    brdcast = i_brdcast;
52    rsp     = i_rsp;
53    srcid       = i_srcid;
54    trdid       = i_trdid;
55    pktid       = i_pktid;
56    nline       = i_nline;
57    count       = i_count;
58  }
59
60  UpdateTabEntry(const UpdateTabEntry &source)
61  {
62    valid   = source.valid;
63    update  = source.update;
64    brdcast = source.brdcast;
65    rsp     = source.rsp;
66    srcid   = source.srcid;
67    trdid   = source.trdid;
68    pktid   = source.pktid;
69    nline   = source.nline;
70    count   = source.count;
71  }
72
73  ////////////////////////////////////////////////////
74  // The init() function initializes the entry
75  ///////////////////////////////////////////////////
76  void init()
77  {
78    valid  = false;
79    update = false;
80    brdcast= false;
81    rsp    = false;
82    srcid  = 0;
83    trdid  = 0;
84    pktid  = 0;
85    nline  = 0;
86    count  = 0;
87  }
88
89  ////////////////////////////////////////////////////////////////////
90  // The copy() function copies an existing entry
91  // Its arguments are :
92  // - source : the update tab entry to copy
93  ////////////////////////////////////////////////////////////////////
94  void copy(const UpdateTabEntry &source)
95  {
96    valid  = source.valid;
97    update = source.update;
98    brdcast= source.brdcast;
99    rsp    = source.rsp;
100    srcid  = source.srcid;
101    trdid  = source.trdid;
102    pktid  = source.pktid;
103    nline  = source.nline;
104    count  = source.count;
105  }
106
107  ////////////////////////////////////////////////////////////////////
108  // The print() function prints the entry 
109  ////////////////////////////////////////////////////////////////////
110  void print(){
111    std::cout << std::dec << "valid  = " << valid  << std::endl;
112    std::cout << "update = " << update << std::endl;
113    std::cout << "brdcast= " << brdcast<< std::endl;
114    std::cout << "rsp    = " << rsp    << std::endl;
115    std::cout << "srcid  = " << srcid  << std::endl; 
116    std::cout << "trdid  = " << trdid  << std::endl; 
117    std::cout << "pktid  = " << pktid  << std::endl; 
118    std::cout << std::hex << "nline  = " << nline  << std::endl;
119    std::cout << std::dec << "count  = " << count  << std::endl;
120  }
121};
122
123////////////////////////////////////////////////////////////////////////
124//                        The update tab             
125////////////////////////////////////////////////////////////////////////
126class UpdateTab{
127
128  typedef sc_dt::sc_uint<40> addr_t;
129
130  private:
131  size_t size_tab;
132  std::vector<UpdateTabEntry> tab;
133
134  public:
135
136  UpdateTab()
137    : tab(0)
138  {
139    size_tab=0;
140  }
141
142  UpdateTab(size_t size_tab_i)
143    : tab(size_tab_i)
144  {
145    size_tab=size_tab_i;
146  }
147
148  ////////////////////////////////////////////////////////////////////
149  // The size() function returns the size of the tab 
150  ////////////////////////////////////////////////////////////////////
151  const size_t size(){
152    return size_tab;
153  }
154
155
156  ////////////////////////////////////////////////////////////////////
157  // The print() function diplays the tab content
158  ////////////////////////////////////////////////////////////////////
159  void print(){
160    for(size_t i=0; i<size_tab; i++) {
161      std::cout << "UPDATE TAB ENTRY " << std::dec << i << "--------" << std::endl;
162      tab[i].print();
163    }
164    return;
165  }
166
167
168  /////////////////////////////////////////////////////////////////////
169  // The init() function initializes the tab
170  /////////////////////////////////////////////////////////////////////
171  void init(){
172    for ( size_t i=0; i<size_tab; i++) {
173      tab[i].init();
174    }
175  }
176
177
178  /////////////////////////////////////////////////////////////////////
179  // The reads() function reads an entry
180  // Arguments :
181  // - entry : the entry to read
182  // This function returns a copy of the entry.
183  /////////////////////////////////////////////////////////////////////
184  UpdateTabEntry read (size_t entry)
185  {
186    assert(entry<size_tab && "Bad Update Tab Entry");
187    return UpdateTabEntry(tab[entry]);
188  }
189
190  ///////////////////////////////////////////////////////////////////////////
191  // The set() function writes an entry in the Update Table
192  // Arguments :
193  // - update : transaction type (bool)
194  // - srcid : srcid of the initiator
195  // - trdid : trdid of the initiator
196  // - pktid : pktid of the initiator
197  // - count : number of expected responses
198  // - index : (return argument) index of the selected entry
199  // This function returns true if the write successed (an entry was empty).
200  ///////////////////////////////////////////////////////////////////////////
201  bool set(const bool   update,
202      const bool   brdcast,
203      const bool   rsp,
204      const size_t srcid,
205      const size_t trdid,
206      const size_t pktid,
207      const addr_t nline,
208      const size_t count,
209      size_t &index)
210  {
211    for ( size_t i=0 ; i<size_tab ; i++ ) {
212      if( !tab[i].valid ) {
213        tab[i].valid            = true;
214        tab[i].update           = update;
215        tab[i].brdcast      = brdcast;
216        tab[i].rsp          = rsp;
217        tab[i].srcid            = (size_t) srcid;
218        tab[i].trdid            = (size_t) trdid;
219        tab[i].pktid            = (size_t) pktid;
220        tab[i].nline            = (addr_t) nline;
221        tab[i].count            = (size_t) count;
222        index                       = i;
223        return true;
224      }
225    }
226    return false;
227  } // end set()
228
229  /////////////////////////////////////////////////////////////////////
230  // The decrement() function decrements the counter for a given entry.
231  // Arguments :
232  // - index   : the index of the entry
233  // - counter : (return argument) value of the counter after decrement
234  // This function returns true if the entry is valid.
235  /////////////////////////////////////////////////////////////////////
236  bool decrement( const size_t index,
237      size_t &counter ) 
238  {
239    assert((index<size_tab) && "Bad Update Tab Entry");
240    if ( tab[index].valid ) {
241      tab[index].count--;
242      counter = tab[index].count;
243      return true;
244    } else {
245      return false;
246    }
247  }
248
249  /////////////////////////////////////////////////////////////////////
250  // The is_full() function returns true if the table is full
251  /////////////////////////////////////////////////////////////////////
252  bool is_full()
253  {
254    for(size_t i = 0 ; i < size_tab ; i++){
255      if(!tab[i].valid){
256        return false;
257      }
258    }
259    return true;
260  }
261
262  /////////////////////////////////////////////////////////////////////
263  // The is_not_empty() function returns true if the table is not empty
264  /////////////////////////////////////////////////////////////////////
265  bool is_not_empty()
266  {
267    for(size_t i = 0 ; i < size_tab ; i++){
268      if(tab[i].valid){
269        return true;
270      }
271    }
272    return false;
273  }
274
275  /////////////////////////////////////////////////////////////////////
276  // The need_rsp() function returns the need of a response
277  // Arguments :
278  // - index : the index of the entry
279  /////////////////////////////////////////////////////////////////////
280  bool need_rsp(const size_t index)
281  {
282    assert(index<size_tab && "Bad Update Tab Entry");
283    return tab[index].rsp;     
284  }
285
286  /////////////////////////////////////////////////////////////////////
287  // The is_update() function returns the transaction type
288  // Arguments :
289  // - index : the index of the entry
290  /////////////////////////////////////////////////////////////////////
291  bool is_brdcast(const size_t index)
292  {
293    assert(index<size_tab && "Bad Update Tab Entry");
294    return tab[index].brdcast; 
295  }
296
297  /////////////////////////////////////////////////////////////////////
298  // The is_update() function returns the transaction type
299  // Arguments :
300  // - index : the index of the entry
301  /////////////////////////////////////////////////////////////////////
302  bool is_update(const size_t index)
303  {
304    assert(index<size_tab && "Bad Update Tab Entry");
305    return tab[index].update;   
306  }
307
308  /////////////////////////////////////////////////////////////////////
309  // The srcid() function returns the srcid value
310  // Arguments :
311  // - index : the index of the entry
312  /////////////////////////////////////////////////////////////////////
313  size_t srcid(const size_t index)
314  {
315    assert(index<size_tab && "Bad Update Tab Entry");
316    return tab[index].srcid;   
317  }
318
319  /////////////////////////////////////////////////////////////////////
320  // The trdid() function returns the trdid value
321  // Arguments :
322  // - index : the index of the entry
323  /////////////////////////////////////////////////////////////////////
324  size_t trdid(const size_t index)
325  {
326    assert(index<size_tab && "Bad Update Tab Entry");
327    return tab[index].trdid;   
328  }
329
330  /////////////////////////////////////////////////////////////////////
331  // The pktid() function returns the pktid value
332  // Arguments :
333  // - index : the index of the entry
334  /////////////////////////////////////////////////////////////////////
335  size_t pktid(const size_t index)
336  {
337    assert(index<size_tab && "Bad Update Tab Entry");
338    return tab[index].pktid;   
339  }
340
341  /////////////////////////////////////////////////////////////////////
342  // The nline() function returns the nline value
343  // Arguments :
344  // - index : the index of the entry
345  /////////////////////////////////////////////////////////////////////
346  addr_t nline(const size_t index)
347  {
348    assert(index<size_tab && "Bad Update Tab Entry");
349    return tab[index].nline;
350  }
351
352  /////////////////////////////////////////////////////////////////////
353  // The search_inval() function returns the index of the entry in UPT
354  // Arguments :
355  // - nline : the line number of the entry in the directory
356  /////////////////////////////////////////////////////////////////////
357  bool search_inval(const addr_t nline,size_t &index)
358  {
359    size_t i ;
360
361    for (i = 0 ; i < size_tab ; i++){
362      if((tab[i].nline == nline) && tab[i].valid){
363        if(!tab[i].update){
364          index = i ;
365          return true;
366        }
367      }
368    }
369    return false;
370  }
371
372  /////////////////////////////////////////////////////////////////////
373  // The read_nline() function returns the index of the entry in UPT
374  // Arguments :
375  // - nline : the line number of the entry in the directory
376  /////////////////////////////////////////////////////////////////////
377  bool read_nline(const addr_t nline,size_t &index) 
378  {
379    size_t i ;
380
381    for (i = 0 ; i < size_tab ; i++){
382      if((tab[i].nline == nline) && tab[i].valid){
383        index = i ;
384        return true;
385      }
386    }
387    return false;
388  }
389
390  /////////////////////////////////////////////////////////////////////
391  // The clear() function erases an entry of the tab
392  // Arguments :
393  // - index : the index of the entry
394  /////////////////////////////////////////////////////////////////////       
395  void clear(const size_t index)
396  {
397    assert(index<size_tab && "Bad Update Tab Entry");
398    tab[index].valid=false;
399    return;     
400  }
401
402};
403
404#endif
405
406// Local Variables:
407// tab-width: 4
408// c-basic-offset: 4
409// c-file-offsets:((innamespace . 0)(inline-open . 0))
410// indent-tabs-mode: nil
411// End:
412
413// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
414
Note: See TracBrowser for help on using the repository browser.