summaryrefslogtreecommitdiff
path: root/macros.h
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-07-17 09:41:28 +0000
committertron <tron@openttd.org>2005-07-17 09:41:28 +0000
commite7fa78d60bb78d3752fd1735d91f36641375c490 (patch)
treecdb82083e05a8aa2c0e78967b709a832fb2801d9 /macros.h
parentde19186be3001000286e0893cd0e2da2f3f5925d (diff)
downloadopenttd-e7fa78d60bb78d3752fd1735d91f36641375c490.tar.xz
(svn r2596) Add macros ROL and ROR to ROtate values Left/Right. Also shorten the parameter names for GB and SB to increase readability
Diffstat (limited to 'macros.h')
-rw-r--r--macros.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/macros.h b/macros.h
index b5c4d11d8..28b61c308 100644
--- a/macros.h
+++ b/macros.h
@@ -153,9 +153,16 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
}
#endif
-// Fetch count bits starting at bit start from value
-#define GB(value, start, count) (((value) >> (start)) & ((1 << (count)) - 1))
-// Set count bits in value starting at bit start to data
-#define SB(value, start, count, data) ((value) = ((value) & ~(((1 << (count)) - 1) << (start))) | ((data) << (start)))
+/// Fetch n bits starting at bit s from x
+#define GB(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1))
+/// Set n bits in x starting at bit s to d
+#define SB(x, s, n, d) ((x) = ((x) & ~(((1 << (n)) - 1) << (s))) | ((d) << (s)))
+
+/**
+ * ROtate x Left/Right by n (must be >= 0)
+ * @note Assumes a byte has 8 bits
+ */
+#define ROL(x, n) ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
+#define ROR(x, n) ((x) >> (n) | (x) << (sizeof(x) * 8 - (n)))
#endif /* MACROS_H */