|
@@ -1,7 +1,8 @@
|
1
|
1
|
#ifndef ETHERBOOT_BITS_BYTESWAP_H
|
2
|
2
|
#define ETHERBOOT_BITS_BYTESWAP_H
|
3
|
3
|
|
4
|
|
-static inline uint16_t __i386_bswap_16(uint16_t x)
|
|
4
|
+static inline __attribute__ ((always_inline)) uint16_t
|
|
5
|
+__i386_bswap_16(uint16_t x)
|
5
|
6
|
{
|
6
|
7
|
__asm__("xchgb %b0,%h0\n\t"
|
7
|
8
|
: "=q" (x)
|
|
@@ -9,7 +10,8 @@ static inline uint16_t __i386_bswap_16(uint16_t x)
|
9
|
10
|
return x;
|
10
|
11
|
}
|
11
|
12
|
|
12
|
|
-static inline uint32_t __i386_bswap_32(uint32_t x)
|
|
13
|
+static inline __attribute__ ((always_inline)) uint32_t
|
|
14
|
+__i386_bswap_32(uint32_t x)
|
13
|
15
|
{
|
14
|
16
|
__asm__("xchgb %b0,%h0\n\t"
|
15
|
17
|
"rorl $16,%0\n\t"
|
|
@@ -19,27 +21,56 @@ static inline uint32_t __i386_bswap_32(uint32_t x)
|
19
|
21
|
return x;
|
20
|
22
|
}
|
21
|
23
|
|
|
24
|
+static inline __attribute__ ((always_inline)) uint64_t
|
|
25
|
+__i386_bswap_64(uint64_t x)
|
|
26
|
+{
|
|
27
|
+ union {
|
|
28
|
+ uint64_t qword;
|
|
29
|
+ uint32_t dword[2];
|
|
30
|
+ } u;
|
|
31
|
+
|
|
32
|
+ u.qword = x;
|
|
33
|
+ u.dword[0] = __i386_bswap_32(u.dword[0]);
|
|
34
|
+ u.dword[1] = __i386_bswap_32(u.dword[1]);
|
|
35
|
+ __asm__("xchgl %0,%1"
|
|
36
|
+ : "=r" ( u.dword[0] ), "=r" ( u.dword[1] )
|
|
37
|
+ : "0" ( u.dword[0] ), "1" ( u.dword[1] ) );
|
|
38
|
+ return u.qword;
|
|
39
|
+}
|
22
|
40
|
|
23
|
41
|
#define __bswap_constant_16(x) \
|
24
|
42
|
((uint16_t)((((uint16_t)(x) & 0x00ff) << 8) | \
|
25
|
|
- (((uint16_t)(x) & 0xff00) >> 8)))
|
|
43
|
+ (((uint16_t)(x) & 0xff00) >> 8)))
|
26
|
44
|
|
27
|
45
|
#define __bswap_constant_32(x) \
|
28
|
46
|
((uint32_t)((((uint32_t)(x) & 0x000000ffU) << 24) | \
|
29
|
|
- (((uint32_t)(x) & 0x0000ff00U) << 8) | \
|
30
|
|
- (((uint32_t)(x) & 0x00ff0000U) >> 8) | \
|
31
|
|
- (((uint32_t)(x) & 0xff000000U) >> 24)))
|
|
47
|
+ (((uint32_t)(x) & 0x0000ff00U) << 8) | \
|
|
48
|
+ (((uint32_t)(x) & 0x00ff0000U) >> 8) | \
|
|
49
|
+ (((uint32_t)(x) & 0xff000000U) >> 24)))
|
|
50
|
+
|
|
51
|
+#define __bswap_constant_64(x) \
|
|
52
|
+ ((uint64_t)((((uint64_t)(x) & 0x00000000000000ffULL) << 56) | \
|
|
53
|
+ (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \
|
|
54
|
+ (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
|
|
55
|
+ (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \
|
|
56
|
+ (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
|
|
57
|
+ (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \
|
|
58
|
+ (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
|
|
59
|
+ (((uint64_t)(x) & 0xff00000000000000ULL) >> 56)))
|
32
|
60
|
|
33
|
61
|
#define __bswap_16(x) \
|
34
|
62
|
((uint16_t)(__builtin_constant_p(x) ? \
|
35
|
63
|
__bswap_constant_16(x) : \
|
36
|
64
|
__i386_bswap_16(x)))
|
37
|
65
|
|
38
|
|
-
|
39
|
66
|
#define __bswap_32(x) \
|
40
|
67
|
((uint32_t)(__builtin_constant_p(x) ? \
|
41
|
68
|
__bswap_constant_32(x) : \
|
42
|
69
|
__i386_bswap_32(x)))
|
43
|
70
|
|
|
71
|
+#define __bswap_64(x) \
|
|
72
|
+ ((uint64_t)(__builtin_constant_p(x) ? \
|
|
73
|
+ __bswap_constant_64(x) : \
|
|
74
|
+ __i386_bswap_64(x)))
|
44
|
75
|
|
45
|
76
|
#endif /* ETHERBOOT_BITS_BYTESWAP_H */
|