From 3fc4c0a415436c47d95f37ffd3900e0b3a209f08 Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Fri, 8 Nov 2019 14:21:21 +0100 Subject: [PATCH] mem-cache: Allow inheriting from DitionaryCompressor's comp data Previously either the compression data was the one declared within DictionaryCompressor, or the derived class would have to override the compress() to use a derived compression data. With this change, the instantiation can be overridden, and thus any derived class can choose the compression data pointer type they need to use. Change-Id: I387936265a3de6785a6096c7a6bd21774202b1c7 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33378 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- src/mem/cache/compressors/dictionary_compressor.hh | 8 ++++++++ src/mem/cache/compressors/dictionary_compressor_impl.hh | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/mem/cache/compressors/dictionary_compressor.hh b/src/mem/cache/compressors/dictionary_compressor.hh index b5e9e673e..a0bdf4d43 100644 --- a/src/mem/cache/compressors/dictionary_compressor.hh +++ b/src/mem/cache/compressors/dictionary_compressor.hh @@ -221,6 +221,14 @@ class DictionaryCompressor : public BaseDictionaryCompressor */ virtual void addToDictionary(const DictionaryEntry data) = 0; + /** + * Instantiate a compression data of the sub-class compressor. + * + * @return The new compression data entry. + */ + virtual std::unique_ptr + instantiateDictionaryCompData() const; + /** * Apply compression. * diff --git a/src/mem/cache/compressors/dictionary_compressor_impl.hh b/src/mem/cache/compressors/dictionary_compressor_impl.hh index 6b6e5fbc6..b15721667 100644 --- a/src/mem/cache/compressors/dictionary_compressor_impl.hh +++ b/src/mem/cache/compressors/dictionary_compressor_impl.hh @@ -79,6 +79,13 @@ DictionaryCompressor::resetDictionary() std::fill(dictionary.begin(), dictionary.end(), toDictionaryEntry(0)); } +template +std::unique_ptr::CompData> +DictionaryCompressor::instantiateDictionaryCompData() const +{ + return std::unique_ptr::CompData>(new CompData()); +} + template std::unique_ptr::Pattern> DictionaryCompressor::compressValue(const T data) @@ -119,7 +126,7 @@ std::unique_ptr DictionaryCompressor::compress(const uint64_t* data) { std::unique_ptr comp_data = - std::unique_ptr(new CompData()); + instantiateDictionaryCompData(); // Reset dictionary resetDictionary(); -- 2.30.2