[ATL] Add CString.AllocSysString
[reactos.git] / sdk / lib / rtl / byteswap.c
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
36 FASTCALL
37 RtlUshortByteSwap(
38 IN USHORT Source)
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
60 FASTCALL
61 RtlUlongByteSwap(
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 */
85 ULONGLONG FASTCALL
86 RtlUlonglongByteSwap(
87 IN ULONGLONG Source)
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 */