int_endianness.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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(__SVR4) && defined(__sun)
  18. #include <sys/byteorder.h>
  19. #if defined(_BIG_ENDIAN)
  20. #define _YUGA_LITTLE_ENDIAN 0
  21. #define _YUGA_BIG_ENDIAN 1
  22. #elif defined(_LITTLE_ENDIAN)
  23. #define _YUGA_LITTLE_ENDIAN 1
  24. #define _YUGA_BIG_ENDIAN 0
  25. #else /* !_LITTLE_ENDIAN */
  26. #error "unknown endianness"
  27. #endif /* !_LITTLE_ENDIAN */
  28. #endif /* Solaris and AuroraUX. */
  29. /* .. */
  30. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
  31. defined(__minix)
  32. #include <sys/endian.h>
  33. #if _BYTE_ORDER == _BIG_ENDIAN
  34. #define _YUGA_LITTLE_ENDIAN 0
  35. #define _YUGA_BIG_ENDIAN 1
  36. #elif _BYTE_ORDER == _LITTLE_ENDIAN
  37. #define _YUGA_LITTLE_ENDIAN 1
  38. #define _YUGA_BIG_ENDIAN 0
  39. #endif /* _BYTE_ORDER */
  40. #endif /* *BSD */
  41. #if defined(__OpenBSD__) || defined(__Bitrig__)
  42. #include <machine/endian.h>
  43. #if _BYTE_ORDER == _BIG_ENDIAN
  44. #define _YUGA_LITTLE_ENDIAN 0
  45. #define _YUGA_BIG_ENDIAN 1
  46. #elif _BYTE_ORDER == _LITTLE_ENDIAN
  47. #define _YUGA_LITTLE_ENDIAN 1
  48. #define _YUGA_BIG_ENDIAN 0
  49. #endif /* _BYTE_ORDER */
  50. #endif /* OpenBSD and Bitrig. */
  51. /* .. */
  52. /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the
  53. * compiler (at least with GCC) */
  54. #if defined(__APPLE__) || defined(__ellcc__ )
  55. #ifdef __BIG_ENDIAN__
  56. #if __BIG_ENDIAN__
  57. #define _YUGA_LITTLE_ENDIAN 0
  58. #define _YUGA_BIG_ENDIAN 1
  59. #endif
  60. #endif /* __BIG_ENDIAN__ */
  61. #ifdef __LITTLE_ENDIAN__
  62. #if __LITTLE_ENDIAN__
  63. #define _YUGA_LITTLE_ENDIAN 1
  64. #define _YUGA_BIG_ENDIAN 0
  65. #endif
  66. #endif /* __LITTLE_ENDIAN__ */
  67. #endif /* Mac OSX */
  68. /* .. */
  69. #if defined(__linux__)
  70. #include <endian.h>
  71. #if __BYTE_ORDER == __BIG_ENDIAN
  72. #define _YUGA_LITTLE_ENDIAN 0
  73. #define _YUGA_BIG_ENDIAN 1
  74. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  75. #define _YUGA_LITTLE_ENDIAN 1
  76. #define _YUGA_BIG_ENDIAN 0
  77. #endif /* __BYTE_ORDER */
  78. #endif /* GNU/Linux */
  79. #if defined(_WIN32)
  80. #define _YUGA_LITTLE_ENDIAN 1
  81. #define _YUGA_BIG_ENDIAN 0
  82. #endif /* Windows */
  83. /* . */
  84. #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
  85. #error Unable to determine endian
  86. #endif /* Check we found an endianness correctly. */
  87. #endif /* INT_ENDIANNESS_H */