ReactOS  0.4.14-dev-554-g2f8d847
byteswap.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: lib/rtl/byteswap.c
5  * PURPOSE: Memory functions
6  * PROGRAMMER: David Welch (welch@mcmail.com)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <rtl.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 #if defined(_M_IX86)
17 /* RtlUlonglongByteSwap is broken and cannot be done in C on x86 */
18 #error "Use rtlswap.S!"
19 #endif
20 
21 #undef RtlUlonglongByteSwap
22 #undef RtlUlongByteSwap
23 #undef RtlUshortByteSwap
24 
25 /*************************************************************************
26  * RtlUshortByteSwap
27  *
28  * Swap the bytes of an unsigned short value.
29  *
30  * NOTES
31  * Based on the inline versions in Wine winternl.h
32  *
33  * @implemented
34  */
35 USHORT
39 {
40 #if defined(_M_AMD64)
41  return _byteswap_ushort(Source);
42 #else
43  return (Source >> 8) | (Source << 8);
44 #endif
45 }
46 
47 
48 
49 /*************************************************************************
50  * RtlUlongByteSwap [NTDLL.@]
51  *
52  * Swap the bytes of an unsigned int value.
53  *
54  * NOTES
55  * Based on the inline versions in Wine winternl.h
56  *
57  * @implemented
58  */
59 ULONG
62  IN ULONG Source)
63 {
64 #if defined(_M_AMD64)
65  return _byteswap_ulong(Source);
66 #else
67  return ((ULONG)RtlUshortByteSwap((USHORT)Source) << 16) | RtlUshortByteSwap((USHORT)(Source >> 16));
68 #endif
69 }
70 
71 
72 /*************************************************************************
73  * RtlUlonglongByteSwap
74  *
75  * Swap the bytes of an unsigned long long value.
76  *
77  * PARAMS
78  * i [I] Value to swap bytes of
79  *
80  * RETURNS
81  * The value with its bytes swapped.
82  *
83  * @implemented
84  */
88 {
89 #if defined(_M_AMD64)
90  return _byteswap_uint64(Source);
91 #else
92  return ((ULONGLONG) RtlUlongByteSwap (Source) << 32) | RtlUlongByteSwap (Source>>32);
93 #endif
94 }
95 
96 
97 /* EOF */
#define IN
Definition: typedefs.h:38
ULONGLONG FASTCALL RtlUlonglongByteSwap(IN ULONGLONG Source)
Definition: byteswap.c:86
USHORT FASTCALL RtlUshortByteSwap(IN USHORT Source)
Definition: byteswap.c:37
#define FASTCALL
Definition: nt_native.h:50
_Check_return_ unsigned short __cdecl _byteswap_ushort(_In_ unsigned short)
_Check_return_ unsigned long __cdecl _byteswap_ulong(_In_ unsigned long)
uint64_t ULONGLONG
Definition: typedefs.h:65
_Check_return_ unsigned __int64 __cdecl _byteswap_uint64(_In_ unsigned __int64)
unsigned short USHORT
Definition: pedump.c:61
ULONG FASTCALL RtlUlongByteSwap(IN ULONG Source)
Definition: byteswap.c:61
unsigned int ULONG
Definition: retypes.h:1
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167