2015-02-01 13:33:06 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2006-09-25 23:26:08 +00:00
|
|
|
* PROJECT: ReactOS system libraries
|
2015-11-07 12:22:52 +00:00
|
|
|
* FILE: lib/rtl/byteswap.c
|
2006-09-25 23:26:08 +00:00
|
|
|
* PURPOSE: Memory functions
|
|
|
|
* PROGRAMMER: David Welch (welch@mcmail.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <rtl.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2011-10-12 21:11:02 +00:00
|
|
|
#if defined(_M_IX86)
|
|
|
|
/* RtlUlonglongByteSwap is broken and cannot be done in C on x86 */
|
|
|
|
#error "Use rtlswap.S!"
|
|
|
|
#endif
|
|
|
|
|
2006-09-25 23:26:08 +00:00
|
|
|
#undef RtlUlonglongByteSwap
|
|
|
|
#undef RtlUlongByteSwap
|
|
|
|
#undef RtlUshortByteSwap
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RtlUshortByteSwap
|
|
|
|
*
|
|
|
|
* Swap the bytes of an unsigned short value.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Based on the inline versions in Wine winternl.h
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-08-19 18:39:47 +00:00
|
|
|
USHORT
|
|
|
|
FASTCALL
|
|
|
|
RtlUshortByteSwap(
|
|
|
|
IN USHORT Source)
|
2006-09-25 23:26:08 +00:00
|
|
|
{
|
2011-10-12 21:11:02 +00:00
|
|
|
#if defined(_M_AMD64)
|
2011-08-19 18:39:47 +00:00
|
|
|
return _byteswap_ushort(Source);
|
|
|
|
#else
|
|
|
|
return (Source >> 8) | (Source << 8);
|
|
|
|
#endif
|
2006-09-25 23:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RtlUlongByteSwap [NTDLL.@]
|
|
|
|
*
|
|
|
|
* Swap the bytes of an unsigned int value.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Based on the inline versions in Wine winternl.h
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
FASTCALL
|
|
|
|
RtlUlongByteSwap(
|
2011-08-19 18:39:47 +00:00
|
|
|
IN ULONG Source)
|
2006-09-25 23:26:08 +00:00
|
|
|
{
|
2011-10-12 21:11:02 +00:00
|
|
|
#if defined(_M_AMD64)
|
2011-08-19 18:39:47 +00:00
|
|
|
return _byteswap_ulong(Source);
|
|
|
|
#else
|
|
|
|
return ((ULONG)RtlUshortByteSwap((USHORT)Source) << 16) | RtlUshortByteSwap((USHORT)(Source >> 16));
|
|
|
|
#endif
|
2006-09-25 23:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RtlUlonglongByteSwap
|
|
|
|
*
|
|
|
|
* Swap the bytes of an unsigned long long value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* i [I] Value to swap bytes of
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The value with its bytes swapped.
|
|
|
|
*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONGLONG FASTCALL
|
2011-08-19 18:39:47 +00:00
|
|
|
RtlUlonglongByteSwap(
|
|
|
|
IN ULONGLONG Source)
|
2006-09-25 23:26:08 +00:00
|
|
|
{
|
2011-10-12 21:11:02 +00:00
|
|
|
#if defined(_M_AMD64)
|
2011-08-19 18:39:47 +00:00
|
|
|
return _byteswap_uint64(Source);
|
|
|
|
#else
|
|
|
|
return ((ULONGLONG) RtlUlongByteSwap (Source) << 32) | RtlUlongByteSwap (Source>>32);
|
|
|
|
#endif
|
2006-09-25 23:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* EOF */
|