您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2014-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #ifndef STARWELS_COMPAT_BYTESWAP_H
  5. #define STARWELS_COMPAT_BYTESWAP_H
  6. #if defined(HAVE_CONFIG_H)
  7. #include "config/starwels-config.h"
  8. #endif
  9. #include <stdint.h>
  10. #if defined(HAVE_BYTESWAP_H)
  11. #include <byteswap.h>
  12. #endif
  13. #if defined(__APPLE__)
  14. #if !defined(bswap_16)
  15. // Mac OS X / Darwin features; we include a check for bswap_16 because if it is already defined, protobuf has
  16. // defined these macros for us already; if it isn't, we do it ourselves. In either case, we get the exact same
  17. // result regardless which path was taken
  18. #include <libkern/OSByteOrder.h>
  19. #define bswap_16(x) OSSwapInt16(x)
  20. #define bswap_32(x) OSSwapInt32(x)
  21. #define bswap_64(x) OSSwapInt64(x)
  22. #endif // !defined(bswap_16)
  23. #else
  24. // Non-Mac OS X / non-Darwin
  25. #if HAVE_DECL_BSWAP_16 == 0
  26. inline uint16_t bswap_16(uint16_t x)
  27. {
  28. return (x >> 8) | ((x & 0x00ff) << 8);
  29. }
  30. #endif // HAVE_DECL_BSWAP16
  31. #if HAVE_DECL_BSWAP_32 == 0
  32. inline uint32_t bswap_32(uint32_t x)
  33. {
  34. return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) |
  35. ((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24));
  36. }
  37. #endif // HAVE_DECL_BSWAP32
  38. #if HAVE_DECL_BSWAP_64 == 0
  39. inline uint64_t bswap_64(uint64_t x)
  40. {
  41. return (((x & 0xff00000000000000ull) >> 56)
  42. | ((x & 0x00ff000000000000ull) >> 40)
  43. | ((x & 0x0000ff0000000000ull) >> 24)
  44. | ((x & 0x000000ff00000000ull) >> 8)
  45. | ((x & 0x00000000ff000000ull) << 8)
  46. | ((x & 0x0000000000ff0000ull) << 24)
  47. | ((x & 0x000000000000ff00ull) << 40)
  48. | ((x & 0x00000000000000ffull) << 56));
  49. }
  50. #endif // HAVE_DECL_BSWAP64
  51. #endif // defined(__APPLE__)
  52. #endif // STARWELS_COMPAT_BYTESWAP_H