Deleted Added
sdiff udiff text old ( 13942:e8b59b523af6 ) new ( 13943:4046b0c547be )
full compact
1/*
2 * Copyright (c) 2018 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 basic cache compressor.
33 * A cache compressor must consist of a compression and a decompression
34 * methods. It must also be aware of the size of an uncompressed cache
35 * line.
36 */
37
38#ifndef __MEM_CACHE_COMPRESSORS_BASE_HH__
39#define __MEM_CACHE_COMPRESSORS_BASE_HH__
40
41#include <cstdint>
42
43#include "base/types.hh"
44#include "sim/sim_object.hh"
45
46class CacheBlk;
47struct BaseCacheCompressorParams;
48
49/**
50 * Base cache compressor interface. Every cache compressor must implement a
51 * compression and a decompression method.
52 */
53class BaseCacheCompressor : public SimObject {
54 protected:
55 /**
56 * Forward declaration of compression data. Every new compressor must
57 * create a new compression data based on it.
58 */
59 class CompressionData;
60
61 /**
62 * Uncompressed cache line size (in bytes).
63 */
64 const std::size_t blkSize;
65
66 /**
67 * Apply the compression process to the cache line.
68 * Returns the number of cycles used by the compressor, however it is
69 * usually covered by a good pipelined execution, and is currently ignored.
70 * The decompression latency is also returned, in order to avoid
71 * increasing simulation time and memory consumption.
72 *
73 * @param cache_line The cache line to be compressed.
74 * @param comp_lat Compression latency in number of cycles.
75 * @param decomp_lat Decompression latency in number of cycles.
76 * @return Cache line after compression.
77 */
78 virtual std::unique_ptr<CompressionData> compress(
79 const uint64_t* cache_line, Cycles& comp_lat, Cycles& decomp_lat) = 0;
80
81 /**
82 * Apply the decompression process to the compressed data.
83 *
84 * @param comp_data Compressed cache line.
85 * @param cache_line The cache line to be decompressed.
86 */
87 virtual void decompress(const CompressionData* comp_data,
88 uint64_t* cache_line) = 0;
89
90 public:
91 /** Convenience typedef. */
92 typedef BaseCacheCompressorParams Params;
93
94 /**
95 * Default constructor.
96 */
97 BaseCacheCompressor(const Params *p);
98
99 /**
100 * Default destructor.
101 */
102 virtual ~BaseCacheCompressor() {};
103
104 /**
105 * Apply the compression process to the cache line. Ignores compression
106 * cycles.
107 *
108 * @param data The cache line to be compressed.
109 * @param comp_lat Compression latency in number of cycles.
110 * @param decomp_lat Decompression latency in number of cycles.
111 * @param comp_size_bits Compressed data size (in bits).
112 */
113 void compress(const uint64_t* data, Cycles& comp_lat,
114 Cycles& decomp_lat, std::size_t& comp_size_bits);
115
116 /**
117 * Get the decompression latency if the block is compressed. Latency is 0
118 * otherwise.
119 *
120 * @param blk The compressed block.
121 */
122 static Cycles getDecompressionLatency(const CacheBlk* blk);
123
124 /**
125 * Set the decompression latency of compressed block.
126 *
127 * @param blk The compressed block.
128 * @param lat The decompression latency.
129 */
130 static void setDecompressionLatency(CacheBlk* blk, const Cycles lat);
131
132 /**
133 * Set the size of the compressed block, in bits.
134 *
135 * @param blk The compressed block.
136 * @param size_bits The block size.
137 */
138 static void setSizeBits(CacheBlk* blk, const std::size_t size_bits);
139};
140
141class BaseCacheCompressor::CompressionData {
142 private:
143 /**
144 * Compressed cache line size (in bits).
145 */
146 std::size_t _size;
147
148 public:
149 /**
150 * Default constructor.
151 */
152 CompressionData();
153
154 /**
155 * Virtual destructor. Without it unique_ptr will cause mem leak.
156 */
157 virtual ~CompressionData();
158
159 /**
160 * Set compression size (in bits).
161 *
162 * @param size Compressed data size.
163 */
164 void setSizeBits(std::size_t size);
165
166 /**
167 * Get compression size (in bits).
168 *
169 * @return Compressed data size.
170 */
171 std::size_t getSizeBits() const;
172
173 /**
174 * Get compression size (in bytes).
175 *
176 * @return Compressed data size.
177 */
178 std::size_t getSize() const;
179};
180
181#endif //__MEM_CACHE_COMPRESSORS_BASE_HH__