Common: Use the OSX equivalent byte-swap functions

This commit is contained in:
lioncash 2014-08-08 13:26:26 -04:00
parent 62cc22ac11
commit 85ace9751e
1 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,10 @@
#define SLEEP(x) usleep(x*1000) #define SLEEP(x) usleep(x*1000)
#endif #endif
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#endif
#include <clocale> #include <clocale>
#include <cstddef> #include <cstddef>
#include <type_traits> #include <type_traits>
@ -186,11 +190,11 @@ inline u32 swap32(u32 _data) {return bswap_32(_data);}
inline u64 swap64(u64 _data) {return bswap_64(_data);} inline u64 swap64(u64 _data) {return bswap_64(_data);}
#elif __APPLE__ #elif __APPLE__
inline __attribute__((always_inline)) u16 swap16(u16 _data) inline __attribute__((always_inline)) u16 swap16(u16 _data)
{return (_data >> 8) | (_data << 8);} {return OSSwapInt16(_data);}
inline __attribute__((always_inline)) u32 swap32(u32 _data) inline __attribute__((always_inline)) u32 swap32(u32 _data)
{return __builtin_bswap32(_data);} {return OSSwapInt32(_data);}
inline __attribute__((always_inline)) u64 swap64(u64 _data) inline __attribute__((always_inline)) u64 swap64(u64 _data)
{return __builtin_bswap64(_data);} {return OSSwapInt64(_data);}
#elif __FreeBSD__ #elif __FreeBSD__
inline u16 swap16(u16 _data) {return bswap16(_data);} inline u16 swap16(u16 _data) {return bswap16(_data);}
inline u32 swap32(u32 _data) {return bswap32(_data);} inline u32 swap32(u32 _data) {return bswap32(_data);}