/** Which curTick() will this block be accessible */
Tick whenReady;
- /**
- * The set and way this block belongs to.
- * @todo Move this into subclasses when we fix CacheTags to use them.
- */
- int set, way;
-
/** Number of references to this block since it was brought in. */
unsigned refCount;
*/
class ReplaceableEntry
{
- public:
+ private:
+ /**
+ * Set to which this entry belongs.
+ */
+ uint32_t _set;
+
+ /**
+ * Way (relative position within the set) to which this entry belongs.
+ */
+ uint32_t _way;
+
+ public:
+ /**
+ * Replacement data associated to this entry.
+ * It is instantiated by the replacement policy.
+ */
+ std::shared_ptr<ReplacementData> replacementData;
+
/**
- * Replacement data associated to this entry.
- * It is instantiated by the replacement policy.
+ * Set both the set and way. Should be called only once.
+ *
+ * @param set The set of this entry.
+ * @param way The way of this entry.
+ */
+ void setPosition(const uint32_t set, const uint32_t way) {
+ _set = set;
+ _way = way;
+ }
+
+ /**
+ * Get set number.
+ *
+ * @return The set to which this entry belongs.
+ */
+ uint32_t getSet() const { return _set; }
+
+ /**
+ * Get way number.
+ *
+ * @return The way to which this entry belongs.
*/
- std::shared_ptr<ReplacementData> replacementData;
+ uint32_t getWay() const { return _way; }
};
/**
auto print_blk = [&str](CacheBlk &blk) {
if (blk.isValid())
- str += csprintf("\tset: %d way: %d %s\n", blk.set, blk.way,
- blk.print());
+ str += csprintf("\tset: %x, way: %x %s\n", blk.getSet(),
+ blk.getWay(), blk.print());
};
forEachBlk(print_blk);
// hash table; won't matter because the block is invalid
blk->tag = j;
- // Set its set and way
- blk->set = i;
- blk->way = j;
+ // Set its index
+ blk->setPosition(i, j);
// Update block index
++blkIndex;
evict_blks.push_back(victim);
DPRINTF(CacheRepl, "set %x, way %x: selecting blk for replacement\n",
- victim->set, victim->way);
+ victim->getSet(), victim->getWay());
return victim;
}
*/
Addr regenerateBlkAddr(const CacheBlk* blk) const override
{
- return ((blk->tag << tagShift) | ((Addr)blk->set << setShift));
+ const Addr set = blk->getSet() << setShift;
+ return ((blk->tag << tagShift) | set);
}
void forEachBlk(std::function<void(CacheBlk &)> visitor) override {
head = &(blks[0]);
head->prev = nullptr;
head->next = &(blks[1]);
- head->set = 0;
- head->way = 0;
+ head->setPosition(0, 0);
head->data = &dataBlks[0];
for (unsigned i = 1; i < numBlocks - 1; i++) {
blks[i].prev = &(blks[i-1]);
blks[i].next = &(blks[i+1]);
- blks[i].set = 0;
- blks[i].way = i;
+ blks[i].setPosition(0, i);
// Associate a data chunk to the block
blks[i].data = &dataBlks[blkSize*i];
tail = &(blks[numBlocks - 1]);
tail->prev = &(blks[numBlocks - 2]);
tail->next = nullptr;
- tail->set = 0;
- tail->way = numBlocks - 1;
+ tail->setPosition(0, numBlocks - 1);
tail->data = &dataBlks[(numBlocks - 1) * blkSize];
cacheTracking.init(head, tail);
// Associate a replacement data entry to the sector
sec_blk->replacementData = replacementPolicy->instantiateEntry();
+ // Set its index
+ sec_blk->setPosition(i, j);
+
// Initialize all blocks in this sector
sec_blk->blks.resize(numBlocksPerSector);
for (unsigned k = 0; k < numBlocksPerSector; ++k){
// Associate the sector replacement data to this block
blk->replacementData = sec_blk->replacementData;
- // Set its set, way and sector offset
- blk->set = i;
- blk->way = j;
+ // Set its index and sector offset
+ blk->setPosition(i, j);
blk->setSectorOffset(k);
// Update block index
}
}
- DPRINTF(CacheRepl, "set %x, way %x, sector offset %x: %s\n",
- "selecting blk for replacement\n", victim->set, victim->way,
+ DPRINTF(CacheRepl, "set %x, way %x, sector offset %x: selecting blk " \
+ "for replacement\n", victim->getSet(), victim->getWay(),
victim->getSectorOffset());
return victim;
SectorTags::regenerateBlkAddr(const CacheBlk* blk) const
{
const SectorSubBlk* blk_cast = static_cast<const SectorSubBlk*>(blk);
- return ((blk_cast->getTag() << tagShift) | ((Addr)blk->set << setShift) |
+ const Addr set = blk_cast->getSectorBlock()->getSet() << setShift;
+ return ((blk_cast->getTag() << tagShift) | set |
((Addr)blk_cast->getSectorOffset() << sectorShift));
}
Addr
SkewedAssoc::regenerateBlkAddr(const CacheBlk* blk) const
{
- const Addr addr = (blk->tag << (msbShift + 1)) | blk->set;
- const Addr set = deskew(addr, blk->way) & setMask;
+ const Addr addr = (blk->tag << (msbShift + 1)) | blk->getSet();
+ const Addr set = deskew(addr, blk->getWay()) & setMask;
return (blk->tag << tagShift) | (set << setShift);
}