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.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef ETHERBOOT_BITS_BYTESWAP_H
  2. #define ETHERBOOT_BITS_BYTESWAP_H
  3. static inline __attribute__ ((always_inline, const)) uint16_t
  4. __bswap_variable_16(uint16_t x)
  5. {
  6. __asm__("xchgb %b0,%h0\n\t"
  7. : "=q" (x)
  8. : "0" (x));
  9. return x;
  10. }
  11. static inline __attribute__ ((always_inline, const)) uint32_t
  12. __bswap_variable_32(uint32_t x)
  13. {
  14. __asm__("xchgb %b0,%h0\n\t"
  15. "rorl $16,%0\n\t"
  16. "xchgb %b0,%h0"
  17. : "=q" (x)
  18. : "0" (x));
  19. return x;
  20. }
  21. static inline __attribute__ ((always_inline, const)) uint64_t
  22. __bswap_variable_64(uint64_t x)
  23. {
  24. union {
  25. uint64_t qword;
  26. uint32_t dword[2];
  27. } u;
  28. u.qword = x;
  29. u.dword[0] = __bswap_variable_32(u.dword[0]);
  30. u.dword[1] = __bswap_variable_32(u.dword[1]);
  31. __asm__("xchgl %0,%1"
  32. : "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
  33. : "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
  34. return u.qword;
  35. }
  36. #endif /* ETHERBOOT_BITS_BYTESWAP_H */