2 * Copyright (c) 2019 Inria
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.
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.
28 * Authors: Daniel Carvalho
32 * Definition of a zero compressor, which compressed data if it is entirely
33 * composed of zero bits.
36 #ifndef __MEM_CACHE_COMPRESSORS_ZERO_HH__
37 #define __MEM_CACHE_COMPRESSORS_ZERO_HH__
44 #include "mem/cache/compressors/dictionary_compressor.hh"
46 struct ZeroCompressorParams;
48 class ZeroCompressor : public DictionaryCompressor<uint64_t>
51 using DictionaryEntry = DictionaryCompressor<uint64_t>::DictionaryEntry;
53 // Forward declaration of all possible patterns
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.
68 * Convenience factory declaration. The templates must be organized by
69 * size, with the smallest first, and "no-match" last.
71 using PatternFactory = Factory<PatternZ, PatternX>;
73 uint64_t getNumPatterns() const override { return NUM_PATTERNS; }
76 getName(int number) const override
78 static std::map<int, std::string> pattern_names = {
82 return pattern_names[number];
85 std::unique_ptr<Pattern>
86 getPattern(const DictionaryEntry& bytes, const DictionaryEntry& dict_bytes,
87 const int match_location) const override
89 return PatternFactory::getPattern(bytes, dict_bytes, match_location);
92 void addToDictionary(DictionaryEntry data) override;
94 std::unique_ptr<BaseCacheCompressor::CompressionData> compress(
95 const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override;
98 typedef ZeroCompressorParams Params;
99 ZeroCompressor(const Params *p);
100 ~ZeroCompressor() = default;
103 class ZeroCompressor::PatternX
104 : public DictionaryCompressor::UncompressedPattern
107 PatternX(const DictionaryEntry bytes, const int match_location)
108 : DictionaryCompressor::UncompressedPattern(X, 0, 1, match_location,
114 class ZeroCompressor::PatternZ
115 : public DictionaryCompressor::MaskedValuePattern<0, 0xFFFFFFFFFFFFFFFF>
118 PatternZ(const DictionaryEntry bytes, const int match_location)
119 : DictionaryCompressor::MaskedValuePattern<0, 0xFFFFFFFFFFFFFFFF>(
120 Z, 1, 1, match_location, bytes)
125 #endif //__MEM_CACHE_COMPRESSORS_ZERO_HH__