Browse Source

Add 64-bit byte-swapping operations.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
1ad72e0e79

+ 38
- 7
src/arch/i386/include/bits/byteswap.h View File

@@ -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 */

+ 4
- 0
src/include/big_bswap.h View File

@@ -5,12 +5,16 @@
5 5
 #define htonl(x) 	(x)
6 6
 #define ntohs(x) 	(x)
7 7
 #define htons(x) 	(x)
8
+#define cpu_to_le64(x)	__bswap_64(x)
8 9
 #define cpu_to_le32(x)	__bswap_32(x)
9 10
 #define cpu_to_le16(x)	__bswap_16(x)
11
+#define cpu_to_be64(x)	(x)
10 12
 #define cpu_to_be32(x)	(x)
11 13
 #define cpu_to_be16(x)	(x)
14
+#define le64_to_cpu(x)	__bswap_64(x)
12 15
 #define le32_to_cpu(x)	__bswap_32(x)
13 16
 #define le16_to_cpu(x)	__bswap_16(x)
17
+#define be64_to_cpu(x)	(x)
14 18
 #define be32_to_cpu(x)	(x)
15 19
 #define be16_to_cpu(x)	(x)
16 20
 

+ 2
- 0
src/include/byteswap.h View File

@@ -12,8 +12,10 @@
12 12
 #endif
13 13
 
14 14
 /* Make routines available to all */
15
+#define swap64(x)	__bswap_64(x)
15 16
 #define swap32(x)	__bswap_32(x)
16 17
 #define swap16(x)	__bswap_16(x)
18
+#define bswap_64(x)	__bswap_64(x)
17 19
 #define bswap_32(x)	__bswap_32(x)
18 20
 #define bswap_16(x)	__bswap_16(x)
19 21
 	

+ 4
- 0
src/include/little_bswap.h View File

@@ -5,12 +5,16 @@
5 5
 #define htonl(x) 	__bswap_32(x)
6 6
 #define ntohs(x) 	__bswap_16(x)
7 7
 #define htons(x) 	__bswap_16(x)
8
+#define cpu_to_le64(x)	(x)
8 9
 #define cpu_to_le32(x)	(x)
9 10
 #define cpu_to_le16(x)	(x)
11
+#define cpu_to_be64(x)	__bswap_64(x)
10 12
 #define cpu_to_be32(x)	__bswap_32(x)
11 13
 #define cpu_to_be16(x)	__bswap_16(x)
14
+#define le64_to_cpu(x)	(x)
12 15
 #define le32_to_cpu(x)	(x)
13 16
 #define le16_to_cpu(x)	(x)
17
+#define be64_to_cpu(x)	__bswap_64(x)
14 18
 #define be32_to_cpu(x)	__bswap_32(x)
15 19
 #define be16_to_cpu(x)	__bswap_16(x)
16 20
 

Loading…
Cancel
Save