43#ifndef __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
44#define __MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__
62struct BaseDictionaryCompressorParams;
102 virtual std::string
getName(
int number)
const = 0;
105 typedef BaseDictionaryCompressorParams
Params;
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);
524template <T value, T 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);
571template <T mask,
int location>
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) &&
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;
681template <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),
720 const typename std::make_signed<T>::type
limit = DeltaSizeBits ?
721 mask(DeltaSizeBits - 1) : 0;
726 const typename std::make_signed<T>::type delta = value -
base;
734 return (match_location >= 0) && isValidDelta(bytes, dict_bytes);
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)
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Cycles is a wrapper class for representing cycle counts, i.e.
virtual std::string getName(int number) const =0
Get meta-name assigned to the given pattern.
~BaseDictionaryCompressor()=default
const std::size_t dictionarySize
Dictionary size.
BaseDictionaryCompressor(const Params &p)
virtual uint64_t getNumPatterns() const =0
Trick function to get the number of patterns.
std::size_t numEntries
Number of valid entries in the dictionary.
BaseDictionaryCompressorParams Params
gem5::compression::BaseDictionaryCompressor::DictionaryStats dictionaryStats
Base cache compressor interface.
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.
std::vector< std::unique_ptr< Pattern > > entries
The patterns matched in the original line.
A pattern that checks whether the difference of the value and the dictionary entries' is below a cert...
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.
const DictionaryEntry bytes
The original value.
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...
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...
LocatedMaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern that compares masked values against dictionary entries.
MaskedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const int match_location, const DictionaryEntry bytes, const bool allocate=true)
const T bits
A copy of the bits that do not belong to the mask.
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.
A pattern that compares masked values to a masked portion of a fixed value.
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)
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
The compressed data is composed of multiple pattern entries.
const int matchLocation
Index representing the the match location.
virtual DictionaryEntry decompress(const DictionaryEntry dict_bytes) const =0
Decompress the pattern.
const uint8_t length
Length, in bits, of the code and match location.
std::string print() const
Extract pattern's information to a string.
uint8_t getCode() const
Get code of this pattern.
bool shouldAllocate() const
Determine if pattern allocates a dictionary entry.
virtual 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.
const int patternNumber
Pattern enum number.
int getPatternNumber() const
Get enum number associated to this pattern.
const bool allocate
Wether the pattern allocates a dictionary entry or not.
const uint8_t numUnmatchedBits
Number of unmatched bits.
uint8_t getMatchLocation() const
Get the index of the dictionary match location.
const uint8_t code
Code associated to the pattern.
virtual ~Pattern()=default
Default destructor.
A pattern that checks if dictionary entry sized values are solely composed of multiple copies of a si...
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)
RepT value
The repeated value.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A pattern that checks whether the value is an N bits sign-extended value, that is,...
SignExtendedPattern(const int number, const uint64_t code, const uint64_t metadata_length, const DictionaryEntry bytes, const bool allocate=false)
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
const T bits
The non-extended original value.
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Decompress the pattern.
A pattern containing the original uncompressed data.
UncompressedPattern(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.
const DictionaryEntry data
A copy of the original data.
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
A template version of the dictionary compressor that allows to choose the dictionary size.
static T fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
std::vector< DictionaryEntry > dictionary
The dictionary.
virtual void addToDictionary(const DictionaryEntry data)=0
Add an entry to the dictionary.
~DictionaryCompressor()=default
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...
BaseDictionaryCompressorParams Params
virtual void resetDictionary()
Clear all dictionary entries.
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.
std::array< uint8_t, sizeof(T)> DictionaryEntry
Convenience typedef for a dictionary entry.
T decompressValue(const Pattern *pattern)
Decompress a pattern into a value that fits in a dictionary entry.
void decompress(const CompressionData *comp_data, uint64_t *data) override
Apply the decompression process to the compressed data.
std::unique_ptr< Base::CompressionData > compress(const std::vector< Chunk > &chunks)
Apply compression.
static DictionaryEntry toDictionaryEntry(T value)
Turn a value into a dictionary entry.
A vector of scalar stats.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr int popCount(uint64_t val)
Returns the number of set ones in the provided value.
constexpr uint64_t szext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition of a basic cache compressor.
BitfieldType< SegDescriptorLimit > limit
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::string csprintf(const char *format, const Args &...args)
Declaration of Statistics objects.
statistics::Vector patterns
Number of data entries that were compressed to each pattern.
const BaseDictionaryCompressor & compressor
void regStats() override
Callback to set stat parameters.
DictionaryStats(BaseStats &base_group, BaseDictionaryCompressor &_compressor)
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Create a factory to determine if input matches a pattern.
static std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)