// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. /*++ --*/ #ifndef __PAL_ENDIAN_H__ #define __PAL_ENDIAN_H__ #ifdef __cplusplus extern "C++" { inline UINT16 SWAP16(UINT16 x) { return (x >> 8) | (x << 8); } inline UINT32 SWAP32(UINT32 x) { return (x >> 24) | ((x >> 8) & 0x0000FF00L) | ((x & 0x0000FF00L) << 8) | (x << 24); } } #endif // __cplusplus #if BIGENDIAN #ifdef __cplusplus extern "C++" { inline UINT16 VAL16(UINT16 x) { return SWAP16(x); } inline UINT32 VAL32(UINT32 x) { return SWAP32(x); } inline UINT64 VAL64(UINT64 x) { return ((UINT64)VAL32(x) << 32) | VAL32(x >> 32); } inline void SwapString(WCHAR *szString) { unsigned i; for (i = 0; szString[i] != L'\0'; i++) { szString[i] = VAL16(szString[i]); } } inline void SwapStringLength(WCHAR *szString, ULONG StringLength) { unsigned i; for (i = 0; i < StringLength; i++) { szString[i] = VAL16(szString[i]); } } inline void SwapGuid(GUID *pGuid) { pGuid->Data1 = VAL32(pGuid->Data1); pGuid->Data2 = VAL16(pGuid->Data2); pGuid->Data3 = VAL16(pGuid->Data3); } }; #else // __cplusplus /* C Version of VAL functionality. Swap functions omitted for lack of use in C code */ #define VAL16(x) (((x) >> 8) | ((x) << 8)) #define VAL32(y) (((y) >> 24) | (((y) >> 8) & 0x0000FF00L) | (((y) & 0x0000FF00L) << 8) | ((y) << 24)) #define VAL64(z) (((UINT64)VAL32(z) << 32) | VAL32((z) >> 32)) #endif // __cplusplus #else // !BIGENDIAN #define VAL16(x) x #define VAL32(x) x #define VAL64(x) x #define SwapString(x) #define SwapStringLength(x, y) #define SwapGuid(x) #endif // !BIGENDIAN #ifdef BIT64 #define VALPTR(x) VAL64(x) #else #define VALPTR(x) VAL32(x) #endif #ifdef _ARM_ #define LOG2_PTRSIZE 2 #define ALIGN_ACCESS ((1<