diff options
Diffstat (limited to 'src/common/common_funcs.h')
-rw-r--r-- | src/common/common_funcs.h | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index c18afe119..67b3679b0 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -4,6 +4,9 @@ #pragma once +#include "common_types.h" +#include <cstdlib> + #ifdef _WIN32 #define SLEEP(x) Sleep(x) #else @@ -17,7 +20,7 @@ template<> struct CompileTimeAssert<true> {}; #define b2(x) ( (x) | ( (x) >> 1) ) #define b4(x) ( b2(x) | ( b2(x) >> 2) ) #define b8(x) ( b4(x) | ( b4(x) >> 4) ) -#define b16(x) ( b8(x) | ( b8(x) >> 8) ) +#define b16(x) ( b8(x) | ( b8(x) >> 8) ) #define b32(x) (b16(x) | (b16(x) >>16) ) #define ROUND_UP_POW2(x) (b32(x - 1) + 1) @@ -73,18 +76,20 @@ inline u64 _rotr64(u64 x, unsigned int shift){ } #else // WIN32 +#include <locale.h> + // Function Cross-Compatibility #define strcasecmp _stricmp #define strncasecmp _strnicmp #define unlink _unlink #define snprintf _snprintf #define vscprintf _vscprintf - + // Locale Cross-Compatibility #define locale_t _locale_t #define freelocale _free_locale #define newlocale(mask, locale, base) _create_locale(mask, locale) - + #define LC_GLOBAL_LOCALE ((locale_t)-1) #define LC_ALL_MASK LC_ALL #define LC_COLLATE_MASK LC_COLLATE @@ -92,7 +97,7 @@ inline u64 _rotr64(u64 x, unsigned int shift){ #define LC_MONETARY_MASK LC_MONETARY #define LC_NUMERIC_MASK LC_NUMERIC #define LC_TIME_MASK LC_TIME - + inline locale_t uselocale(locale_t new_locale) { // Retrieve the current per thread locale setting @@ -106,7 +111,7 @@ inline u64 _rotr64(u64 x, unsigned int shift){ // Restore the global locale _configthreadlocale(_DISABLE_PER_THREAD_LOCALE); } - else if(new_locale != NULL) + else if(new_locale != nullptr) { // Configure the thread to set the locale only for this thread _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); @@ -168,8 +173,8 @@ inline u16 swap16(u16 _data) {return _byteswap_ushort(_data);} inline u32 swap32(u32 _data) {return _byteswap_ulong (_data);} inline u64 swap64(u64 _data) {return _byteswap_uint64(_data);} #elif _M_ARM -inline u16 swap16 (u16 _data) { u32 data = _data; __asm__ ("rev16 %0, %1\n" : "=l" (data) : "l" (data)); return (u16)data;} -inline u32 swap32 (u32 _data) {__asm__ ("rev %0, %1\n" : "=l" (_data) : "l" (_data)); return _data;} +inline u16 swap16 (u16 _data) { u32 data = _data; __asm__ ("rev16 %0, %1\n" : "=l" (data) : "l" (data)); return (u16)data;} +inline u32 swap32 (u32 _data) {__asm__ ("rev %0, %1\n" : "=l" (_data) : "l" (_data)); return _data;} inline u64 swap64(u64 _data) {return ((u64)swap32(_data) << 32) | swap32(_data >> 32);} #elif __linux__ inline u16 swap16(u16 _data) {return bswap_16(_data);} @@ -226,7 +231,7 @@ template <typename T> inline T FromBigEndian(T data) { //static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types"); - + swap<sizeof(data)>(reinterpret_cast<u8*>(&data)); return data; } |