mem-cache: Use shouldAllocate() instead of CPack's decompress()
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Tue, 16 Jul 2019 08:51:08 +0000 (10:51 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Tue, 29 Oct 2019 21:32:02 +0000 (21:32 +0000)
Split decompression functionality using the proper function to
determine if a dictionary entry should be allocated after
decompression or not.

Change-Id: I4995304f4c4508c03c9fc1685f04511622969556
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21146
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/cache/compressors/cpack.cc
src/mem/cache/compressors/cpack.hh

index 1192963e227082cef87a41c20fa14cedaca60554..625bedcd8bdc95686606b158309b728ae17d302b 100644 (file)
@@ -159,8 +159,6 @@ CPack::compress(const uint64_t* data, Cycles& comp_lat, Cycles& decomp_lat)
 uint32_t
 CPack::decompressWord(const Pattern* pattern)
 {
-    std::array<uint8_t, 4> data;
-
     // Search for matching entry
     std::vector<std::array<uint8_t, 4>>::iterator entry_it =
         dictionary.begin();
@@ -168,7 +166,8 @@ CPack::decompressWord(const Pattern* pattern)
 
     // Decompress the match. If the decompressed value must be added to
     // the dictionary, do it
-    if (pattern->decompress(*entry_it, data)) {
+    const std::array<uint8_t, 4> data = pattern->decompress(*entry_it);
+    if (pattern->shouldAllocate()) {
         dictionary[numEntries++] = data;
     }
 
index 664a37601b649403819a4a6b7314f706d45198b3..1a271eeae7408bec57e74c246b47421775fe1e2f 100644 (file)
@@ -357,11 +357,10 @@ class CPack::Pattern
      * its data.
      *
      * @param dict_bytes The bytes in the corresponding matching entry.
-     * @param data The decompressed pattern.
-     * @return Whether entry should be added to dictionary or not.
+     * @return The decompressed pattern.
      */
-    virtual bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                            std::array<uint8_t, 4>& data) const = 0;
+    virtual std::array<uint8_t, 4> decompress(
+        const std::array<uint8_t, 4> dict_bytes) const = 0;
 };
 
 class CPack::PatternZZZZ : public Pattern
@@ -378,11 +377,10 @@ class CPack::PatternZZZZ : public Pattern
                (bytes[0] == 0);
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = {0, 0, 0, 0};
-        return false;
+        return {0, 0, 0, 0};
     }
 };
 
@@ -407,11 +405,10 @@ class CPack::PatternXXXX : public Pattern
         return true;
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = bytes;
-        return true;
+        return bytes;
     }
 };
 
@@ -428,11 +425,10 @@ class CPack::PatternMMMM : public Pattern
         return (bytes == dict_bytes) && (match_location >= 0);
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = dict_bytes;
-        return true;
+        return dict_bytes;
     }
 };
 
@@ -461,11 +457,10 @@ class CPack::PatternMMXX : public Pattern
 
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = {byte0, byte1, dict_bytes[2], dict_bytes[3]};
-        return true;
+        return {byte0, byte1, dict_bytes[2], dict_bytes[3]};
     }
 };
 
@@ -489,11 +484,10 @@ class CPack::PatternZZZX : public Pattern
                (bytes[0] != 0);
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = {byte, 0, 0, 0};
-        return false;
+        return {byte, 0, 0, 0};
     }
 };
 
@@ -519,11 +513,10 @@ class CPack::PatternMMMX : public Pattern
                (match_location >= 0);
     }
 
-    bool decompress(const std::array<uint8_t, 4> dict_bytes,
-                    std::array<uint8_t, 4>& data) const override
+    std::array<uint8_t, 4>
+    decompress(const std::array<uint8_t, 4> dict_bytes) const override
     {
-        data = {byte, dict_bytes[1], dict_bytes[2], dict_bytes[3]};
-        return true;
+        return {byte, dict_bytes[1], dict_bytes[2], dict_bytes[3]};
     }
 };