gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
49namespace gem5
50{
51
52struct FPCParams;
53
54namespace compression
55{
56
57class FPC : public DictionaryCompressor<uint32_t>
58{
59 private:
61
66 class FPCCompData;
67
68 // Declaration of all possible patterns
69 class ZeroRun;
75 class RepBytes;
76 class Uncompressed;
77
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
137class FPC::FPCCompData : public DictionaryCompressor<uint32_t>::CompData
138{
139 protected:
145
146 public:
148 ~FPCCompData() = default;
149
150 void addEntry(std::unique_ptr<Pattern> pattern) override;
151};
152
153// Pattern implementations
154
155class 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
208class 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
218class 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
228class 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
238class 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
248class 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
288class 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
298class 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__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
A template version of the dictionary compressor that allows to choose the dictionary size.
static uint32_t fromDictionaryEntry(const DictionaryEntry &entry)
std::array< uint8_t, sizeof(T)> DictionaryEntry
Convenience typedef for a dictionary entry.
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition fpc.hh:144
void addEntry(std::unique_ptr< Pattern > pattern) override
Definition fpc.cc:46
FPCCompData(int zeroRunSizeBits)
Definition fpc.cc:40
RepBytes(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:291
SignExtended1Byte(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:221
SignExtended4Bits(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:211
SignExtendedHalfword(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:231
DictionaryEntry decompress(const DictionaryEntry dict_bytes) const override
Definition fpc.hh:278
static bool isPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location)
Definition fpc.hh:265
SignExtendedTwoHalfwords(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:255
const int8_t extendedBytes[2]
These are the bytes that are extended to form the two halfwords.
Definition fpc.hh:252
Uncompressed(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:301
ZeroPaddedHalfword(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:241
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
ZeroRun(const DictionaryEntry bytes, const int match_location)
Definition fpc.hh:170
int _realSize
A zero run consists of a main ZeroRun pattern, which has a meaningful real size (i....
Definition fpc.hh:167
std::size_t getSizeBits() const override
Definition fpc.hh:178
int getRunLength() const
Get the number of zeros in the run so far.
Definition fpc.hh:188
void setRunLength(int length)
Set the number of zeros in the run so far.
Definition fpc.hh:195
int _runLength
Run length so far.
Definition fpc.hh:159
std::string getName(int number) const override
Get meta-name assigned to the given pattern.
Definition fpc.hh:99
const int zeroRunSizeBits
Number of bits of the zero run size bitfield.
Definition fpc.hh:94
uint64_t getNumPatterns() const override
Trick function to get the number of patterns.
Definition fpc.hh:96
PatternNumber
The possible patterns.
Definition fpc.hh:83
@ SIGN_EXTENDED_TWO_HALFWORDS
Definition fpc.hh:86
DictionaryCompressor< uint32_t >::DictionaryEntry DictionaryEntry
Definition fpc.hh:60
FPC(const Params &p)
Definition fpc.cc:80
std::unique_ptr< Pattern > getPattern(const DictionaryEntry &bytes, const DictionaryEntry &dict_bytes, const int match_location) const override
Definition fpc.hh:115
std::unique_ptr< DictionaryCompressor::CompData > instantiateDictionaryCompData() const override
Instantiate a compression data of the sub-class compressor.
Definition fpc.cc:95
FPCParams Params
Definition fpc.hh:132
void addToDictionary(const DictionaryEntry data) override
Definition fpc.cc:86
Definition of a dictionary based cache compressor.
constexpr uint64_t szext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition bitfield.hh:161
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:04 for gem5 by doxygen 1.11.0