mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-09 19:10:38 +00:00
Use consistent casts/types for byte swap functions
This commit is contained in:
parent
a8786632f7
commit
4b9a4ae695
@ -402,14 +402,14 @@ static inline T ROR(const T x, const uint8 n)
|
|||||||
* (since it will use hardware swapping if available).
|
* (since it will use hardware swapping if available).
|
||||||
* Even though they should return uint16 and uint32, we get
|
* Even though they should return uint16 and uint32, we get
|
||||||
* warnings if we don't cast those (why?) */
|
* warnings if we don't cast those (why?) */
|
||||||
#define BSWAP64(x) ((uint64)CFSwapInt64(x))
|
#define BSWAP64(x) ((uint64)CFSwapInt64((uint64)x))
|
||||||
#define BSWAP32(x) ((uint32)CFSwapInt32(x))
|
#define BSWAP32(x) ((uint32)CFSwapInt32((uint32)x))
|
||||||
#define BSWAP16(x) ((uint16)CFSwapInt16(x))
|
#define BSWAP16(x) ((uint16)CFSwapInt16((uint16)x))
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
/* MSVC has intrinsics for swapping, resulting in faster code */
|
/* MSVC has intrinsics for swapping, resulting in faster code */
|
||||||
#define BSWAP64(x) (_byteswap_uint64(x))
|
#define BSWAP64(x) ((uint64)_byteswap_uint64((uint64)x))
|
||||||
#define BSWAP32(x) (_byteswap_ulong(x))
|
#define BSWAP32(x) ((uint32)_byteswap_ulong((uint32)x))
|
||||||
#define BSWAP16(x) (_byteswap_ushort(x))
|
#define BSWAP16(x) ((uint16)_byteswap_ushort((uint16)x))
|
||||||
#else
|
#else
|
||||||
/**
|
/**
|
||||||
* Perform a 64 bits endianness bitswap on x.
|
* Perform a 64 bits endianness bitswap on x.
|
||||||
@ -437,7 +437,7 @@ static inline T ROR(const T x, const uint8 n)
|
|||||||
{
|
{
|
||||||
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
|
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
|
||||||
/* GCC >= 4.3 provides a builtin, resulting in faster code */
|
/* GCC >= 4.3 provides a builtin, resulting in faster code */
|
||||||
return (uint32)__builtin_bswap32((int32)x);
|
return (uint32)__builtin_bswap32((uint32)x);
|
||||||
#else
|
#else
|
||||||
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
|
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
|
||||||
#endif /* __GNUC__ || __clang__ */
|
#endif /* __GNUC__ || __clang__ */
|
||||||
@ -450,7 +450,12 @@ static inline T ROR(const T x, const uint8 n)
|
|||||||
*/
|
*/
|
||||||
static inline uint16 BSWAP16(uint16 x)
|
static inline uint16 BSWAP16(uint16 x)
|
||||||
{
|
{
|
||||||
|
#if !defined(__ICC) && (defined(__GNUC__) || defined(__clang__))
|
||||||
|
/* GCC >= 4.3 provides a builtin, resulting in faster code */
|
||||||
|
return (uint16)__builtin_bswap16((uint16)x);
|
||||||
|
#else
|
||||||
return (x >> 8) | (x << 8);
|
return (x >> 8) | (x << 8);
|
||||||
|
#endif /* __GNUC__ || __clang__ */
|
||||||
}
|
}
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user