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>
58 struct BaseDictionaryCompressorParams;
97 virtual std::string
getName(
int number)
const = 0;
100 typedef BaseDictionaryCompressorParams
Params;
126 class UncompressedPattern;
129 template <T value, T mask>
131 template <T mask,
int location>
133 template <
class RepT>
135 template <std::
size_t DeltaSizeBits>
143 template <
class Head,
class... Tail>
148 const int match_location)
154 if (Head::isPattern(bytes, dict_bytes, match_location)) {
155 return std::unique_ptr<Pattern>(
156 new Head(bytes, match_location));
171 template <
class Head>
174 static_assert(std::is_base_of<UncompressedPattern, Head>::value,
175 "The last pattern must always be derived from the uncompressed "
178 static std::unique_ptr<Pattern>
182 return std::unique_ptr<Pattern>(
new Head(bytes, match_location));
194 virtual std::unique_ptr<Pattern>
196 const int match_location)
const = 0;
229 virtual std::unique_ptr<DictionaryCompressor::CompData>
238 std::unique_ptr<Base::CompressionData>
compress(
268 typedef BaseDictionaryCompressorParams
Params;
311 Pattern(
const int number,
const uint64_t code,
312 const uint64_t metadata_length,
const uint64_t num_unmatched_bits,
313 const int match_location,
const bool allocate =
true)
314 : patternNumber(number), code(code),
length(metadata_length),
315 numUnmatchedBits(num_unmatched_bits),
316 matchLocation(match_location), allocate(allocate)
353 return numUnmatchedBits +
length;
371 return csprintf(
"pattern %s (encoding %x, size %u bits)",
372 getPatternNumber(), getCode(), getSizeBits());
401 virtual void addEntry(std::unique_ptr<Pattern>);
420 const uint64_t metadata_length,
421 const int match_location,
424 sizeof(T) * 8, match_location, true),
431 const int match_location)
462 static_assert(
mask != 0,
"The pattern's value mask must not be zero. Use "
463 "the uncompressed pattern instead.");
471 const uint64_t metadata_length,
472 const int match_location,
474 const bool allocate =
true)
476 popCount(static_cast<T>(~
mask)), match_location, allocate),
483 const int match_location)
485 const T masked_bytes =
487 const T masked_dict_bytes =
489 return (match_location >= 0) && (masked_bytes == masked_dict_bytes);
495 const T masked_dict_bytes =
498 bits | masked_dict_bytes);
519 template <T value, T mask>
521 :
public MaskedPattern<mask>
524 static_assert(
mask != 0,
"The pattern's value mask must not be zero.");
529 const uint64_t metadata_length,
530 const int match_location,
532 const bool allocate =
false)
540 const int match_location)
545 const T masked_bytes =
547 return ((value &
mask) == masked_bytes);
566 template <T mask,
int location>
568 :
public MaskedPattern<mask>
573 const uint64_t metadata_length,
574 const int match_location,
576 const bool allocate =
true)
584 const int match_location)
588 return (match_location == location) &&
604 template <
class RepT>
609 static_assert(
sizeof(T) >
sizeof(RepT),
"The repeated value's type must "
610 "be smaller than the dictionary entry's type.");
618 const uint64_t metadata_length,
619 const int match_location,
621 const bool allocate =
true)
623 8 * sizeof(RepT), match_location, allocate),
630 const int match_location)
636 const RepT rep_value = bytes_value;
637 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
638 RepT cur_value = bytes_value;
639 if (cur_value != rep_value) {
642 bytes_value >>= 8 *
sizeof(RepT);
653 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
654 decomp_value <<= 8 *
sizeof(RepT);
655 decomp_value |= value;
676 template <std::
size_t DeltaSizeBits>
681 static_assert(DeltaSizeBits < (
sizeof(T) * 8),
682 "Delta size must be smaller than base size");
694 const uint64_t metadata_length,
695 const int match_location,
698 DeltaSizeBits, match_location, false),
716 mask(DeltaSizeBits - 1) : 0;
729 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
741 #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
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)
DictionaryCompressor(const Params *p)
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.
BaseDictionaryCompressor(const Params *p)
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.
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.
int popCount(uint64_t val)
Returns the number of set ones in the provided value.
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.
std::size_t getSizeBits() const
Get size, in bits, of the pattern (excluding prefix).
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
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.
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)
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
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)
~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
Decompress 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.
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17