45 #ifndef __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__ 46 #define __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__ 53 #include <type_traits> 59 struct BaseDictionaryCompressorParams;
95 virtual std::string
getName(
int number)
const = 0;
98 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>
147 const DictionaryEntry& bytes,
const DictionaryEntry& dict_bytes,
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>
180 const DictionaryEntry& dict_bytes,
const int match_location)
182 return std::unique_ptr<Pattern>(
new Head(bytes, match_location));
194 virtual std::unique_ptr<Pattern>
195 getPattern(
const DictionaryEntry& bytes,
const DictionaryEntry& dict_bytes,
196 const int match_location)
const = 0;
204 std::unique_ptr<Pattern> compressValue(
const T
data);
212 T decompressValue(
const Pattern* pattern);
215 virtual void resetDictionary();
222 virtual void addToDictionary(
const DictionaryEntry
data) = 0;
230 std::unique_ptr<BaseCacheCompressor::CompressionData>
compress(
231 const uint64_t*
data);
249 static DictionaryEntry toDictionaryEntry(T value);
257 static T fromDictionaryEntry(
const DictionaryEntry& entry);
260 typedef BaseDictionaryCompressorParams
Params;
303 Pattern(
const int number,
const uint64_t code,
304 const uint64_t metadata_length,
const uint64_t num_unmatched_bits,
305 const int match_location,
const bool allocate =
true)
306 : patternNumber(number), code(code), length(metadata_length),
307 numUnmatchedBits(num_unmatched_bits),
308 matchLocation(match_location), allocate(allocate)
345 return numUnmatchedBits +
length;
363 return csprintf(
"pattern %s (encoding %x, size %u bits)",
364 getPatternNumber(), getCode(), getSizeBits());
393 virtual void addEntry(std::unique_ptr<Pattern>);
412 const uint64_t metadata_length,
413 const int match_location,
416 sizeof(T) * 8, match_location, true),
423 const int match_location)
454 static_assert(
mask != 0,
"The pattern's value mask must not be zero. Use " 455 "the uncompressed pattern instead.");
463 const uint64_t metadata_length,
464 const int match_location,
466 const bool allocate =
true)
475 const int match_location)
477 const T masked_bytes =
479 const T masked_dict_bytes =
481 return (match_location >= 0) && (masked_bytes == masked_dict_bytes);
487 const T masked_dict_bytes =
490 bits | masked_dict_bytes);
511 template <T value, T mask>
516 static_assert(
mask != 0,
"The pattern's value mask must not be zero.");
521 const uint64_t metadata_length,
522 const int match_location,
524 const bool allocate =
false)
532 const int match_location)
537 const T masked_bytes =
539 return ((value &
mask) == masked_bytes);
558 template <T mask,
int location>
565 const uint64_t metadata_length,
566 const int match_location,
575 const int match_location)
579 return (match_location == location) &&
595 template <
class RepT>
600 static_assert(
sizeof(T) >
sizeof(RepT),
"The repeated value's type must " 601 "be smaller than the dictionary entry's type.");
609 const uint64_t metadata_length,
610 const int match_location,
612 const bool allocate =
true)
614 8 * sizeof(RepT), match_location, allocate),
621 const int match_location)
627 const RepT rep_value = bytes_value;
628 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
629 RepT cur_value = bytes_value;
630 if (cur_value != rep_value) {
633 bytes_value >>= 8 *
sizeof(RepT);
644 for (
int i = 0;
i < (
sizeof(T) /
sizeof(RepT));
i++) {
645 decomp_value <<= 8 *
sizeof(RepT);
646 decomp_value |= value;
667 template <std::
size_t DeltaSizeBits>
672 static_assert(DeltaSizeBits < (
sizeof(T) * 8),
673 "Delta size must be smaller than base size");
685 const uint64_t metadata_length,
686 const int match_location,
689 DeltaSizeBits, match_location, false),
707 mask(DeltaSizeBits - 1) : 0;
713 return (delta >= -limit) && (delta <=
limit);
720 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
730 #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__ MaskedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=false)
virtual std::unique_ptr< CompressionData > compress(const uint64_t *cache_line, Cycles &comp_lat, Cycles &decomp_lat)=0
Apply the compression process to the cache line.
A pattern that compares masked values against dictionary entries.
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.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
static DictionaryEntry toDictionaryEntry(T value)
Turn a value into a dictionary entry.
void regStats() override
Callback to set stat parameters.
static std::unique_ptr< Pattern > getPattern(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)
Definition of a basic cache compressor.
A vector of scalar stats.
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.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern that compares masked values to a masked portion of a fixed value.
uint8_t getCode() const
Get code of this pattern.
bool shouldAllocate() const
Determine if pattern allocates a dictionary entry.
std::string print() const
Extract pattern's information to a string.
const std::size_t dictionarySize
Dictionary size.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
std::size_t getSizeBits() const
Get size, in bits, of the pattern (excluding prefix).
int getPatternNumber() const
Get enum number associated to this pattern.
~BaseDictionaryCompressor()=default
std::string csprintf(const char *format, const Args &...args)
virtual std::string getName(int number) const =0
Get meta-name assigned to the given pattern.
BaseDictionaryCompressorParams Params
virtual uint64_t getNumPatterns() const =0
Trick function to get the number of patterns.
Create a factory to determine if input matches a pattern.
The compressed data is composed of multiple pattern entries.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
const bool allocate
Wether the pattern allocates a dictionary entry or not.
const uint8_t code
Code associated to the pattern.
std::vector< std::unique_ptr< Pattern > > entries
The patterns matched in the original line.
RepT value
The repeated value.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
A pattern that checks if dictionary entry sized values are solely composed of multiple copies of a si...
Base cache compressor interface.
const DictionaryEntry data
A copy of the original data.
A pattern that narrows the MaskedPattern by allowing a only single possible dictionary entry to be ma...
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
static T fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
std::array< uint8_t, sizeof(T)> DictionaryEntry
Convenience typedef for a dictionary entry.
UncompressedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
std::vector< DictionaryEntry > dictionary
The dictionary.
DeltaPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes)
A pattern that checks whether the difference of the value and the dictionary entries' is below a cert...
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.
Stats::Vector patternStats
Number of data entries that were compressed to each pattern.
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
BitfieldType< SegDescriptorLimit > limit
A pattern containing the original uncompressed data.
const DictionaryEntry bytes
The original value.
const int patternNumber
Pattern enum number.
BaseDictionaryCompressor(const Params *p)
const T bits
A copy of the bits that do not belong to the mask.
MaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
LocatedMaskedPattern(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.
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...
BaseDictionaryCompressorParams Params
const uint8_t length
Length, in bits, of the code and match location.
const uint8_t numUnmatchedBits
Number of unmatched bits.
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
RepeatedValuePattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
const int matchLocation
Index representing the the match location.
A template version of the dictionary compressor that allows to choose the dictionary size...
virtual void decompress(const CompressionData *comp_data, uint64_t *cache_line)=0
Apply the decompression process to the compressed data.