113219Sodanrc@yahoo.com.br/* 213219Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 313219Sodanrc@yahoo.com.br * Copyright (c) 2012-2014,2017 ARM Limited 413219Sodanrc@yahoo.com.br * All rights reserved. 513219Sodanrc@yahoo.com.br * 613219Sodanrc@yahoo.com.br * The license below extends only to copyright in the software and shall 713219Sodanrc@yahoo.com.br * not be construed as granting a license to any other intellectual 813219Sodanrc@yahoo.com.br * property including but not limited to intellectual property relating 913219Sodanrc@yahoo.com.br * to a hardware implementation of the functionality of the software 1013219Sodanrc@yahoo.com.br * licensed hereunder. You may use the software subject to the license 1113219Sodanrc@yahoo.com.br * terms below provided that you ensure that this notice is replicated 1213219Sodanrc@yahoo.com.br * unmodified and in its entirety in all distributions of the software, 1313219Sodanrc@yahoo.com.br * modified or unmodified, in source code or in binary form. 1413219Sodanrc@yahoo.com.br * 1513219Sodanrc@yahoo.com.br * Copyright (c) 2003-2005,2014 The Regents of The University of Michigan 1613219Sodanrc@yahoo.com.br * All rights reserved. 1713219Sodanrc@yahoo.com.br * 1813219Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 1913219Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 2013219Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 2113219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 2213219Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 2313219Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 2413219Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 2513219Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 2613219Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 2713219Sodanrc@yahoo.com.br * this software without specific prior written permission. 2813219Sodanrc@yahoo.com.br * 2913219Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3013219Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3113219Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3213219Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3313219Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3413219Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3513219Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3613219Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3713219Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3813219Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3913219Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4013219Sodanrc@yahoo.com.br * 4113219Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 4213219Sodanrc@yahoo.com.br * Erik Hallnor 4313219Sodanrc@yahoo.com.br */ 4413219Sodanrc@yahoo.com.br 4513219Sodanrc@yahoo.com.br/** 4613219Sodanrc@yahoo.com.br * @file 4713219Sodanrc@yahoo.com.br * Definitions of a common framework for indexing policies. 4813219Sodanrc@yahoo.com.br */ 4913219Sodanrc@yahoo.com.br 5013219Sodanrc@yahoo.com.br#include "mem/cache/tags/indexing_policies/base.hh" 5113219Sodanrc@yahoo.com.br 5213219Sodanrc@yahoo.com.br#include <cstdlib> 5313219Sodanrc@yahoo.com.br 5413219Sodanrc@yahoo.com.br#include "base/intmath.hh" 5513219Sodanrc@yahoo.com.br#include "base/logging.hh" 5613225Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/replaceable_entry.hh" 5713219Sodanrc@yahoo.com.br 5813219Sodanrc@yahoo.com.brBaseIndexingPolicy::BaseIndexingPolicy(const Params *p) 5913219Sodanrc@yahoo.com.br : SimObject(p), assoc(p->assoc), 6013219Sodanrc@yahoo.com.br numSets(p->size / (p->entry_size * assoc)), 6113219Sodanrc@yahoo.com.br setShift(floorLog2(p->entry_size)), setMask(numSets - 1), sets(numSets), 6213219Sodanrc@yahoo.com.br tagShift(setShift + floorLog2(numSets)) 6313219Sodanrc@yahoo.com.br{ 6413219Sodanrc@yahoo.com.br fatal_if(!isPowerOf2(numSets), "# of sets must be non-zero and a power " \ 6513219Sodanrc@yahoo.com.br "of 2"); 6613219Sodanrc@yahoo.com.br fatal_if(assoc <= 0, "associativity must be greater than zero"); 6713219Sodanrc@yahoo.com.br 6813219Sodanrc@yahoo.com.br // Make space for the entries 6913219Sodanrc@yahoo.com.br for (uint32_t i = 0; i < numSets; ++i) { 7013219Sodanrc@yahoo.com.br sets[i].resize(assoc); 7113219Sodanrc@yahoo.com.br } 7213219Sodanrc@yahoo.com.br} 7313219Sodanrc@yahoo.com.br 7413219Sodanrc@yahoo.com.brReplaceableEntry* 7513219Sodanrc@yahoo.com.brBaseIndexingPolicy::getEntry(const uint32_t set, const uint32_t way) const 7613219Sodanrc@yahoo.com.br{ 7713219Sodanrc@yahoo.com.br return sets[set][way]; 7813219Sodanrc@yahoo.com.br} 7913219Sodanrc@yahoo.com.br 8013219Sodanrc@yahoo.com.brvoid 8113219Sodanrc@yahoo.com.brBaseIndexingPolicy::setEntry(ReplaceableEntry* entry, const uint64_t index) 8213219Sodanrc@yahoo.com.br{ 8313219Sodanrc@yahoo.com.br // Calculate set and way from entry index 8413219Sodanrc@yahoo.com.br const std::lldiv_t div_result = std::div((long long)index, assoc); 8513219Sodanrc@yahoo.com.br const uint32_t set = div_result.quot; 8613219Sodanrc@yahoo.com.br const uint32_t way = div_result.rem; 8713219Sodanrc@yahoo.com.br 8813219Sodanrc@yahoo.com.br // Sanity check 8913219Sodanrc@yahoo.com.br assert(set < numSets); 9013219Sodanrc@yahoo.com.br 9113219Sodanrc@yahoo.com.br // Assign a free pointer 9213219Sodanrc@yahoo.com.br sets[set][way] = entry; 9313219Sodanrc@yahoo.com.br 9413219Sodanrc@yahoo.com.br // Inform the entry its position 9513219Sodanrc@yahoo.com.br entry->setPosition(set, way); 9613219Sodanrc@yahoo.com.br} 9713219Sodanrc@yahoo.com.br 9813219Sodanrc@yahoo.com.brAddr 9913219Sodanrc@yahoo.com.brBaseIndexingPolicy::extractTag(const Addr addr) const 10013219Sodanrc@yahoo.com.br{ 10113219Sodanrc@yahoo.com.br return (addr >> tagShift); 10213219Sodanrc@yahoo.com.br} 103