int_endianness.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* ===-- int_endianness.h - configuration header for compiler-rt ------------===
  2. *
  3. * The LLVM Compiler Infrastructure
  4. *
  5. * This file is dual licensed under the MIT and the University of Illinois Open
  6. * Source Licenses. See LICENSE.TXT for details.
  7. *
  8. * ===----------------------------------------------------------------------===
  9. *
  10. * This file is a configuration header for compiler-rt.
  11. * This file is not part of the interface of this library.
  12. *
  13. * ===----------------------------------------------------------------------===
  14. */
  15. #ifndef INT_ENDIANNESS_H
  16. #define INT_ENDIANNESS_H
  17. #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  18. defined(__ORDER_LITTLE_ENDIAN__)
  19. /* Clang and GCC provide built-in endianness definitions. */
  20. #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  21. #define _YUGA_LITTLE_ENDIAN 0
  22. #define _YUGA_BIG_ENDIAN 1
  23. #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  24. #define _YUGA_LITTLE_ENDIAN 1
  25. #define _YUGA_BIG_ENDIAN 0
  26. #endif /* __BYTE_ORDER__ */
  27. #else /* Compilers other than Clang or GCC. */
  28. #if defined(__SVR4) && defined(__sun)
  29. #error #include <sys/byteorder.h>
  30. #if defined(_BIG_ENDIAN)
  31. #define _YUGA_LITTLE_ENDIAN 0
  32. #define _YUGA_BIG_ENDIAN 1
  33. #elif defined(_LITTLE_ENDIAN)
  34. #define _YUGA_LITTLE_ENDIAN 1
  35. #define _YUGA_BIG_ENDIAN 0
  36. #else /* !_LITTLE_ENDIAN */
  37. #error "unknown endianness"
  38. #endif /* !_LITTLE_ENDIAN */
  39. #endif /* Solaris and AuroraUX. */
  40. /* .. */
  41. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
  42. defined(__minix)
  43. #include <sys/endian.h>
  44. #if _BYTE_ORDER == _BIG_ENDIAN
  45. #define _YUGA_LITTLE_ENDIAN 0
  46. #define _YUGA_BIG_ENDIAN 1
  47. #elif _BYTE_ORDER == _LITTLE_ENDIAN
  48. #define _YUGA_LITTLE_ENDIAN 1
  49. #define _YUGA_BIG_ENDIAN 0
  50. #endif /* _BYTE_ORDER */
  51. #endif /* *BSD */
  52. #if defined(__OpenBSD__) || defined(__Bitrig__)
  53. #include <machine/endian.h>
  54. #if _BYTE_ORDER == _BIG_ENDIAN
  55. #define _YUGA_LITTLE_ENDIAN 0
  56. #define _YUGA_BIG_ENDIAN 1
  57. #elif _BYTE_ORDER == _LITTLE_ENDIAN
  58. #define _YUGA_LITTLE_ENDIAN 1
  59. #define _YUGA_BIG_ENDIAN 0
  60. #endif /* _BYTE_ORDER */
  61. #endif /* OpenBSD and Bitrig. */
  62. /* .. */
  63. /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the
  64. * compiler (at least with GCC) */
  65. #if defined(__APPLE__) || defined(__ellcc__ )
  66. #ifdef __BIG_ENDIAN__
  67. #if __BIG_ENDIAN__
  68. #define _YUGA_LITTLE_ENDIAN 0
  69. #define _YUGA_BIG_ENDIAN 1
  70. #endif
  71. #endif /* __BIG_ENDIAN__ */
  72. #ifdef __LITTLE_ENDIAN__
  73. #if __LITTLE_ENDIAN__
  74. #define _YUGA_LITTLE_ENDIAN 1
  75. #define _YUGA_BIG_ENDIAN 0
  76. #endif
  77. #endif /* __LITTLE_ENDIAN__ */
  78. #endif /* Mac OSX */
  79. /* .. */
  80. #if defined(_WIN32)
  81. #define _YUGA_LITTLE_ENDIAN 1
  82. #define _YUGA_BIG_ENDIAN 0
  83. #endif /* Windows */
  84. #endif /* Clang or GCC. */
  85. /* . */
  86. #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
  87. #error Unable to determine endian
  88. #endif /* Check we found an endianness correctly. */
  89. #endif /* INT_ENDIANNESS_H */