gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(Compressor, compression);
55 namespace compression
56 {
57 
58 class FPC : public DictionaryCompressor<uint32_t>
59 {
60  private:
62 
67  class FPCCompData;
68 
69  // Declaration of all possible patterns
70  class ZeroRun;
71  class SignExtended4Bits;
72  class SignExtended1Byte;
74  class ZeroPaddedHalfword;
76  class RepBytes;
77  class Uncompressed;
78 
84  {
89  };
90 
95  const int zeroRunSizeBits;
96 
97  uint64_t getNumPatterns() const override { return NUM_PATTERNS; }
98 
99  std::string
100  getName(int number) const override
101  {
102  static std::map<int, std::string> patternNames = {
103  {ZERO_RUN, "ZERO_RUN"},
104  {SIGN_EXTENDED_4_BITS, "SignExtended4Bits"},
105  {SIGN_EXTENDED_1_BYTE, "SignExtended1Byte"},
106  {SIGN_EXTENDED_HALFWORD, "SignExtendedHalfword"},
107  {ZERO_PADDED_HALFWORD, "ZeroPaddedHalfword"},
108  {SIGN_EXTENDED_TWO_HALFWORDS, "SignExtendedTwoHalfwords"},
109  {REP_BYTES, "RepBytes"},
110  {UNCOMPRESSED, "Uncompressed"}
111  };
112 
113  return patternNames[number];
114  };
115 
116  std::unique_ptr<Pattern> getPattern(
117  const DictionaryEntry& bytes,
118  const DictionaryEntry& dict_bytes,
119  const int match_location) const override
120  {
121  using PatternFactory = Factory<ZeroRun, SignExtended4Bits,
124  return PatternFactory::getPattern(bytes, dict_bytes, match_location);
125  }
126 
127  void addToDictionary(const DictionaryEntry data) override;
128 
129  std::unique_ptr<DictionaryCompressor::CompData>
130  instantiateDictionaryCompData() const override;
131 
132  public:
133  typedef FPCParams Params;
134  FPC(const Params &p);
135  ~FPC() = default;
136 };
137 
138 class FPC::FPCCompData : public DictionaryCompressor<uint32_t>::CompData
139 {
140  protected:
145  const int zeroRunSizeBits;
146 
147  public:
149  ~FPCCompData() = default;
150 
151  void addEntry(std::unique_ptr<Pattern> pattern) override;
152 };
153 
154 // Pattern implementations
155 
156 class FPC::ZeroRun : public MaskedValuePattern<0, 0xFFFFFFFF>
157 {
158  private:
161 
169 
170  public:
171  ZeroRun(const DictionaryEntry bytes, const int match_location)
172  : MaskedValuePattern<0, 0xFFFFFFFF>(ZERO_RUN, ZERO_RUN, 3, -1, bytes,
173  false),
174  _runLength(0), _realSize(0)
175  {
176  }
177 
178  std::size_t
179  getSizeBits() const override
180  {
181  return _realSize;
182  }
183 
189  int getRunLength() const { return _runLength; }
190 
196  void setRunLength(int length) { _runLength = length; }
197 
206  void setRealSize(int size) { _realSize = length + size; }
207 };
208 
209 class FPC::SignExtended4Bits : public SignExtendedPattern<4>
210 {
211  public:
212  SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
213  : SignExtendedPattern<4>(SIGN_EXTENDED_4_BITS, SIGN_EXTENDED_4_BITS, 3,
214  bytes)
215  {
216  }
217 };
218 
219 class FPC::SignExtended1Byte : public SignExtendedPattern<8>
220 {
221  public:
222  SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
223  : SignExtendedPattern<8>(SIGN_EXTENDED_1_BYTE, SIGN_EXTENDED_1_BYTE, 3,
224  bytes)
225  {
226  }
227 };
228 
229 class FPC::SignExtendedHalfword : public SignExtendedPattern<16>
230 {
231  public:
232  SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
233  : SignExtendedPattern<16>(SIGN_EXTENDED_HALFWORD, SIGN_EXTENDED_HALFWORD,
234  3, bytes)
235  {
236  }
237 };
238 
239 class FPC::ZeroPaddedHalfword : public MaskedValuePattern<0, 0x0000FFFF>
240 {
241  public:
242  ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
243  : MaskedValuePattern<0, 0x0000FFFF>(ZERO_PADDED_HALFWORD,
244  ZERO_PADDED_HALFWORD, 3, -1, bytes, false)
245  {
246  }
247 };
248 
249 class FPC::SignExtendedTwoHalfwords : public Pattern
250 {
251  private:
253  const int8_t extendedBytes[2];
254 
255  public:
257  const int match_location)
259  16, -1, false),
260  extendedBytes{int8_t(fromDictionaryEntry(bytes) & mask(8)),
261  int8_t((fromDictionaryEntry(bytes) >> 16) & mask(8))}
262  {
263  }
264 
265  static bool
267  const DictionaryEntry& dict_bytes, const int match_location)
268  {
269  const uint32_t data = fromDictionaryEntry(bytes);
270  const int16_t halfwords[2] = {
271  int16_t(data & mask(16)),
272  int16_t((data >> 16) & mask(16))
273  };
274  return (halfwords[0] == (uint16_t)szext<8>(halfwords[0])) &&
275  (halfwords[1] == (uint16_t)szext<8>(halfwords[1]));
276  }
277 
279  decompress(const DictionaryEntry dict_bytes) const override
280  {
281  uint16_t halfwords[2] = {
282  (uint16_t)szext<8>(extendedBytes[0]),
283  (uint16_t)szext<8>(extendedBytes[1])
284  };
285  return toDictionaryEntry((halfwords[1] << 16) | halfwords[0]);
286  }
287 };
288 
289 class FPC::RepBytes : public RepeatedValuePattern<uint8_t>
290 {
291  public:
292  RepBytes(const DictionaryEntry bytes, const int match_location)
293  : RepeatedValuePattern<uint8_t>(REP_BYTES, REP_BYTES, 3, -1, bytes,
294  false)
295  {
296  }
297 };
298 
299 class FPC::Uncompressed : public UncompressedPattern
300 {
301  public:
302  Uncompressed(const DictionaryEntry bytes, const int match_location)
303  : UncompressedPattern(UNCOMPRESSED, UNCOMPRESSED, 3, -1, bytes)
304  {
305  }
306 };
307 
308 } // namespace compression
309 } // namespace gem5
310 
311 #endif //__MEM_CACHE_COMPRESSORS_FPC_HH__
gem5::compression::FPC::addToDictionary
void addToDictionary(const DictionaryEntry data) override
Definition: fpc.cc:87
gem5::compression::FPC::UNCOMPRESSED
@ UNCOMPRESSED
Definition: fpc.hh:87
gem5::compression::DictionaryCompressor
A template version of the dictionary compressor that allows to choose the dictionary size.
Definition: dictionary_compressor.hh:118
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::compression::FPC::PatternNumber
PatternNumber
The possible patterns.
Definition: fpc.hh:83
gem5::compression::FPC::SIGN_EXTENDED_4_BITS
@ SIGN_EXTENDED_4_BITS
Definition: fpc.hh:85
gem5::compression::FPC::ZeroRun::getRunLength
int getRunLength() const
Get the number of zeros in the run so far.
Definition: fpc.hh:189
gem5::compression::FPC::SignExtendedTwoHalfwords
Definition: fpc.hh:249
gem5::compression::FPC::FPCCompData::zeroRunSizeBits
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:145
gem5::compression::FPC::FPCCompData::addEntry
void addEntry(std::unique_ptr< Pattern > pattern) override
Definition: fpc.cc:47
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:168
gem5::compression::FPC::SignExtended4Bits
Definition: fpc.hh:209
gem5::compression::Base::Params
BaseCacheCompressorParams Params
Definition: base.hh:202
gem5::compression::FPC::SignExtendedHalfword::SignExtendedHalfword
SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:232
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:253
gem5::compression::FPC::NUM_PATTERNS
@ NUM_PATTERNS
Definition: fpc.hh:88
gem5::compression::FPC::RepBytes
Definition: fpc.hh:289
gem5::compression::FPC::SignExtendedTwoHalfwords::SignExtendedTwoHalfwords
SignExtendedTwoHalfwords(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:256
gem5::compression::FPC::Uncompressed
Definition: fpc.hh:299
gem5::compression::FPC::SIGN_EXTENDED_1_BYTE
@ SIGN_EXTENDED_1_BYTE
Definition: fpc.hh:85
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:230
gem5::compression::FPC::getName
std::string getName(int number) const override
Get meta-name assigned to the given pattern.
Definition: fpc.hh:100
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:160
dictionary_compressor.hh
gem5::compression::FPC::ZeroPaddedHalfword
Definition: fpc.hh:239
gem5::compression::FPC::ZeroRun::getSizeBits
std::size_t getSizeBits() const override
Definition: fpc.hh:179
bitfield.hh
gem5::compression::FPC::SignExtended1Byte
Definition: fpc.hh:219
gem5::compression::FPC::SignExtended4Bits::SignExtended4Bits
SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:212
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::compression::FPC::getNumPatterns
uint64_t getNumPatterns() const override
Trick function to get the number of patterns.
Definition: fpc.hh:97
gem5::compression::FPC::SignExtendedHalfword
Definition: fpc.hh:229
gem5::compression::FPC::FPCCompData::FPCCompData
FPCCompData(int zeroRunSizeBits)
Definition: fpc.cc:41
gem5::compression::FPC::ZeroRun::ZeroRun
ZeroRun(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:171
gem5::compression::FPC::FPC
FPC(const Params &p)
Definition: fpc.cc:81
gem5::compression::FPC::zeroRunSizeBits
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:95
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:116
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::compression::FPC::FPCCompData::~FPCCompData
~FPCCompData()=default
gem5::compression::FPC::ZERO_PADDED_HALFWORD
@ ZERO_PADDED_HALFWORD
Definition: fpc.hh:86
gem5::compression::FPC::RepBytes::RepBytes
RepBytes(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:292
gem5::compression::FPC::SignExtendedTwoHalfwords::isPattern
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Definition: fpc.hh:266
gem5::compression::FPC::SignExtendedTwoHalfwords::decompress
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Definition: fpc.hh:279
types.hh
gem5::compression::FPC::ZERO_RUN
@ ZERO_RUN
Definition: fpc.hh:85
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:206
gem5::compression::FPC::SIGN_EXTENDED_TWO_HALFWORDS
@ SIGN_EXTENDED_TWO_HALFWORDS
Definition: fpc.hh:87
gem5::compression::FPC::FPCCompData
Definition: fpc.hh:138
gem5::compression::DictionaryCompressor< uint32_t >::toDictionaryEntry
static DictionaryEntry toDictionaryEntry(uint32_t value)
Turn a value into a dictionary entry.
Definition: dictionary_compressor_impl.hh:218
gem5::compression::FPC
Definition: fpc.hh:58
gem5::compression::FPC::Uncompressed::Uncompressed
Uncompressed(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:302
gem5::compression::FPC::ZeroRun::setRunLength
void setRunLength(int length)
Set the number of zeros in the run so far.
Definition: fpc.hh:196
gem5::compression::FPC::Params
FPCParams Params
Definition: fpc.hh:133
gem5::compression::FPC::ZeroRun
Definition: fpc.hh:156
gem5::compression::FPC::SignExtended1Byte::SignExtended1Byte
SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:222
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::compression::FPC::SIGN_EXTENDED_HALFWORD
@ SIGN_EXTENDED_HALFWORD
Definition: fpc.hh:86
gem5::compression::FPC::REP_BYTES
@ REP_BYTES
Definition: fpc.hh:87
gem5::compression::FPC::ZeroPaddedHalfword::ZeroPaddedHalfword
ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:242
gem5::compression::FPC::instantiateDictionaryCompData
std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const override
Definition: fpc.cc:96
gem5::compression::FPC::DictionaryEntry
DictionaryCompressor< uint32_t >::DictionaryEntry DictionaryEntry
Definition: fpc.hh:61

Generated on Tue Sep 21 2021 12:25:29 for gem5 by doxygen 1.8.17