summaryrefslogtreecommitdiff
path: root/src/mesa/main/imports.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/imports.c')
-rw-r--r--src/mesa/main/imports.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 6ffaddcde9..def045269c 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -48,6 +48,13 @@
#include "context.h"
#include "version.h"
+#ifdef _GNU_SOURCE
+#include <locale.h>
+#ifdef __APPLE__
+#include <xlocale.h>
+#endif
+#endif
+
#define MAXSTRING 4000 /* for vsnprintf() */
@@ -101,8 +108,8 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
{
#if defined(HAVE_POSIX_MEMALIGN)
void *mem;
-
- (void) posix_memalign(& mem, alignment, bytes);
+ int err = posix_memalign(& mem, alignment, bytes);
+ (void) err;
return mem;
#elif defined(_WIN32) && defined(_MSC_VER)
return _aligned_malloc(bytes, alignment);
@@ -453,7 +460,7 @@ _mesa_inv_sqrtf(float n)
#if 0 /* not used, see below -BP */
float r3, x3, y3;
#endif
- union { float f; unsigned int i; } u;
+ fi_type u;
unsigned int magic;
/*
@@ -622,11 +629,15 @@ _mesa_ffsll(int64_t val)
unsigned int
_mesa_bitcount(unsigned int n)
{
+#if defined(__GNUC__)
+ return __builtin_popcount(n);
+#else
unsigned int bits;
for (bits = 0; n > 0; n = n >> 1) {
bits += (n & 1);
}
return bits;
+#endif
}
@@ -638,10 +649,10 @@ _mesa_bitcount(unsigned int n)
GLhalfARB
_mesa_float_to_half(float val)
{
- const int flt = *((int *) (void *) &val);
- const int flt_m = flt & 0x7fffff;
- const int flt_e = (flt >> 23) & 0xff;
- const int flt_s = (flt >> 31) & 0x1;
+ const fi_type fi = {val};
+ const int flt_m = fi.i & 0x7fffff;
+ const int flt_e = (fi.i >> 23) & 0xff;
+ const int flt_s = (fi.i >> 31) & 0x1;
int s, e, m = 0;
GLhalfARB result;
@@ -728,7 +739,8 @@ _mesa_half_to_float(GLhalfARB val)
const int m = val & 0x3ff;
const int e = (val >> 10) & 0x1f;
const int s = (val >> 15) & 0x1;
- int flt_m, flt_e, flt_s, flt;
+ int flt_m, flt_e, flt_s;
+ fi_type fi;
float result;
/* sign bit */
@@ -763,8 +775,8 @@ _mesa_half_to_float(GLhalfARB val)
flt_m = m << 13;
}
- flt = (flt_s << 31) | (flt_e << 23) | flt_m;
- result = *((float *) (void *) &flt);
+ fi.i = (flt_s << 31) | (flt_e << 23) | flt_m;
+ result = fi.f;
return result;
}
@@ -908,7 +920,15 @@ _mesa_atoi(const char *s)
double
_mesa_strtod( const char *s, char **end )
{
+#ifdef _GNU_SOURCE
+ static locale_t loc = NULL;
+ if (!loc) {
+ loc = newlocale(LC_CTYPE_MASK, "C", NULL);
+ }
+ return strtod_l(s, end, loc);
+#else
return strtod(s, end);
+#endif
}
/** Compute simple checksum/hash for a string */
@@ -919,9 +939,9 @@ _mesa_str_checksum(const char *str)
unsigned int sum, i;
const char *c;
sum = i = 1;
- for (c = str; *c; c++)
+ for (c = str; *c; c++, i++)
sum += *c * (i % 100);
- return sum;
+ return sum + i;
}
@@ -1219,13 +1239,3 @@ _mesa_debug( const GLcontext *ctx, const char *fmtString, ... )
}
/*@}*/
-
-
-/**
- * Wrapper for exit().
- */
-void
-_mesa_exit( int status )
-{
- exit(status);
-}