mem-cache: Fix integer promotion of mask
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Wed, 26 Feb 2020 12:44:41 +0000 (13:44 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 31 Aug 2020 17:45:43 +0000 (17:45 +0000)
When applying the bitwise not to a short integer the compiler
automatically promotes it to an integer. For example, if a 8-bit
mask=0xFF, and the compiler decides to promote the mask to 32-bit
to apply the bitwise not, ~mask=0xFFFFFF00, which will yield wrong
results for popcount(): expected=0, got=24.

Change-Id: I95efba5532c27ca004ff6947d4b51a8a14f09741
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33374
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/cache/compressors/dictionary_compressor.hh

index fce79d5e81b1d9c426fe9f6c118a348681f74f8c..650edab5a07e6d9c18eb073bbaa1507be5b1e009 100644 (file)
@@ -464,7 +464,7 @@ class DictionaryCompressor<T>::MaskedPattern
         const DictionaryEntry bytes,
         const bool allocate = true)
       : DictionaryCompressor<T>::Pattern(number, code, metadata_length,
-            popCount(~mask), match_location, allocate),
+            popCount(static_cast<T>(~mask)), match_location, allocate),
         bits(DictionaryCompressor<T>::fromDictionaryEntry(bytes) & ~mask)
     {
     }