1.1 --- a/include/SDL_bits.h Tue Feb 12 22:23:42 2013 -0800
1.2 +++ b/include/SDL_bits.h Wed Feb 13 17:19:21 2013 -0800
1.3 @@ -65,27 +65,24 @@
1.4 #else
1.5 /* Based off of Bit Twiddling Hacks by Sean Eron Anderson
1.6 * <seander@cs.stanford.edu>, released in the public domain.
1.7 - * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
1.8 + * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
1.9 */
1.10 - static const Sint8 LogTable256[256] =
1.11 + const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
1.12 + const Uint8 S[] = {1, 2, 4, 8, 16};
1.13 +
1.14 + Uint8 msbIndex = 0;
1.15 + int i;
1.16 +
1.17 + for (i = 4; i >= 0; i--)
1.18 {
1.19 - #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
1.20 - -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
1.21 - LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
1.22 - LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
1.23 - #undef LT
1.24 - };
1.25 + if (x & b[i])
1.26 + {
1.27 + x >>= S[i];
1.28 + msbIndex |= S[i];
1.29 + }
1.30 + }
1.31
1.32 - register unsigned int t, tt;
1.33 -
1.34 - if (tt = x >> 16)
1.35 - {
1.36 - return ((t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt]);
1.37 - }
1.38 - else
1.39 - {
1.40 - return ((t = x >> 8) ? 8 + LogTable256[t] : LogTable256[x]);
1.41 - }
1.42 + return msbIndex;
1.43 #endif
1.44 }
1.45