#include "base/logging.hh"
CompressionBlk::CompressionBlk()
- : SectorSubBlk()
+ : SectorSubBlk(), _size(0), _decompressionLatency(0)
{
}
+
+bool
+CompressionBlk::isCompressed() const
+{
+ return (status & BlkCompressed) != 0;
+}
+
+void
+CompressionBlk::setCompressed()
+{
+ status |= BlkCompressed;
+}
+
+void
+CompressionBlk::setUncompressed()
+{
+ status &= ~BlkCompressed;
+}
+
+std::size_t
+CompressionBlk::getSizeBits() const
+{
+ return _size;
+}
+
+void
+CompressionBlk::setSizeBits(const std::size_t size)
+{
+ _size = size;
+}
+
+Cycles
+CompressionBlk::getDecompressionLatency() const
+{
+ return _decompressionLatency;
+}
+
+void
+CompressionBlk::setDecompressionLatency(const Cycles lat)
+{
+ _decompressionLatency = lat;
+}
+
+std::string
+CompressionBlk::print() const
+{
+ return csprintf("%s compressed: %d size: %llu decompression latency: %d",
+ SectorSubBlk::print(), isCompressed(), getSizeBits(),
+ getDecompressionLatency());
+}
+
+bool
+SuperBlk::isCompressed() const
+{
+ for (const auto& blk : blks) {
+ if (blk->isValid()) {
+ return static_cast<CompressionBlk*>(blk)->isCompressed();
+ }
+ }
+
+ // An invalid block is seen as compressed
+ return true;
+}
*/
class CompressionBlk : public SectorSubBlk
{
+ private:
+ /**
+ * Set size, in bits, of this compressed block's data.
+ */
+ std::size_t _size;
+
+ /**
+ * Number of cycles needed to decompress this block. We store it to avoid
+ * doing decompressions.
+ */
+ Cycles _decompressionLatency;
+
public:
CompressionBlk();
CompressionBlk(const CompressionBlk&) = delete;
CompressionBlk& operator=(const CompressionBlk&) = delete;
~CompressionBlk() {};
+
+ /**
+ * Check if this block holds compressed data.
+ *
+ * @return True if the block holds compressed data.
+ */
+ bool isCompressed() const;
+
+ /**
+ * Set compression bit.
+ */
+ void setCompressed();
+
+ /**
+ * Clear compression bit.
+ */
+ void setUncompressed();
+
+ /*
+ * Get size, in bits, of this compressed block's data.
+ *
+ * @return The compressed size.
+ */
+ std::size_t getSizeBits() const;
+
+ /**
+ * Set size, in bits, of this compressed block's data.
+ *
+ * @param The compressed size.
+ */
+ void setSizeBits(const std::size_t size);
+
+ /**
+ * Get number of cycles needed to decompress this block.
+ *
+ * @return Decompression latency.
+ */
+ Cycles getDecompressionLatency() const;
+
+ /**
+ * Set number of cycles needed to decompress this block.
+ *
+ * @param Decompression latency.
+ */
+ void setDecompressionLatency(const Cycles lat);
+
+ /**
+ * Pretty-print sector offset and other CacheBlk information.
+ *
+ * @return string with basic state information
+ */
+ std::string print() const override;
};
/**
SuperBlk(const SuperBlk&) = delete;
SuperBlk& operator=(const SuperBlk&) = delete;
~SuperBlk() {};
+
+ /**
+ * Returns whether the superblock contains compressed blocks or not. By
+ * default, if not blocks are valid, the superblock is compressible.
+ *
+ * @return The compressibility state of the superblock.
+ */
+ bool isCompressed() const;
};
#endif //__MEM_CACHE_TAGS_SUPER_BLK_HH__