base_set_assoc.cc revision 13219
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 6613216Sodanrc@yahoo.com.brBaseSetAssoc::init(BaseCache* cache) 6713216Sodanrc@yahoo.com.br{ 6813216Sodanrc@yahoo.com.br // Set parent cache 6913216Sodanrc@yahoo.com.br setCache(cache); 7013216Sodanrc@yahoo.com.br 7113219Sodanrc@yahoo.com.br // Initialize all blocks 7213219Sodanrc@yahoo.com.br for (unsigned blk_index = 0; blk_index < numBlocks; blk_index++) { 7313219Sodanrc@yahoo.com.br // Locate next cache block 7413219Sodanrc@yahoo.com.br BlkType* blk = &blks[blk_index]; 7510263Satgutier@umich.edu 7613219Sodanrc@yahoo.com.br // Link block to indexing policy 7713219Sodanrc@yahoo.com.br indexingPolicy->setEntry(blk, blk_index); 7812549Sodanrc@yahoo.com.br 7913219Sodanrc@yahoo.com.br // Associate a data chunk to the block 8013219Sodanrc@yahoo.com.br blk->data = &dataBlks[blkSize*blk_index]; 8112549Sodanrc@yahoo.com.br 8213219Sodanrc@yahoo.com.br // Associate a replacement data entry to the block 8313219Sodanrc@yahoo.com.br blk->replacementData = replacementPolicy->instantiateEntry(); 8410263Satgutier@umich.edu } 8510263Satgutier@umich.edu} 8610263Satgutier@umich.edu 8712684Sodanrc@yahoo.com.brvoid 8812684Sodanrc@yahoo.com.brBaseSetAssoc::invalidate(CacheBlk *blk) 8912684Sodanrc@yahoo.com.br{ 9012684Sodanrc@yahoo.com.br BaseTags::invalidate(blk); 9112684Sodanrc@yahoo.com.br 9212745Sodanrc@yahoo.com.br // Decrease the number of tags in use 9312745Sodanrc@yahoo.com.br tagsInUse--; 9412745Sodanrc@yahoo.com.br 9512684Sodanrc@yahoo.com.br // Invalidate replacement data 9612684Sodanrc@yahoo.com.br replacementPolicy->invalidate(blk->replacementData); 9712684Sodanrc@yahoo.com.br} 9812684Sodanrc@yahoo.com.br 9912600Sodanrc@yahoo.com.brBaseSetAssoc * 10012600Sodanrc@yahoo.com.brBaseSetAssocParams::create() 10112600Sodanrc@yahoo.com.br{ 10213219Sodanrc@yahoo.com.br // There must be a indexing policy 10313219Sodanrc@yahoo.com.br fatal_if(!indexing_policy, "An indexing policy is required"); 10413219Sodanrc@yahoo.com.br 10512600Sodanrc@yahoo.com.br return new BaseSetAssoc(this); 10612600Sodanrc@yahoo.com.br} 107