… | |
… | |
48 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
48 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
49 | |
49 | |
50 | // lots of stuff taken from FXT |
50 | // lots of stuff taken from FXT |
51 | |
51 | |
52 | /* Rotate right. This is used in various places for checksumming */ |
52 | /* Rotate right. This is used in various places for checksumming */ |
53 | //TODO: this sucks, use a better checksum algo |
53 | //TODO: that sucks, use a better checksum algo |
54 | static inline uint32_t |
54 | static inline uint32_t |
55 | rotate_right (uint32_t c) |
55 | rotate_right (uint32_t c, uint32_t count = 1) |
56 | { |
56 | { |
57 | return (c << 31) | (c >> 1); |
57 | return (c << (32 - count)) | (c >> count); |
|
|
58 | } |
|
|
59 | |
|
|
60 | static inline uint32_t |
|
|
61 | rotate_left (uint32_t c, uint32_t count = 1) |
|
|
62 | { |
|
|
63 | return (c >> (32 - count)) | (c << count); |
58 | } |
64 | } |
59 | |
65 | |
60 | // Return abs(a-b) |
66 | // Return abs(a-b) |
61 | // Both a and b must not have the most significant bit set |
67 | // Both a and b must not have the most significant bit set |
62 | static inline uint32_t |
68 | static inline uint32_t |