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; --- 22 unchanged lines hidden (view full) --- 31/** @file 32 * Definition of a basic cache compressor. 33 */ 34 35#include "mem/cache/compressors/base.hh" 36 37#include <algorithm> 38#include <cstdint> |
39#include <string> |
40 41#include "debug/CacheComp.hh" 42#include "mem/cache/tags/super_blk.hh" 43#include "params/BaseCacheCompressor.hh" 44 45// Uncomment this line if debugging compression 46//#define DEBUG_COMPRESSION 47 --- 48 unchanged lines hidden (view full) --- 96 // Check if decompressed line matches original cache line 97 fatal_if(std::memcmp(data, decomp_data, blkSize), 98 "Decompressed line does not match original line."); 99 #endif 100 101 // Get compression size 102 comp_size_bits = comp_data->getSizeBits(); 103 |
104 // Update stats 105 compressionSize[std::ceil(std::log2(comp_size_bits))]++; 106 |
107 // Print debug information 108 DPRINTF(CacheComp, "Compressed cache line from %d to %d bits. " \ 109 "Compression latency: %llu, decompression latency: %llu\n", 110 blkSize*8, comp_size_bits, comp_lat, decomp_lat); 111} 112 113Cycles 114BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) --- 24 unchanged lines hidden (view full) --- 139{ 140 // Sanity check 141 assert(blk != nullptr); 142 143 // Assign size 144 static_cast<CompressionBlk*>(blk)->setSizeBits(size_bits); 145} 146 |
147void 148BaseCacheCompressor::regStats() 149{ 150 SimObject::regStats(); 151 152 // We also store when compression is bigger than original block size 153 compressionSize 154 .init(std::log2(blkSize*8) + 2) 155 .name(name() + ".compression_size") 156 .desc("Number of blocks that were compressed to this power of" \ 157 "two size.") 158 ; 159 160 for (unsigned i = 0; i <= std::log2(blkSize*8) + 1; ++i) { 161 compressionSize.subname(i, std::to_string(1 << i)); 162 compressionSize.subdesc(i, "Number of blocks that compressed to fit " \ 163 "in " + std::to_string(1 << i) + " bits"); 164 } 165} 166 |