Go to the documentation of this file.
43 #ifndef __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
44 #define __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
51 #include <type_traits>
59 struct BaseDictionaryCompressorParams;
98 virtual std::string
getName(
int number)
const = 0;
101 typedef BaseDictionaryCompressorParams
Params;
127 class UncompressedPattern;
130 template <T value, T mask>
132 template <T mask,
int location>
134 template <
class RepT>
136 template <std::
size_t DeltaSizeBits>
138 template <
unsigned N>
146 template <
class Head,
class... Tail>
151 const int match_location)
157 if (Head::isPattern(bytes, dict_bytes, match_location)) {
158 return std::unique_ptr<Pattern>(
159 new Head(bytes, match_location));
174 template <
class Head>
177 static_assert(std::is_base_of<UncompressedPattern, Head>::value,
178 "The last pattern must always be derived from the uncompressed "
181 static std::unique_ptr<Pattern>
185 return std::unique_ptr<Pattern>(
new Head(bytes, match_location));
197 virtual std::unique_ptr<Pattern>
199 const int match_location)
const = 0;
232 virtual std::unique_ptr<DictionaryCompressor::CompData>
241 std::unique_ptr<Base::CompressionData>
compress(
244 std::unique_ptr<Base::CompressionData>
compress(
269 typedef BaseDictionaryCompressorParams
Params;
312 Pattern(
const int number,
const uint64_t code,
313 const uint64_t metadata_length,
const uint64_t num_unmatched_bits,
314 const int match_location,
const bool allocate =
true)
315 : patternNumber(number), code(code), length(metadata_length),
316 numUnmatchedBits(num_unmatched_bits),
317 matchLocation(match_location), allocate(allocate)
354 return numUnmatchedBits + length;
372 return csprintf(
"pattern %s (encoding %x, size %u bits)",
373 getPatternNumber(), getCode(), getSizeBits());
402 virtual void addEntry(std::unique_ptr<Pattern>);
421 const uint64_t metadata_length,
422 const int match_location,
425 sizeof(T) * 8, match_location, true),
432 const int match_location)
463 static_assert(
mask != 0,
"The pattern's value mask must not be zero. Use "
464 "the uncompressed pattern instead.");
472 const uint64_t metadata_length,
473 const int match_location,
475 const bool allocate =
true)
477 popCount(static_cast<T>(~
mask)), match_location, allocate),
484 const int match_location)
486 const T masked_bytes =
488 const T masked_dict_bytes =
490 return (match_location >= 0) && (masked_bytes == masked_dict_bytes);
496 const T masked_dict_bytes =
499 bits | masked_dict_bytes);
520 template <T value, T mask>
522 :
public MaskedPattern<mask>
525 static_assert(
mask != 0,
"The pattern's value mask must not be zero.");
530 const uint64_t metadata_length,
531 const int match_location,
533 const bool allocate =
false)
541 const int match_location)
546 const T masked_bytes =
548 return ((value &
mask) == masked_bytes);
567 template <T mask,
int location>
569 :
public MaskedPattern<mask>
574 const uint64_t metadata_length,
575 const int match_location,
577 const bool allocate =
true)
585 const int match_location)
589 return (match_location == location) &&
605 template <
class RepT>
610 static_assert(
sizeof(T) >
sizeof(RepT),
"The repeated value's type must "
611 "be smaller than the dictionary entry's type.");
619 const uint64_t metadata_length,
620 const int match_location,
622 const bool allocate =
true)
624 8 * sizeof(RepT), match_location, allocate),
631 const int match_location)
637 const RepT rep_value = bytes_value;
638 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
639 RepT cur_value = bytes_value;
640 if (cur_value != rep_value) {
643 bytes_value >>= 8 *
sizeof(RepT);
654 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
655 decomp_value <<= 8 *
sizeof(RepT);
656 decomp_value |= value;
677 template <std::
size_t DeltaSizeBits>
682 static_assert(DeltaSizeBits < (
sizeof(T) * 8),
683 "Delta size must be smaller than base size");
695 const uint64_t metadata_length,
696 const int match_location,
699 DeltaSizeBits, match_location, false),
717 mask(DeltaSizeBits - 1) : 0;
730 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
751 template <
unsigned N>
756 static_assert((N > 0) & (N <= (
sizeof(T) * 8)),
757 "The original data's type size must be smaller than the dictionary's");
765 const uint64_t metadata_length,
767 const bool allocate =
false)
791 #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
virtual std::size_t getSizeBits() const
Get size, in bits, of the pattern (excluding prefix).
BaseDictionaryCompressor(const Params &p)
virtual uint64_t getNumPatterns() const =0
Trick function to get the number of patterns.
virtual std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location) const =0
Since the factory cannot be instantiated here, classes that inherit from this base class have to impl...
DeltaPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
MaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
constexpr int popCount(uint64_t val)
Returns the number of set ones in the provided value.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
uint8_t getMatchLocation() const
Get the index of the dictionary match location.
RepeatedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
std::array< uint8_t, sizeof(uint64_t)> DictionaryEntry
Convenience typedef for a dictionary entry.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
std::string print() const
Extract pattern's information to a string.
Compressor::BaseDictionaryCompressor::DictionaryStats dictionaryStats
virtual void addToDictionary(const DictionaryEntry data)=0
Add an entry to the dictionary.
const uint8_t numUnmatchedBits
Number of unmatched bits.
virtual void resetDictionary()
Clear all dictionary entries.
RepT value
The repeated value.
std::unique_ptr< Base::CompressionData > compress(const std::vector< Chunk > &chunks)
Apply compression.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
const DictionaryEntry data
A copy of the original data.
virtual std::string getName(int number) const =0
Get meta-name assigned to the given pattern.
std::size_t numEntries
Number of valid entries in the dictionary.
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Base cache compressor interface.
~BaseDictionaryCompressor()=default
A vector of scalar stats.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
virtual std::unique_ptr< CompressionData > compress(const std::vector< Chunk > &chunks, Cycles &comp_lat, Cycles &decomp_lat)=0
Apply the compression process to the cache line.
const int matchLocation
Index representing the the match location.
Pattern(const int number, const uint64_t code, const uint64_t metadata_length, const uint64_t num_unmatched_bits, const int match_location, const bool allocate=true)
Default constructor.
A template version of the dictionary compressor that allows to choose the dictionary size.
MaskedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=false)
const bool allocate
Wether the pattern allocates a dictionary entry or not.
Stats::Vector patterns
Number of data entries that were compressed to each pattern.
const int patternNumber
Pattern enum number.
DictionaryStats(BaseStats &base_group, BaseDictionaryCompressor &_compressor)
BaseCacheCompressorParams Params
A pattern that compares masked values to a masked portion of a fixed value.
const T bits
The non-extended original value.
const T bits
A copy of the bits that do not belong to the mask.
std::vector< std::unique_ptr< Pattern > > entries
The patterns matched in the original line.
A pattern that checks whether the value is an N bits sign-extended value, that is,...
bool shouldAllocate() const
Determine if pattern allocates a dictionary entry.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
const DictionaryEntry bytes
The original value.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
virtual std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const
Instantiate a compression data of the sub-class compressor.
BaseDictionaryCompressorParams Params
static T fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern that checks if dictionary entry sized values are solely composed of multiple copies of a si...
static DictionaryEntry toDictionaryEntry(T value)
Turn a value into a dictionary entry.
A pattern that checks whether the difference of the value and the dictionary entries' is below a cert...
UncompressedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
BaseDictionaryCompressorParams Params
LocatedMaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
Cycles is a wrapper class for representing cycle counts, i.e.
Create a factory to determine if input matches a pattern.
std::vector< DictionaryEntry > dictionary
The dictionary.
T decompressValue(const Pattern *pattern)
Decompress a pattern into a value that fits in a dictionary entry.
BitfieldType< SegDescriptorLimit > limit
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
uint8_t getCode() const
Get code of this pattern.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
const BaseDictionaryCompressor & compressor
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
SignExtendedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const DictionaryEntry bytes, const bool allocate=false)
DictionaryCompressor(const Params &p)
~DictionaryCompressor()=default
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern that narrows the MaskedPattern by allowing a only single possible dictionary entry to be ma...
The compressed data is composed of multiple pattern entries.
static bool isValidDelta(const DictionaryEntry &bytes, const DictionaryEntry &base_bytes)
Compares a given value against a base to calculate their delta, and then determines whether it fits a...
const uint8_t length
Length, in bits, of the code and match location.
const std::size_t dictionarySize
Dictionary size.
void decompress(const CompressionData *comp_data, uint64_t *data) override
Apply the decompression process to the compressed data.
std::unique_ptr< Pattern > compressValue(const T data)
Compress data.
std::string csprintf(const char *format, const Args &...args)
const uint8_t code
Code associated to the pattern.
A pattern that compares masked values against dictionary entries.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern containing the original uncompressed data.
int getPatternNumber() const
Get enum number associated to this pattern.
void regStats() override
Callback to set stat parameters.
Generated on Tue Jun 22 2021 15:28:29 for gem5 by doxygen 1.8.17