base.hh revision 13942
110512SAli.Saidi@ARM.com/* 210512SAli.Saidi@ARM.com * Copyright (c) 2018 Inria 310512SAli.Saidi@ARM.com * All rights reserved. 410512SAli.Saidi@ARM.com * 510512SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 610512SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 710512SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 810512SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 910512SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 1010512SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 1110512SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 1210512SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 1310512SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 1410512SAli.Saidi@ARM.com * this software without specific prior written permission. 1510512SAli.Saidi@ARM.com * 1610512SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710512SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1810512SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1910512SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2010512SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110512SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2210512SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310512SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410512SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2510512SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610512SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710512SAli.Saidi@ARM.com * 2810512SAli.Saidi@ARM.com * Authors: Daniel Carvalho 2910512SAli.Saidi@ARM.com */ 3010512SAli.Saidi@ARM.com 3110512SAli.Saidi@ARM.com/** @file 3210512SAli.Saidi@ARM.com * Definition of a basic cache compressor. 3310512SAli.Saidi@ARM.com * A cache compressor must consist of a compression and a decompression 3410512SAli.Saidi@ARM.com * methods. It must also be aware of the size of an uncompressed cache 3510512SAli.Saidi@ARM.com * line. 3610512SAli.Saidi@ARM.com */ 3710512SAli.Saidi@ARM.com 3810512SAli.Saidi@ARM.com#ifndef __MEM_CACHE_COMPRESSORS_BASE_HH__ 3910512SAli.Saidi@ARM.com#define __MEM_CACHE_COMPRESSORS_BASE_HH__ 4010512SAli.Saidi@ARM.com 4110512SAli.Saidi@ARM.com#include <cstdint> 4210512SAli.Saidi@ARM.com 4310512SAli.Saidi@ARM.com#include "base/types.hh" 4411837Swendy.elsasser@arm.com#include "sim/sim_object.hh" 4510947Sandreas.sandberg@arm.com 4610512SAli.Saidi@ARM.comclass CacheBlk; 4710512SAli.Saidi@ARM.comstruct BaseCacheCompressorParams; 4810512SAli.Saidi@ARM.com 4910512SAli.Saidi@ARM.com/** 5010512SAli.Saidi@ARM.com * 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__ 182