swab.h 3.5 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_TITANIA12)
  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. #endif // CONFIG_PLATFORM_MSTAR_TITANIA12
  67. #ifndef __arch__swab16
  68. __inline static __u16 __arch__swab16(__u16 x)
  69. {
  70. return ___swab16(x);
  71. }
  72. #endif
  73. #ifndef __arch__swab32
  74. __inline static __u32 __arch__swab32(__u32 x)
  75. {
  76. __u32 __tmp = (x) ;
  77. return ___swab32(__tmp);
  78. }
  79. #endif
  80. #ifndef __arch__swab64
  81. __inline static __u64 __arch__swab64(__u64 x)
  82. {
  83. __u64 __tmp = (x) ;
  84. return ___swab64(__tmp);
  85. }
  86. #endif
  87. #ifndef __swab16
  88. #define __swab16(x) __fswab16(x)
  89. #define __swab32(x) __fswab32(x)
  90. #define __swab64(x) __fswab64(x)
  91. #endif // __swab16
  92. #ifdef PLATFORM_FREEBSD
  93. __inline static __u16 __fswab16(__u16 x)
  94. #else
  95. __inline static const __u16 __fswab16(__u16 x)
  96. #endif //PLATFORM_FREEBSD
  97. {
  98. return __arch__swab16(x);
  99. }
  100. #ifdef PLATFORM_FREEBSD
  101. __inline static __u32 __fswab32(__u32 x)
  102. #else
  103. __inline static const __u32 __fswab32(__u32 x)
  104. #endif //PLATFORM_FREEBSD
  105. {
  106. return __arch__swab32(x);
  107. }
  108. #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS)
  109. #define swab16 __swab16
  110. #define swab32 __swab32
  111. #define swab64 __swab64
  112. #define swab16p __swab16p
  113. #define swab32p __swab32p
  114. #define swab64p __swab64p
  115. #define swab16s __swab16s
  116. #define swab32s __swab32s
  117. #define swab64s __swab64s
  118. #endif
  119. #endif /* _LINUX_BYTEORDER_SWAB_H */