| 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 | //////////////////////////////////////////////////////////////////////// |
|---|
| 12 | class 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 | //////////////////////////////////////////////////////////////////////// |
|---|
| 126 | class 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 print() function diplays the tab content |
|---|
| 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 is_not_empty() function returns true if the table is not empty |
|---|
| 265 | ///////////////////////////////////////////////////////////////////// |
|---|
| 266 | bool is_not_empty() |
|---|
| 267 | { |
|---|
| 268 | for(size_t i = 0 ; i < size_tab ; i++){ |
|---|
| 269 | if(tab[i].valid){ |
|---|
| 270 | return true; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | return false; |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | ///////////////////////////////////////////////////////////////////// |
|---|
| 277 | // The need_rsp() function returns the need of a response |
|---|
| 278 | // Arguments : |
|---|
| 279 | // - index : the index of the entry |
|---|
| 280 | ///////////////////////////////////////////////////////////////////// |
|---|
| 281 | bool need_rsp(const size_t index) |
|---|
| 282 | { |
|---|
| 283 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 284 | return tab[index].rsp; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | ///////////////////////////////////////////////////////////////////// |
|---|
| 288 | // The is_update() function returns the transaction type |
|---|
| 289 | // Arguments : |
|---|
| 290 | // - index : the index of the entry |
|---|
| 291 | ///////////////////////////////////////////////////////////////////// |
|---|
| 292 | bool is_brdcast(const size_t index) |
|---|
| 293 | { |
|---|
| 294 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 295 | return tab[index].brdcast; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | ///////////////////////////////////////////////////////////////////// |
|---|
| 299 | // The is_update() function returns the transaction type |
|---|
| 300 | // Arguments : |
|---|
| 301 | // - index : the index of the entry |
|---|
| 302 | ///////////////////////////////////////////////////////////////////// |
|---|
| 303 | bool is_update(const size_t index) |
|---|
| 304 | { |
|---|
| 305 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 306 | return tab[index].update; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | ///////////////////////////////////////////////////////////////////// |
|---|
| 310 | // The srcid() function returns the srcid value |
|---|
| 311 | // Arguments : |
|---|
| 312 | // - index : the index of the entry |
|---|
| 313 | ///////////////////////////////////////////////////////////////////// |
|---|
| 314 | size_t srcid(const size_t index) |
|---|
| 315 | { |
|---|
| 316 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 317 | return tab[index].srcid; |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | ///////////////////////////////////////////////////////////////////// |
|---|
| 321 | // The trdid() function returns the trdid value |
|---|
| 322 | // Arguments : |
|---|
| 323 | // - index : the index of the entry |
|---|
| 324 | ///////////////////////////////////////////////////////////////////// |
|---|
| 325 | size_t trdid(const size_t index) |
|---|
| 326 | { |
|---|
| 327 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 328 | return tab[index].trdid; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | ///////////////////////////////////////////////////////////////////// |
|---|
| 332 | // The pktid() function returns the pktid value |
|---|
| 333 | // Arguments : |
|---|
| 334 | // - index : the index of the entry |
|---|
| 335 | ///////////////////////////////////////////////////////////////////// |
|---|
| 336 | size_t pktid(const size_t index) |
|---|
| 337 | { |
|---|
| 338 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 339 | return tab[index].pktid; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | ///////////////////////////////////////////////////////////////////// |
|---|
| 343 | // The nline() function returns the nline value |
|---|
| 344 | // Arguments : |
|---|
| 345 | // - index : the index of the entry |
|---|
| 346 | ///////////////////////////////////////////////////////////////////// |
|---|
| 347 | addr_t nline(const size_t index) |
|---|
| 348 | { |
|---|
| 349 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 350 | return tab[index].nline; |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | ///////////////////////////////////////////////////////////////////// |
|---|
| 354 | // The search_inval() function returns the index of the entry in UPT |
|---|
| 355 | // Arguments : |
|---|
| 356 | // - nline : the line number of the entry in the directory |
|---|
| 357 | ///////////////////////////////////////////////////////////////////// |
|---|
| 358 | bool search_inval(const addr_t nline,size_t &index) |
|---|
| 359 | { |
|---|
| 360 | size_t i ; |
|---|
| 361 | |
|---|
| 362 | for (i = 0 ; i < size_tab ; i++){ |
|---|
| 363 | if((tab[i].nline == nline) && tab[i].valid){ |
|---|
| 364 | if(!tab[i].update){ |
|---|
| 365 | index = i ; |
|---|
| 366 | return true; |
|---|
| 367 | } |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | return false; |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | ///////////////////////////////////////////////////////////////////// |
|---|
| 374 | // The read_nline() function returns the index of the entry in UPT |
|---|
| 375 | // Arguments : |
|---|
| 376 | // - nline : the line number of the entry in the directory |
|---|
| 377 | ///////////////////////////////////////////////////////////////////// |
|---|
| 378 | bool read_nline(const addr_t nline,size_t &index) |
|---|
| 379 | { |
|---|
| 380 | size_t i ; |
|---|
| 381 | |
|---|
| 382 | for (i = 0 ; i < size_tab ; i++){ |
|---|
| 383 | if((tab[i].nline == nline) && tab[i].valid){ |
|---|
| 384 | index = i ; |
|---|
| 385 | return true; |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | return false; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | ///////////////////////////////////////////////////////////////////// |
|---|
| 392 | // The clear() function erases an entry of the tab |
|---|
| 393 | // Arguments : |
|---|
| 394 | // - index : the index of the entry |
|---|
| 395 | ///////////////////////////////////////////////////////////////////// |
|---|
| 396 | void clear(const size_t index) |
|---|
| 397 | { |
|---|
| 398 | assert(index<size_tab && "Bad Update Tab Entry"); |
|---|
| 399 | tab[index].valid=false; |
|---|
| 400 | return; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | }; |
|---|
| 404 | |
|---|
| 405 | #endif |
|---|
| 406 | |
|---|
| 407 | // Local Variables: |
|---|
| 408 | // tab-width: 4 |
|---|
| 409 | // c-basic-offset: 4 |
|---|
| 410 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 411 | // indent-tabs-mode: nil |
|---|
| 412 | // End: |
|---|
| 413 | |
|---|
| 414 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 415 | |
|---|