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