pan/gen_pack: Fix signed integer packing
authorIcecream95 <ixn@disroot.org>
Wed, 16 Dec 2020 10:03:29 +0000 (23:03 +1300)
committerMarge Bot <eric+marge@anholt.net>
Wed, 16 Dec 2020 21:47:09 +0000 (21:47 +0000)
Any excess sign-extend bits would spill into adjacent fields, so mask
off anything after the end bit.

Shift from 2 instead of 1, because there needs to be one extra bit in
the mask as 'end' is inclusive.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8130>

src/panfrost/lib/gen_pack.py

index c70b8b3..bb17bd5 100644 (file)
@@ -78,7 +78,7 @@ __gen_sint(int32_t v, uint32_t start, uint32_t end)
    }
 #endif
 
-   return ((uint32_t) v) << start;
+   return (((uint32_t) v) << start) & ((2ll << end) - 1);
 }
 
 static inline uint32_t