cc799df24fa208a88d01ac50c337146921f1c8bb
2 * Copyright (c) 2018 Inria
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Daniel Carvalho
33 * Definitions of a base set associative compressed superblocks tag store.
36 #include "mem/cache/tags/compressed_tags.hh"
38 #include "mem/cache/replacement_policies/base.hh"
39 #include "mem/cache/tags/indexing_policies/base.hh"
40 #include "params/CompressedTags.hh"
42 CompressedTags::CompressedTags(const Params
*p
)
48 CompressedTags::tagsInit()
50 // Create blocks and superblocks
51 blks
= std::vector
<CompressionBlk
>(numBlocks
);
52 superBlks
= std::vector
<SuperBlk
>(numSectors
);
54 // Initialize all blocks
55 unsigned blk_index
= 0; // index into blks array
56 for (unsigned superblock_index
= 0; superblock_index
< numSectors
;
59 // Locate next cache superblock
60 SuperBlk
* superblock
= &superBlks
[superblock_index
];
62 // Link block to indexing policy
63 indexingPolicy
->setEntry(superblock
, superblock_index
);
65 // Associate a replacement data entry to the block
66 superblock
->replacementData
= replacementPolicy
->instantiateEntry();
68 // Initialize all blocks in this superblock
69 superblock
->blks
.resize(numBlocksPerSector
, nullptr);
70 for (unsigned k
= 0; k
< numBlocksPerSector
; ++k
){
71 // Select block within the set to be linked
72 SectorSubBlk
*& blk
= superblock
->blks
[k
];
74 // Locate next cache block
75 blk
= &blks
[blk_index
];
77 // Associate a data chunk to the block
78 blk
->data
= &dataBlks
[blkSize
*blk_index
];
80 // Associate superblock to this block
81 blk
->setSectorBlock(superblock
);
83 // Associate the superblock replacement data to this block
84 blk
->replacementData
= superblock
->replacementData
;
86 // Set its index and sector offset
87 blk
->setSectorOffset(k
);
96 CompressedTags::forEachBlk(std::function
<void(CacheBlk
&)> visitor
)
98 for (CompressionBlk
& blk
: blks
) {
104 CompressedTags::anyBlk(std::function
<bool(CacheBlk
&)> visitor
)
106 for (CompressionBlk
& blk
: blks
) {
115 CompressedTagsParams::create()
117 return new CompressedTags(this);