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 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef _BITS_BYTESWAP_H
  2. #define _BITS_BYTESWAP_H
  3. /** @file
  4. *
  5. * Byte-order swapping functions
  6. *
  7. */
  8. #include <stdint.h>
  9. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  10. static inline __attribute__ (( always_inline, const )) uint16_t
  11. __bswap_variable_16 ( uint16_t x ) {
  12. __asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
  13. return x;
  14. }
  15. static inline __attribute__ (( always_inline )) void
  16. __bswap_16s ( uint16_t *x ) {
  17. __asm__ ( "rorw $8, %0" : "+m" ( *x ) );
  18. }
  19. static inline __attribute__ (( always_inline, const )) uint32_t
  20. __bswap_variable_32 ( uint32_t x ) {
  21. __asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
  22. return x;
  23. }
  24. static inline __attribute__ (( always_inline )) void
  25. __bswap_32s ( uint32_t *x ) {
  26. __asm__ ( "bswapl %k0" : "=r" ( *x ) : "0" ( *x ) );
  27. }
  28. static inline __attribute__ (( always_inline, const )) uint64_t
  29. __bswap_variable_64 ( uint64_t x ) {
  30. __asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
  31. return x;
  32. }
  33. static inline __attribute__ (( always_inline )) void
  34. __bswap_64s ( uint64_t *x ) {
  35. __asm__ ( "bswapq %q0" : "=r" ( *x ) : "0" ( *x ) );
  36. }
  37. #endif /* _BITS_BYTESWAP_H */