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;
103 virtual std::string
getName(
int number)
const = 0;
106 typedef BaseDictionaryCompressorParams
Params;
132 class UncompressedPattern;
135 template <T value, T mask>
137 template <T mask,
int location>
139 template <
class RepT>
141 template <std::
size_t DeltaSizeBits>
143 template <
unsigned N>
151 template <
class Head,
class... Tail>
156 const int match_location)
162 if (Head::isPattern(bytes, dict_bytes, match_location)) {
163 return std::unique_ptr<Pattern>(
164 new Head(bytes, match_location));
179 template <
class Head>
182 static_assert(std::is_base_of_v<UncompressedPattern, Head>,
183 "The last pattern must always be derived from the uncompressed "
186 static std::unique_ptr<Pattern>
190 return std::unique_ptr<Pattern>(
new Head(bytes, match_location));
202 virtual std::unique_ptr<Pattern>
204 const int match_location)
const = 0;
237 virtual std::unique_ptr<DictionaryCompressor::CompData>
246 std::unique_ptr<Base::CompressionData>
compress(
249 std::unique_ptr<Base::CompressionData>
compress(
274 typedef BaseDictionaryCompressorParams
Params;
317 Pattern(
const int number,
const uint64_t code,
318 const uint64_t metadata_length,
const uint64_t num_unmatched_bits,
319 const int match_location,
const bool allocate =
true)
320 : patternNumber(number), code(code), length(metadata_length),
321 numUnmatchedBits(num_unmatched_bits),
322 matchLocation(match_location), allocate(allocate)
359 return numUnmatchedBits + length;
377 return csprintf(
"pattern %s (encoding %x, size %u bits)",
378 getPatternNumber(), getCode(), getSizeBits());
407 virtual void addEntry(std::unique_ptr<Pattern>);
426 const uint64_t metadata_length,
427 const int match_location,
430 sizeof(T) * 8, match_location, true),
437 const int match_location)
468 static_assert(
mask != 0,
"The pattern's value mask must not be zero. Use "
469 "the uncompressed pattern instead.");
477 const uint64_t metadata_length,
478 const int match_location,
480 const bool allocate =
true)
482 popCount(static_cast<T>(~
mask)), match_location, allocate),
489 const int match_location)
491 const T masked_bytes =
493 const T masked_dict_bytes =
495 return (match_location >= 0) && (masked_bytes == masked_dict_bytes);
501 const T masked_dict_bytes =
504 bits | masked_dict_bytes);
525 template <T value, T mask>
527 :
public MaskedPattern<mask>
530 static_assert(
mask != 0,
"The pattern's value mask must not be zero.");
535 const uint64_t metadata_length,
536 const int match_location,
538 const bool allocate =
false)
546 const int match_location)
551 const T masked_bytes =
553 return ((value &
mask) == masked_bytes);
572 template <T mask,
int location>
574 :
public MaskedPattern<mask>
579 const uint64_t metadata_length,
580 const int match_location,
582 const bool allocate =
true)
590 const int match_location)
594 return (match_location == location) &&
610 template <
class RepT>
615 static_assert(
sizeof(T) >
sizeof(RepT),
"The repeated value's type must "
616 "be smaller than the dictionary entry's type.");
624 const uint64_t metadata_length,
625 const int match_location,
627 const bool allocate =
true)
629 8 * sizeof(RepT), match_location, allocate),
636 const int match_location)
642 const RepT rep_value = bytes_value;
643 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
644 RepT cur_value = bytes_value;
645 if (cur_value != rep_value) {
648 bytes_value >>= 8 *
sizeof(RepT);
659 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
660 decomp_value <<= 8 *
sizeof(RepT);
661 decomp_value |= value;
682 template <std::
size_t DeltaSizeBits>
687 static_assert(DeltaSizeBits < (
sizeof(T) * 8),
688 "Delta size must be smaller than base size");
700 const uint64_t metadata_length,
701 const int match_location,
704 DeltaSizeBits, match_location, false),
722 mask(DeltaSizeBits - 1) : 0;
735 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
756 template <
unsigned N>
761 static_assert((N > 0) & (N <= (
sizeof(T) * 8)),
762 "The original data's type size must be smaller than the dictionary's");
770 const uint64_t metadata_length,
772 const bool allocate =
false)
797 #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.
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
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 Tue Feb 8 2022 11:47:09 for gem5 by doxygen 1.8.17