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"
56 setSizeBits(getSizeBits() + pattern->getSizeBits());
59 entries.push_back(std::move(pattern));
66 dictionary.resize(dictionarySize);
79 std::fill(dictionary.begin(), dictionary.end(), toDictionaryEntry(0));
83 std::unique_ptr<typename DictionaryCompressor<T>::CompData>
86 return std::unique_ptr<DictionaryCompressor<T>::CompData>(
new CompData());
90 std::unique_ptr<typename DictionaryCompressor<T>::Pattern>
98 std::unique_ptr<Pattern> pattern =
99 getPattern(bytes, toDictionaryEntry(0), -1);
102 for (std::size_t
i = 0;
i < numEntries;
i++) {
104 std::unique_ptr<Pattern> temp_pattern =
105 getPattern(bytes, dictionary[
i],
i);
108 if (temp_pattern->getSizeBits() < pattern->getSizeBits()) {
109 pattern = std::move(temp_pattern);
114 dictionaryStats.patterns[pattern->getPatternNumber()]++;
117 if (pattern->shouldAllocate()) {
118 addToDictionary(bytes);
125 std::unique_ptr<Base::CompressionData>
128 std::unique_ptr<Base::CompressionData> comp_data =
129 instantiateDictionaryCompData();
135 CompData*
const comp_data_ptr =
static_cast<CompData*
>(comp_data.get());
136 for (
const auto& value : chunks) {
137 std::unique_ptr<Pattern> pattern = compressValue(value);
138 DPRINTF(CacheComp,
"Compressed %016x to %s\n", value,
140 comp_data_ptr->addEntry(std::move(pattern));
152 auto entry_it = dictionary.begin();
153 std::advance(entry_it, pattern->getMatchLocation());
158 if (pattern->shouldAllocate()) {
159 addToDictionary(
data);
163 return fromDictionaryEntry(
data);
171 const CompData* casted_comp_data =
static_cast<const CompData*
>(comp_data);
178 for (
const auto& entry : casted_comp_data->entries) {
179 const T value = decompressValue(&*entry);
180 decomp_values.push_back(value);
181 DPRINTF(CacheComp,
"Decompressed %s to %x\n", entry->print(), value);
185 for (std::size_t
i = 0;
i < blkSize/8;
i++) {
187 const std::size_t values_per_entry =
sizeof(uint64_t)/
sizeof(T);
188 for (
int j = values_per_entry - 1;
j >= 0;
j--) {
190 static_cast<uint64_t
>(decomp_values[values_per_entry*
i+
j]) <<
201 for (
int i = 0;
i <
sizeof(T);
i++) {
202 entry[
i] = value & 0xFF;
213 for (
int i =
sizeof(T) - 1;
i >= 0;
i--) {
222 #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_IMPL_HH__