diff -r 149ecc360ab3 -r 8a20e71247f8 src/mem/cache/tags/base_set_assoc.hh --- a/src/mem/cache/tags/base_set_assoc.hh Mon Aug 31 10:17:45 2015 +0100 +++ b/src/mem/cache/tags/base_set_assoc.hh Mon Aug 31 10:19:41 2015 +0100 @@ -81,7 +81,7 @@ /** Typedef for a list of pointers to the local block class. */ typedef std::list BlkList; /** Typedef the set type used in this tag store. */ - typedef CacheSet SetType; + typedef CacheSet SetType; protected: diff -r 149ecc360ab3 -r 8a20e71247f8 src/mem/cache/tags/cacheset.hh --- a/src/mem/cache/tags/cacheset.hh Mon Aug 31 10:17:45 2015 +0100 +++ b/src/mem/cache/tags/cacheset.hh Mon Aug 31 10:19:41 2015 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 ARM Limited + * Copyright (c) 2013, 2015 ARM Limited * All rights reserved. * * The license below extends only to copyright in the software and shall @@ -45,17 +45,16 @@ * Declaration of an associative set */ -#ifndef __CACHESET_HH__ -#define __CACHESET_HH__ +#ifndef __MEM_CACHE_TAGS_CACHESET_HH__ +#define __MEM_CACHE_TAGS_CACHESET_HH__ #include -#include "mem/cache/blk.hh" // base class +#include "mem/cache/blk.hh" /** * An associative set of cache blocks. */ -template class CacheSet { public: @@ -63,7 +62,7 @@ int assoc; /** Cache blocks in this set, maintained in LRU order 0 = MRU. */ - Blktype **blks; + CacheBlk **blks; /** * Find a block matching the tag in this set. @@ -72,98 +71,77 @@ * @param is_secure True if the target memory space is secure. * @return Pointer to the block if found. Set way_id to assoc if none found */ - Blktype* findBlk(Addr tag, bool is_secure, int& way_id) const ; - Blktype* findBlk(Addr tag, bool is_secure) const ; + CacheBlk* findBlk(Addr tag, bool is_secure, int& way_id) const + { + /** + * Way_id returns the id of the way that matches the block + * If no block is found way_id is set to assoc. + */ + way_id = assoc; + for (int i = 0; i < assoc; ++i) { + if (blks[i]->tag == tag && blks[i]->isValid() && + blks[i]->isSecure() == is_secure) { + way_id = i; + return blks[i]; + } + } + return NULL; + } + + CacheBlk* findBlk(Addr tag, bool is_secure) const + { + int ignored_way_id; + return findBlk(tag, is_secure, ignored_way_id); + } /** * Move the given block to the head of the list. * @param blk The block to move. */ - void moveToHead(Blktype *blk); + void moveToHead(CacheBlk *blk) + { + // nothing to do if blk is already head + if (blks[0] == blk) + return; + + // write 'next' block into blks[i], moving up from MRU toward LRU + // until we overwrite the block we moved to head. + + // start by setting up to write 'blk' into blks[0] + int i = 0; + CacheBlk *next = blk; + + do { + assert(i < assoc); + std::swap(blks[i], next); + ++i; + } while (next != blk); + } /** * Move the given block to the tail of the list. * @param blk The block to move */ - void moveToTail(Blktype *blk); + void moveToTail(CacheBlk *blk) + { + // nothing to do if blk is already tail + if (blks[assoc - 1] == blk) + return; + + // write 'next' block into blks[i], moving from LRU to MRU + // until we overwrite the block we moved to tail. + + // start by setting up to write 'blk' into tail + int i = assoc - 1; + CacheBlk *next = blk; + + do { + assert(i >= 0); + std::swap(blks[i], next); + --i; + } while (next != blk); + } }; -template -Blktype* -CacheSet::findBlk(Addr tag, bool is_secure, int& way_id) const -{ - /** - * Way_id returns the id of the way that matches the block - * If no block is found way_id is set to assoc. - */ - way_id = assoc; - for (int i = 0; i < assoc; ++i) { - if (blks[i]->tag == tag && blks[i]->isValid() && - blks[i]->isSecure() == is_secure) { - way_id = i; - return blks[i]; - } - } - return NULL; -} - -template -Blktype* -CacheSet::findBlk(Addr tag, bool is_secure) const -{ - int ignored_way_id; - return findBlk(tag, is_secure, ignored_way_id); -} - -template -void -CacheSet::moveToHead(Blktype *blk) -{ - // nothing to do if blk is already head - if (blks[0] == blk) - return; - - // write 'next' block into blks[i], moving up from MRU toward LRU - // until we overwrite the block we moved to head. - - // start by setting up to write 'blk' into blks[0] - int i = 0; - Blktype *next = blk; - - do { - assert(i < assoc); - // swap blks[i] and next - Blktype *tmp = blks[i]; - blks[i] = next; - next = tmp; - ++i; - } while (next != blk); -} - -template -void -CacheSet::moveToTail(Blktype *blk) -{ - // nothing to do if blk is already tail - if (blks[assoc - 1] == blk) - return; - - // write 'next' block into blks[i], moving from LRU to MRU - // until we overwrite the block we moved to tail. - - // start by setting up to write 'blk' into tail - int i = assoc - 1; - Blktype *next = blk; - - do { - assert(i >= 0); - // swap blks[i] and next - Blktype *tmp = blks[i]; - blks[i] = next; - next = tmp; - --i; - } while (next != blk); -} - #endif