source: bootcd/isolinux/syslinux-6.03/gpxe/src/arch/i386/include/bits/byteswap.h

Last change on this file was e16e8f2, checked in by Edwin Eefting <edwin@datux.nl>, 3 years ago

bootstuff

  • Property mode set to 100644
File size: 905 bytes
Line 
1#ifndef ETHERBOOT_BITS_BYTESWAP_H
2#define ETHERBOOT_BITS_BYTESWAP_H
3
4FILE_LICENCE ( GPL2_OR_LATER );
5
6static 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
15static 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
26static 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 */
Note: See TracBrowser for help on using the repository browser.