mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[OSKITTCP]
Use RtlUlongByteSwap / RtlUshortByteSwap for byte swapping. They are portable and intrinsics on x86. svn path=/trunk/; revision=47831
This commit is contained in:
parent
6b1edeb54a
commit
0959625c7e
1 changed files with 2 additions and 55 deletions
|
@ -56,61 +56,8 @@
|
|||
#include <sys/cdefs.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static inline unsigned long __byte_swap_long ( unsigned long i )
|
||||
{
|
||||
char dst[4];
|
||||
char* src = (char*)&i;
|
||||
dst[0] = src[3];
|
||||
dst[1] = src[2];
|
||||
dst[2] = src[1];
|
||||
dst[3] = src[0];
|
||||
return *(unsigned long*)&dst[0];
|
||||
}
|
||||
|
||||
static inline unsigned short __byte_swap_word ( unsigned short i )
|
||||
{
|
||||
char dst[2];
|
||||
char* src = (char*)&i;
|
||||
dst[0] = src[1];
|
||||
dst[1] = src[0];
|
||||
return *(unsigned short*)&dst[0];
|
||||
}
|
||||
#else/*_MSC_VER*/
|
||||
#define __word_swap_long(x) \
|
||||
({ register u_long __X = (x); \
|
||||
__asm ("rorl $16, %1" \
|
||||
: "=r" (__X) \
|
||||
: "0" (__X)); \
|
||||
__X; })
|
||||
#if __GNUC__ >= 2
|
||||
#define __byte_swap_long(x) \
|
||||
__extension__ ({ register u_long __X = (x); \
|
||||
__asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \
|
||||
: "=q" (__X) \
|
||||
: "0" (__X)); \
|
||||
__X; })
|
||||
#define __byte_swap_word(x) \
|
||||
__extension__ ({ register u_short __X = (x); \
|
||||
__asm ("xchgb %h1, %b1" \
|
||||
: "=q" (__X) \
|
||||
: "0" (__X)); \
|
||||
__X; })
|
||||
#else /* __GNUC__ >= 2 */
|
||||
#define __byte_swap_long(x) \
|
||||
({ register u_long __X = (x); \
|
||||
__asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \
|
||||
: "=r" (__X) \
|
||||
: "0" (__X)); \
|
||||
__X; })
|
||||
#define __byte_swap_word(x) \
|
||||
({ register u_short __X = (x); \
|
||||
__asm ("rorw $8, %w1" \
|
||||
: "=r" (__X) \
|
||||
: "0" (__X)); \
|
||||
__X; })
|
||||
#endif /* __GNUC__ >= 2 */
|
||||
#endif /* _MSC_VER */
|
||||
#define __byte_swap_long RtlUlongByteSwap
|
||||
#define __byte_swap_word RtlUshortByteSwap
|
||||
|
||||
/*
|
||||
* Macros for network/external number representation conversion.
|
||||
|
|
Loading…
Reference in a new issue