diff options
author | tron <tron@openttd.org> | 2005-07-17 09:41:28 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-07-17 09:41:28 +0000 |
commit | 10bc66eb42bb731ecb77f8771ce10f7e91427c5f (patch) | |
tree | cdb82083e05a8aa2c0e78967b709a832fb2801d9 | |
parent | 9ca761b06534ed191b0624a6c7049db296997a73 (diff) | |
download | openttd-10bc66eb42bb731ecb77f8771ce10f7e91427c5f.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
-rw-r--r-- | macros.h | 15 | ||||
-rw-r--r-- | misc.c | 5 |
2 files changed, 11 insertions, 9 deletions
@@ -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 */ @@ -19,11 +19,6 @@ extern void InitNewsItemStructs(void); char _name_array[512][32]; -static inline uint32 ROR(uint32 x, int n) -{ - return (x >> n) + (x << ((sizeof(x)*8)-n)); -} - #ifndef MERSENNE_TWISTER #ifdef RANDOM_DEBUG |