byte_order_generic_x86.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Optimized function-like macros for the x86 architecture (_WIN32 included).
  14. */
  15. #define sint2korr(A) (*((const int16 *) (A)))
  16. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  17. (((uint32) 255L << 24) | \
  18. (((uint32) (uchar) (A)[2]) << 16) |\
  19. (((uint32) (uchar) (A)[1]) << 8) | \
  20. ((uint32) (uchar) (A)[0])) : \
  21. (((uint32) (uchar) (A)[2]) << 16) |\
  22. (((uint32) (uchar) (A)[1]) << 8) | \
  23. ((uint32) (uchar) (A)[0])))
  24. #define sint4korr(A) (*((const long *) (A)))
  25. #define uint2korr(A) (*((const uint16 *) (A)))
  26. #define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
  27. (((uint32) ((uchar) (A)[1])) << 8) +\
  28. (((uint32) ((uchar) (A)[2])) << 16))
  29. #define uint4korr(A) (*((const uint32 *) (A)))
  30. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  31. (((uint32) ((uchar) (A)[1])) << 8) +\
  32. (((uint32) ((uchar) (A)[2])) << 16) +\
  33. (((uint32) ((uchar) (A)[3])) << 24)) +\
  34. (((ulonglong) ((uchar) (A)[4])) << 32))
  35. #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
  36. (((uint32) ((uchar) (A)[1])) << 8) + \
  37. (((uint32) ((uchar) (A)[2])) << 16) + \
  38. (((uint32) ((uchar) (A)[3])) << 24)) + \
  39. (((ulonglong) ((uchar) (A)[4])) << 32) + \
  40. (((ulonglong) ((uchar) (A)[5])) << 40))
  41. #define uint8korr(A) (*((const ulonglong *) (A)))
  42. #define sint8korr(A) (*((const longlong *) (A)))
  43. #define int2store(T,A) *((uint16*) (T))= (uint16) (A)
  44. #define int3store(T,A) do { *(T)= (uchar) ((A));\
  45. *(T+1)=(uchar) (((uint) (A) >> 8));\
  46. *(T+2)=(uchar) (((A) >> 16));\
  47. } while (0)
  48. #define int4store(T,A) *((long *) (T))= (long) (A)
  49. #define int5store(T,A) do { *(T)= (uchar)((A));\
  50. *((T)+1)=(uchar) (((A) >> 8));\
  51. *((T)+2)=(uchar) (((A) >> 16));\
  52. *((T)+3)=(uchar) (((A) >> 24));\
  53. *((T)+4)=(uchar) (((A) >> 32));\
  54. } while(0)
  55. #define int6store(T,A) do { *(T)= (uchar)((A)); \
  56. *((T)+1)=(uchar) (((A) >> 8)); \
  57. *((T)+2)=(uchar) (((A) >> 16)); \
  58. *((T)+3)=(uchar) (((A) >> 24)); \
  59. *((T)+4)=(uchar) (((A) >> 32)); \
  60. *((T)+5)=(uchar) (((A) >> 40)); \
  61. } while(0)
  62. #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
  63. typedef union {
  64. double v;
  65. long m[2];
  66. } doubleget_union;
  67. #define doubleget(V,M) \
  68. do { doubleget_union _tmp; \
  69. _tmp.m[0] = *((const long*)(M)); \
  70. _tmp.m[1] = *(((const long*) (M))+1); \
  71. (V) = _tmp.v; } while(0)
  72. #define doublestore(T,V) \
  73. do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \
  74. *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \
  75. } while (0)
  76. #define float4get(V,M) \
  77. do { *((float *) &(V)) = *((const float*) (M)); } while(0)
  78. #define float8get(V,M) doubleget((V),(M))
  79. #define float4store(V,M) memcpy((uchar*)(V), (uchar*)(&M), sizeof(float))
  80. #define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V), sizeof(float))
  81. #define floatget(V,M) memcpy((uchar*)(&V),(uchar*) (M), sizeof(float))
  82. #define float8store(V,M) doublestore((V),(M))