mem-cache: Move unused prefetches counter update
[gem5.git] / src / mem / cache / compressors / zero.hh
1 /*
2 * Copyright (c) 2019 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 * Authors: Daniel Carvalho
29 */
30
31 /** @file
32 * Definition of a zero compressor, which compressed data if it is entirely
33 * composed of zero bits.
34 */
35
36 #ifndef __MEM_CACHE_COMPRESSORS_ZERO_HH__
37 #define __MEM_CACHE_COMPRESSORS_ZERO_HH__
38
39 #include <array>
40 #include <cstdint>
41 #include <map>
42 #include <memory>
43
44 #include "mem/cache/compressors/dictionary_compressor.hh"
45
46 struct ZeroCompressorParams;
47
48 class ZeroCompressor : public DictionaryCompressor<uint64_t>
49 {
50 protected:
51 using DictionaryEntry = DictionaryCompressor<uint64_t>::DictionaryEntry;
52
53 // Forward declaration of all possible patterns
54 class PatternX;
55 class PatternZ;
56
57 /**
58 * The patterns proposed in the paper. Each letter represents a byte:
59 * Z is a null byte, M is a dictionary match, X is a new value.
60 * These are used as indexes to reference the pattern data. If a new
61 * pattern is added, it must be done before NUM_PATTERNS.
62 */
63 typedef enum {
64 X, Z, NUM_PATTERNS
65 } PatternNumber;
66
67 /**
68 * Convenience factory declaration. The templates must be organized by
69 * size, with the smallest first, and "no-match" last.
70 */
71 using PatternFactory = Factory<PatternZ, PatternX>;
72
73 uint64_t getNumPatterns() const override { return NUM_PATTERNS; }
74
75 std::string
76 getName(int number) const override
77 {
78 static std::map<int, std::string> pattern_names = {
79 {X, "X"}, {Z, "Z"}
80 };
81
82 return pattern_names[number];
83 };
84
85 std::unique_ptr<Pattern>
86 getPattern(const DictionaryEntry& bytes, const DictionaryEntry& dict_bytes,
87 const int match_location) const override
88 {
89 return PatternFactory::getPattern(bytes, dict_bytes, match_location);
90 }
91
92 void addToDictionary(DictionaryEntry data) override;
93
94 std::unique_ptr<BaseCacheCompressor::CompressionData> compress(
95 const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override;
96
97 public:
98 typedef ZeroCompressorParams Params;
99 ZeroCompressor(const Params *p);
100 ~ZeroCompressor() = default;
101 };
102
103 class ZeroCompressor::PatternX
104 : public DictionaryCompressor::UncompressedPattern
105 {
106 public:
107 PatternX(const DictionaryEntry bytes, const int match_location)
108 : DictionaryCompressor::UncompressedPattern(X, 0, 1, match_location,
109 bytes)
110 {
111 }
112 };
113
114 class ZeroCompressor::PatternZ
115 : public DictionaryCompressor::MaskedValuePattern<0, 0xFFFFFFFFFFFFFFFF>
116 {
117 public:
118 PatternZ(const DictionaryEntry bytes, const int match_location)
119 : DictionaryCompressor::MaskedValuePattern<0, 0xFFFFFFFFFFFFFFFF>(
120 Z, 1, 1, match_location, bytes)
121 {
122 }
123 };
124
125 #endif //__MEM_CACHE_COMPRESSORS_ZERO_HH__