mesa: refactor GenerateTextureMipmap handling
[mesa.git] / src / mesa / main / imports.c
index 230ebbc67f461e3376fb195e4c857330d56f717d..96f8ad443f3c6ee27117da0653c976f25086b5ca 100644 (file)
 #include <stdio.h>
 #include <stdarg.h>
 #include "c99_math.h"
-#include "util/rounding.h" /* for _mesa_roundeven */
 #include "imports.h"
 #include "context.h"
-#include "mtypes.h"
 #include "version.h"
 
 #ifdef _GNU_SOURCE
@@ -89,7 +87,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
    if (err)
       return NULL;
    return mem;
-#elif defined(_WIN32) && defined(_MSC_VER)
+#elif defined(_WIN32)
    return _aligned_malloc(bytes, alignment);
 #else
    uintptr_t ptr, buf;
@@ -103,7 +101,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
    buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
    *(uintptr_t *)(buf - sizeof(void *)) = ptr;
 
-#ifdef DEBUG
+#ifndef NDEBUG
    /* mark the non-aligned area */
    while ( ptr < buf - sizeof(void *) ) {
       *(unsigned long *)ptr = 0xcdcdcdcd;
@@ -131,7 +129,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
    }
 
    return mem;
-#elif defined(_WIN32) && defined(_MSC_VER)
+#elif defined(_WIN32)
    void *mem;
 
    mem = _aligned_malloc(bytes, alignment);
@@ -152,7 +150,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
    buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1);
    *(uintptr_t *)(buf - sizeof(void *)) = ptr;
 
-#ifdef DEBUG
+#ifndef NDEBUG
    /* mark the non-aligned area */
    while ( ptr < buf - sizeof(void *) ) {
       *(unsigned long *)ptr = 0xcdcdcdcd;
@@ -178,7 +176,7 @@ _mesa_align_free(void *ptr)
 {
 #if defined(HAVE_POSIX_MEMALIGN)
    free(ptr);
-#elif defined(_WIN32) && defined(_MSC_VER)
+#elif defined(_WIN32)
    _aligned_free(ptr);
 #else
    if (ptr) {
@@ -196,7 +194,7 @@ void *
 _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
                     unsigned long alignment)
 {
-#if defined(_WIN32) && defined(_MSC_VER)
+#if defined(_WIN32)
    (void) oldSize;
    return _aligned_realloc(oldBuffer, newSize, alignment);
 #else
@@ -214,124 +212,6 @@ _mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize,
 /*@}*/
 
 
-/**********************************************************************/
-/** \name Math */
-/*@{*/
-
-
-#ifndef HAVE___BUILTIN_FFS
-/**
- * Find the first bit set in a word.
- */
-int
-ffs(int i)
-{
-   register int bit = 0;
-   if (i != 0) {
-      if ((i & 0xffff) == 0) {
-         bit += 16;
-         i >>= 16;
-      }
-      if ((i & 0xff) == 0) {
-         bit += 8;
-         i >>= 8;
-      }
-      if ((i & 0xf) == 0) {
-         bit += 4;
-         i >>= 4;
-      }
-      while ((i & 1) == 0) {
-         bit++;
-         i >>= 1;
-      }
-      bit++;
-   }
-   return bit;
-}
-#endif
-
-#ifndef HAVE___BUILTIN_FFSLL
-/**
- * Find position of first bit set in given value.
- * XXX Warning: this function can only be used on 64-bit systems!
- * \return  position of least-significant bit set, starting at 1, return zero
- *          if no bits set.
- */
-int
-ffsll(long long int val)
-{
-   int bit;
-
-   assert(sizeof(val) == 8);
-
-   bit = ffs((int) val);
-   if (bit != 0)
-      return bit;
-
-   bit = ffs((int) (val >> 32));
-   if (bit != 0)
-      return 32 + bit;
-
-   return 0;
-}
-#endif
-
-
-#ifndef HAVE___BUILTIN_POPCOUNT
-/**
- * Return number of bits set in given GLuint.
- */
-unsigned int
-_mesa_bitcount(unsigned int n)
-{
-   unsigned int bits;
-   for (bits = 0; n > 0; n = n >> 1) {
-      bits += (n & 1);
-   }
-   return bits;
-}
-#endif
-
-#ifndef HAVE___BUILTIN_POPCOUNTLL
-/**
- * Return number of bits set in given 64-bit uint.
- */
-unsigned int
-_mesa_bitcount_64(uint64_t n)
-{
-   unsigned int bits;
-   for (bits = 0; n > 0; n = n >> 1) {
-      bits += (n & 1);
-   }
-   return bits;
-}
-#endif
-
-/*@}*/
-
-
-/**********************************************************************/
-/** \name String */
-/*@{*/
-
-
-/** Compute simple checksum/hash for a string */
-unsigned int
-_mesa_str_checksum(const char *str)
-{
-   /* This could probably be much better */
-   unsigned int sum, i;
-   const char *c;
-   sum = i = 1;
-   for (c = str; *c; c++, i++)
-      sum += *c * (i % 100);
-   return sum + i;
-}
-
-
-/*@}*/
-
-
 /** Needed due to #ifdef's, above. */
 int
 _mesa_vsnprintf(char *str, size_t size, const char *fmt, va_list args)