From b935a747829c1bc2255cb3a1a0c91d91d0b5a380 Mon Sep 17 00:00:00 2001 From: truelight Date: Sun, 4 Nov 2007 23:06:39 +0000 Subject: (svn r11383) -Codechange: fixed all the mess around KillFirstBit (tnx to Rubidium and skidd13) --- src/macros.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/macros.h') 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 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). @@ -368,17 +368,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. * @@ -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 static inline T KillFirstBit(T value) { - return value &= (uint)(value - 1) | 0x3FFFC0C0; + return value &= (T)(value - 1); } /** -- cgit v1.2.3-54-g00ecf