summaryrefslogtreecommitdiff
path: root/macros.h
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-11-16 13:11:28 +0000
committertron <tron@openttd.org>2005-11-16 13:11:28 +0000
commitec57ef78a21fc57f752e1ee2c353b42da663f007 (patch)
tree658be9e3a7c385d16ddddacc093d3d9fe27855d0 /macros.h
parent8cebe2f607d65de4df376bb5bc4f3caac62a2616 (diff)
downloadopenttd-ec57ef78a21fc57f752e1ee2c353b42da663f007.tar.xz
(svn r3205) Some more uses for GB/SB
Diffstat (limited to 'macros.h')
-rw-r--r--macros.h26
1 files changed, 13 insertions, 13 deletions
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