From ec57ef78a21fc57f752e1ee2c353b42da663f007 Mon Sep 17 00:00:00 2001 From: tron Date: Wed, 16 Nov 2005 13:11:28 +0000 Subject: (svn r3205) Some more uses for GB/SB --- macros.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'macros.h') diff --git a/macros.h b/macros.h index 0918d44e5..acf6a6c6b 100644 --- a/macros.h +++ b/macros.h @@ -5,6 +5,13 @@ #include "map.h" +/// Fetch n bits starting at bit s from x +#define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1)) +/// Set n bits starting at bit s in x to d +#define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s))) +/// Add i to the n bits starting at bit s in x +#define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s)))) + #ifdef min #undef min #endif @@ -86,20 +93,20 @@ static inline int FindFirstBit2x64(int value) Faster ( or at least cleaner ) implementation below? */ - if ( (byte) value == 0) { - return FIND_FIRST_BIT((value >> 8) & 0x3F) + 8; + if (GB(value, 0, 8) == 0) { + return FIND_FIRST_BIT(GB(value, 8, 6)) + 8; } else { - return FIND_FIRST_BIT(value & 0x3F); + return FIND_FIRST_BIT(GB(value, 0, 6)); } } static inline int KillFirstBit2x64(int value) { - if ( (byte) value == 0) { - return KILL_FIRST_BIT((value >> 8) & 0x3F) << 8; + if (GB(value, 0, 8) == 0) { + return KILL_FIRST_BIT(GB(value, 8, 6)) << 8; } else { - return value & (KILL_FIRST_BIT(value & 0x3F)|0x3F00); + return value & (KILL_FIRST_BIT(GB(value, 0, 6)) | 0x3F00); } } @@ -144,13 +151,6 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a } #endif -/// Fetch n bits starting at bit s from x -#define GB(x, s, n) (((x) >> (s)) & ((1U << (n)) - 1)) -/// Set n bits starting at bit s in x to d -#define SB(x, s, n, d) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | ((d) << (s))) -/// Add i to the n bits starting at bit s in x -#define AB(x, s, n, i) ((x) = ((x) & ~(((1U << (n)) - 1) << (s))) | (((x) + ((i) << (s))) & (((1U << (n)) - 1) << (s)))) - /** * ROtate x Left/Right by n (must be >= 0) * @note Assumes a byte has 8 bits -- cgit v1.2.3-54-g00ecf