/src/VBox/GuestHost/OpenGL/include/cr_endian.h

https://gitlab.com/ufo/virtualbox-ose-3-1-8 · C Header · 90 lines · 77 code · 13 blank · 0 comment · 0 complexity · add4996f20159502f50d793c6fc19e3b MD5 · raw file

  1. #ifndef CR_ENDIAN_H
  2. #define CR_ENDIAN_H
  3. #define CR_LITTLE_ENDIAN 0
  4. #define CR_BIG_ENDIAN 1
  5. #include <iprt/cdefs.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. extern DECLEXPORT(char) crDetermineEndianness( void );
  10. #ifdef WINDOWS
  11. typedef __int64 CR64BitType;
  12. #else
  13. #ifndef __STDC__
  14. typedef long long CR64BitType;
  15. #else
  16. typedef struct _CR64BitType
  17. {
  18. unsigned int lo;
  19. unsigned int hi;
  20. } CR64BitType;
  21. #endif
  22. #endif
  23. #define SWAP8(x) x
  24. #define SWAP16(x) (short) ((((x) & 0x00FF) << 8) | (((x) & 0xFF00) >> 8))
  25. #define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
  26. (((x) & 0x0000FF00) << 8) | \
  27. (((x) & 0x00FF0000) >> 8) | \
  28. (((x) & 0xFF000000) >> 24))
  29. #ifdef WINDOWS
  30. #define SWAP64(x) \
  31. ((((x) & 0xFF00000000000000L) >> 56) | \
  32. (((x) & 0x00FF000000000000L) >> 40) | \
  33. (((x) & 0x0000FF0000000000L) >> 24) | \
  34. (((x) & 0x000000FF00000000L) >> 8) | \
  35. (((x) & 0x00000000FF000000L) << 8) | \
  36. (((x) & 0x0000000000FF0000L) << 24) | \
  37. (((x) & 0x000000000000FF00L) << 40) | \
  38. (((x) & 0x00000000000000FFL) << 56))
  39. #else
  40. #ifndef __STDC__
  41. #define SWAP64(x) \
  42. x = ((((x) & 0xFF00000000000000LL) >> 56) | \
  43. (((x) & 0x00FF000000000000LL) >> 40) | \
  44. (((x) & 0x0000FF0000000000LL) >> 24) | \
  45. (((x) & 0x000000FF00000000LL) >> 8) | \
  46. (((x) & 0x00000000FF000000LL) << 8) | \
  47. (((x) & 0x0000000000FF0000LL) << 24) | \
  48. (((x) & 0x000000000000FF00LL) << 40) | \
  49. (((x) & 0x00000000000000FFLL) << 56))
  50. #else
  51. #define SWAP64(x) \
  52. { \
  53. GLubyte *bytes = (GLubyte *) &(x); \
  54. GLubyte tmp = bytes[0]; \
  55. bytes[0] = bytes[7]; \
  56. bytes[7] = tmp; \
  57. tmp = bytes[1]; \
  58. bytes[1] = bytes[6]; \
  59. bytes[6] = tmp; \
  60. tmp = bytes[2]; \
  61. bytes[2] = bytes[5]; \
  62. bytes[5] = tmp; \
  63. tmp = bytes[4]; \
  64. bytes[4] = bytes[3]; \
  65. bytes[3] = tmp; \
  66. }
  67. #endif
  68. #endif
  69. DECLEXPORT(double) SWAPDOUBLE( double d );
  70. #define SWAPFLOAT(x) ( ((*((int *) &(x)) & 0x000000FF) << 24) | \
  71. ((*((int *) &(x)) & 0x0000FF00) << 8) | \
  72. ((*((int *) &(x)) & 0x00FF0000) >> 8) | \
  73. ((*((int *) &(x)) & 0xFF000000) >> 24))
  74. #ifdef __cplusplus
  75. } /* extern "C" */
  76. #endif
  77. #endif /* CR_ENDIAN_H */