replace malloc macros in imports.h with u_memory.h versions
[mesa.git] / src / mesa / main / texcompress_bptc_tmp.h
index 3c4ea2c01316c071ef7f840912a03504917474a1..95b83814a3cbbb62b592ebb53aed7a4bc96b0b3b 100644 (file)
@@ -25,6 +25,9 @@
  * Included by texcompress_bptc and gallium to define BPTC decoding routines.
  */
 
+#ifndef TEXCOMPRESS_BPTC_TMP_H
+#define TEXCOMPRESS_BPTC_TMP_H
+
 #include "util/format_srgb.h"
 #include "util/half_float.h"
 #include "macros.h"
@@ -823,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
@@ -1741,3 +1743,5 @@ compress_rgb_float(int width, int height,
       dst += dst_row_diff;
    }
 }
+
+#endif