[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / arch / i386 / include / bits / byteswap.h
blobddbd40edbd414d2019b95be72d672ab73e303994
1 #ifndef ETHERBOOT_BITS_BYTESWAP_H
2 #define ETHERBOOT_BITS_BYTESWAP_H
4 FILE_LICENCE ( GPL2_OR_LATER );
6 static inline __attribute__ ((always_inline, const)) uint16_t
7 __bswap_variable_16(uint16_t x)
9 __asm__("xchgb %b0,%h0\n\t"
10 : "=q" (x)
11 : "0" (x));
12 return x;
15 static inline __attribute__ ((always_inline, const)) uint32_t
16 __bswap_variable_32(uint32_t x)
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;
26 static inline __attribute__ ((always_inline, const)) uint64_t
27 __bswap_variable_64(uint64_t x)
29 union {
30 uint64_t qword;
31 uint32_t dword[2];
32 } u;
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;
43 #endif /* ETHERBOOT_BITS_BYTESWAP_H */