From 101e16facf1c6edc2fbf7a20205ab8b1ed69c109 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Sun, 23 Aug 2020 16:31:00 +0200 Subject: [PATCH] mem-cache: Create Compressor namespace Creation of the Compressor namespace. It encapsulates all the cache compressors, and other classes used by them. The following classes have been renamed: BaseCacheCompressor -> Base PerfectCompressor - Perfect RepeatedQwordsCompressor -> RepeatedQwords ZeroCompressor -> Zero BaseDictionaryCompressor and DictionaryCompressor were not renamed because the there is a high probability that users may want to create a Dictionary class that encompasses the dictionary contained by these compressors. To apply this patch one must force recompilation (e.g., by deleting it) of build//params/BaseCache.hh (and any other files that were previously using these compressors). Change-Id: I78cb3b6fb8e3e50a52a04268e0e08dd664d81230 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33294 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- src/mem/cache/base.hh | 2 +- src/mem/cache/compressors/Compressors.py | 28 ++++++++------- src/mem/cache/compressors/base.cc | 30 ++++++++-------- src/mem/cache/compressors/base.hh | 34 ++++++++---------- src/mem/cache/compressors/base_delta.cc | 30 +++++++++------- src/mem/cache/compressors/base_delta.hh | 8 +++-- src/mem/cache/compressors/base_delta_impl.hh | 10 ++++-- .../compressors/base_dictionary_compressor.cc | 10 ++++-- src/mem/cache/compressors/cpack.cc | 14 +++++--- src/mem/cache/compressors/cpack.hh | 8 +++-- .../compressors/dictionary_compressor.hh | 11 +++--- .../compressors/dictionary_compressor_impl.hh | 10 ++++-- src/mem/cache/compressors/fpcd.cc | 14 +++++--- src/mem/cache/compressors/fpcd.hh | 8 +++-- src/mem/cache/compressors/multi.cc | 36 ++++++++++--------- src/mem/cache/compressors/multi.hh | 29 ++++++++------- src/mem/cache/compressors/perfect.cc | 24 +++++++------ src/mem/cache/compressors/perfect.hh | 14 +++++--- src/mem/cache/compressors/repeated_qwords.cc | 20 ++++++----- src/mem/cache/compressors/repeated_qwords.hh | 18 ++++++---- src/mem/cache/compressors/zero.cc | 20 ++++++----- src/mem/cache/compressors/zero.hh | 18 ++++++---- 22 files changed, 231 insertions(+), 165 deletions(-) diff --git a/src/mem/cache/base.hh b/src/mem/cache/base.hh index 3efc7c7ed..d30de3f13 100644 --- a/src/mem/cache/base.hh +++ b/src/mem/cache/base.hh @@ -320,7 +320,7 @@ class BaseCache : public ClockedObject BaseTags *tags; /** Compression method being used. */ - BaseCacheCompressor* compressor; + Compressor::Base* compressor; /** Prefetcher */ Prefetcher::Base *prefetcher; diff --git a/src/mem/cache/compressors/Compressors.py b/src/mem/cache/compressors/Compressors.py index eb1952a7d..46050f636 100644 --- a/src/mem/cache/compressors/Compressors.py +++ b/src/mem/cache/compressors/Compressors.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Inria +# Copyright (c) 2018-2020 Inria # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -31,6 +31,7 @@ from m5.SimObject import SimObject class BaseCacheCompressor(SimObject): type = 'BaseCacheCompressor' abstract = True + cxx_class = 'Compressor::Base' cxx_header = "mem/cache/compressors/base.hh" block_size = Param.Int(Parent.cache_line_size, "Block size in bytes") @@ -41,6 +42,7 @@ class BaseCacheCompressor(SimObject): class BaseDictionaryCompressor(BaseCacheCompressor): type = 'BaseDictionaryCompressor' abstract = True + cxx_class = 'Compressor::BaseDictionaryCompressor' cxx_header = "mem/cache/compressors/dictionary_compressor.hh" dictionary_size = Param.Int(Parent.cache_line_size, @@ -48,49 +50,49 @@ class BaseDictionaryCompressor(BaseCacheCompressor): class Base64Delta8(BaseDictionaryCompressor): type = 'Base64Delta8' - cxx_class = 'Base64Delta8' + cxx_class = 'Compressor::Base64Delta8' cxx_header = "mem/cache/compressors/base_delta.hh" class Base64Delta16(BaseDictionaryCompressor): type = 'Base64Delta16' - cxx_class = 'Base64Delta16' + cxx_class = 'Compressor::Base64Delta16' cxx_header = "mem/cache/compressors/base_delta.hh" class Base64Delta32(BaseDictionaryCompressor): type = 'Base64Delta32' - cxx_class = 'Base64Delta32' + cxx_class = 'Compressor::Base64Delta32' cxx_header = "mem/cache/compressors/base_delta.hh" class Base32Delta8(BaseDictionaryCompressor): type = 'Base32Delta8' - cxx_class = 'Base32Delta8' + cxx_class = 'Compressor::Base32Delta8' cxx_header = "mem/cache/compressors/base_delta.hh" class Base32Delta16(BaseDictionaryCompressor): type = 'Base32Delta16' - cxx_class = 'Base32Delta16' + cxx_class = 'Compressor::Base32Delta16' cxx_header = "mem/cache/compressors/base_delta.hh" class Base16Delta8(BaseDictionaryCompressor): type = 'Base16Delta8' - cxx_class = 'Base16Delta8' + cxx_class = 'Compressor::Base16Delta8' cxx_header = "mem/cache/compressors/base_delta.hh" class CPack(BaseDictionaryCompressor): type = 'CPack' - cxx_class = 'CPack' + cxx_class = 'Compressor::CPack' cxx_header = "mem/cache/compressors/cpack.hh" class FPCD(BaseDictionaryCompressor): type = 'FPCD' - cxx_class = 'FPCD' + cxx_class = 'Compressor::FPCD' cxx_header = "mem/cache/compressors/fpcd.hh" dictionary_size = 2 class MultiCompressor(BaseCacheCompressor): type = 'MultiCompressor' - cxx_class = 'MultiCompressor' + cxx_class = 'Compressor::Multi' cxx_header = "mem/cache/compressors/multi.hh" # Dummy default compressor list. This might not be an optimal choice, @@ -100,7 +102,7 @@ class MultiCompressor(BaseCacheCompressor): class PerfectCompressor(BaseCacheCompressor): type = 'PerfectCompressor' - cxx_class = 'PerfectCompressor' + cxx_class = 'Compressor::Perfect' cxx_header = "mem/cache/compressors/perfect.hh" max_compression_ratio = Param.Int(2, @@ -112,12 +114,12 @@ class PerfectCompressor(BaseCacheCompressor): class RepeatedQwordsCompressor(BaseDictionaryCompressor): type = 'RepeatedQwordsCompressor' - cxx_class = 'RepeatedQwordsCompressor' + cxx_class = 'Compressor::RepeatedQwords' cxx_header = "mem/cache/compressors/repeated_qwords.hh" class ZeroCompressor(BaseDictionaryCompressor): type = 'ZeroCompressor' - cxx_class = 'ZeroCompressor' + cxx_class = 'Compressor::Zero' cxx_header = "mem/cache/compressors/zero.hh" class BDI(MultiCompressor): diff --git a/src/mem/cache/compressors/base.cc b/src/mem/cache/compressors/base.cc index d08a5b9ab..f8fda81cc 100644 --- a/src/mem/cache/compressors/base.cc +++ b/src/mem/cache/compressors/base.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,37 +42,39 @@ #include "mem/cache/tags/super_blk.hh" #include "params/BaseCacheCompressor.hh" +namespace Compressor { + // Uncomment this line if debugging compression //#define DEBUG_COMPRESSION -BaseCacheCompressor::CompressionData::CompressionData() +Base::CompressionData::CompressionData() : _size(0) { } -BaseCacheCompressor::CompressionData::~CompressionData() +Base::CompressionData::~CompressionData() { } void -BaseCacheCompressor::CompressionData::setSizeBits(std::size_t size) +Base::CompressionData::setSizeBits(std::size_t size) { _size = size; } std::size_t -BaseCacheCompressor::CompressionData::getSizeBits() const +Base::CompressionData::getSizeBits() const { return _size; } std::size_t -BaseCacheCompressor::CompressionData::getSize() const +Base::CompressionData::getSize() const { return std::ceil(_size/8); } -BaseCacheCompressor::BaseCacheCompressor(const Params *p) +Base::Base(const Params *p) : SimObject(p), blkSize(p->block_size), sizeThreshold(p->size_threshold), stats(*this) { @@ -80,7 +82,7 @@ BaseCacheCompressor::BaseCacheCompressor(const Params *p) } void -BaseCacheCompressor::compress(const uint64_t* data, Cycles& comp_lat, +Base::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat, std::size_t& comp_size_bits) { // Apply compression @@ -119,7 +121,7 @@ BaseCacheCompressor::compress(const uint64_t* data, Cycles& comp_lat, } Cycles -BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) +Base::getDecompressionLatency(const CacheBlk* blk) { const CompressionBlk* comp_blk = static_cast(blk); @@ -137,7 +139,7 @@ BaseCacheCompressor::getDecompressionLatency(const CacheBlk* blk) } void -BaseCacheCompressor::setDecompressionLatency(CacheBlk* blk, const Cycles lat) +Base::setDecompressionLatency(CacheBlk* blk, const Cycles lat) { // Sanity check assert(blk != nullptr); @@ -147,7 +149,7 @@ BaseCacheCompressor::setDecompressionLatency(CacheBlk* blk, const Cycles lat) } void -BaseCacheCompressor::setSizeBits(CacheBlk* blk, const std::size_t size_bits) +Base::setSizeBits(CacheBlk* blk, const std::size_t size_bits) { // Sanity check assert(blk != nullptr); @@ -156,8 +158,7 @@ BaseCacheCompressor::setSizeBits(CacheBlk* blk, const std::size_t size_bits) static_cast(blk)->setSizeBits(size_bits); } -BaseCacheCompressor::BaseCacheCompressorStats::BaseCacheCompressorStats( - BaseCacheCompressor& _compressor) +Base::BaseStats::BaseStats(Base& _compressor) : Stats::Group(&_compressor), compressor(_compressor), compressions(this, "compressions", "Total number of compressions"), @@ -173,7 +174,7 @@ BaseCacheCompressor::BaseCacheCompressorStats::BaseCacheCompressorStats( } void -BaseCacheCompressor::BaseCacheCompressorStats::regStats() +Base::BaseStats::regStats() { Stats::Group::regStats(); @@ -189,3 +190,4 @@ BaseCacheCompressor::BaseCacheCompressorStats::regStats() avgCompressionSizeBits = compressionSizeBits / compressions; } +} // namespace Compressor diff --git a/src/mem/cache/compressors/base.hh b/src/mem/cache/compressors/base.hh index 61233c380..87cb0fca8 100644 --- a/src/mem/cache/compressors/base.hh +++ b/src/mem/cache/compressors/base.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,18 +45,20 @@ class CacheBlk; struct BaseCacheCompressorParams; +namespace Compressor { + /** * Base cache compressor interface. Every cache compressor must implement a * compression and a decompression method. */ -class BaseCacheCompressor : public SimObject +class Base : public SimObject { protected: /** * This compressor must be able to access the protected functions of * its sub-compressors. */ - friend class MultiCompressor; + friend class Multi; /** * Forward declaration of compression data. Every new compressor must @@ -75,11 +77,11 @@ class BaseCacheCompressor : public SimObject */ const std::size_t sizeThreshold; - struct BaseCacheCompressorStats : public Stats::Group + struct BaseStats : public Stats::Group { - const BaseCacheCompressor& compressor; + const Base& compressor; - BaseCacheCompressorStats(BaseCacheCompressor& compressor); + BaseStats(Base& compressor); void regStats() override; @@ -124,18 +126,9 @@ class BaseCacheCompressor : public SimObject uint64_t* cache_line) = 0; public: - /** Convenience typedef. */ - typedef BaseCacheCompressorParams Params; - - /** - * Default constructor. - */ - BaseCacheCompressor(const Params *p); - - /** - * Default destructor. - */ - virtual ~BaseCacheCompressor() {}; + typedef BaseCacheCompressorParams Params; + Base(const Params *p); + virtual ~Base() = default; /** * Apply the compression process to the cache line. Ignores compression @@ -174,7 +167,8 @@ class BaseCacheCompressor : public SimObject static void setSizeBits(CacheBlk* blk, const std::size_t size_bits); }; -class BaseCacheCompressor::CompressionData { +class Base::CompressionData +{ private: /** * Compressed cache line size (in bits). @@ -214,4 +208,6 @@ class BaseCacheCompressor::CompressionData { std::size_t getSize() const; }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_BASE_HH__ diff --git a/src/mem/cache/compressors/base_delta.cc b/src/mem/cache/compressors/base_delta.cc index 5af3b38f5..2d0aafe68 100644 --- a/src/mem/cache/compressors/base_delta.cc +++ b/src/mem/cache/compressors/base_delta.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ #include "params/Base64Delta32.hh" #include "params/Base64Delta8.hh" +namespace Compressor { + Base64Delta8::Base64Delta8(const Params *p) : BaseDelta(p) { @@ -69,38 +71,40 @@ Base16Delta8::Base16Delta8(const Params *p) { } -Base64Delta8* +} // namespace Compressor + +Compressor::Base64Delta8* Base64Delta8Params::create() { - return new Base64Delta8(this); + return new Compressor::Base64Delta8(this); } -Base64Delta16* +Compressor::Base64Delta16* Base64Delta16Params::create() { - return new Base64Delta16(this); + return new Compressor::Base64Delta16(this); } -Base64Delta32* +Compressor::Base64Delta32* Base64Delta32Params::create() { - return new Base64Delta32(this); + return new Compressor::Base64Delta32(this); } -Base32Delta8* +Compressor::Base32Delta8* Base32Delta8Params::create() { - return new Base32Delta8(this); + return new Compressor::Base32Delta8(this); } -Base32Delta16* +Compressor::Base32Delta16* Base32Delta16Params::create() { - return new Base32Delta16(this); + return new Compressor::Base32Delta16(this); } -Base16Delta8* +Compressor::Base16Delta8* Base16Delta8Params::create() { - return new Base16Delta8(this); + return new Compressor::Base16Delta8(this); } diff --git a/src/mem/cache/compressors/base_delta.hh b/src/mem/cache/compressors/base_delta.hh index 6c54acd7e..1e4b70e45 100644 --- a/src/mem/cache/compressors/base_delta.hh +++ b/src/mem/cache/compressors/base_delta.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,8 @@ struct Base32Delta8Params; struct Base32Delta16Params; struct Base16Delta8Params; +namespace Compressor { + /** * Base class for all base-delta-immediate compressors. Although not proposed * like this in the original paper, the sub-compressors of BDI are dictionary @@ -113,7 +115,7 @@ class BaseDelta : public DictionaryCompressor void addToDictionary(DictionaryEntry data) override; - std::unique_ptr + std::unique_ptr compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; @@ -201,4 +203,6 @@ class Base16Delta8 : public BaseDelta ~Base16Delta8() = default; }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_BASE_DELTA_HH__ diff --git a/src/mem/cache/compressors/base_delta_impl.hh b/src/mem/cache/compressors/base_delta_impl.hh index fb3dfecf0..97ab1cf56 100644 --- a/src/mem/cache/compressors/base_delta_impl.hh +++ b/src/mem/cache/compressors/base_delta_impl.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,6 +37,8 @@ #include "mem/cache/compressors/base_delta.hh" #include "mem/cache/compressors/dictionary_compressor_impl.hh" +namespace Compressor { + template BaseDelta::BaseDelta(const Params *p) : DictionaryCompressor(p) @@ -64,11 +66,11 @@ BaseDelta::addToDictionary(DictionaryEntry data) } template -std::unique_ptr +std::unique_ptr BaseDelta::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = DictionaryCompressor::compress(data); // If there are more bases than the maximum, the compressor failed. @@ -98,4 +100,6 @@ BaseDelta::compress(const uint64_t* data, return comp_data; } +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_BASE_DELTA_IMPL_HH__ diff --git a/src/mem/cache/compressors/base_dictionary_compressor.cc b/src/mem/cache/compressors/base_dictionary_compressor.cc index e454bbd72..d6af8ee77 100644 --- a/src/mem/cache/compressors/base_dictionary_compressor.cc +++ b/src/mem/cache/compressors/base_dictionary_compressor.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,15 +34,17 @@ #include "mem/cache/compressors/dictionary_compressor.hh" #include "params/BaseDictionaryCompressor.hh" +namespace Compressor { + BaseDictionaryCompressor::BaseDictionaryCompressor(const Params *p) - : BaseCacheCompressor(p), dictionarySize(p->dictionary_size), numEntries(0) + : Base(p), dictionarySize(p->dictionary_size), numEntries(0) { } void BaseDictionaryCompressor::regStats() { - BaseCacheCompressor::regStats(); + Base::regStats(); // We store the frequency of each pattern patternStats @@ -57,3 +59,5 @@ BaseDictionaryCompressor::regStats() getName(i)); } } + +} // namespace Compressor diff --git a/src/mem/cache/compressors/cpack.cc b/src/mem/cache/compressors/cpack.cc index b99bf62a1..40e983a10 100644 --- a/src/mem/cache/compressors/cpack.cc +++ b/src/mem/cache/compressors/cpack.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,8 @@ #include "mem/cache/compressors/dictionary_compressor_impl.hh" #include "params/CPack.hh" +namespace Compressor { + CPack::CPack(const Params *p) : DictionaryCompressor(p) { @@ -47,10 +49,10 @@ CPack::addToDictionary(DictionaryEntry data) dictionary[numEntries++] = data; } -std::unique_ptr +std::unique_ptr CPack::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = DictionaryCompressor::compress(data); // Set compression latency (Accounts for pattern matching, length @@ -64,8 +66,10 @@ CPack::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) return comp_data; } -CPack* +} // namespace Compressor + +Compressor::CPack* CPackParams::create() { - return new CPack(this); + return new Compressor::CPack(this); } diff --git a/src/mem/cache/compressors/cpack.hh b/src/mem/cache/compressors/cpack.hh index a7ffe11c2..2925b54d2 100644 --- a/src/mem/cache/compressors/cpack.hh +++ b/src/mem/cache/compressors/cpack.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ struct CPackParams; +namespace Compressor { + class CPack : public DictionaryCompressor { private: @@ -104,7 +106,7 @@ class CPack : public DictionaryCompressor * @param decomp_lat Decompression latency in number of cycles. * @return Cache line after compression. */ - std::unique_ptr compress( + std::unique_ptr compress( const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; public: @@ -178,4 +180,6 @@ class CPack::PatternMMMX : public MaskedPattern<0xFFFFFF00> } }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_CPACK_HH__ diff --git a/src/mem/cache/compressors/dictionary_compressor.hh b/src/mem/cache/compressors/dictionary_compressor.hh index 06a90cb67..fce79d5e8 100644 --- a/src/mem/cache/compressors/dictionary_compressor.hh +++ b/src/mem/cache/compressors/dictionary_compressor.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,9 @@ struct BaseDictionaryCompressorParams; -class BaseDictionaryCompressor : public BaseCacheCompressor +namespace Compressor { + +class BaseDictionaryCompressor : public Base { protected: /** Dictionary size. */ @@ -225,8 +227,7 @@ class DictionaryCompressor : public BaseDictionaryCompressor * @param data The cache line to be compressed. * @return Cache line after compression. */ - std::unique_ptr compress( - const uint64_t* data); + std::unique_ptr compress(const uint64_t* data); using BaseDictionaryCompressor::compress; @@ -725,4 +726,6 @@ class DictionaryCompressor::DeltaPattern } }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_HH__ diff --git a/src/mem/cache/compressors/dictionary_compressor_impl.hh b/src/mem/cache/compressors/dictionary_compressor_impl.hh index d771d5278..0b486e3f8 100644 --- a/src/mem/cache/compressors/dictionary_compressor_impl.hh +++ b/src/mem/cache/compressors/dictionary_compressor_impl.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Inria + * Copyright (c) 2018-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +40,8 @@ #include "mem/cache/compressors/dictionary_compressor.hh" #include "params/BaseDictionaryCompressor.hh" +namespace Compressor { + template DictionaryCompressor::CompData::CompData() : CompressionData() @@ -113,10 +115,10 @@ DictionaryCompressor::compressValue(const T data) } template -std::unique_ptr +std::unique_ptr DictionaryCompressor::compress(const uint64_t* data) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = std::unique_ptr(new CompData()); // Reset dictionary @@ -209,4 +211,6 @@ DictionaryCompressor::fromDictionaryEntry(const DictionaryEntry& entry) return value; } +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_DICTIONARY_COMPRESSOR_IMPL_HH__ diff --git a/src/mem/cache/compressors/fpcd.cc b/src/mem/cache/compressors/fpcd.cc index e3529e5d2..ba46379cb 100644 --- a/src/mem/cache/compressors/fpcd.cc +++ b/src/mem/cache/compressors/fpcd.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,8 @@ #include "mem/cache/compressors/dictionary_compressor_impl.hh" #include "params/FPCD.hh" +namespace Compressor { + FPCD::FPCD(const Params *p) : DictionaryCompressor(p) { @@ -52,10 +54,10 @@ FPCD::addToDictionary(DictionaryEntry data) } } -std::unique_ptr +std::unique_ptr FPCD::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = DictionaryCompressor::compress(data); // Set compression latency (Accounts for zero checks, ones check, match @@ -71,8 +73,10 @@ FPCD::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) return comp_data; } -FPCD* +} // namespace Compressor + +Compressor::FPCD* FPCDParams::create() { - return new FPCD(this); + return new Compressor::FPCD(this); } diff --git a/src/mem/cache/compressors/fpcd.hh b/src/mem/cache/compressors/fpcd.hh index 61785bc73..8aed461ef 100644 --- a/src/mem/cache/compressors/fpcd.hh +++ b/src/mem/cache/compressors/fpcd.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,8 @@ struct FPCDParams; +namespace Compressor { + class FPCD : public DictionaryCompressor { private: @@ -137,7 +139,7 @@ class FPCD : public DictionaryCompressor void addToDictionary(DictionaryEntry data) override; - std::unique_ptr compress( + std::unique_ptr compress( const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; public: @@ -318,4 +320,6 @@ class FPCD::PatternXXXX : public UncompressedPattern } }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_FPCD_HH__ diff --git a/src/mem/cache/compressors/multi.cc b/src/mem/cache/compressors/multi.cc index d1e7fbc5d..f42602e82 100644 --- a/src/mem/cache/compressors/multi.cc +++ b/src/mem/cache/compressors/multi.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,45 +41,47 @@ #include "debug/CacheComp.hh" #include "params/MultiCompressor.hh" -MultiCompressor::MultiCompData::MultiCompData(unsigned index, - std::unique_ptr comp_data) +namespace Compressor { + +Multi::MultiCompData::MultiCompData(unsigned index, + std::unique_ptr comp_data) : CompressionData(), index(index), compData(std::move(comp_data)) { setSizeBits(compData->getSizeBits()); } uint8_t -MultiCompressor::MultiCompData::getIndex() const +Multi::MultiCompData::getIndex() const { return index; } -MultiCompressor::MultiCompressor(const Params *p) - : BaseCacheCompressor(p), compressors(p->compressors) +Multi::Multi(const Params *p) + : Base(p), compressors(p->compressors) { fatal_if(compressors.size() == 0, "There must be at least one compressor"); } -MultiCompressor::~MultiCompressor() +Multi::~Multi() { for (auto& compressor : compressors) { delete compressor; } } -std::unique_ptr -MultiCompressor::compress(const uint64_t* cache_line, Cycles& comp_lat, +std::unique_ptr +Multi::compress(const uint64_t* cache_line, Cycles& comp_lat, Cycles& decomp_lat) { struct Results { unsigned index; - std::unique_ptr compData; + std::unique_ptr compData; Cycles decompLat; uint8_t compressionFactor; Results(unsigned index, - std::unique_ptr comp_data, + std::unique_ptr comp_data, Cycles decomp_lat, std::size_t blk_size) : index(index), compData(std::move(comp_data)), decompLat(decomp_lat) @@ -147,7 +149,7 @@ MultiCompressor::compress(const uint64_t* cache_line, Cycles& comp_lat, } void -MultiCompressor::decompress(const CompressionData* comp_data, +Multi::decompress(const CompressionData* comp_data, uint64_t* cache_line) { const MultiCompData* casted_comp_data = @@ -157,9 +159,9 @@ MultiCompressor::decompress(const CompressionData* comp_data, } void -MultiCompressor::regStats() +Multi::regStats() { - BaseCacheCompressor::regStats(); + Base::regStats(); rankStats .init(compressors.size(), compressors.size()) @@ -177,8 +179,10 @@ MultiCompressor::regStats() } } -MultiCompressor* +} // namespace Compressor + +Compressor::Multi* MultiCompressorParams::create() { - return new MultiCompressor(this); + return new Compressor::Multi(this); } diff --git a/src/mem/cache/compressors/multi.hh b/src/mem/cache/compressors/multi.hh index 3c96d4d7a..db4f3767c 100644 --- a/src/mem/cache/compressors/multi.hh +++ b/src/mem/cache/compressors/multi.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,9 @@ struct MultiCompressorParams; -class MultiCompressor : public BaseCacheCompressor +namespace Compressor { + +class Multi : public Base { protected: /** @@ -53,7 +55,7 @@ class MultiCompressor : public BaseCacheCompressor class MultiCompData; /** List of sub-compressors. */ - std::vector compressors; + std::vector compressors; /** * @defgroup CompressionStats Compression specific statistics. @@ -68,24 +70,19 @@ class MultiCompressor : public BaseCacheCompressor */ public: - /** Convenience typedef. */ - typedef MultiCompressorParams Params; - - /** Default constructor. */ - MultiCompressor(const Params *p); - - /** Default destructor. */ - ~MultiCompressor(); + typedef MultiCompressorParams Params; + Multi(const Params *p); + ~Multi(); void regStats() override; - std::unique_ptr compress( + std::unique_ptr compress( const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; void decompress(const CompressionData* comp_data, uint64_t* data) override; }; -class MultiCompressor::MultiCompData : public CompressionData +class Multi::MultiCompData : public CompressionData { private: /** Index of the compressor that provided these compression results. */ @@ -93,7 +90,7 @@ class MultiCompressor::MultiCompData : public CompressionData public: /** Compression data of the best compressor. */ - std::unique_ptr compData; + std::unique_ptr compData; /** * Default constructor. @@ -102,7 +99,7 @@ class MultiCompressor::MultiCompData : public CompressionData * @param comp_data Compression data of the best compressor. */ MultiCompData(unsigned index, - std::unique_ptr comp_data); + std::unique_ptr comp_data); /** Default destructor. */ ~MultiCompData() = default; @@ -111,4 +108,6 @@ class MultiCompressor::MultiCompData : public CompressionData uint8_t getIndex() const; }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_MULTI_HH__ diff --git a/src/mem/cache/compressors/perfect.cc b/src/mem/cache/compressors/perfect.cc index b53e1f92d..41a7e6da0 100644 --- a/src/mem/cache/compressors/perfect.cc +++ b/src/mem/cache/compressors/perfect.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,26 +38,28 @@ #include "debug/CacheComp.hh" #include "params/PerfectCompressor.hh" -PerfectCompressor::CompData::CompData(const uint64_t* data, +namespace Compressor { + +Perfect::CompData::CompData(const uint64_t* data, std::size_t num_entries) : CompressionData(), entries(data, data + num_entries) { } -PerfectCompressor::PerfectCompressor(const Params *p) - : BaseCacheCompressor(p), +Perfect::Perfect(const Params *p) + : Base(p), compressedSize(8 * blkSize / p->max_compression_ratio), compressionLatency(p->compression_latency), decompressionLatency(p->decompression_latency) { } -std::unique_ptr -PerfectCompressor::compress(const uint64_t* cache_line, Cycles& comp_lat, +std::unique_ptr +Perfect::compress(const uint64_t* cache_line, Cycles& comp_lat, Cycles& decomp_lat) { // Compress every word sequentially - std::unique_ptr comp_data( + std::unique_ptr comp_data( new CompData(cache_line, blkSize/8)); // Set relevant metadata @@ -69,7 +71,7 @@ PerfectCompressor::compress(const uint64_t* cache_line, Cycles& comp_lat, } void -PerfectCompressor::decompress(const CompressionData* comp_data, +Perfect::decompress(const CompressionData* comp_data, uint64_t* data) { // Decompress every entry sequentially @@ -79,8 +81,10 @@ PerfectCompressor::decompress(const CompressionData* comp_data, std::copy(entries.begin(), entries.end(), data); } -PerfectCompressor* +} // namespace Compressor + +Compressor::Perfect* PerfectCompressorParams::create() { - return new PerfectCompressor(this); + return new Compressor::Perfect(this); } diff --git a/src/mem/cache/compressors/perfect.hh b/src/mem/cache/compressors/perfect.hh index 0ef8d131c..e279ec627 100644 --- a/src/mem/cache/compressors/perfect.hh +++ b/src/mem/cache/compressors/perfect.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,9 @@ struct PerfectCompressorParams; -class PerfectCompressor : public BaseCacheCompressor +namespace Compressor { + +class Perfect : public Base { protected: class CompData; @@ -64,11 +66,11 @@ class PerfectCompressor : public BaseCacheCompressor public: typedef PerfectCompressorParams Params; - PerfectCompressor(const Params *p); - ~PerfectCompressor() {}; + Perfect(const Params *p); + ~Perfect() = default; }; -class PerfectCompressor::CompData : public CompressionData +class Perfect::CompData : public CompressionData { public: /** The original data is simply copied over to this vector. */ @@ -84,4 +86,6 @@ class PerfectCompressor::CompData : public CompressionData ~CompData() = default; }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_PERFECT_COMPRESSOR_HH__ diff --git a/src/mem/cache/compressors/repeated_qwords.cc b/src/mem/cache/compressors/repeated_qwords.cc index a51c05f90..db19b266e 100644 --- a/src/mem/cache/compressors/repeated_qwords.cc +++ b/src/mem/cache/compressors/repeated_qwords.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,23 +38,25 @@ #include "mem/cache/compressors/dictionary_compressor_impl.hh" #include "params/RepeatedQwordsCompressor.hh" -RepeatedQwordsCompressor::RepeatedQwordsCompressor(const Params *p) +namespace Compressor { + +RepeatedQwords::RepeatedQwords(const Params *p) : DictionaryCompressor(p) { } void -RepeatedQwordsCompressor::addToDictionary(DictionaryEntry data) +RepeatedQwords::addToDictionary(DictionaryEntry data) { assert(numEntries < dictionarySize); dictionary[numEntries++] = data; } -std::unique_ptr -RepeatedQwordsCompressor::compress(const uint64_t* data, Cycles& comp_lat, +std::unique_ptr +RepeatedQwords::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = DictionaryCompressor::compress(data); // Since there is a single value repeated over and over, there should be @@ -75,8 +77,10 @@ RepeatedQwordsCompressor::compress(const uint64_t* data, Cycles& comp_lat, return comp_data; } -RepeatedQwordsCompressor* +} // namespace Compressor + +Compressor::RepeatedQwords* RepeatedQwordsCompressorParams::create() { - return new RepeatedQwordsCompressor(this); + return new Compressor::RepeatedQwords(this); } diff --git a/src/mem/cache/compressors/repeated_qwords.hh b/src/mem/cache/compressors/repeated_qwords.hh index 3af63dcf8..c361900c9 100644 --- a/src/mem/cache/compressors/repeated_qwords.hh +++ b/src/mem/cache/compressors/repeated_qwords.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,9 @@ struct RepeatedQwordsCompressorParams; -class RepeatedQwordsCompressor : public DictionaryCompressor +namespace Compressor { + +class RepeatedQwords : public DictionaryCompressor { protected: using DictionaryEntry = DictionaryCompressor::DictionaryEntry; @@ -89,16 +91,16 @@ class RepeatedQwordsCompressor : public DictionaryCompressor void addToDictionary(DictionaryEntry data) override; - std::unique_ptr compress( + std::unique_ptr compress( const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; public: typedef RepeatedQwordsCompressorParams Params; - RepeatedQwordsCompressor(const Params *p); - ~RepeatedQwordsCompressor() = default; + RepeatedQwords(const Params *p); + ~RepeatedQwords() = default; }; -class RepeatedQwordsCompressor::PatternX +class RepeatedQwords::PatternX : public DictionaryCompressor::UncompressedPattern { public: @@ -108,7 +110,7 @@ class RepeatedQwordsCompressor::PatternX } }; -class RepeatedQwordsCompressor::PatternM +class RepeatedQwords::PatternM : public DictionaryCompressor::LocatedMaskedPattern<0xFFFFFFFFFFFFFFFF, 0> { public: @@ -119,4 +121,6 @@ class RepeatedQwordsCompressor::PatternM } }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_REPEATED_QWORDS_HH__ diff --git a/src/mem/cache/compressors/zero.cc b/src/mem/cache/compressors/zero.cc index 45675e694..db8067995 100644 --- a/src/mem/cache/compressors/zero.cc +++ b/src/mem/cache/compressors/zero.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,23 +38,25 @@ #include "mem/cache/compressors/dictionary_compressor_impl.hh" #include "params/ZeroCompressor.hh" -ZeroCompressor::ZeroCompressor(const Params *p) +namespace Compressor { + +Zero::Zero(const Params *p) : DictionaryCompressor(p) { } void -ZeroCompressor::addToDictionary(DictionaryEntry data) +Zero::addToDictionary(DictionaryEntry data) { assert(numEntries < dictionarySize); dictionary[numEntries++] = data; } -std::unique_ptr -ZeroCompressor::compress(const uint64_t* data, Cycles& comp_lat, +std::unique_ptr +Zero::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) { - std::unique_ptr comp_data = + std::unique_ptr comp_data = DictionaryCompressor::compress(data); // If there is any non-zero entry, the compressor failed @@ -73,8 +75,10 @@ ZeroCompressor::compress(const uint64_t* data, Cycles& comp_lat, return comp_data; } -ZeroCompressor* +} // namespace Compressor + +Compressor::Zero* ZeroCompressorParams::create() { - return new ZeroCompressor(this); + return new Compressor::Zero(this); } diff --git a/src/mem/cache/compressors/zero.hh b/src/mem/cache/compressors/zero.hh index dd9ca06e7..f45a63967 100644 --- a/src/mem/cache/compressors/zero.hh +++ b/src/mem/cache/compressors/zero.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Inria + * Copyright (c) 2019-2020 Inria * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,9 @@ struct ZeroCompressorParams; -class ZeroCompressor : public DictionaryCompressor +namespace Compressor { + +class Zero : public DictionaryCompressor { protected: using DictionaryEntry = DictionaryCompressor::DictionaryEntry; @@ -89,16 +91,16 @@ class ZeroCompressor : public DictionaryCompressor void addToDictionary(DictionaryEntry data) override; - std::unique_ptr compress( + std::unique_ptr compress( const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat) override; public: typedef ZeroCompressorParams Params; - ZeroCompressor(const Params *p); - ~ZeroCompressor() = default; + Zero(const Params *p); + ~Zero() = default; }; -class ZeroCompressor::PatternX +class Zero::PatternX : public DictionaryCompressor::UncompressedPattern { public: @@ -109,7 +111,7 @@ class ZeroCompressor::PatternX } }; -class ZeroCompressor::PatternZ +class Zero::PatternZ : public DictionaryCompressor::MaskedValuePattern<0, 0xFFFFFFFFFFFFFFFF> { public: @@ -120,4 +122,6 @@ class ZeroCompressor::PatternZ } }; +} // namespace Compressor + #endif //__MEM_CACHE_COMPRESSORS_ZERO_HH__ -- 2.30.2