compressed_tags.cc revision 13938
113938Sodanrc@yahoo.com.br/*
213938Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria
313938Sodanrc@yahoo.com.br * All rights reserved.
413938Sodanrc@yahoo.com.br *
513938Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without
613938Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are
713938Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright
813938Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer;
913938Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright
1013938Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the
1113938Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution;
1213938Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its
1313938Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from
1413938Sodanrc@yahoo.com.br * this software without specific prior written permission.
1513938Sodanrc@yahoo.com.br *
1613938Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713938Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813938Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913938Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013938Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113938Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213938Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313938Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413938Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513938Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613938Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713938Sodanrc@yahoo.com.br *
2813938Sodanrc@yahoo.com.br * Authors: Daniel Carvalho
2913938Sodanrc@yahoo.com.br */
3013938Sodanrc@yahoo.com.br
3113938Sodanrc@yahoo.com.br/**
3213938Sodanrc@yahoo.com.br * @file
3313938Sodanrc@yahoo.com.br * Definitions of a base set associative compressed superblocks tag store.
3413938Sodanrc@yahoo.com.br */
3513938Sodanrc@yahoo.com.br
3613938Sodanrc@yahoo.com.br#include "mem/cache/tags/compressed_tags.hh"
3713938Sodanrc@yahoo.com.br
3813938Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/base.hh"
3913938Sodanrc@yahoo.com.br#include "mem/cache/tags/indexing_policies/base.hh"
4013938Sodanrc@yahoo.com.br#include "params/CompressedTags.hh"
4113938Sodanrc@yahoo.com.br
4213938Sodanrc@yahoo.com.brCompressedTags::CompressedTags(const Params *p)
4313938Sodanrc@yahoo.com.br    : SectorTags(p)
4413938Sodanrc@yahoo.com.br{
4513938Sodanrc@yahoo.com.br}
4613938Sodanrc@yahoo.com.br
4713938Sodanrc@yahoo.com.brvoid
4813938Sodanrc@yahoo.com.brCompressedTags::tagsInit()
4913938Sodanrc@yahoo.com.br{
5013938Sodanrc@yahoo.com.br    // Create blocks and superblocks
5113938Sodanrc@yahoo.com.br    blks = std::vector<CompressionBlk>(numBlocks);
5213938Sodanrc@yahoo.com.br    superBlks = std::vector<SuperBlk>(numSectors);
5313938Sodanrc@yahoo.com.br
5413938Sodanrc@yahoo.com.br    // Initialize all blocks
5513938Sodanrc@yahoo.com.br    unsigned blk_index = 0;          // index into blks array
5613938Sodanrc@yahoo.com.br    for (unsigned superblock_index = 0; superblock_index < numSectors;
5713938Sodanrc@yahoo.com.br         superblock_index++)
5813938Sodanrc@yahoo.com.br    {
5913938Sodanrc@yahoo.com.br        // Locate next cache superblock
6013938Sodanrc@yahoo.com.br        SuperBlk* superblock = &superBlks[superblock_index];
6113938Sodanrc@yahoo.com.br
6213938Sodanrc@yahoo.com.br        // Link block to indexing policy
6313938Sodanrc@yahoo.com.br        indexingPolicy->setEntry(superblock, superblock_index);
6413938Sodanrc@yahoo.com.br
6513938Sodanrc@yahoo.com.br        // Associate a replacement data entry to the block
6613938Sodanrc@yahoo.com.br        superblock->replacementData = replacementPolicy->instantiateEntry();
6713938Sodanrc@yahoo.com.br
6813938Sodanrc@yahoo.com.br        // Initialize all blocks in this superblock
6913938Sodanrc@yahoo.com.br        superblock->blks.resize(numBlocksPerSector, nullptr);
7013938Sodanrc@yahoo.com.br        for (unsigned k = 0; k < numBlocksPerSector; ++k){
7113938Sodanrc@yahoo.com.br            // Select block within the set to be linked
7213938Sodanrc@yahoo.com.br            SectorSubBlk*& blk = superblock->blks[k];
7313938Sodanrc@yahoo.com.br
7413938Sodanrc@yahoo.com.br            // Locate next cache block
7513938Sodanrc@yahoo.com.br            blk = &blks[blk_index];
7613938Sodanrc@yahoo.com.br
7713938Sodanrc@yahoo.com.br            // Associate a data chunk to the block
7813938Sodanrc@yahoo.com.br            blk->data = &dataBlks[blkSize*blk_index];
7913938Sodanrc@yahoo.com.br
8013938Sodanrc@yahoo.com.br            // Associate superblock to this block
8113938Sodanrc@yahoo.com.br            blk->setSectorBlock(superblock);
8213938Sodanrc@yahoo.com.br
8313938Sodanrc@yahoo.com.br            // Associate the superblock replacement data to this block
8413938Sodanrc@yahoo.com.br            blk->replacementData = superblock->replacementData;
8513938Sodanrc@yahoo.com.br
8613938Sodanrc@yahoo.com.br            // Set its index and sector offset
8713938Sodanrc@yahoo.com.br            blk->setSectorOffset(k);
8813938Sodanrc@yahoo.com.br
8913938Sodanrc@yahoo.com.br            // Update block index
9013938Sodanrc@yahoo.com.br            ++blk_index;
9113938Sodanrc@yahoo.com.br        }
9213938Sodanrc@yahoo.com.br    }
9313938Sodanrc@yahoo.com.br}
9413938Sodanrc@yahoo.com.br
9513938Sodanrc@yahoo.com.brvoid
9613938Sodanrc@yahoo.com.brCompressedTags::forEachBlk(std::function<void(CacheBlk &)> visitor)
9713938Sodanrc@yahoo.com.br{
9813938Sodanrc@yahoo.com.br    for (CompressionBlk& blk : blks) {
9913938Sodanrc@yahoo.com.br        visitor(blk);
10013938Sodanrc@yahoo.com.br    }
10113938Sodanrc@yahoo.com.br}
10213938Sodanrc@yahoo.com.br
10313938Sodanrc@yahoo.com.brbool
10413938Sodanrc@yahoo.com.brCompressedTags::anyBlk(std::function<bool(CacheBlk &)> visitor)
10513938Sodanrc@yahoo.com.br{
10613938Sodanrc@yahoo.com.br    for (CompressionBlk& blk : blks) {
10713938Sodanrc@yahoo.com.br        if (visitor(blk)) {
10813938Sodanrc@yahoo.com.br            return true;
10913938Sodanrc@yahoo.com.br        }
11013938Sodanrc@yahoo.com.br    }
11113938Sodanrc@yahoo.com.br    return false;
11213938Sodanrc@yahoo.com.br}
11313938Sodanrc@yahoo.com.br
11413938Sodanrc@yahoo.com.brCompressedTags *
11513938Sodanrc@yahoo.com.brCompressedTagsParams::create()
11613938Sodanrc@yahoo.com.br{
11713938Sodanrc@yahoo.com.br    return new CompressedTags(this);
11813938Sodanrc@yahoo.com.br}
119