diff options
Diffstat (limited to 'src/mem/cache/tags/random_repl.cc')
-rw-r--r-- | src/mem/cache/tags/random_repl.cc | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/mem/cache/tags/random_repl.cc b/src/mem/cache/tags/random_repl.cc index e7422a335..9f1ef800a 100644 --- a/src/mem/cache/tags/random_repl.cc +++ b/src/mem/cache/tags/random_repl.cc @@ -54,14 +54,22 @@ CacheBlk* RandomRepl::findVictim(Addr addr) { CacheBlk *blk = BaseSetAssoc::findVictim(addr); + unsigned set = extractSet(addr); // if all blocks are valid, pick a replacement at random - if (blk->isValid()) { + if (blk && blk->isValid()) { // find a random index within the bounds of the set int idx = random_mt.random<int>(0, assoc - 1); + blk = sets[set].blks[idx]; + // Enforce allocation limit + while (blk->way >= allocAssoc) { + idx = (idx + 1) % assoc; + blk = sets[set].blks[idx]; + } + assert(idx < assoc); assert(idx >= 0); - blk = sets[extractSet(addr)].blks[idx]; + assert(blk->way < allocAssoc); DPRINTF(CacheRepl, "set %x: selecting blk %x for replacement\n", blk->set, regenerateBlkAddr(blk->tag, blk->set)); |