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>
62 struct BaseDictionaryCompressorParams;
102 virtual std::string
getName(
int number)
const = 0;
105 typedef BaseDictionaryCompressorParams
Params;
131 class UncompressedPattern;
134 template <T value, T mask>
136 template <T mask,
int location>
138 template <
class RepT>
140 template <std::
size_t DeltaSizeBits>
142 template <
unsigned N>
150 template <
class Head,
class... Tail>
155 const int match_location)
161 if (Head::isPattern(bytes, dict_bytes, match_location)) {
162 return std::unique_ptr<Pattern>(
163 new Head(bytes, match_location));
178 template <
class Head>
181 static_assert(std::is_base_of_v<UncompressedPattern, Head>,
182 "The last pattern must always be derived from the uncompressed "
185 static std::unique_ptr<Pattern>
189 return std::unique_ptr<Pattern>(
new Head(bytes, match_location));
201 virtual std::unique_ptr<Pattern>
203 const int match_location)
const = 0;
236 virtual std::unique_ptr<DictionaryCompressor::CompData>
245 std::unique_ptr<Base::CompressionData>
compress(
248 std::unique_ptr<Base::CompressionData>
compress(
273 typedef BaseDictionaryCompressorParams
Params;
316 Pattern(
const int number,
const uint64_t code,
317 const uint64_t metadata_length,
const uint64_t num_unmatched_bits,
318 const int match_location,
const bool allocate =
true)
319 : patternNumber(number), code(code), length(metadata_length),
320 numUnmatchedBits(num_unmatched_bits),
321 matchLocation(match_location), allocate(allocate)
358 return numUnmatchedBits + length;
376 return csprintf(
"pattern %s (encoding %x, size %u bits)",
377 getPatternNumber(), getCode(), getSizeBits());
406 virtual void addEntry(std::unique_ptr<Pattern>);
425 const uint64_t metadata_length,
426 const int match_location,
429 sizeof(T) * 8, match_location, true),
436 const int match_location)
467 static_assert(
mask != 0,
"The pattern's value mask must not be zero. Use "
468 "the uncompressed pattern instead.");
476 const uint64_t metadata_length,
477 const int match_location,
479 const bool allocate =
true)
481 popCount(static_cast<T>(~
mask)), match_location, allocate),
488 const int match_location)
490 const T masked_bytes =
492 const T masked_dict_bytes =
494 return (match_location >= 0) && (masked_bytes == masked_dict_bytes);
500 const T masked_dict_bytes =
503 bits | masked_dict_bytes);
524 template <T value, T mask>
526 :
public MaskedPattern<mask>
529 static_assert(
mask != 0,
"The pattern's value mask must not be zero.");
534 const uint64_t metadata_length,
535 const int match_location,
537 const bool allocate =
false)
545 const int match_location)
550 const T masked_bytes =
552 return ((value &
mask) == masked_bytes);
571 template <T mask,
int location>
573 :
public MaskedPattern<mask>
578 const uint64_t metadata_length,
579 const int match_location,
581 const bool allocate =
true)
589 const int match_location)
593 return (match_location == location) &&
609 template <
class RepT>
614 static_assert(
sizeof(T) >
sizeof(RepT),
"The repeated value's type must "
615 "be smaller than the dictionary entry's type.");
623 const uint64_t metadata_length,
624 const int match_location,
626 const bool allocate =
true)
628 8 * sizeof(RepT), match_location, allocate),
635 const int match_location)
641 const RepT rep_value = bytes_value;
642 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
643 RepT cur_value = bytes_value;
644 if (cur_value != rep_value) {
647 bytes_value >>= 8 *
sizeof(RepT);
658 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
659 decomp_value <<= 8 *
sizeof(RepT);
660 decomp_value |= value;
681 template <std::
size_t DeltaSizeBits>
686 static_assert(DeltaSizeBits < (
sizeof(T) * 8),
687 "Delta size must be smaller than base size");
699 const uint64_t metadata_length,
700 const int match_location,
703 DeltaSizeBits, match_location, false),
721 mask(DeltaSizeBits - 1) : 0;
734 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
755 template <
unsigned N>
760 static_assert((N > 0) & (N <= (
sizeof(T) * 8)),
761 "The original data's type size must be smaller than the dictionary's");
769 const uint64_t metadata_length,
771 const bool allocate =
false)
796 #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
const std::size_t dictionarySize
Dictionary size.
~BaseDictionaryCompressor()=default
A template version of the dictionary compressor that allows to choose the dictionary size.
std::vector< DictionaryEntry > dictionary
The dictionary.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
statistics::Vector patterns
Number of data entries that were compressed to each pattern.
A pattern that compares masked values to a masked portion of a fixed value.
DeltaPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
A pattern that checks whether the value is an N bits sign-extended value, that is,...
Create a factory to determine if input matches a pattern.
virtual void addToDictionary(const DictionaryEntry data)=0
Add an entry to the dictionary.
const DictionaryEntry bytes
The original value.
SignExtendedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const DictionaryEntry bytes, const bool allocate=false)
std::array< uint8_t, sizeof(uint64_t)> DictionaryEntry
Convenience typedef for a dictionary entry.
const uint8_t code
Code associated to the pattern.
const uint8_t numUnmatchedBits
Number of unmatched bits.
A pattern that checks if dictionary entry sized values are solely composed of multiple copies of a si...
DictionaryStats(BaseStats &base_group, BaseDictionaryCompressor &_compressor)
BaseCacheCompressorParams Params
A pattern containing the original uncompressed data.
A vector of scalar stats.
std::string csprintf(const char *format, const Args &...args)
BitfieldType< SegDescriptorLimit > limit
std::unique_ptr< Base::CompressionData > compress(const std::vector< Chunk > &chunks)
Apply compression.
BaseDictionaryCompressor(const Params &p)
const BaseDictionaryCompressor & compressor
static T fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Cycles is a wrapper class for representing cycle counts, i.e.
const int patternNumber
Pattern enum number.
RepT value
The repeated value.
virtual std::string getName(int number) const =0
Get meta-name assigned to the given pattern.
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...
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.
BaseDictionaryCompressorParams Params
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
std::vector< std::unique_ptr< Pattern > > entries
The patterns matched in the original line.
A pattern that compares masked values against dictionary entries.
void regStats() override
Callback to set stat parameters.
DictionaryCompressor(const Params &p)
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
constexpr int popCount(uint64_t val)
Returns the number of set ones in the provided value.
std::size_t numEntries
Number of valid entries in the dictionary.
virtual uint64_t getNumPatterns() const =0
Trick function to get the number of patterns.
Base cache compressor interface.
gem5::compression::BaseDictionaryCompressor::DictionaryStats dictionaryStats
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
const bool allocate
Wether the pattern allocates a dictionary entry or not.
A pattern that narrows the MaskedPattern by allowing a only single possible dictionary entry to be ma...
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
LocatedMaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
BaseDictionaryCompressorParams Params
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.
const uint8_t length
Length, in bits, of the code and match location.
const int matchLocation
Index representing the the match location.
virtual std::size_t getSizeBits() const
Get size, in bits, of the pattern (excluding prefix).
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
MaskedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=false)
void decompress(const CompressionData *comp_data, uint64_t *data) override
Apply the decompression process to the compressed data.
const DictionaryEntry data
A copy of the original data.
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)
const T bits
A copy of the bits that do not belong to the mask.
~DictionaryCompressor()=default
int getPatternNumber() const
Get enum number associated to this pattern.
uint8_t getMatchLocation() const
Get the index of the dictionary match location.
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.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
uint8_t getCode() const
Get code of this pattern.
virtual void resetDictionary()
Clear all dictionary entries.
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.
A pattern that checks whether the difference of the value and the dictionary entries' is below a cert...
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...
MaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
static DictionaryEntry toDictionaryEntry(T value)
Turn a value into a dictionary entry.
bool shouldAllocate() const
Determine if pattern allocates a dictionary entry.
T decompressValue(const Pattern *pattern)
Decompress a pattern into a value that fits in a dictionary entry.
const T bits
The non-extended original value.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
UncompressedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
The compressed data is composed of multiple pattern entries.
RepeatedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17