Mesa (android-radeonsi-build-fix): mesa: Silence 'left shift of negative value' warning in BPTC compression code

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Dec 5 08:08:27 UTC 2019


Module: Mesa
Branch: android-radeonsi-build-fix
Commit: a7e607641a2b6f1d89e1c5e6eaf91d6faf156286
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a7e607641a2b6f1d89e1c5e6eaf91d6faf156286

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Nov 18 19:33:06 2019 -0800

mesa: Silence 'left shift of negative value' warning in BPTC compression code

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 at amd.com> [v1]
Reviewed-by: Neil Roberts <nroberts at igalia.com>

---

 src/mesa/main/texcompress_bptc_tmp.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/texcompress_bptc_tmp.h b/src/mesa/main/texcompress_bptc_tmp.h
index 90837d6af3a..95b83814a3c 100644
--- a/src/mesa/main/texcompress_bptc_tmp.h
+++ b/src/mesa/main/texcompress_bptc_tmp.h
@@ -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




More information about the mesa-commit mailing list