diff options
author | marha <marha@users.sourceforge.net> | 2011-06-09 09:24:20 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-06-09 09:24:20 +0200 |
commit | 0a9d2abef2e6fac5d52556969655a62711df6418 (patch) | |
tree | 86d46767bedf8271ec0f67442259c5b3e7a8bb87 /mesalib/src/gallium/auxiliary/util/u_math.h | |
parent | adeb8256da9b636648178f729d7b3316a0a8e990 (diff) | |
download | vcxsrv-0a9d2abef2e6fac5d52556969655a62711df6418.tar.gz vcxsrv-0a9d2abef2e6fac5d52556969655a62711df6418.tar.bz2 vcxsrv-0a9d2abef2e6fac5d52556969655a62711df6418.zip |
mesa xkbcomp xkeyboard-config git update 9 Jun 2011
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util/u_math.h')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_math.h | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h index 65a99fcb3..0b5284428 100644 --- a/mesalib/src/gallium/auxiliary/util/u_math.h +++ b/mesalib/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) && (PIPE_CC_GCC_VERSION >= 304) + return ((sizeof(unsigned) * 8 - 1) - __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 } @@ -493,17 +497,29 @@ util_logbase2(unsigned n) static INLINE unsigned util_next_power_of_two(unsigned x) { - unsigned i; - - if (x == 0) - return 1; +#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304) + if (x <= 1) + return 1; - --x; + return (1 << ((sizeof(unsigned) * 8) - __builtin_clz(x - 1))); +#else + unsigned val = x; - for (i = 1; i < sizeof(unsigned) * 8; i <<= 1) - x |= x >> i; + if (x <= 1) + return 1; - 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 } @@ -513,7 +529,7 @@ util_next_power_of_two(unsigned x) static INLINE unsigned util_bitcount(unsigned n) { -#if defined(PIPE_CC_GCC) +#if defined(PIPE_CC_GCC) && (PIPE_CC_GCC_VERSION >= 304) return __builtin_popcount(n); #else /* K&R classic bitcount. |