110263Satgutier@umich.edu/* 210941Sdavid.guillen@arm.com * Copyright (c) 2012-2014 ARM Limited 310263Satgutier@umich.edu * All rights reserved. 410263Satgutier@umich.edu * 510263Satgutier@umich.edu * The license below extends only to copyright in the software and shall 610263Satgutier@umich.edu * not be construed as granting a license to any other intellectual 710263Satgutier@umich.edu * property including but not limited to intellectual property relating 810263Satgutier@umich.edu * to a hardware implementation of the functionality of the software 910263Satgutier@umich.edu * licensed hereunder. You may use the software subject to the license 1010263Satgutier@umich.edu * terms below provided that you ensure that this notice is replicated 1110263Satgutier@umich.edu * unmodified and in its entirety in all distributions of the software, 1210263Satgutier@umich.edu * modified or unmodified, in source code or in binary form. 1310263Satgutier@umich.edu * 1410263Satgutier@umich.edu * Copyright (c) 2003-2005,2014 The Regents of The University of Michigan 1510263Satgutier@umich.edu * All rights reserved. 1610263Satgutier@umich.edu * 1710263Satgutier@umich.edu * Redistribution and use in source and binary forms, with or without 1810263Satgutier@umich.edu * modification, are permitted provided that the following conditions are 1910263Satgutier@umich.edu * met: redistributions of source code must retain the above copyright 2010263Satgutier@umich.edu * notice, this list of conditions and the following disclaimer; 2110263Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright 2210263Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the 2310263Satgutier@umich.edu * documentation and/or other materials provided with the distribution; 2410263Satgutier@umich.edu * neither the name of the copyright holders nor the names of its 2510263Satgutier@umich.edu * contributors may be used to endorse or promote products derived from 2610263Satgutier@umich.edu * this software without specific prior written permission. 2710263Satgutier@umich.edu * 2810263Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2910263Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3010263Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3110263Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3210263Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3310263Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3410263Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3510263Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3610263Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3710263Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3810263Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3910263Satgutier@umich.edu * 4010263Satgutier@umich.edu * Authors: Erik Hallnor 4110263Satgutier@umich.edu */ 4210263Satgutier@umich.edu 4310263Satgutier@umich.edu/** 4410263Satgutier@umich.edu * @file 4513219Sodanrc@yahoo.com.br * Definitions of a conventional tag store. 4610263Satgutier@umich.edu */ 4710263Satgutier@umich.edu 4811486Snikos.nikoleris@arm.com#include "mem/cache/tags/base_set_assoc.hh" 4911486Snikos.nikoleris@arm.com 5010263Satgutier@umich.edu#include <string> 5110263Satgutier@umich.edu 5210263Satgutier@umich.edu#include "base/intmath.hh" 5310263Satgutier@umich.edu 5410263Satgutier@umich.eduBaseSetAssoc::BaseSetAssoc(const Params *p) 5513219Sodanrc@yahoo.com.br :BaseTags(p), allocAssoc(p->assoc), blks(p->size / p->block_size), 5612548Sodanrc@yahoo.com.br sequentialAccess(p->sequential_access), 5712600Sodanrc@yahoo.com.br replacementPolicy(p->replacement_policy) 5810263Satgutier@umich.edu{ 5910263Satgutier@umich.edu // Check parameters 6010263Satgutier@umich.edu if (blkSize < 4 || !isPowerOf2(blkSize)) { 6110263Satgutier@umich.edu fatal("Block size must be at least 4 and a power of 2"); 6210263Satgutier@umich.edu } 6313216Sodanrc@yahoo.com.br} 6410263Satgutier@umich.edu 6513216Sodanrc@yahoo.com.brvoid 6613419Sodanrc@yahoo.com.brBaseSetAssoc::tagsInit() 6713216Sodanrc@yahoo.com.br{ 6813219Sodanrc@yahoo.com.br // Initialize all blocks 6913219Sodanrc@yahoo.com.br for (unsigned blk_index = 0; blk_index < numBlocks; blk_index++) { 7013219Sodanrc@yahoo.com.br // Locate next cache block 7113220Sodanrc@yahoo.com.br CacheBlk* blk = &blks[blk_index]; 7210263Satgutier@umich.edu 7313219Sodanrc@yahoo.com.br // Link block to indexing policy 7413219Sodanrc@yahoo.com.br indexingPolicy->setEntry(blk, blk_index); 7512549Sodanrc@yahoo.com.br 7613219Sodanrc@yahoo.com.br // Associate a data chunk to the block 7713219Sodanrc@yahoo.com.br blk->data = &dataBlks[blkSize*blk_index]; 7812549Sodanrc@yahoo.com.br 7913219Sodanrc@yahoo.com.br // Associate a replacement data entry to the block 8013219Sodanrc@yahoo.com.br blk->replacementData = replacementPolicy->instantiateEntry(); 8110263Satgutier@umich.edu } 8210263Satgutier@umich.edu} 8310263Satgutier@umich.edu 8412684Sodanrc@yahoo.com.brvoid 8512684Sodanrc@yahoo.com.brBaseSetAssoc::invalidate(CacheBlk *blk) 8612684Sodanrc@yahoo.com.br{ 8712684Sodanrc@yahoo.com.br BaseTags::invalidate(blk); 8812684Sodanrc@yahoo.com.br 8912745Sodanrc@yahoo.com.br // Decrease the number of tags in use 9012745Sodanrc@yahoo.com.br tagsInUse--; 9112745Sodanrc@yahoo.com.br 9212684Sodanrc@yahoo.com.br // Invalidate replacement data 9312684Sodanrc@yahoo.com.br replacementPolicy->invalidate(blk->replacementData); 9412684Sodanrc@yahoo.com.br} 9512684Sodanrc@yahoo.com.br 9612600Sodanrc@yahoo.com.brBaseSetAssoc * 9712600Sodanrc@yahoo.com.brBaseSetAssocParams::create() 9812600Sodanrc@yahoo.com.br{ 9913219Sodanrc@yahoo.com.br // There must be a indexing policy 10013219Sodanrc@yahoo.com.br fatal_if(!indexing_policy, "An indexing policy is required"); 10113219Sodanrc@yahoo.com.br 10212600Sodanrc@yahoo.com.br return new BaseSetAssoc(this); 10312600Sodanrc@yahoo.com.br} 104