mirror of
https://github.com/rehlds/rehlds.git
synced 2025-04-16 22:32:30 +03:00
Declare and use __builtin_bswapXX.
This commit is contained in:
parent
e1fa1ed090
commit
141c867810
@ -65,32 +65,31 @@ typedef union DLONG_u
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline T min(T a, T b) {
|
||||
inline T min(T a, T b)
|
||||
{
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T max(T a, T b) {
|
||||
inline T max(T a, T b)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T clamp(T a, T min, T max) {
|
||||
inline T clamp(T a, T min, T max)
|
||||
{
|
||||
return (a > max) ? max : (a < min) ? min : a;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T bswap(T s) {
|
||||
switch (sizeof(T)) {
|
||||
#ifdef _WIN32
|
||||
case 2: {auto res = _byteswap_ushort(*(uint16 *)&s); return *(T *)&res;}
|
||||
case 4: {auto res = _byteswap_ulong(*(uint32 *)(&s)); return *(T *)&res;}
|
||||
case 8: {auto res = _byteswap_uint64(*(uint64 *)&s); return *(T *)&res;}
|
||||
#else
|
||||
case 2: {auto res = _bswap16(*(uint16 *)&s); return *(T *)&res;}
|
||||
case 4: {auto res = _bswap(*(uint32 *)&s); return *(T *)&res;}
|
||||
case 8: {auto res = _bswap64(*(uint64 *)&s); return *(T *)&res;}
|
||||
#endif
|
||||
inline T bswap(T s)
|
||||
{
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 2: {auto res = __builtin_bswap16(*(uint16 *)&s); return *(T *)&res; }
|
||||
case 4: {auto res = __builtin_bswap32(*(uint32 *)&s); return *(T *)&res; }
|
||||
case 8: {auto res = __builtin_bswap64(*(uint64 *)&s); return *(T *)&res; }
|
||||
default: return s;
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,7 @@
|
||||
#include <smmintrin.h>
|
||||
#include <xmmintrin.h>
|
||||
|
||||
|
||||
#ifdef _WIN32 // WINDOWS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@ -106,6 +107,10 @@
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#define FORCE_STACK_ALIGN
|
||||
|
||||
#define __builtin_bswap16 _byteswap_ushort
|
||||
#define __builtin_bswap32 _byteswap_ulong
|
||||
#define __builtin_bswap64 _byteswap_uint64
|
||||
|
||||
//inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctlsocket(s, FIONBIO, (u_long*)&m) == 0); }
|
||||
//inline int SOCKET_MSGLEN(SOCKET s, u_long& r) { return ioctlsocket(s, FIONREAD, (u_long*)&r); }
|
||||
typedef int socklen_t;
|
||||
@ -152,6 +157,12 @@
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#define FORCE_STACK_ALIGN __attribute__((force_align_arg_pointer))
|
||||
|
||||
#if defined __INTEL_COMPILER
|
||||
#define __builtin_bswap16 _bswap16
|
||||
#define __builtin_bswap32 _bswap
|
||||
#define __builtin_bswap64 _bswap64
|
||||
#endif // __INTEL_COMPILER
|
||||
|
||||
//inline bool SOCKET_FIONBIO(SOCKET s, int m) { return (ioctl(s, FIONBIO, (int*)&m) == 0); }
|
||||
//inline int SOCKET_MSGLEN(SOCKET s, u_long& r) { return ioctl(s, FIONREAD, (int*)&r); }
|
||||
typedef int SOCKET;
|
||||
|
Loading…
x
Reference in New Issue
Block a user