32a33,35
> #include <memory>
>
> #include "base/logging.hh" // For fatal_if
34d36
< #include "debug/CacheRepl.hh"
40,42c42
< if (maxRRPV == 0){
< fatal("max_RRPV should be greater than zero.\n");
< }
---
> fatal_if(maxRRPV <= 0, "max_RRPV should be greater than zero.\n");
46c46,47
< BRRIPRP::touch(CacheBlk *blk)
---
> BRRIPRP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data)
> const
48c49,50
< BaseReplacementPolicy::touch(blk);
---
> std::shared_ptr<BRRIPReplData> casted_replacement_data =
> std::static_pointer_cast<BRRIPReplData>(replacement_data);
49a52,61
> // Set RRPV to an invalid distance
> casted_replacement_data->rrpv = maxRRPV + 1;
> }
>
> void
> BRRIPRP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const
> {
> std::shared_ptr<BRRIPReplData> casted_replacement_data =
> std::static_pointer_cast<BRRIPReplData>(replacement_data);
>
51,52c63,64
< // Every hit in HP mode makes the block the last to be evicted, while
< // in FP mode a hit makes the block less likely to be evicted
---
> // Every hit in HP mode makes the entry the last to be evicted, while
> // in FP mode a hit makes the entry less likely to be evicted
54,56c66,68
< blk->rrpv = 0;
< } else if (blk->rrpv > 0) {
< blk->rrpv--;
---
> casted_replacement_data->rrpv = 0;
> } else if (casted_replacement_data->rrpv > 0) {
> casted_replacement_data->rrpv--;
61c73
< BRRIPRP::reset(CacheBlk *blk)
---
> BRRIPRP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const
63c75,76
< BaseReplacementPolicy::reset(blk);
---
> std::shared_ptr<BRRIPReplData> casted_replacement_data =
> std::static_pointer_cast<BRRIPReplData>(replacement_data);
66c79
< // Blocks are inserted as "long re-reference" if lower than btp,
---
> // Replacement data is inserted as "long re-reference" if lower than btp,
69c82
< blk->rrpv = maxRRPV-1;
---
> casted_replacement_data->rrpv = maxRRPV-1;
71c84
< blk->rrpv = maxRRPV;
---
> casted_replacement_data->rrpv = maxRRPV;
75,76c88,89
< CacheBlk*
< BRRIPRP::getVictim(const ReplacementCandidates& candidates)
---
> ReplaceableEntry*
> BRRIPRP::getVictim(const ReplacementCandidates& candidates) const
81,82c94,101
< // Use visitor to search for the victim
< CacheBlk* blk = candidates[0];
---
> // Use first candidate as dummy victim
> ReplaceableEntry* victim = candidates[0];
>
> // Store victim->rrpv in a variable to improve code readability
> int victim_RRPV = std::static_pointer_cast<BRRIPReplData>(
> victim->replacementData)->rrpv;
>
> // Visit all candidates to find victim
84,91c103,113
< // Stop iteration if found an invalid block
< if (!candidate->isValid()) {
< blk = candidate;
< blk->rrpv = maxRRPV;
< break;
< // Update victim block if necessary
< } else if (candidate->rrpv > blk->rrpv) {
< blk = candidate;
---
> // Get candidate's rrpv
> int candidate_RRPV = std::static_pointer_cast<BRRIPReplData>(
> candidate->replacementData)->rrpv;
>
> // Stop searching for victims if an invalid entry is found
> if (candidate_RRPV == maxRRPV + 1) {
> return candidate;
> // Update victim entry if necessary
> } else if (candidate_RRPV > victim_RRPV) {
> victim = candidate;
> victim_RRPV = candidate_RRPV;
95,96c117,119
< // Make sure we don't have an invalid rrpv
< assert(blk->rrpv <= maxRRPV);
---
> // Get difference of victim's RRPV to the highest possible RRPV in
> // order to update the RRPV of all the other entries accordingly
> int diff = maxRRPV - victim_RRPV;
98,101d120
< // Get difference of block's RRPV to the highest possible RRPV in
< // order to update the RRPV of all the other blocks accordingly
< unsigned diff = maxRRPV - blk->rrpv;
<
106,107c125,126
< // Update the block's RPPV with the new value
< candidate->rrpv += diff;
---
> std::static_pointer_cast<BRRIPReplData>(
> candidate->replacementData)->rrpv += diff;
111,112c130,131
< DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
< blk->set, blk->way);
---
> return victim;
> }
114c133,136
< return blk;
---
> std::shared_ptr<ReplacementData>
> BRRIPRP::instantiateEntry()
> {
> return std::shared_ptr<ReplacementData>(new BRRIPReplData(maxRRPV));