source: trunk/modules/vci_mem_cache_v3/caba/source/include/update_tab_v3.h @ 2

Last change on this file since 2 was 2, checked in by nipo, 14 years ago

Import TSAR modules in TSAR's own svn

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Rev URL Revision"
  • Property svn:mime-type set to text/plain
File size: 11.9 KB
Line 
1#ifndef UPDATE_TAB_V3_H_
2#define UPDATE_TAB_V3_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 uint32_t size_t;
129  typedef sc_dt::sc_uint<40> addr_t;
130
131  private:
132  size_t size_tab;
133  std::vector<UpdateTabEntry> tab;
134
135  public:
136
137  UpdateTab()
138    : tab(0)
139  {
140    size_tab=0;
141  }
142
143  UpdateTab(size_t size_tab_i)
144    : tab(size_tab_i)
145  {
146    size_tab=size_tab_i;
147  }
148
149  ////////////////////////////////////////////////////////////////////
150  // The size() function returns the size of the tab 
151  ////////////////////////////////////////////////////////////////////
152  const size_t size(){
153    return size_tab;
154  }
155
156
157  ////////////////////////////////////////////////////////////////////
158  // The size() function returns the size of the tab 
159  ////////////////////////////////////////////////////////////////////
160  void print(){
161    for(size_t i=0; i<size_tab; i++) {
162      std::cout << "UPDATE TAB ENTRY " << std::dec << i << "--------" << std::endl;
163      tab[i].print();
164    }
165    return;
166  }
167
168
169  /////////////////////////////////////////////////////////////////////
170  // The init() function initializes the tab
171  /////////////////////////////////////////////////////////////////////
172  void init(){
173    for ( size_t i=0; i<size_tab; i++) {
174      tab[i].init();
175    }
176  }
177
178
179  /////////////////////////////////////////////////////////////////////
180  // The reads() function reads an entry
181  // Arguments :
182  // - entry : the entry to read
183  // This function returns a copy of the entry.
184  /////////////////////////////////////////////////////////////////////
185  UpdateTabEntry read (size_t entry)
186  {
187    assert(entry<size_tab && "Bad Update Tab Entry");
188    return UpdateTabEntry(tab[entry]);
189  }
190
191  ///////////////////////////////////////////////////////////////////////////
192  // The set() function writes an entry in the Update Table
193  // Arguments :
194  // - update : transaction type (bool)
195  // - srcid : srcid of the initiator
196  // - trdid : trdid of the initiator
197  // - pktid : pktid of the initiator
198  // - count : number of expected responses
199  // - index : (return argument) index of the selected entry
200  // This function returns true if the write successed (an entry was empty).
201  ///////////////////////////////////////////////////////////////////////////
202  bool set(const bool   update,
203      const bool   brdcast,
204      const bool   rsp,
205      const size_t srcid,
206      const size_t trdid,
207      const size_t pktid,
208      const addr_t nline,
209      const size_t count,
210      size_t &index)
211  {
212    for ( size_t i=0 ; i<size_tab ; i++ ) {
213      if( !tab[i].valid ) {
214        tab[i].valid            = true;
215        tab[i].update           = update;
216        tab[i].brdcast      = brdcast;
217        tab[i].rsp          = rsp;
218        tab[i].srcid            = (size_t) srcid;
219        tab[i].trdid            = (size_t) trdid;
220        tab[i].pktid            = (size_t) pktid;
221        tab[i].nline            = (addr_t) nline;
222        tab[i].count            = (size_t) count;
223        index                       = i;
224        return true;
225      }
226    }
227    return false;
228  } // end set()
229
230  /////////////////////////////////////////////////////////////////////
231  // The decrement() function decrements the counter for a given entry.
232  // Arguments :
233  // - index   : the index of the entry
234  // - counter : (return argument) value of the counter after decrement
235  // This function returns true if the entry is valid.
236  /////////////////////////////////////////////////////////////////////
237  bool decrement( const size_t index,
238      size_t &counter )
239  {
240    assert((index<size_tab) && "Bad Update Tab Entry");
241    if ( tab[index].valid ) {
242      tab[index].count--;
243      counter = tab[index].count;
244      return true;
245    } else {
246      return false;
247    }
248  }
249
250  /////////////////////////////////////////////////////////////////////
251  // The is_full() function returns true if the table is full
252  /////////////////////////////////////////////////////////////////////
253  bool is_full()
254  {
255    for(size_t i = 0 ; i < size_tab ; i++){
256      if(!tab[i].valid){
257        return false;
258      }
259    }
260    return true;
261  }
262
263  /////////////////////////////////////////////////////////////////////
264  // The need_rsp() function returns the need of a response
265  // Arguments :
266  // - index : the index of the entry
267  /////////////////////////////////////////////////////////////////////
268  bool need_rsp(const size_t index)
269  {
270    assert(index<size_tab && "Bad Update Tab Entry");
271    return tab[index].rsp;     
272  }
273
274  /////////////////////////////////////////////////////////////////////
275  // The is_update() function returns the transaction type
276  // Arguments :
277  // - index : the index of the entry
278  /////////////////////////////////////////////////////////////////////
279  bool is_brdcast(const size_t index)
280  {
281    assert(index<size_tab && "Bad Update Tab Entry");
282    return tab[index].brdcast; 
283  }
284
285  /////////////////////////////////////////////////////////////////////
286  // The is_update() function returns the transaction type
287  // Arguments :
288  // - index : the index of the entry
289  /////////////////////////////////////////////////////////////////////
290  bool is_update(const size_t index)
291  {
292    assert(index<size_tab && "Bad Update Tab Entry");
293    return tab[index].update;   
294  }
295
296  /////////////////////////////////////////////////////////////////////
297  // The srcid() function returns the srcid value
298  // Arguments :
299  // - index : the index of the entry
300  /////////////////////////////////////////////////////////////////////
301  size_t srcid(const size_t index)
302  {
303    assert(index<size_tab && "Bad Update Tab Entry");
304    return tab[index].srcid;   
305  }
306
307  /////////////////////////////////////////////////////////////////////
308  // The trdid() function returns the trdid value
309  // Arguments :
310  // - index : the index of the entry
311  /////////////////////////////////////////////////////////////////////
312  size_t trdid(const size_t index)
313  {
314    assert(index<size_tab && "Bad Update Tab Entry");
315    return tab[index].trdid;   
316  }
317
318  /////////////////////////////////////////////////////////////////////
319  // The pktid() function returns the pktid value
320  // Arguments :
321  // - index : the index of the entry
322  /////////////////////////////////////////////////////////////////////
323  size_t pktid(const size_t index)
324  {
325    assert(index<size_tab && "Bad Update Tab Entry");
326    return tab[index].pktid;   
327  }
328
329  /////////////////////////////////////////////////////////////////////
330  // The nline() function returns the nline value
331  // Arguments :
332  // - index : the index of the entry
333  /////////////////////////////////////////////////////////////////////
334  addr_t nline(const size_t index)
335  {
336    assert(index<size_tab && "Bad Update Tab Entry");
337    return tab[index].nline;
338  }
339
340  /////////////////////////////////////////////////////////////////////
341  // The search_inval() function returns the index of the entry in UPT
342  // Arguments :
343  // - nline : the line number of the entry in the directory
344  /////////////////////////////////////////////////////////////////////
345  bool search_inval(const addr_t nline,size_t &index)
346  {
347    size_t i ;
348
349    for (i = 0 ; i < size_tab ; i++){
350      if((tab[i].nline == nline) && tab[i].valid){
351        if(!tab[i].update){
352          index = i ;
353          return true;
354        }
355      }
356    }
357    return false;
358  }
359
360  /////////////////////////////////////////////////////////////////////
361  // The read_nline() function returns the index of the entry in UPT
362  // Arguments :
363  // - nline : the line number of the entry in the directory
364  /////////////////////////////////////////////////////////////////////
365  bool read_nline(const addr_t nline,size_t &index)
366  {
367    size_t i ;
368
369    for (i = 0 ; i < size_tab ; i++){
370      if((tab[i].nline == nline) && tab[i].valid){
371        index = i ;
372        return true;
373      }
374    }
375    return false;
376  }
377
378  /////////////////////////////////////////////////////////////////////
379  // The clear() function erases an entry of the tab
380  // Arguments :
381  // - index : the index of the entry
382  /////////////////////////////////////////////////////////////////////       
383  void clear(const size_t index)
384  {
385    assert(index<size_tab && "Bad Update Tab Entry");
386    tab[index].valid=false;
387    return;     
388  }
389
390};
391
392#endif
393
394// Local Variables:
395// tab-width: 4
396// c-basic-offset: 4
397// c-file-offsets:((innamespace . 0)(inline-open . 0))
398// indent-tabs-mode: nil
399// End:
400
401// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
402
Note: See TracBrowser for help on using the repository browser.