vidya7732/AI_Doctor_LLM_GenModel
0
1/* Bytes swap functions, reverse order of bytes:2 3 - _Py_bswap16(uint16_t)4 - _Py_bswap32(uint32_t)5 - _Py_bswap64(uint64_t)6*/7 8#ifndef Py_INTERNAL_BSWAP_H9#define Py_INTERNAL_BSWAP_H10#ifdef __cplusplus11extern "C" {12#endif13 14#ifndef Py_BUILD_CORE15# error "this header requires Py_BUILD_CORE define"16#endif17 18#if ((defined(__GNUC__) \19 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) \20 || (defined(__clang__) \21 && (__clang_major__ >= 4 \22 || (__clang_major__ == 3 && __clang_minor__ >= 2))))23 /* __builtin_bswap16() is available since GCC 4.8 and clang 3.2,24 __builtin_bswap32() is available since GCC 4.3,25 __builtin_bswap64() is available since GCC 4.3. */26# define _PY_HAVE_BUILTIN_BSWAP27#endif28 29#ifdef _MSC_VER30 /* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */31# include <intrin.h>32#endif33 34static inline uint16_t35_Py_bswap16(uint16_t word)36{37#ifdef _PY_HAVE_BUILTIN_BSWAP38 return __builtin_bswap16(word);39#elif defined(_MSC_VER)40 Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short));41 return _byteswap_ushort(word);42#else43 // Portable implementation which doesn't rely on circular bit shift44 return ( ((word & UINT16_C(0x00FF)) << 8)45 | ((word & UINT16_C(0xFF00)) >> 8));46#endif47}48 49static inline uint32_t50_Py_bswap32(uint32_t word)51{52#ifdef _PY_HAVE_BUILTIN_BSWAP53 return __builtin_bswap32(word);54#elif defined(_MSC_VER)55 Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long));56 return _byteswap_ulong(word);57#else58 // Portable implementation which doesn't rely on circular bit shift59 return ( ((word & UINT32_C(0x000000FF)) << 24)60 | ((word & UINT32_C(0x0000FF00)) << 8)61 | ((word & UINT32_C(0x00FF0000)) >> 8)62 | ((word & UINT32_C(0xFF000000)) >> 24));63#endif64}65 66static inline uint64_t67_Py_bswap64(uint64_t word)68{69#ifdef _PY_HAVE_BUILTIN_BSWAP70 return __builtin_bswap64(word);71#elif defined(_MSC_VER)72 return _byteswap_uint64(word);73#else74 // Portable implementation which doesn't rely on circular bit shift75 return ( ((word & UINT64_C(0x00000000000000FF)) << 56)76 | ((word & UINT64_C(0x000000000000FF00)) << 40)77 | ((word & UINT64_C(0x0000000000FF0000)) << 24)78 | ((word & UINT64_C(0x00000000FF000000)) << 8)79 | ((word & UINT64_C(0x000000FF00000000)) >> 8)80 | ((word & UINT64_C(0x0000FF0000000000)) >> 24)81 | ((word & UINT64_C(0x00FF000000000000)) >> 40)82 | ((word & UINT64_C(0xFF00000000000000)) >> 56));83#endif84}85 86 87#ifdef __cplusplus88}89#endif90#endif /* !Py_INTERNAL_BSWAP_H */91 92 