diff options
author | truelight <truelight@openttd.org> | 2007-11-04 23:06:39 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2007-11-04 23:06:39 +0000 |
commit | 4b8aaa994c3f79ba360bc2e3535f7319b09ef0a9 (patch) | |
tree | b50a237674dc49109595b0832ab58f70e3f9af9c /src/macros.h | |
parent | 69b1d97c0348229bf1ff14a672d7e50aa3d9eb3f (diff) | |
download | openttd-4b8aaa994c3f79ba360bc2e3535f7319b09ef0a9.tar.xz |
(svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13)
Diffstat (limited to 'src/macros.h')
-rw-r--r-- | src/macros.h | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/macros.h b/src/macros.h index 8d9759235..1982e939e 100644 --- a/src/macros.h +++ b/src/macros.h @@ -354,7 +354,7 @@ template<typename T> static inline T TOGGLEBIT(T& x, const uint8 y) */ #define IS_CUSTOM_SPRITE(sprite) ((sprite) >= SPR_SIGNALS_BASE) -extern const byte _ffb_64[128]; +extern const byte _ffb_64[64]; /** * Returns the first occure of a bit in a 6-bit value (from right). @@ -369,17 +369,6 @@ extern const byte _ffb_64[128]; #define FIND_FIRST_BIT(x) _ffb_64[(x)] /** - * Returns a value with the first occured of a bit set to zero. - * - * Returns x with the first bit from LSB that is not zero set - * to zero. So, 110100 returns 110000, 000001 returns 000000, etc. - * - * @param x The value to returned a new value - * @return The value which the first bit is set to zero - */ -#define KILL_FIRST_BIT(x) _ffb_64[(x) + 64] - -/** * Finds the position of the first bit in an integer. * * This function returns the position of the first bit set in the @@ -416,14 +405,15 @@ Faster ( or at least cleaner ) implementation below? * Clear the first bit in an integer. * * This function returns a value where the first bit (from LSB) - * is cleared. This function checks only the bits of 0x3F3F! + * is cleared. + * So, 110100 returns 110000, 000001 returns 000000, etc. * * @param value The value to clear the first bit * @return The new value with the first bit cleared */ -static inline uint KillFirstBit2x64(uint value) +template<typename T> static inline T KillFirstBit(T value) { - return value &= (uint)(value - 1) | 0x3FFFC0C0; + return value &= (T)(value - 1); } /** |