2 * Copyright (c) 2019-2020 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.
30 * Definition of the a multi compressor that choses the best compression
31 * among multiple compressors.
34 #ifndef __MEM_CACHE_COMPRESSORS_MULTI_HH__
35 #define __MEM_CACHE_COMPRESSORS_MULTI_HH__
40 #include "base/statistics.hh"
41 #include "base/types.hh"
42 #include "mem/cache/compressors/base.hh"
44 struct MultiCompressorParams;
46 namespace Compressor {
48 class Multi : public Base
52 * Compression data for the multi compressor. It contains the compression
53 * data of the best compressor, along with its index in the list of
58 /** List of sub-compressors. */
59 std::vector<Base*> compressors;
61 struct MultiStats : public Stats::Group
63 const Multi& compressor;
65 MultiStats(BaseStats &base_group, Multi& _compressor);
67 void regStats() override;
70 * Number of times each compressor provided the nth best compression.
72 Stats::Vector2d ranks;
76 typedef MultiCompressorParams Params;
77 Multi(const Params *p);
80 std::unique_ptr<Base::CompressionData> compress(
81 const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override;
83 void decompress(const CompressionData* comp_data, uint64_t* data) override;
86 class Multi::MultiCompData : public CompressionData
89 /** Index of the compressor that provided these compression results. */
93 /** Compression data of the best compressor. */
94 std::unique_ptr<Base::CompressionData> compData;
97 * Default constructor.
99 * @param index Index of the compressor that provided this compression.
100 * @param comp_data Compression data of the best compressor.
102 MultiCompData(unsigned index,
103 std::unique_ptr<Base::CompressionData> comp_data);
105 /** Default destructor. */
106 ~MultiCompData() = default;
108 /** Get the index of the best compressor. */
109 uint8_t getIndex() const;
112 } // namespace Compressor
114 #endif //__MEM_CACHE_COMPRESSORS_MULTI_HH__