33 #ifndef __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_IMPL_HH__
34 #define __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_IMPL_HH__
39 #include "debug/CacheComp.hh"
41 #include "params/BaseDictionaryCompressor.hh"
61 setSizeBits(getSizeBits() + pattern->getSizeBits());
64 entries.push_back(std::move(pattern));
84 std::fill(dictionary.begin(), dictionary.end(), toDictionaryEntry(0));
88 std::unique_ptr<typename DictionaryCompressor<T>::CompData>
91 return std::unique_ptr<DictionaryCompressor<T>::CompData>(
new CompData());
95 std::unique_ptr<typename DictionaryCompressor<T>::Pattern>
103 std::unique_ptr<Pattern> pattern =
104 getPattern(bytes, toDictionaryEntry(0), -1);
107 for (std::size_t
i = 0;
i < numEntries;
i++) {
109 std::unique_ptr<Pattern> temp_pattern =
110 getPattern(bytes, dictionary[
i],
i);
113 if (temp_pattern->getSizeBits() < pattern->getSizeBits()) {
114 pattern = std::move(temp_pattern);
119 dictionaryStats.patterns[pattern->getPatternNumber()]++;
122 if (pattern->shouldAllocate()) {
123 addToDictionary(bytes);
130 std::unique_ptr<Base::CompressionData>
133 std::unique_ptr<Base::CompressionData> comp_data =
134 instantiateDictionaryCompData();
141 for (
const auto& value : chunks) {
142 std::unique_ptr<Pattern> pattern = compressValue(value);
143 DPRINTF(CacheComp,
"Compressed %016x to %s\n", value,
145 comp_data_ptr->
addEntry(std::move(pattern));
153 std::unique_ptr<Base::CompressionData>
159 comp_lat =
Cycles(compExtraLatency +
160 (chunks.size() / compChunksPerCycle));
161 decomp_lat =
Cycles(decompExtraLatency +
162 (chunks.size() / decompChunksPerCycle));
164 return compress(chunks);
172 auto entry_it = dictionary.begin();
179 addToDictionary(
data);
183 return fromDictionaryEntry(
data);
198 for (
const auto& entry : casted_comp_data->
entries) {
199 const T value = decompressValue(&*entry);
200 decomp_values.push_back(value);
201 DPRINTF(CacheComp,
"Decompressed %s to %x\n", entry->print(), value);
205 for (std::size_t
i = 0;
i < blkSize/8;
i++) {
207 const std::size_t values_per_entry =
sizeof(uint64_t)/
sizeof(T);
208 for (
int j = values_per_entry - 1;
j >= 0;
j--) {
210 static_cast<uint64_t
>(decomp_values[values_per_entry*
i+
j]) <<
221 for (
int i = 0;
i <
sizeof(T);
i++) {
222 entry[
i] = value & 0xFF;
233 for (
int i =
sizeof(T) - 1;
i >= 0;
i--) {
Cycles is a wrapper class for representing cycle counts, i.e.
const std::size_t dictionarySize
Dictionary size.
BaseCacheCompressorParams Params
static void setSizeBits(CacheBlk *blk, const std::size_t size_bits)
Set the size of the compressed block, in bits.
virtual void addEntry(std::unique_ptr< Pattern >)
Add a pattern entry to the list of patterns.
std::vector< std::unique_ptr< Pattern > > entries
The patterns matched in the original line.
The compressed data is composed of multiple pattern entries.
virtual DictionaryEntry decompress(const DictionaryEntry dict_bytes) const =0
Decompress the pattern.
bool shouldAllocate() const
Determine if pattern allocates a dictionary entry.
uint8_t getMatchLocation() const
Get the index of the dictionary match location.
static T fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
std::vector< DictionaryEntry > dictionary
The dictionary.
virtual void resetDictionary()
Clear all dictionary entries.
std::unique_ptr< Pattern > compressValue(const T data)
Compress data.
virtual std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const
Instantiate a compression data of the sub-class compressor.
std::array< uint8_t, sizeof(T)> DictionaryEntry
Convenience typedef for a dictionary entry.
T decompressValue(const Pattern *pattern)
Decompress a pattern into a value that fits in a dictionary entry.
void decompress(const CompressionData *comp_data, uint64_t *data) override
Apply the decompression process to the compressed data.
std::unique_ptr< Base::CompressionData > compress(const std::vector< Chunk > &chunks)
Apply compression.
DictionaryCompressor(const Params &p)
static DictionaryEntry toDictionaryEntry(T value)
Turn a value into a dictionary entry.
Definition of a dictionary based cache compressor.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)