From: Daniel R. Carvalho Date: Wed, 26 Feb 2020 12:44:41 +0000 (+0100) Subject: mem-cache: Fix integer promotion of mask X-Git-Tag: v20.1.0.0~192 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9e7dbd0544babf7c0389a92ef439e4b04f0a3032;p=gem5.git mem-cache: Fix integer promotion of mask 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33374 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris Tested-by: kokoro --- diff --git a/src/mem/cache/compressors/dictionary_compressor.hh b/src/mem/cache/compressors/dictionary_compressor.hh index fce79d5e8..650edab5a 100644 --- a/src/mem/cache/compressors/dictionary_compressor.hh +++ b/src/mem/cache/compressors/dictionary_compressor.hh @@ -464,7 +464,7 @@ class DictionaryCompressor::MaskedPattern const DictionaryEntry bytes, const bool allocate = true) : DictionaryCompressor::Pattern(number, code, metadata_length, - popCount(~mask), match_location, allocate), + popCount(static_cast(~mask)), match_location, allocate), bits(DictionaryCompressor::fromDictionaryEntry(bytes) & ~mask) { }