diff options
Diffstat (limited to 'src/common/common_funcs.h')
| -rw-r--r-- | src/common/common_funcs.h | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 4633897ce..ad5bdbc08 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor. | 15 | /// Textually concatenates two tokens. The double-expansion is required by the C preprocessor. |
| 16 | #define CONCAT2(x, y) DO_CONCAT2(x, y) | 16 | #define CONCAT2(x, y) DO_CONCAT2(x, y) |
| 17 | #define DO_CONCAT2(x, y) x ## y | 17 | #define DO_CONCAT2(x, y) x##y |
| 18 | 18 | ||
| 19 | // helper macro to properly align structure members. | 19 | // helper macro to properly align structure members. |
| 20 | // Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121", | 20 | // Calling INSERT_PADDING_BYTES will add a new member variable with a name like "pad121", |
| @@ -24,9 +24,9 @@ | |||
| 24 | 24 | ||
| 25 | // Inlining | 25 | // Inlining |
| 26 | #ifdef _WIN32 | 26 | #ifdef _WIN32 |
| 27 | #define FORCE_INLINE __forceinline | 27 | #define FORCE_INLINE __forceinline |
| 28 | #else | 28 | #else |
| 29 | #define FORCE_INLINE inline __attribute__((always_inline)) | 29 | #define FORCE_INLINE inline __attribute__((always_inline)) |
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | #ifndef _MSC_VER | 32 | #ifndef _MSC_VER |
| @@ -46,7 +46,8 @@ | |||
| 46 | #else | 46 | #else |
| 47 | inline u32 rotl(u32 x, int shift) { | 47 | inline u32 rotl(u32 x, int shift) { |
| 48 | shift &= 31; | 48 | shift &= 31; |
| 49 | if (!shift) return x; | 49 | if (!shift) |
| 50 | return x; | ||
| 50 | return (x << shift) | (x >> (32 - shift)); | 51 | return (x << shift) | (x >> (32 - shift)); |
| 51 | } | 52 | } |
| 52 | #endif | 53 | #endif |
| @@ -56,17 +57,18 @@ inline u32 rotl(u32 x, int shift) { | |||
| 56 | #else | 57 | #else |
| 57 | inline u32 rotr(u32 x, int shift) { | 58 | inline u32 rotr(u32 x, int shift) { |
| 58 | shift &= 31; | 59 | shift &= 31; |
| 59 | if (!shift) return x; | 60 | if (!shift) |
| 61 | return x; | ||
| 60 | return (x >> shift) | (x << (32 - shift)); | 62 | return (x >> shift) | (x << (32 - shift)); |
| 61 | } | 63 | } |
| 62 | #endif | 64 | #endif |
| 63 | 65 | ||
| 64 | inline u64 _rotl64(u64 x, unsigned int shift){ | 66 | inline u64 _rotl64(u64 x, unsigned int shift) { |
| 65 | unsigned int n = shift % 64; | 67 | unsigned int n = shift % 64; |
| 66 | return (x << n) | (x >> (64 - n)); | 68 | return (x << n) | (x >> (64 - n)); |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | inline u64 _rotr64(u64 x, unsigned int shift){ | 71 | inline u64 _rotr64(u64 x, unsigned int shift) { |
| 70 | unsigned int n = shift % 64; | 72 | unsigned int n = shift % 64; |
| 71 | return (x >> n) | (x << (64 - n)); | 73 | return (x >> n) | (x << (64 - n)); |
| 72 | } | 74 | } |
| @@ -74,17 +76,18 @@ inline u64 _rotr64(u64 x, unsigned int shift){ | |||
| 74 | #else // _MSC_VER | 76 | #else // _MSC_VER |
| 75 | 77 | ||
| 76 | #if (_MSC_VER < 1900) | 78 | #if (_MSC_VER < 1900) |
| 77 | // Function Cross-Compatibility | 79 | // Function Cross-Compatibility |
| 78 | #define snprintf _snprintf | 80 | #define snprintf _snprintf |
| 79 | #endif | 81 | #endif |
| 80 | 82 | ||
| 81 | // Locale Cross-Compatibility | 83 | // Locale Cross-Compatibility |
| 82 | #define locale_t _locale_t | 84 | #define locale_t _locale_t |
| 83 | 85 | ||
| 84 | extern "C" { | 86 | extern "C" { |
| 85 | __declspec(dllimport) void __stdcall DebugBreak(void); | 87 | __declspec(dllimport) void __stdcall DebugBreak(void); |
| 86 | } | 88 | } |
| 87 | #define Crash() {DebugBreak();} | 89 | #define Crash() \ |
| 90 | { DebugBreak(); } | ||
| 88 | 91 | ||
| 89 | // cstdlib provides these on MSVC | 92 | // cstdlib provides these on MSVC |
| 90 | #define rotr _rotr | 93 | #define rotr _rotr |