swab.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  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. *****************************************************************************/
  15. #ifndef _LINUX_BYTEORDER_SWAB_H
  16. #define _LINUX_BYTEORDER_SWAB_H
  17. #if !defined(CONFIG_PLATFORM_MSTAR)
  18. #ifndef __u16
  19. typedef unsigned short __u16;
  20. #endif
  21. #ifndef __u32
  22. typedef unsigned int __u32;
  23. #endif
  24. #ifndef __u8
  25. typedef unsigned char __u8;
  26. #endif
  27. #ifndef __u64
  28. typedef unsigned long long __u64;
  29. #endif
  30. __inline static __u16 ___swab16(__u16 x)
  31. {
  32. __u16 __x = x;
  33. return
  34. (__u16)(
  35. (((__u16)(__x)&(__u16)0x00ffU) << 8) |
  36. (((__u16)(__x)&(__u16)0xff00U) >> 8));
  37. }
  38. __inline static __u32 ___swab32(__u32 x)
  39. {
  40. __u32 __x = (x);
  41. return (__u32)(
  42. (((__u32)(__x)&(__u32)0x000000ffUL) << 24) |
  43. (((__u32)(__x)&(__u32)0x0000ff00UL) << 8) |
  44. (((__u32)(__x)&(__u32)0x00ff0000UL) >> 8) |
  45. (((__u32)(__x)&(__u32)0xff000000UL) >> 24));
  46. }
  47. __inline static __u64 ___swab64(__u64 x)
  48. {
  49. __u64 __x = (x);
  50. return
  51. (__u64)(\
  52. (__u64)(((__u64)(__x)&(__u64)0x00000000000000ffULL) << 56) | \
  53. (__u64)(((__u64)(__x)&(__u64)0x000000000000ff00ULL) << 40) | \
  54. (__u64)(((__u64)(__x)&(__u64)0x0000000000ff0000ULL) << 24) | \
  55. (__u64)(((__u64)(__x)&(__u64)0x00000000ff000000ULL) << 8) | \
  56. (__u64)(((__u64)(__x)&(__u64)0x000000ff00000000ULL) >> 8) | \
  57. (__u64)(((__u64)(__x)&(__u64)0x0000ff0000000000ULL) >> 24) | \
  58. (__u64)(((__u64)(__x)&(__u64)0x00ff000000000000ULL) >> 40) | \
  59. (__u64)(((__u64)(__x)&(__u64)0xff00000000000000ULL) >> 56));
  60. \
  61. }
  62. #endif /* CONFIG_PLATFORM_MSTAR */
  63. #ifndef __arch__swab16
  64. __inline static __u16 __arch__swab16(__u16 x)
  65. {
  66. return ___swab16(x);
  67. }
  68. #endif
  69. #ifndef __arch__swab32
  70. __inline static __u32 __arch__swab32(__u32 x)
  71. {
  72. __u32 __tmp = (x) ;
  73. return ___swab32(__tmp);
  74. }
  75. #endif
  76. #ifndef __arch__swab64
  77. __inline static __u64 __arch__swab64(__u64 x)
  78. {
  79. __u64 __tmp = (x) ;
  80. return ___swab64(__tmp);
  81. }
  82. #endif
  83. #ifndef __swab16
  84. #define __swab16(x) __fswab16(x)
  85. #define __swab32(x) __fswab32(x)
  86. #define __swab64(x) __fswab64(x)
  87. #endif /* __swab16 */
  88. #ifdef PLATFORM_FREEBSD
  89. __inline static __u16 __fswab16(__u16 x)
  90. #else
  91. __inline static const __u16 __fswab16(__u16 x)
  92. #endif /* PLATFORM_FREEBSD */
  93. {
  94. return __arch__swab16(x);
  95. }
  96. #ifdef PLATFORM_FREEBSD
  97. __inline static __u32 __fswab32(__u32 x)
  98. #else
  99. __inline static const __u32 __fswab32(__u32 x)
  100. #endif /* PLATFORM_FREEBSD */
  101. {
  102. return __arch__swab32(x);
  103. }
  104. #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS)
  105. #define swab16 __swab16
  106. #define swab32 __swab32
  107. #define swab64 __swab64
  108. #define swab16p __swab16p
  109. #define swab32p __swab32p
  110. #define swab64p __swab64p
  111. #define swab16s __swab16s
  112. #define swab32s __swab32s
  113. #define swab64s __swab64s
  114. #endif
  115. #endif /* _LINUX_BYTEORDER_SWAB_H */