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>
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