swab.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #ifndef _LINUX_BYTEORDER_SWAB_H
  21. #define _LINUX_BYTEORDER_SWAB_H
  22. #if !defined(CONFIG_PLATFORM_MSTAR)
  23. #ifndef __u16
  24. typedef unsigned short __u16;
  25. #endif
  26. #ifndef __u32
  27. typedef unsigned int __u32;
  28. #endif
  29. #ifndef __u8
  30. typedef unsigned char __u8;
  31. #endif
  32. #ifndef __u64
  33. typedef unsigned long long __u64;
  34. #endif
  35. __inline static __u16 ___swab16(__u16 x)
  36. {
  37. __u16 __x = x;
  38. return
  39. (__u16)(
  40. (((__u16)(__x)&(__u16)0x00ffU) << 8) |
  41. (((__u16)(__x)&(__u16)0xff00U) >> 8));
  42. }
  43. __inline static __u32 ___swab32(__u32 x)
  44. {
  45. __u32 __x = (x);
  46. return (__u32)(
  47. (((__u32)(__x)&(__u32)0x000000ffUL) << 24) |
  48. (((__u32)(__x)&(__u32)0x0000ff00UL) << 8) |
  49. (((__u32)(__x)&(__u32)0x00ff0000UL) >> 8) |
  50. (((__u32)(__x)&(__u32)0xff000000UL) >> 24));
  51. }
  52. __inline static __u64 ___swab64(__u64 x)
  53. {
  54. __u64 __x = (x);
  55. return
  56. (__u64)(\
  57. (__u64)(((__u64)(__x)&(__u64)0x00000000000000ffULL) << 56) | \
  58. (__u64)(((__u64)(__x)&(__u64)0x000000000000ff00ULL) << 40) | \
  59. (__u64)(((__u64)(__x)&(__u64)0x0000000000ff0000ULL) << 24) | \
  60. (__u64)(((__u64)(__x)&(__u64)0x00000000ff000000ULL) << 8) | \
  61. (__u64)(((__u64)(__x)&(__u64)0x000000ff00000000ULL) >> 8) | \
  62. (__u64)(((__u64)(__x)&(__u64)0x0000ff0000000000ULL) >> 24) | \
  63. (__u64)(((__u64)(__x)&(__u64)0x00ff000000000000ULL) >> 40) | \
  64. (__u64)(((__u64)(__x)&(__u64)0xff00000000000000ULL) >> 56));
  65. \
  66. }
  67. #endif /* CONFIG_PLATFORM_MSTAR */
  68. #ifndef __arch__swab16
  69. __inline static __u16 __arch__swab16(__u16 x)
  70. {
  71. return ___swab16(x);
  72. }
  73. #endif
  74. #ifndef __arch__swab32
  75. __inline static __u32 __arch__swab32(__u32 x)
  76. {
  77. __u32 __tmp = (x) ;
  78. return ___swab32(__tmp);
  79. }
  80. #endif
  81. #ifndef __arch__swab64
  82. __inline static __u64 __arch__swab64(__u64 x)
  83. {
  84. __u64 __tmp = (x) ;
  85. return ___swab64(__tmp);
  86. }
  87. #endif
  88. #ifndef __swab16
  89. #define __swab16(x) __fswab16(x)
  90. #define __swab32(x) __fswab32(x)
  91. #define __swab64(x) __fswab64(x)
  92. #endif /* __swab16 */
  93. #ifdef PLATFORM_FREEBSD
  94. __inline static __u16 __fswab16(__u16 x)
  95. #else
  96. __inline static const __u16 __fswab16(__u16 x)
  97. #endif /* PLATFORM_FREEBSD */
  98. {
  99. return __arch__swab16(x);
  100. }
  101. #ifdef PLATFORM_FREEBSD
  102. __inline static __u32 __fswab32(__u32 x)
  103. #else
  104. __inline static const __u32 __fswab32(__u32 x)
  105. #endif /* PLATFORM_FREEBSD */
  106. {
  107. return __arch__swab32(x);
  108. }
  109. #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS)
  110. #define swab16 __swab16
  111. #define swab32 __swab32
  112. #define swab64 __swab64
  113. #define swab16p __swab16p
  114. #define swab32p __swab32p
  115. #define swab64p __swab64p
  116. #define swab16s __swab16s
  117. #define swab32s __swab32s
  118. #define swab64s __swab64s
  119. #endif
  120. #endif /* _LINUX_BYTEORDER_SWAB_H */