From: Brian Paul Date: Fri, 4 Nov 2005 16:47:22 +0000 (+0000) Subject: better ffs() function (bug 4956) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2cb1cf484ad2f78b9c4ec9aea025b5afc9b4b43a;p=mesa.git better ffs() function (bug 4956) --- diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 3bf9b95a0b5..de8456d3b7d 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