You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

byteswap.h 970B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef ETHERBOOT_BITS_BYTESWAP_H
  2. #define ETHERBOOT_BITS_BYTESWAP_H
  3. /* We do not have byte swap functions ... We are
  4. * RISC processor ...
  5. */
  6. static inline unsigned short __swap16(volatile unsigned short v)
  7. {
  8. return ((v << 8) | (v >> 8));
  9. }
  10. static inline unsigned int __swap32(volatile unsigned long v)
  11. {
  12. return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
  13. }
  14. #define __bswap_constant_16(x) \
  15. ((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
  16. (((uint16_t)(x) & 0xff00) >> 8)))
  17. #define __bswap_constant_32(x) \
  18. ((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
  19. (((uint32_t)(x) & 0x0000ff00U) << 8) | \
  20. (((uint32_t)(x) & 0x00ff0000U) >> 8) | \
  21. (((uint32_t)(x) & 0xff000000U) >> 24)))
  22. #define __bswap_16(x) \
  23. (__builtin_constant_p(x) ? \
  24. __bswap_constant_16(x) : \
  25. __swap16(x))
  26. #define __bswap_32(x) \
  27. (__builtin_constant_p(x) ? \
  28. __bswap_constant_32(x) : \
  29. __swap32(x))
  30. #endif /* ETHERBOOT_BITS_BYTESWAP_H */