summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2005-11-04 16:47:22 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2005-11-04 16:47:22 +0000
commit2cb1cf484ad2f78b9c4ec9aea025b5afc9b4b43a (patch)
treeebcdbb147966614ccc13437843b220dc9dbe2775 /src/mesa
parent8ff68b2bf3d67f84f52d92686143175cb5446f76 (diff)
better ffs() function (bug 4956)
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/imports.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
index 3bf9b95a0b..de8456d3b7 100644
--- a/src/mesa/main/imports.c
+++ b/src/mesa/main/imports.c
@@ -535,12 +535,26 @@ int
_mesa_ffs(int i)
{
#if defined(_WIN32) && !defined(__MINGW32__)
- int bit;
- if (i == 0)
- return 0;
- for (bit = 1; !(i & 1); bit++)
- i >>= 1;
- return bit;
+ 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;
+ }
+ return bit;
+ }
#elif defined(XFree86LOADER) && defined(IN_MODULE)
return xf86ffs(i);
#else