mesa: Silence 'left shift of negative value' warning in BPTC compression code
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 19 Nov 2019 03:33:06 +0000 (19:33 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 4 Dec 2019 23:34:03 +0000 (15:34 -0800)
src/util/format/../../mesa/main/texcompress_bptc_tmp.h:830:31: warning: left shift of negative value [-Wshift-negative-value]
  830 |       value |= (~(int32_t) 0) << n_bits;
      |                               ^~

v2: Rewrite to just shift left then shift right.  Based on conversation
with Neil in
https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2792#note_320272,
this should be fine.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> [v1]
Reviewed-by: Neil Roberts <nroberts@igalia.com>
src/mesa/main/texcompress_bptc_tmp.h

index 90837d6af3a5251e34aa224d53a1f27b8f13d21b..95b83814a3cbbb62b592ebb53aed7a4bc96b0b3b 100644 (file)
@@ -826,11 +826,10 @@ static int32_t
 sign_extend(int32_t value,
             int n_bits)
 {
-   if ((value & (1 << (n_bits - 1)))) {
-      value |= (~(int32_t) 0) << n_bits;
-   }
+   assert(n_bits > 0 && n_bits < 32);
 
-   return value;
+   const unsigned n = 32 - n_bits;
+   return (int32_t)((uint32_t)value << n) >> n;
 }
 
 static int