--- deliantra/server/include/util.h 2007/01/25 03:54:45 1.36 +++ deliantra/server/include/util.h 2007/02/15 15:43:36 1.37 @@ -47,6 +47,45 @@ template static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } +// lots of stuff taken from FXT + +/* Rotate right. This is used in various places for checksumming */ +//TODO: this sucks, use a better checksum algo +static inline uint32_t +rotate_right (uint32_t c) +{ + return (c << 31) | (c >> 1); +} + +// Return abs(a-b) +// Both a and b must not have the most significant bit set +static inline uint32_t +upos_abs_diff (uint32_t a, uint32_t b) +{ + long d1 = b - a; + long d2 = (d1 & (d1 >> 31)) << 1; + + return d1 - d2; // == (b - d) - (a + d); +} + +// Both a and b must not have the most significant bit set +static inline uint32_t +upos_min (uint32_t a, uint32_t b) +{ + int32_t d = b - a; + d &= d >> 31; + return a + d; +} + +// Both a and b must not have the most significant bit set +static inline uint32_t +upos_max (uint32_t a, uint32_t b) +{ + int32_t d = b - a; + d &= d >> 31; + return b - d; +} + // this is much faster than crossfires original algorithm // on modern cpus inline int