Le 08/06/2011 22:08, Roland Scheidegger a écrit :
> Looks good to me - but skip the special n <= 1 case that's what the
> (n|1) input to the __builtin_clz is good for.
Ok, I'm not familiar with bit manipulation in fact...
> Oh and I didn't notice before but there's an error in the gcc version
> check (as that's defined as (__GNUC__ * 100 + __GNUC_MINOR__) - we're
> ignoring patchlevel). Though as said there's the popcount usage right
> next to it which doesn't do a version check neither - if that's the only
> thing requiring gcc 3.4 we should fix that otherwise could just make gcc
> 3.4 a requirement.
Ok I did'nt know that.
Here is my 3 patchs fixed. I hope this are the last of the series :-)
Benjamin
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 65a99fc..9d82cc5 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -493,17 +493,29 @@ util_logbase2(unsigned n)
static INLINE unsigned
util_next_power_of_two(unsigned x)
{
- unsigned i;
+#if defined(PIPE_CC_GCC)
+ if (x <= 1)
+ return 1;
+
+ return (1 << ((sizeof(unsigned) * 8) - __builtin_clz(x - 1)));
+#else
+ unsigned val = x;
- if (x == 0)
+ if (x <= 1)
return 1;
- --x;
-
- for (i = 1; i < sizeof(unsigned) * 8; i <<= 1)
- x |= x >> i;
-
- return x + 1;
+ if (util_is_power_of_two(x))
+ return x;
+
+ val--;
+ val = (val >> 1) | val;
+ val = (val >> 2) | val;
+ val = (val >> 4) | val;
+ val = (val >> 8) | val;
+ val = (val >> 16) | val;
+ val++;
+ return val;
+#endif
}
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 65a99fc..294f964 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -477,6 +477,9 @@ float_to_byte_tex(float f)
static INLINE unsigned
util_logbase2(unsigned n)
{
+#if defined(PIPE_CC_GCC)
+ return (31 - __builtin_clz(n | 1));
+#else
unsigned pos = 0;
if (n >= 1<<16) { n >>= 16; pos += 16; }
if (n >= 1<< 8) { n >>= 8; pos += 8; }
@@ -484,6 +487,7 @@ util_logbase2(unsigned n)
if (n >= 1<< 2) { n >>= 2; pos += 2; }
if (n >= 1<< 1) { pos += 1; }
return pos;
+#endif
}
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 3e42911..6ca1bd9 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -86,6 +86,9 @@ _mesa_free_texmemory(void *m)
static GLuint
logbase2(GLuint n)
{
+#if defined(PIPE_CC_GCC)
+ return (31 - __builtin_clz(n | 1));
+#else
GLuint pos = 0;
if (n >= 1<<16) { n >>= 16; pos += 16; }
if (n >= 1<< 8) { n >>= 8; pos += 8; }
@@ -93,6 +96,7 @@ logbase2(GLuint n)
if (n >= 1<< 2) { n >>= 2; pos += 2; }
if (n >= 1<< 1) { pos += 1; }
return pos;
+#endif
}
_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev