1/* 2 * Copyright (c) 2013,2016-2017 ARM Limited 3 * All rights reserved. 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 50 unchanged lines hidden (view full) --- 59 if (!isPowerOf2(blkSize)) 60 fatal("cache block size (in bytes) `%d' must be a power of two", 61 blkSize); 62 if (!isPowerOf2(size)) 63 fatal("Cache Size must be power of 2 for now"); 64 65 // Track all cache sizes from 128K up by powers of 2 66 numCaches = floorLog2(size) - 17; |
67 if (numCaches > 0){ |
68 cacheBoundaries = new FALRUBlk *[numCaches]; 69 cacheMask = (ULL(1) << numCaches) - 1; 70 } else { 71 cacheMask = 0; 72 } 73 74 blks = new FALRUBlk[numBlocks]; 75 head = &(blks[0]); --- 83 unchanged lines hidden (view full) --- 159 return (*iter).second; 160 } 161 return nullptr; 162} 163 164void 165FALRU::invalidate(CacheBlk *blk) 166{ |
167 BaseTags::invalidate(blk); 168 |
169 // Move the block to the tail to make it the next victim 170 moveToTail((FALRUBlk*)blk); 171 |
172 // Erase block entry in the hash table 173 tagHash.erase(blk->tag); 174} 175 176CacheBlk* 177FALRU::accessBlock(Addr addr, bool is_secure, Cycles &lat) 178{ 179 return accessBlock(addr, is_secure, lat, 0); --- 93 unchanged lines hidden (view full) --- 273 tagHash[falruBlk->tag] = falruBlk; 274 275 //assert(check()); 276} 277 278void 279FALRU::moveToHead(FALRUBlk *blk) 280{ |
281 // If block is not already head, do the moving |
282 if (blk != head) { |
283 // Get all caches that this block does not reside in 284 int updateMask = blk->inCache ^ cacheMask; 285 286 // Update boundaries for all cache sizes 287 for (unsigned i = 0; i < numCaches; i++){ 288 // If block has been moved to a place before this boundary, 289 // all blocks in it will be pushed towards the LRU position, 290 // making one leave the boundary 291 if ((1U<<i) & updateMask) { 292 cacheBoundaries[i]->inCache &= ~(1U<<i); 293 cacheBoundaries[i] = cacheBoundaries[i]->prev; 294 // If the block resides exactly at this boundary, the previous 295 // block is pushed to its position 296 } else if (cacheBoundaries[i] == blk) { 297 cacheBoundaries[i] = blk->prev; 298 } 299 } 300 301 // Make block reside in all caches 302 blk->inCache = cacheMask; 303 304 // If block is tail, set previous block as new tail |
305 if (blk == tail){ 306 assert(blk->next == nullptr); 307 tail = blk->prev; 308 tail->next = nullptr; |
309 // Inform block's surrounding blocks that it has been moved |
310 } else { 311 blk->prev->next = blk->next; 312 blk->next->prev = blk->prev; 313 } |
314 315 // Swap pointers |
316 blk->next = head; 317 blk->prev = nullptr; 318 head->prev = blk; 319 head = blk; 320 } 321} 322 |
323void 324FALRU::moveToTail(FALRUBlk *blk) 325{ 326 // If block is not already tail, do the moving 327 if (blk != tail) { 328 // Update boundaries for all cache sizes 329 for (unsigned i = 0; i < numCaches; i++){ 330 // If block has been moved to a place after this boundary, 331 // all blocks in it will be pushed towards the MRU position, 332 // making one enter the boundary 333 if ((1U<<i) & blk->inCache) { 334 // If the first block after the boundary is the block, 335 // get its successor 336 if (cacheBoundaries[i]->next == blk){ 337 cacheBoundaries[i] = cacheBoundaries[i]->next->next; 338 } else { 339 cacheBoundaries[i] = cacheBoundaries[i]->next; 340 } 341 cacheBoundaries[i]->inCache |= (1U<<i); 342 } 343 } 344 345 // Make block reside in the last cache only 346 blk->inCache = 0; 347 348 // If block is head, set next block as new head 349 if (blk == head){ 350 assert(blk->prev == nullptr); 351 head = blk->next; 352 head->prev = nullptr; 353 // Inform block's surrounding blocks that it has been moved 354 } else { 355 blk->prev->next = blk->next; 356 blk->next->prev = blk->prev; 357 } 358 359 // Swap pointers 360 blk->prev = tail; 361 blk->next = nullptr; 362 tail->next = blk; 363 tail = blk; 364 } 365} 366 |
367bool 368FALRU::check() 369{ 370 FALRUBlk* blk = head; 371 int tot_size = 0; 372 int boundary = 1<<17; 373 int j = 0; 374 int flags = cacheMask; --- 24 unchanged lines hidden --- |