110970Sdavid.hashe@amd.com/*
210970Sdavid.hashe@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc
310970Sdavid.hashe@amd.com * All rights reserved.
410970Sdavid.hashe@amd.com *
510970Sdavid.hashe@amd.com * Redistribution and use in source and binary forms, with or without
610970Sdavid.hashe@amd.com * modification, are permitted provided that the following conditions are
710970Sdavid.hashe@amd.com * met: redistributions of source code must retain the above copyright
810970Sdavid.hashe@amd.com * notice, this list of conditions and the following disclaimer;
910970Sdavid.hashe@amd.com * redistributions in binary form must reproduce the above copyright
1010970Sdavid.hashe@amd.com * notice, this list of conditions and the following disclaimer in the
1110970Sdavid.hashe@amd.com * documentation and/or other materials provided with the distribution;
1210970Sdavid.hashe@amd.com * neither the name of the copyright holders nor the names of its
1310970Sdavid.hashe@amd.com * contributors may be used to endorse or promote products derived from
1410970Sdavid.hashe@amd.com * this software without specific prior written permission.
1510970Sdavid.hashe@amd.com *
1610970Sdavid.hashe@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710970Sdavid.hashe@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810970Sdavid.hashe@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910970Sdavid.hashe@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010970Sdavid.hashe@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110970Sdavid.hashe@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210970Sdavid.hashe@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310970Sdavid.hashe@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410970Sdavid.hashe@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510970Sdavid.hashe@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610970Sdavid.hashe@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710970Sdavid.hashe@amd.com *
2810970Sdavid.hashe@amd.com * Author: Derek Hower
2910970Sdavid.hashe@amd.com */
3010970Sdavid.hashe@amd.com
3110970Sdavid.hashe@amd.com#include "mem/ruby/structures/LRUPolicy.hh"
3210970Sdavid.hashe@amd.com
3310970Sdavid.hashe@amd.comLRUPolicy::LRUPolicy(const Params * p)
3410970Sdavid.hashe@amd.com    : AbstractReplacementPolicy(p)
3510970Sdavid.hashe@amd.com{
3610970Sdavid.hashe@amd.com}
3710970Sdavid.hashe@amd.com
3810970Sdavid.hashe@amd.com
3910970Sdavid.hashe@amd.comLRUPolicy::~LRUPolicy()
4010970Sdavid.hashe@amd.com{
4110970Sdavid.hashe@amd.com}
4210970Sdavid.hashe@amd.com
4310970Sdavid.hashe@amd.comLRUPolicy *
4410970Sdavid.hashe@amd.comLRUReplacementPolicyParams::create()
4510970Sdavid.hashe@amd.com{
4610970Sdavid.hashe@amd.com    return new LRUPolicy(this);
4710970Sdavid.hashe@amd.com}
4810970Sdavid.hashe@amd.com
4910970Sdavid.hashe@amd.com
5010970Sdavid.hashe@amd.comvoid
5111061Snilay@cs.wisc.eduLRUPolicy::touch(int64_t set, int64_t index, Tick time)
5210970Sdavid.hashe@amd.com{
5310970Sdavid.hashe@amd.com    assert(index >= 0 && index < m_assoc);
5410970Sdavid.hashe@amd.com    assert(set >= 0 && set < m_num_sets);
5510970Sdavid.hashe@amd.com
5610970Sdavid.hashe@amd.com    m_last_ref_ptr[set][index] = time;
5710970Sdavid.hashe@amd.com}
5810970Sdavid.hashe@amd.com
5911061Snilay@cs.wisc.eduint64_t
6011061Snilay@cs.wisc.eduLRUPolicy::getVictim(int64_t set) const
6110970Sdavid.hashe@amd.com{
6210970Sdavid.hashe@amd.com    Tick time, smallest_time;
6311061Snilay@cs.wisc.edu    int64_t smallest_index = 0;
6410970Sdavid.hashe@amd.com    smallest_time = m_last_ref_ptr[set][0];
6510970Sdavid.hashe@amd.com
6610970Sdavid.hashe@amd.com    for (unsigned i = 0; i < m_assoc; i++) {
6710970Sdavid.hashe@amd.com        time = m_last_ref_ptr[set][i];
6810970Sdavid.hashe@amd.com
6910970Sdavid.hashe@amd.com        if (time < smallest_time) {
7010970Sdavid.hashe@amd.com            smallest_index = i;
7110970Sdavid.hashe@amd.com            smallest_time = time;
7210970Sdavid.hashe@amd.com        }
7310970Sdavid.hashe@amd.com    }
7410970Sdavid.hashe@amd.com
7510970Sdavid.hashe@amd.com    return smallest_index;
7610970Sdavid.hashe@amd.com}
77