45effe905c387579dfc55a4ceaf1591ae1d058e2
[gem5.git] / src / mem / cache / compressors / Compressors.py
1 # Copyright (c) 2018-2020 Inria
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 from m5.params import *
28 from m5.proxy import *
29 from m5.SimObject import SimObject
30
31 class BaseCacheCompressor(SimObject):
32 type = 'BaseCacheCompressor'
33 abstract = True
34 cxx_class = 'Compressor::Base'
35 cxx_header = "mem/cache/compressors/base.hh"
36
37 block_size = Param.Int(Parent.cache_line_size, "Block size in bytes")
38 chunk_size_bits = Param.Unsigned(32,
39 "Size of a parsing data chunk (in bits)")
40 size_threshold = Param.Unsigned(Parent.cache_line_size, "Minimum size, "
41 "in bytes, in which a block must be compressed to. Otherwise it is "
42 "stored in its uncompressed state")
43
44 class BaseDictionaryCompressor(BaseCacheCompressor):
45 type = 'BaseDictionaryCompressor'
46 abstract = True
47 cxx_class = 'Compressor::BaseDictionaryCompressor'
48 cxx_header = "mem/cache/compressors/dictionary_compressor.hh"
49
50 dictionary_size = Param.Int(Parent.cache_line_size,
51 "Number of dictionary entries")
52
53 class Base64Delta8(BaseDictionaryCompressor):
54 type = 'Base64Delta8'
55 cxx_class = 'Compressor::Base64Delta8'
56 cxx_header = "mem/cache/compressors/base_delta.hh"
57
58 chunk_size_bits = 64
59
60 class Base64Delta16(BaseDictionaryCompressor):
61 type = 'Base64Delta16'
62 cxx_class = 'Compressor::Base64Delta16'
63 cxx_header = "mem/cache/compressors/base_delta.hh"
64
65 chunk_size_bits = 64
66
67 class Base64Delta32(BaseDictionaryCompressor):
68 type = 'Base64Delta32'
69 cxx_class = 'Compressor::Base64Delta32'
70 cxx_header = "mem/cache/compressors/base_delta.hh"
71
72 chunk_size_bits = 64
73
74 class Base32Delta8(BaseDictionaryCompressor):
75 type = 'Base32Delta8'
76 cxx_class = 'Compressor::Base32Delta8'
77 cxx_header = "mem/cache/compressors/base_delta.hh"
78
79 chunk_size_bits = 32
80
81 class Base32Delta16(BaseDictionaryCompressor):
82 type = 'Base32Delta16'
83 cxx_class = 'Compressor::Base32Delta16'
84 cxx_header = "mem/cache/compressors/base_delta.hh"
85
86 chunk_size_bits = 32
87
88 class Base16Delta8(BaseDictionaryCompressor):
89 type = 'Base16Delta8'
90 cxx_class = 'Compressor::Base16Delta8'
91 cxx_header = "mem/cache/compressors/base_delta.hh"
92
93 chunk_size_bits = 16
94
95 class CPack(BaseDictionaryCompressor):
96 type = 'CPack'
97 cxx_class = 'Compressor::CPack'
98 cxx_header = "mem/cache/compressors/cpack.hh"
99
100 class FPCD(BaseDictionaryCompressor):
101 type = 'FPCD'
102 cxx_class = 'Compressor::FPCD'
103 cxx_header = "mem/cache/compressors/fpcd.hh"
104
105 dictionary_size = 2
106
107 class MultiCompressor(BaseCacheCompressor):
108 type = 'MultiCompressor'
109 cxx_class = 'Compressor::Multi'
110 cxx_header = "mem/cache/compressors/multi.hh"
111
112 # Dummy default compressor list. This might not be an optimal choice,
113 # since these compressors have many overlapping patterns
114 compressors = VectorParam.BaseCacheCompressor([CPack(), FPCD()],
115 "Array of compressors")
116 encoding_in_tags = Param.Bool(False, "If set the bits to inform which "
117 "sub-compressor compressed some data are added to its corresponding "
118 "tag entry.")
119
120 class PerfectCompressor(BaseCacheCompressor):
121 type = 'PerfectCompressor'
122 cxx_class = 'Compressor::Perfect'
123 cxx_header = "mem/cache/compressors/perfect.hh"
124
125 chunk_size_bits = 64
126 max_compression_ratio = Param.Int(2,
127 "Maximum compression ratio allowed")
128 compression_latency = Param.Cycles(1,
129 "Number of cycles to perform data compression")
130 decompression_latency = Param.Cycles(1,
131 "Number of cycles to perform data decompression")
132
133 class RepeatedQwordsCompressor(BaseDictionaryCompressor):
134 type = 'RepeatedQwordsCompressor'
135 cxx_class = 'Compressor::RepeatedQwords'
136 cxx_header = "mem/cache/compressors/repeated_qwords.hh"
137
138 chunk_size_bits = 64
139
140 class ZeroCompressor(BaseDictionaryCompressor):
141 type = 'ZeroCompressor'
142 cxx_class = 'Compressor::Zero'
143 cxx_header = "mem/cache/compressors/zero.hh"
144
145 chunk_size_bits = 64
146
147 class BDI(MultiCompressor):
148 encoding_in_tags=True
149 compressors = [ZeroCompressor(), RepeatedQwordsCompressor(),
150 Base64Delta8(), Base64Delta16(), Base64Delta32(), Base32Delta8(),
151 Base32Delta16(), Base16Delta8()]