gem5  v22.1.0.0
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__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
BaseCacheCompressorParams Params
Definition: base.hh:202
A template version of the dictionary compressor that allows to choose the dictionary size.
static uint32_t fromDictionaryEntry(const DictionaryEntry &entry)
Turn a dictionary entry into a value.
static DictionaryEntry toDictionaryEntry(uint32_t value)
Turn a value into a dictionary entry.
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:145
void addEntry(std::unique_ptr< Pattern > pattern) override
Definition: fpc.cc:47
FPCCompData(int zeroRunSizeBits)
Definition: fpc.cc:41
RepBytes(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:292
SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:222
SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:212
SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:232
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Definition: fpc.hh:279
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Definition: fpc.hh:266
SignExtendedTwoHalfwords(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:256
const int8_t extendedBytes[2]
These are the bytes that are extended to form the two halfwords.
Definition: fpc.hh:253
Uncompressed(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:302
ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:242
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
ZeroRun(const DictionaryEntry bytes, const int match_location)
Definition: fpc.hh:171
int _realSize
A zero run consists of a main ZeroRun pattern, which has a meaningful real size (i....
Definition: fpc.hh:168
std::size_t getSizeBits() const override
Definition: fpc.hh:179
int getRunLength() const
Get the number of zeros in the run so far.
Definition: fpc.hh:189
void setRunLength(int length)
Set the number of zeros in the run so far.
Definition: fpc.hh:196
int _runLength
Run length so far.
Definition: fpc.hh:160
std::string getName(int number) const override
Get meta-name assigned to the given pattern.
Definition: fpc.hh:100
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition: fpc.hh:95
uint64_t getNumPatterns() const override
Trick function to get the number of patterns.
Definition: fpc.hh:97
PatternNumber
The possible patterns.
Definition: fpc.hh:84
@ SIGN_EXTENDED_TWO_HALFWORDS
Definition: fpc.hh:87
DictionaryCompressor< uint32_t >::DictionaryEntry DictionaryEntry
Definition: fpc.hh:61
std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location) const override
Definition: fpc.hh:116
FPC(const Params &p)
Definition: fpc.cc:81
std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const override
Instantiate a compression data of the sub-class compressor.
Definition: fpc.cc:96
FPCParams Params
Definition: fpc.hh:133
void addToDictionary(const DictionaryEntry data) override
Definition: fpc.cc:87
Definition of a dictionary based cache compressor.
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:36 for gem5 by doxygen 1.9.1