diff -r 2f4c95464651 -r f042ae287155 include/SDL_bits.h --- a/include/SDL_bits.h Tue Feb 12 22:23:42 2013 -0800 +++ b/include/SDL_bits.h Wed Feb 13 17:19:21 2013 -0800 @@ -65,27 +65,24 @@ #else /* Based off of Bit Twiddling Hacks by Sean Eron Anderson * , released in the public domain. - * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup + * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog */ - static const Sint8 LogTable256[256] = + const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; + const Uint8 S[] = {1, 2, 4, 8, 16}; + + Uint8 msbIndex = 0; + int i; + + for (i = 4; i >= 0; i--) { - #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n - -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, - LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6), - LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7) - #undef LT - }; + if (x & b[i]) + { + x >>= S[i]; + msbIndex |= S[i]; + } + } - register unsigned int t, tt; - - if (tt = x >> 16) - { - return ((t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt]); - } - else - { - return ((t = x >> 8) ? 8 + LogTable256[t] : LogTable256[x]); - } + return msbIndex; #endif }