ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.36 by root, Thu Jan 25 03:54:45 2007 UTC vs.
Revision 1.37 by root, Thu Feb 15 15:43:36 2007 UTC

44template<typename T, typename U> static inline T min (T a, U b) { return (U)a < b ? (U)a : b; } 44template<typename T, typename U> static inline T min (T a, U b) { return (U)a < b ? (U)a : b; }
45template<typename T, typename U> static inline T max (T a, U b) { return (U)a > b ? (U)a : b; } 45template<typename T, typename U> static inline T max (T a, U b) { return (U)a > b ? (U)a : b; }
46template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? (T)a : v >(T)b ? (T)b : v; } 46template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? (T)a : v >(T)b ? (T)b : v; }
47 47
48template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } 48template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; }
49
50// lots of stuff taken from FXT
51
52/* Rotate right. This is used in various places for checksumming */
53//TODO: this sucks, use a better checksum algo
54static inline uint32_t
55rotate_right (uint32_t c)
56{
57 return (c << 31) | (c >> 1);
58}
59
60// Return abs(a-b)
61// Both a and b must not have the most significant bit set
62static inline uint32_t
63upos_abs_diff (uint32_t a, uint32_t b)
64{
65 long d1 = b - a;
66 long d2 = (d1 & (d1 >> 31)) << 1;
67
68 return d1 - d2; // == (b - d) - (a + d);
69}
70
71// Both a and b must not have the most significant bit set
72static inline uint32_t
73upos_min (uint32_t a, uint32_t b)
74{
75 int32_t d = b - a;
76 d &= d >> 31;
77 return a + d;
78}
79
80// Both a and b must not have the most significant bit set
81static inline uint32_t
82upos_max (uint32_t a, uint32_t b)
83{
84 int32_t d = b - a;
85 d &= d >> 31;
86 return b - d;
87}
49 88
50// this is much faster than crossfires original algorithm 89// this is much faster than crossfires original algorithm
51// on modern cpus 90// on modern cpus
52inline int 91inline int
53isqrt (int n) 92isqrt (int n)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines