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