swab.h 816 B

123456789101112131415161718192021222324252627282930
  1. #ifndef _PPC_BOOT_SWAB_H_
  2. #define _PPC_BOOT_SWAB_H_
  3. static inline u16 swab16(u16 x)
  4. {
  5. return ((x & (u16)0x00ffU) << 8) |
  6. ((x & (u16)0xff00U) >> 8);
  7. }
  8. static inline u32 swab32(u32 x)
  9. {
  10. return ((x & (u32)0x000000ffUL) << 24) |
  11. ((x & (u32)0x0000ff00UL) << 8) |
  12. ((x & (u32)0x00ff0000UL) >> 8) |
  13. ((x & (u32)0xff000000UL) >> 24);
  14. }
  15. static inline u64 swab64(u64 x)
  16. {
  17. return (u64)((x & (u64)0x00000000000000ffULL) << 56) |
  18. (u64)((x & (u64)0x000000000000ff00ULL) << 40) |
  19. (u64)((x & (u64)0x0000000000ff0000ULL) << 24) |
  20. (u64)((x & (u64)0x00000000ff000000ULL) << 8) |
  21. (u64)((x & (u64)0x000000ff00000000ULL) >> 8) |
  22. (u64)((x & (u64)0x0000ff0000000000ULL) >> 24) |
  23. (u64)((x & (u64)0x00ff000000000000ULL) >> 40) |
  24. (u64)((x & (u64)0xff00000000000000ULL) >> 56);
  25. }
  26. #endif /* _PPC_BOOT_SWAB_H_ */