source: branches/RWT/modules/vci_mem_cache/caba/source/include/update_tab.h @ 814

Last change on this file since 814 was 814, checked in by devigne, 10 years ago

RWT commit : Cosmetic (Remove trailing whitespace)

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