mesa/bptc: Use util_sign_extend
authorJason Ekstrand <jason.ekstrand@collabora.com>
Thu, 23 Jun 2022 17:52:27 +0000 (12:52 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 6 Jul 2022 11:23:18 +0000 (11:23 +0000)
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17214>

src/mesa/main/texcompress_bptc_tmp.h

index 0f5db43..4f92fe8 100644 (file)
@@ -818,16 +818,6 @@ decompress_rgba_unorm(int width, int height,
 }
 #endif // BPTC_BLOCK_DECODE
 
-static int32_t
-sign_extend(int32_t value,
-            int n_bits)
-{
-   assert(n_bits > 0 && n_bits < 32);
-
-   const unsigned n = 32 - n_bits;
-   return (int32_t)((uint32_t)value << n) >> n;
-}
-
 static int
 signed_unquantize(int value, int n_endpoint_bits)
 {
@@ -912,8 +902,8 @@ extract_float_endpoints(const struct bptc_float_mode *mode,
       /* The endpoints are specified as signed offsets from e0 */
       for (endpoint = 1; endpoint < n_endpoints; endpoint++) {
          for (component = 0; component < 3; component++) {
-            value = sign_extend(endpoints[endpoint][component],
-                                mode->n_delta_bits[component]);
+            value = util_sign_extend(endpoints[endpoint][component],
+                                     mode->n_delta_bits[component]);
             endpoints[endpoint][component] =
                ((endpoints[0][component] + value) &
                 ((1 << mode->n_endpoint_bits) - 1));
@@ -924,8 +914,8 @@ extract_float_endpoints(const struct bptc_float_mode *mode,
    if (is_signed) {
       for (endpoint = 0; endpoint < n_endpoints; endpoint++) {
          for (component = 0; component < 3; component++) {
-            value = sign_extend(endpoints[endpoint][component],
-                                mode->n_endpoint_bits);
+            value = util_sign_extend(endpoints[endpoint][component],
+                                     mode->n_endpoint_bits);
             endpoints[endpoint][component] =
                signed_unquantize(value, mode->n_endpoint_bits);
          }