gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fpc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
35 #ifndef __MEM_CACHE_COMPRESSORS_FPC_HH__
36 #define __MEM_CACHE_COMPRESSORS_FPC_HH__
37 
38 #include <cstdint>
39 #include <map>
40 #include <memory>
41 #include <string>
42 #include <type_traits>
43 #include <vector>
44 
45 #include "base/bitfield.hh"
46 #include "base/types.hh"
48 
49 namespace gem5
50 {
51 
52 struct FPCParams;
53 
54 namespace compression
55 {
56 
57 class FPC : public DictionaryCompressor<uint32_t>
58 {
59  private:
61 
66  class FPCCompData;
67 
68  // Declaration of all possible patterns
69  class ZeroRun;
70  class SignExtended4Bits;
71  class SignExtended1Byte;
73  class ZeroPaddedHalfword;
75  class RepBytes;
76  class Uncompressed;
77 
83  {
88  };
89 
94  const int zeroRunSizeBits;
95 
96  uint64_t getNumPatterns() const override { return NUM_PATTERNS; }
97 
98  std::string
99  getName(int number) const override
100  {
101  static std::map<int, std::string> patternNames = {
102  {ZERO_RUN, "ZERO_RUN"},
103  {SIGN_EXTENDED_4_BITS, "SignExtended4Bits"},
104  {SIGN_EXTENDED_1_BYTE, "SignExtended1Byte"},
105  {SIGN_EXTENDED_HALFWORD, "SignExtendedHalfword"},
106  {ZERO_PADDED_HALFWORD, "ZeroPaddedHalfword"},
107  {SIGN_EXTENDED_TWO_HALFWORDS, "SignExtendedTwoHalfwords"},
108  {REP_BYTES, "RepBytes"},
109  {UNCOMPRESSED, "Uncompressed"}
110  };
111 
112  return patternNames[number];
113  };
114 
115  std::unique_ptr<Pattern> getPattern(
116  const DictionaryEntry& bytes,
117  const DictionaryEntry& dict_bytes,
118  const int match_location) const override
119  {
120  using PatternFactory = Factory<ZeroRun, SignExtended4Bits,
123  return PatternFactory::getPattern(bytes, dict_bytes, match_location);
124  }
125 
126  void addToDictionary(const DictionaryEntry data) override;
127 
128  std::unique_ptr<DictionaryCompressor::CompData>
129  instantiateDictionaryCompData() const override;
130 
131  public:
132  typedef FPCParams Params;
133  FPC(const Params &p);
134  ~FPC() = default;
135 };
136 
137 class FPC::FPCCompData : public DictionaryCompressor<uint32_t>::CompData
138 {
139  protected:
144  const int zeroRunSizeBits;
145 
146  public:
148  ~FPCCompData() = default;
149 
150  void addEntry(std::unique_ptr<Pattern> pattern) override;
151 };
152 
153 // Pattern implementations
154 
155 class FPC::ZeroRun : public MaskedValuePattern<0, 0xFFFFFFFF>
156 {
157  private:
160 
168 
169  public:
170  ZeroRun(const DictionaryEntry bytes, const int match_location)
171  : MaskedValuePattern<0, 0xFFFFFFFF>(ZERO_RUN, ZERO_RUN, 3, -1, bytes,
172  false),
173  _runLength(0), _realSize(0)
174  {
175  }
176 
177  std::size_t
178  getSizeBits() const override
179  {
180  return _realSize;
181  }
182 
188  int getRunLength() const { return _runLength; }
189 
195  void setRunLength(int length) { _runLength = length; }
196 
205  void setRealSize(int size) { _realSize = length + size; }
206 };
207 
208 class FPC::SignExtended4Bits : public SignExtendedPattern<4>
209 {
210  public:
211  SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
212  : SignExtendedPattern<4>(SIGN_EXTENDED_4_BITS, SIGN_EXTENDED_4_BITS, 3,
213  bytes)
214  {
215  }
216 };
217 
218 class FPC::SignExtended1Byte : public SignExtendedPattern<8>
219 {
220  public:
221  SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
222  : SignExtendedPattern<8>(SIGN_EXTENDED_1_BYTE, SIGN_EXTENDED_1_BYTE, 3,
223  bytes)
224  {
225  }
226 };
227 
228 class FPC::SignExtendedHalfword : public SignExtendedPattern<16>
229 {
230  public:
231  SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
232  : SignExtendedPattern<16>(SIGN_EXTENDED_HALFWORD, SIGN_EXTENDED_HALFWORD,
233  3, bytes)
234  {
235  }
236 };
237 
238 class FPC::ZeroPaddedHalfword : public MaskedValuePattern<0, 0x0000FFFF>
239 {
240  public:
241  ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
242  : MaskedValuePattern<0, 0x0000FFFF>(ZERO_PADDED_HALFWORD,
243  ZERO_PADDED_HALFWORD, 3, -1, bytes, false)
244  {
245  }
246 };
247 
248 class FPC::SignExtendedTwoHalfwords : public Pattern
249 {
250  private:
252  const int8_t extendedBytes[2];
253 
254  public:
256  const int match_location)
258  16, -1, false),
259  extendedBytes{int8_t(fromDictionaryEntry(bytes) & mask(8)),
260  int8_t((fromDictionaryEntry(bytes) >> 16) & mask(8))}
261  {
262  }
263 
264  static bool
266  const DictionaryEntry& dict_bytes, const int match_location)
267  {
268  const uint32_t data = fromDictionaryEntry(bytes);
269  const int16_t halfwords[2] = {
270  int16_t(data & mask(16)),
271  int16_t((data >> 16) & mask(16))
272  };
273  return (halfwords[0] == (uint16_t)szext<8>(halfwords[0])) &&
274  (halfwords[1] == (uint16_t)szext<8>(halfwords[1]));
275  }
276 
278  decompress(const DictionaryEntry dict_bytes) const override
279  {
280  uint16_t halfwords[2] = {
281  (uint16_t)szext<8>(extendedBytes[0]),
282  (uint16_t)szext<8>(extendedBytes[1])
283  };
284  return toDictionaryEntry((halfwords[1] << 16) | halfwords[0]);
285  }
286 };
287 
288 class FPC::RepBytes : public RepeatedValuePattern<uint8_t>
289 {
290  public:
291  RepBytes(const DictionaryEntry bytes, const int match_location)
292  : RepeatedValuePattern<uint8_t>(REP_BYTES, REP_BYTES, 3, -1, bytes,
293  false)
294  {
295  }
296 };
297 
298 class FPC::Uncompressed : public UncompressedPattern
299 {
300  public:
301  Uncompressed(const DictionaryEntry bytes, const int match_location)
302  : UncompressedPattern(UNCOMPRESSED, UNCOMPRESSED, 3, -1, bytes)
303  {
304  }
305 };
306 
307 } // namespace compression
308 } // namespace gem5
309 
310 #endif //__MEM_CACHE_COMPRESSORS_FPC_HH__
gem5::compression::FPC::addToDictionary
void addToDictionary(const DictionaryEntry data) override
Definition: fpc.cc:86
gem5::compression::FPC::UNCOMPRESSED
@ UNCOMPRESSED
Definition: fpc.hh:86
gem5::compression::DictionaryCompressor
A template version of the dictionary compressor that allows to choose the dictionary size.
Definition: dictionary_compressor.hh:117
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::compression::FPC::PatternNumber
PatternNumber
The possible patterns.
Definition: fpc.hh:82
gem5::compression::FPC::SIGN_EXTENDED_4_BITS
@ SIGN_EXTENDED_4_BITS
Definition: fpc.hh:84
gem5::compression::FPC::ZeroRun::getRunLength
int getRunLength() const
Get the number of zeros in the run so far.
Definition: fpc.hh:188
gem5::compression::FPC::SignExtendedTwoHalfwords
Definition: fpc.hh:248
gem5::compression::FPC::FPCCompData::zeroRunSizeBits
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:144
gem5::compression::FPC::FPCCompData::addEntry
void addEntry(std::unique_ptr< Pattern > pattern) override
Definition: fpc.cc:46
gem5::compression::FPC::~FPC
~FPC()=default
gem5::compression::FPC::ZeroRun::_realSize
int _realSize
A zero run consists of a main ZeroRun pattern, which has a meaningful real size (i....
Definition: fpc.hh:167
gem5::compression::FPC::SignExtended4Bits
Definition: fpc.hh:208
gem5::compression::Base::Params
BaseCacheCompressorParams Params
Definition: base.hh:201
gem5::compression::FPC::SignExtendedHalfword::SignExtendedHalfword
SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:231
gem5::compression::FPC::SignExtendedTwoHalfwords::extendedBytes
const int8_t extendedBytes[2]
These are the bytes that are extended to form the two halfwords.
Definition: fpc.hh:252
gem5::compression::FPC::NUM_PATTERNS
@ NUM_PATTERNS
Definition: fpc.hh:87
gem5::compression::FPC::RepBytes
Definition: fpc.hh:288
gem5::compression::FPC::SignExtendedTwoHalfwords::SignExtendedTwoHalfwords
SignExtendedTwoHalfwords(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:255
gem5::compression::FPC::Uncompressed
Definition: fpc.hh:298
gem5::compression::FPC::SIGN_EXTENDED_1_BYTE
@ SIGN_EXTENDED_1_BYTE
Definition: fpc.hh:84
gem5::compression::DictionaryCompressor< uint32_t >::fromDictionaryEntry
static uint32_t fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
Definition: dictionary_compressor_impl.hh:229
gem5::compression::FPC::getName
std::string getName(int number) const override
Get meta-name assigned to the given pattern.
Definition: fpc.hh:99
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::compression::FPC::ZeroRun::_runLength
int _runLength
Run length so far.
Definition: fpc.hh:159
dictionary_compressor.hh
gem5::compression::FPC::ZeroPaddedHalfword
Definition: fpc.hh:238
gem5::compression::FPC::ZeroRun::getSizeBits
std::size_t getSizeBits() const override
Definition: fpc.hh:178
bitfield.hh
gem5::compression::FPC::SignExtended1Byte
Definition: fpc.hh:218
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::compression::FPC::SignExtended4Bits::SignExtended4Bits
SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:211
gem5::compression::FPC::getNumPatterns
uint64_t getNumPatterns() const override
Trick function to get the number of patterns.
Definition: fpc.hh:96
gem5::compression::FPC::SignExtendedHalfword
Definition: fpc.hh:228
gem5::compression::FPC::FPCCompData::FPCCompData
FPCCompData(int zeroRunSizeBits)
Definition: fpc.cc:40
gem5::compression::FPC::ZeroRun::ZeroRun
ZeroRun(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:170
gem5::compression::FPC::FPC
FPC(const Params &p)
Definition: fpc.cc:80
gem5::compression::FPC::zeroRunSizeBits
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:94
gem5::compression::FPC::getPattern
std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location) const override
Definition: fpc.hh:115
gem5::compression::FPC::FPCCompData::~FPCCompData
~FPCCompData()=default
gem5::compression::FPC::ZERO_PADDED_HALFWORD
@ ZERO_PADDED_HALFWORD
Definition: fpc.hh:85
gem5::compression::FPC::RepBytes::RepBytes
RepBytes(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:291
gem5::compression::FPC::SignExtendedTwoHalfwords::isPattern
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Definition: fpc.hh:265
gem5::compression::FPC::SignExtendedTwoHalfwords::decompress
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Definition: fpc.hh:278
types.hh
gem5::compression::FPC::ZERO_RUN
@ ZERO_RUN
Definition: fpc.hh:84
gem5::compression::FPC::ZeroRun::setRealSize
void setRealSize(int size)
When the real size is set it means that we are adding the main zero run pattern.
Definition: fpc.hh:205
gem5::compression::FPC::SIGN_EXTENDED_TWO_HALFWORDS
@ SIGN_EXTENDED_TWO_HALFWORDS
Definition: fpc.hh:86
gem5::compression::FPC::FPCCompData
Definition: fpc.hh:137
gem5::compression::DictionaryCompressor< uint32_t >::toDictionaryEntry
static DictionaryEntry toDictionaryEntry(uint32_t value)
Turn a value into a dictionary entry.
Definition: dictionary_compressor_impl.hh:217
gem5::compression::FPC
Definition: fpc.hh:57
gem5::compression::FPC::Uncompressed::Uncompressed
Uncompressed(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:301
gem5::compression::FPC::ZeroRun::setRunLength
void setRunLength(int length)
Set the number of zeros in the run so far.
Definition: fpc.hh:195
gem5::compression::FPC::Params
FPCParams Params
Definition: fpc.hh:132
gem5::compression::FPC::ZeroRun
Definition: fpc.hh:155
gem5::compression::FPC::SignExtended1Byte::SignExtended1Byte
SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:221
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::compression::FPC::SIGN_EXTENDED_HALFWORD
@ SIGN_EXTENDED_HALFWORD
Definition: fpc.hh:85
gem5::compression::FPC::REP_BYTES
@ REP_BYTES
Definition: fpc.hh:86
gem5::compression::FPC::ZeroPaddedHalfword::ZeroPaddedHalfword
ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:241
gem5::compression::FPC::instantiateDictionaryCompData
std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const override
Definition: fpc.cc:95
gem5::compression::FPC::DictionaryEntry
DictionaryCompressor< uint32_t >::DictionaryEntry DictionaryEntry
Definition: fpc.hh:60

Generated on Sun Jul 30 2023 01:56:57 for gem5 by doxygen 1.8.17