112607Sodanrc@yahoo.com.br/** 212607Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312607Sodanrc@yahoo.com.br * All rights reserved. 412607Sodanrc@yahoo.com.br * 512607Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612607Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712607Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812607Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912607Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012607Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112607Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212607Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312607Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412607Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512607Sodanrc@yahoo.com.br * 1612607Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712607Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812607Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912607Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012607Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112607Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212607Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312607Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412607Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512607Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612607Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712607Sodanrc@yahoo.com.br * 2812607Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912607Sodanrc@yahoo.com.br */ 3012607Sodanrc@yahoo.com.br 3112607Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/fifo_rp.hh" 3212607Sodanrc@yahoo.com.br 3312727Snikos.nikoleris@arm.com#include <cassert> 3412684Sodanrc@yahoo.com.br#include <memory> 3512607Sodanrc@yahoo.com.br 3612727Snikos.nikoleris@arm.com#include "params/FIFORP.hh" 3712727Snikos.nikoleris@arm.com 3812607Sodanrc@yahoo.com.brFIFORP::FIFORP(const Params *p) 3912607Sodanrc@yahoo.com.br : BaseReplacementPolicy(p) 4012607Sodanrc@yahoo.com.br{ 4112607Sodanrc@yahoo.com.br} 4212607Sodanrc@yahoo.com.br 4312684Sodanrc@yahoo.com.brvoid 4412684Sodanrc@yahoo.com.brFIFORP::invalidate(const std::shared_ptr<ReplacementData>& replacement_data) 4512684Sodanrc@yahoo.com.brconst 4612684Sodanrc@yahoo.com.br{ 4712684Sodanrc@yahoo.com.br // Reset insertion tick 4812684Sodanrc@yahoo.com.br std::static_pointer_cast<FIFOReplData>( 4912684Sodanrc@yahoo.com.br replacement_data)->tickInserted = Tick(0); 5012684Sodanrc@yahoo.com.br} 5112684Sodanrc@yahoo.com.br 5212684Sodanrc@yahoo.com.brvoid 5312684Sodanrc@yahoo.com.brFIFORP::touch(const std::shared_ptr<ReplacementData>& replacement_data) const 5412684Sodanrc@yahoo.com.br{ 5512684Sodanrc@yahoo.com.br // A touch does not modify the insertion tick 5612684Sodanrc@yahoo.com.br} 5712684Sodanrc@yahoo.com.br 5812684Sodanrc@yahoo.com.brvoid 5912684Sodanrc@yahoo.com.brFIFORP::reset(const std::shared_ptr<ReplacementData>& replacement_data) const 6012684Sodanrc@yahoo.com.br{ 6112684Sodanrc@yahoo.com.br // Set insertion tick 6212684Sodanrc@yahoo.com.br std::static_pointer_cast<FIFOReplData>( 6312684Sodanrc@yahoo.com.br replacement_data)->tickInserted = curTick(); 6412684Sodanrc@yahoo.com.br} 6512684Sodanrc@yahoo.com.br 6612684Sodanrc@yahoo.com.brReplaceableEntry* 6712684Sodanrc@yahoo.com.brFIFORP::getVictim(const ReplacementCandidates& candidates) const 6812607Sodanrc@yahoo.com.br{ 6912607Sodanrc@yahoo.com.br // There must be at least one replacement candidate 7012607Sodanrc@yahoo.com.br assert(candidates.size() > 0); 7112607Sodanrc@yahoo.com.br 7212607Sodanrc@yahoo.com.br // Visit all candidates to find victim 7312684Sodanrc@yahoo.com.br ReplaceableEntry* victim = candidates[0]; 7412607Sodanrc@yahoo.com.br for (const auto& candidate : candidates) { 7512684Sodanrc@yahoo.com.br // Update victim entry if necessary 7612684Sodanrc@yahoo.com.br if (std::static_pointer_cast<FIFOReplData>( 7712684Sodanrc@yahoo.com.br candidate->replacementData)->tickInserted < 7812684Sodanrc@yahoo.com.br std::static_pointer_cast<FIFOReplData>( 7912684Sodanrc@yahoo.com.br victim->replacementData)->tickInserted) { 8012684Sodanrc@yahoo.com.br victim = candidate; 8112607Sodanrc@yahoo.com.br } 8212607Sodanrc@yahoo.com.br } 8312607Sodanrc@yahoo.com.br 8412684Sodanrc@yahoo.com.br return victim; 8512684Sodanrc@yahoo.com.br} 8612607Sodanrc@yahoo.com.br 8712684Sodanrc@yahoo.com.brstd::shared_ptr<ReplacementData> 8812684Sodanrc@yahoo.com.brFIFORP::instantiateEntry() 8912684Sodanrc@yahoo.com.br{ 9012684Sodanrc@yahoo.com.br return std::shared_ptr<ReplacementData>(new FIFOReplData()); 9112607Sodanrc@yahoo.com.br} 9212607Sodanrc@yahoo.com.br 9312607Sodanrc@yahoo.com.brFIFORP* 9412607Sodanrc@yahoo.com.brFIFORPParams::create() 9512607Sodanrc@yahoo.com.br{ 9612607Sodanrc@yahoo.com.br return new FIFORP(this); 9712607Sodanrc@yahoo.com.br} 98