byte_order_generic_x86_64.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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) (int16) (*((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) (int32) (*((int32 *) (A)))
  25. #define uint2korr(A) (uint16) (*((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) (uint32) (*((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) (ulonglong) (*((ulonglong *) (A)))
  42. #define sint8korr(A) (longlong) (*((longlong *) (A)))
  43. #define int2store(T,A) do { uchar *pT= (uchar*)(T);\
  44. *((uint16*)(pT))= (uint16) (A);\
  45. } while (0)
  46. #define int3store(T,A) do { *(T)= (uchar) ((A));\
  47. *(T+1)=(uchar) (((uint) (A) >> 8));\
  48. *(T+2)=(uchar) (((A) >> 16));\
  49. } while (0)
  50. #define int4store(T,A) do { uchar *pT= (uchar*)(T);\
  51. *((uint32 *) (pT))= (uint32) (A); \
  52. } while (0)
  53. #define int5store(T,A) do { *(T)= (uchar)((A));\
  54. *((T)+1)=(uchar) (((A) >> 8));\
  55. *((T)+2)=(uchar) (((A) >> 16));\
  56. *((T)+3)=(uchar) (((A) >> 24));\
  57. *((T)+4)=(uchar) (((A) >> 32));\
  58. } while(0)
  59. #define int6store(T,A) do { *(T)= (uchar)((A)); \
  60. *((T)+1)=(uchar) (((A) >> 8)); \
  61. *((T)+2)=(uchar) (((A) >> 16)); \
  62. *((T)+3)=(uchar) (((A) >> 24)); \
  63. *((T)+4)=(uchar) (((A) >> 32)); \
  64. *((T)+5)=(uchar) (((A) >> 40)); \
  65. } while(0)
  66. #define int8store(T,A) do { uchar *pT= (uchar*)(T);\
  67. *((ulonglong *) (pT))= (ulonglong) (A);\
  68. } while(0)