mesa/main: Add function to find next higher power of two.
[mesa.git] / src / mesa / main / imports.h
index 7b61e22e9322b8a18a359be503b685113f0c0ed8..81cb396b2bb8fe41443080f8915b0f11744b3e05 100644 (file)
@@ -291,6 +291,7 @@ long iround(float f);
 #define IROUND(f)  ((int) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
 #endif
 
+#define IROUND64(f)  ((GLint64) (((f) >= 0.0F) ? ((f) + 0.5F) : ((f) - 0.5F)))
 
 /***
  *** IROUND_POS: return (as an integer) positive float rounded to nearest int
@@ -404,6 +405,52 @@ _mesa_is_pow_two(int x)
    return !(x & (x - 1));
 }
 
+/**
+ * Round given integer to next higer power of two
+ * If X is zero result is undefined.
+ *
+ * Source for the fallback implementation is
+ * Sean Eron Anderson's webpage "Bit Twiddling Hacks"
+ * http://graphics.stanford.edu/~seander/bithacks.html
+ */
+static INLINE int32_t
+_mesa_next_pow_two_32(uint32_t x)
+{
+#ifdef __GNUC__
+       return 1 << (__builtin_clz(x) ^ 31);
+#else
+       x--;
+       x |= x >> 1;
+       x |= x >> 2;
+       x |= x >> 4;
+       x |= x >> 8;
+       x |= x >> 16;
+       x++;
+       return x;
+#endif
+}
+
+static INLINE int64_t
+_mesa_next_pow_two_64(uint64_t x)
+{
+#ifdef __GNUC__
+       if (sizeof(x) == sizeof(long))
+               return 1 << (__builtin_clzl(x) ^ 63);
+       else
+               return 1 << (__builtin_clzll(x) ^ 63);
+#else
+       x--;
+       x |= x >> 1;
+       x |= x >> 2;
+       x |= x >> 4;
+       x |= x >> 8;
+       x |= x >> 16;
+       x |= x >> 32;
+       x++;
+       return x;
+#endif
+}
+
 
 /***
  *** UNCLAMPED_FLOAT_TO_UBYTE: clamp float to [0,1] and map to ubyte in [0,255]
@@ -586,6 +633,9 @@ _mesa_atoi( const char *s );
 extern double
 _mesa_strtod( const char *s, char **end );
 
+extern unsigned int
+_mesa_str_checksum(const char *str);
+
 extern int
 _mesa_sprintf( char *str, const char *fmt, ... );
 
@@ -614,10 +664,6 @@ _mesa_error( __GLcontext *ctx, GLenum error, const char *fmtString, ... );
 extern void
 _mesa_debug( const __GLcontext *ctx, const char *fmtString, ... );
 
-extern void 
-_mesa_exit( int status );
-
-
 #ifdef __cplusplus
 }
 #endif