byte_order_generic.h 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */
  12. /*
  13. Endianness-independent definitions for architectures other
  14. than the x86 architecture.
  15. */
  16. #define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\
  17. ((int16) ((int16) (A)[1]) << 8))
  18. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  19. (((uint32) 255L << 24) | \
  20. (((uint32) (uchar) (A)[2]) << 16) |\
  21. (((uint32) (uchar) (A)[1]) << 8) | \
  22. ((uint32) (uchar) (A)[0])) : \
  23. (((uint32) (uchar) (A)[2]) << 16) |\
  24. (((uint32) (uchar) (A)[1]) << 8) | \
  25. ((uint32) (uchar) (A)[0])))
  26. #define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\
  27. (((int32) ((uchar) (A)[1]) << 8)) +\
  28. (((int32) ((uchar) (A)[2]) << 16)) +\
  29. (((int32) ((int16) (A)[3]) << 24)))
  30. #define sint8korr(A) (longlong) uint8korr(A)
  31. #define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
  32. ((uint16) ((uchar) (A)[1]) << 8))
  33. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  34. (((uint32) ((uchar) (A)[1])) << 8) +\
  35. (((uint32) ((uchar) (A)[2])) << 16))
  36. #define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  37. (((uint32) ((uchar) (A)[1])) << 8) +\
  38. (((uint32) ((uchar) (A)[2])) << 16) +\
  39. (((uint32) ((uchar) (A)[3])) << 24))
  40. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  41. (((uint32) ((uchar) (A)[1])) << 8) +\
  42. (((uint32) ((uchar) (A)[2])) << 16) +\
  43. (((uint32) ((uchar) (A)[3])) << 24)) +\
  44. (((ulonglong) ((uchar) (A)[4])) << 32))
  45. #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
  46. (((uint32) ((uchar) (A)[1])) << 8) + \
  47. (((uint32) ((uchar) (A)[2])) << 16) + \
  48. (((uint32) ((uchar) (A)[3])) << 24)) + \
  49. (((ulonglong) ((uchar) (A)[4])) << 32) + \
  50. (((ulonglong) ((uchar) (A)[5])) << 40))
  51. #define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  52. (((uint32) ((uchar) (A)[1])) << 8) +\
  53. (((uint32) ((uchar) (A)[2])) << 16) +\
  54. (((uint32) ((uchar) (A)[3])) << 24)) +\
  55. (((ulonglong) (((uint32) ((uchar) (A)[4])) +\
  56. (((uint32) ((uchar) (A)[5])) << 8) +\
  57. (((uint32) ((uchar) (A)[6])) << 16) +\
  58. (((uint32) ((uchar) (A)[7])) << 24))) <<\
  59. 32))
  60. #define int2store(T,A) do { uint def_temp= (uint) (A) ;\
  61. *((uchar*) (T))= (uchar)(def_temp); \
  62. *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
  63. } while(0)
  64. #define int3store(T,A) do { /*lint -save -e734 */\
  65. *((uchar*)(T))=(uchar) ((A));\
  66. *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
  67. *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
  68. /*lint -restore */} while(0)
  69. #define int4store(T,A) do { *((char *)(T))=(char) ((A));\
  70. *(((char *)(T))+1)=(char) (((A) >> 8));\
  71. *(((char *)(T))+2)=(char) (((A) >> 16));\
  72. *(((char *)(T))+3)=(char) (((A) >> 24));\
  73. } while(0)
  74. #define int5store(T,A) do { *((char *)(T))= (char)((A)); \
  75. *(((char *)(T))+1)= (char)(((A) >> 8)); \
  76. *(((char *)(T))+2)= (char)(((A) >> 16)); \
  77. *(((char *)(T))+3)= (char)(((A) >> 24)); \
  78. *(((char *)(T))+4)= (char)(((A) >> 32)); \
  79. } while(0)
  80. #define int6store(T,A) do { *((char *)(T))= (char)((A)); \
  81. *(((char *)(T))+1)= (char)(((A) >> 8)); \
  82. *(((char *)(T))+2)= (char)(((A) >> 16)); \
  83. *(((char *)(T))+3)= (char)(((A) >> 24)); \
  84. *(((char *)(T))+4)= (char)(((A) >> 32)); \
  85. *(((char *)(T))+5)= (char)(((A) >> 40)); \
  86. } while(0)
  87. #define int8store(T,A) do { uint def_temp= (uint) (A), \
  88. def_temp2= (uint) ((A) >> 32); \
  89. int4store((T),def_temp); \
  90. int4store((T+4),def_temp2);\
  91. } while(0)