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"
60 setSizeBits(getSizeBits() + pattern->getSizeBits());
63 entries.push_back(std::move(pattern));
83 std::fill(dictionary.begin(), dictionary.end(), toDictionaryEntry(0));
87std::unique_ptr<typename DictionaryCompressor<T>::CompData>
90 return std::unique_ptr<DictionaryCompressor<T>::CompData>(
new CompData());
94std::unique_ptr<typename DictionaryCompressor<T>::Pattern>
102 std::unique_ptr<Pattern> pattern =
103 getPattern(bytes, toDictionaryEntry(0), -1);
106 for (std::size_t
i = 0;
i < numEntries;
i++) {
108 std::unique_ptr<Pattern> temp_pattern =
109 getPattern(bytes, dictionary[
i],
i);
112 if (temp_pattern->getSizeBits() < pattern->getSizeBits()) {
113 pattern = std::move(temp_pattern);
118 dictionaryStats.patterns[pattern->getPatternNumber()]++;
121 if (pattern->shouldAllocate()) {
122 addToDictionary(bytes);
129std::unique_ptr<Base::CompressionData>
132 std::unique_ptr<Base::CompressionData> comp_data =
133 instantiateDictionaryCompData();
140 for (
const auto& value : chunks) {
141 std::unique_ptr<Pattern> pattern = compressValue(value);
142 DPRINTF(CacheComp,
"Compressed %016x to %s\n", value,
144 comp_data_ptr->
addEntry(std::move(pattern));
152std::unique_ptr<Base::CompressionData>
158 comp_lat =
Cycles(compExtraLatency +
159 (chunks.size() / compChunksPerCycle));
160 decomp_lat =
Cycles(decompExtraLatency +
161 (chunks.size() / decompChunksPerCycle));
163 return compress(chunks);
171 auto entry_it = dictionary.begin();
178 addToDictionary(
data);
182 return fromDictionaryEntry(
data);
197 for (
const auto& entry : casted_comp_data->
entries) {
198 const T value = decompressValue(&*entry);
199 decomp_values.push_back(value);
200 DPRINTF(CacheComp,
"Decompressed %s to %x\n", entry->print(), value);
204 for (std::size_t
i = 0;
i < blkSize/8;
i++) {
206 const std::size_t values_per_entry =
sizeof(uint64_t)/
sizeof(T);
207 for (
int j = values_per_entry - 1; j >= 0; j--) {
209 static_cast<uint64_t
>(decomp_values[values_per_entry*
i+j]) <<
220 for (
int i = 0;
i <
sizeof(T);
i++) {
221 entry[
i] = value & 0xFF;
232 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.
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.
BaseDictionaryCompressorParams Params
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.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.