swab.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _LINUX_BYTEORDER_SWAB_H
  2. #define _LINUX_BYTEORDER_SWAB_H
  3. #ifndef __u16
  4. #define __u16 unsigned short
  5. #endif
  6. #ifndef __u32
  7. #define __u32 unsigned int
  8. #endif
  9. #ifndef __u8
  10. #define __u8 unsigned char
  11. #endif
  12. #ifndef __u64
  13. #define __u64 unsigned long long
  14. #endif
  15. static inline __u16 ___swab16(__u16 x)
  16. {
  17. __u16 __x = x;
  18. return (__u16)(
  19. (((__u16)(__x) & (__u16)0x00ffU) << 8) |
  20. (((__u16)(__x) & (__u16)0xff00U) >> 8));
  21. }
  22. static inline __u32 ___swab32(__u32 x)
  23. {
  24. __u32 __x = (x);
  25. return (__u32)(
  26. (((__u32)(__x) & (__u32)0x000000ffUL) << 24) |
  27. (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) |
  28. (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) |
  29. (((__u32)(__x) & (__u32)0xff000000UL) >> 24));
  30. }
  31. static inline __u64 ___swab64(__u64 x)
  32. {
  33. __u64 __x = (x);
  34. return (__u64)( \
  35. (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \
  36. (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \
  37. (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \
  38. (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \
  39. (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \
  40. (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
  41. (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
  42. (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56));
  43. }
  44. #ifndef __arch__swab16
  45. static inline __u16 __arch__swab16(__u16 x)
  46. {
  47. return ___swab16(x);
  48. }
  49. #endif
  50. #ifndef __arch__swab32
  51. static inline __u32 __arch__swab32(__u32 x)
  52. {
  53. __u32 __tmp = (x) ;
  54. return ___swab32(__tmp);
  55. }
  56. #endif
  57. #ifndef __arch__swab64
  58. static inline __u64 __arch__swab64(__u64 x)
  59. {
  60. __u64 __tmp = (x) ;
  61. return ___swab64(__tmp);
  62. }
  63. #endif
  64. #define __swab16(x) __fswab16(x)
  65. #define __swab32(x) __fswab32(x)
  66. #define __swab64(x) __fswab64(x)
  67. static inline const __u16 __fswab16(__u16 x)
  68. {
  69. return __arch__swab16(x);
  70. }
  71. static inline const __u32 __fswab32(__u32 x)
  72. {
  73. return __arch__swab32(x);
  74. }
  75. #define swab16 __swab16
  76. #define swab32 __swab32
  77. #define swab64 __swab64
  78. #define swab16p __swab16p
  79. #define swab32p __swab32p
  80. #define swab64p __swab64p
  81. #define swab16s __swab16s
  82. #define swab32s __swab32s
  83. #define swab64s __swab64s
  84. #endif /* _LINUX_BYTEORDER_SWAB_H */