aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/swab.h
diff options
context:
space:
mode:
authorHarvey Harrison <harvey.harrison@gmail.com>2009-01-06 17:56:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 21:10:26 -0500
commit991c0e6d1ae3df59f0ddfe05edecec8319e35a1b (patch)
tree3bc3d717b6d3e6a05d07b62738e0605851a7259a /include/linux/swab.h
parentc89a9f5a42811aa5b2f258e32750c0109f570fc1 (diff)
byteorder: only use linux/swab.h
The first step to make swab.h a regular header that will include an asm/swab.h with arch overrides. Avoid the gratuitous differences introduced in the new linux/swab.h by naming the ___constant_swabXX bits and __fswabXX bits exactly as found in the old implementation in byteorder/swab[b].h Use this new swab.h in byteorder/[big|little]_endian.h and remove the two old swab headers. Although the inclusion of asm/byteorder.h looks strange in linux/swab.h, this will allow each arch to move the actual arch overrides for the swab bits in an asm file and then the includes can be cleaned up without requiring a flag day for all arches at once. Keep providing __fswabXX in case some userspace was using them directly, but the revised __swabXX should be used instead in any new code and will always do constant folding not dependent on the optimization level, which means the __constant versions can be phased out in-kernel. Arches that use the old-style arch macros will lose their optimized versions until they move to the new style, but at least they will still compile. Many arches have already moved and the patches to move the remaining arches are trivial. Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/swab.h')
-rw-r--r--include/linux/swab.h50
1 files changed, 25 insertions, 25 deletions
diff --git a/include/linux/swab.h b/include/linux/swab.h
index bbed279f3b32..9a2d33e0a98a 100644
--- a/include/linux/swab.h
+++ b/include/linux/swab.h
@@ -9,17 +9,17 @@
9 * casts are necessary for constants, because we never know how for sure 9 * casts are necessary for constants, because we never know how for sure
10 * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way. 10 * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
11 */ 11 */
12#define __const_swab16(x) ((__u16)( \ 12#define ___constant_swab16(x) ((__u16)( \
13 (((__u16)(x) & (__u16)0x00ffU) << 8) | \ 13 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
14 (((__u16)(x) & (__u16)0xff00U) >> 8))) 14 (((__u16)(x) & (__u16)0xff00U) >> 8)))
15 15
16#define __const_swab32(x) ((__u32)( \ 16#define ___constant_swab32(x) ((__u32)( \
17 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \ 17 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
18 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ 18 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
19 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ 19 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
20 (((__u32)(x) & (__u32)0xff000000UL) >> 24))) 20 (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
21 21
22#define __const_swab64(x) ((__u64)( \ 22#define ___constant_swab64(x) ((__u64)( \
23 (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \ 23 (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
24 (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \ 24 (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
25 (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \ 25 (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
@@ -29,11 +29,11 @@
29 (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ 29 (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
30 (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56))) 30 (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
31 31
32#define __const_swahw32(x) ((__u32)( \ 32#define ___constant_swahw32(x) ((__u32)( \
33 (((__u32)(x) & (__u32)0x0000ffffUL) << 16) | \ 33 (((__u32)(x) & (__u32)0x0000ffffUL) << 16) | \
34 (((__u32)(x) & (__u32)0xffff0000UL) >> 16))) 34 (((__u32)(x) & (__u32)0xffff0000UL) >> 16)))
35 35
36#define __const_swahb32(x) ((__u32)( \ 36#define ___constant_swahb32(x) ((__u32)( \
37 (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | \ 37 (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | \
38 (((__u32)(x) & (__u32)0xff00ff00UL) >> 8))) 38 (((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))
39 39
@@ -43,25 +43,25 @@
43 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32 43 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
44 */ 44 */
45 45
46static inline __attribute_const__ __u16 ___swab16(__u16 val) 46static inline __attribute_const__ __u16 __fswab16(__u16 val)
47{ 47{
48#ifdef __arch_swab16 48#ifdef __arch_swab16
49 return __arch_swab16(val); 49 return __arch_swab16(val);
50#else 50#else
51 return __const_swab16(val); 51 return ___constant_swab16(val);
52#endif 52#endif
53} 53}
54 54
55static inline __attribute_const__ __u32 ___swab32(__u32 val) 55static inline __attribute_const__ __u32 __fswab32(__u32 val)
56{ 56{
57#ifdef __arch_swab32 57#ifdef __arch_swab32
58 return __arch_swab32(val); 58 return __arch_swab32(val);
59#else 59#else
60 return __const_swab32(val); 60 return ___constant_swab32(val);
61#endif 61#endif
62} 62}
63 63
64static inline __attribute_const__ __u64 ___swab64(__u64 val) 64static inline __attribute_const__ __u64 __fswab64(__u64 val)
65{ 65{
66#ifdef __arch_swab64 66#ifdef __arch_swab64
67 return __arch_swab64(val); 67 return __arch_swab64(val);
@@ -70,25 +70,25 @@ static inline __attribute_const__ __u64 ___swab64(__u64 val)
70 __u32 l = val & ((1ULL << 32) - 1); 70 __u32 l = val & ((1ULL << 32) - 1);
71 return (((__u64)___swab32(l)) << 32) | ((__u64)(___swab32(h))); 71 return (((__u64)___swab32(l)) << 32) | ((__u64)(___swab32(h)));
72#else 72#else
73 return __const_swab64(val); 73 return ___constant_swab64(val);
74#endif 74#endif
75} 75}
76 76
77static inline __attribute_const__ __u32 ___swahw32(__u32 val) 77static inline __attribute_const__ __u32 __fswahw32(__u32 val)
78{ 78{
79#ifdef __arch_swahw32 79#ifdef __arch_swahw32
80 return __arch_swahw32(val); 80 return __arch_swahw32(val);
81#else 81#else
82 return __const_swahw32(val); 82 return ___constant_swahw32(val);
83#endif 83#endif
84} 84}
85 85
86static inline __attribute_const__ __u32 ___swahb32(__u32 val) 86static inline __attribute_const__ __u32 __fswahb32(__u32 val)
87{ 87{
88#ifdef __arch_swahb32 88#ifdef __arch_swahb32
89 return __arch_swahb32(val); 89 return __arch_swahb32(val);
90#else 90#else
91 return __const_swahb32(val); 91 return ___constant_swahb32(val);
92#endif 92#endif
93} 93}
94 94
@@ -98,8 +98,8 @@ static inline __attribute_const__ __u32 ___swahb32(__u32 val)
98 */ 98 */
99#define __swab16(x) \ 99#define __swab16(x) \
100 (__builtin_constant_p((__u16)(x)) ? \ 100 (__builtin_constant_p((__u16)(x)) ? \
101 __const_swab16((x)) : \ 101 ___constant_swab16(x) : \
102 ___swab16((x))) 102 __fswab16(x))
103 103
104/** 104/**
105 * __swab32 - return a byteswapped 32-bit value 105 * __swab32 - return a byteswapped 32-bit value
@@ -107,8 +107,8 @@ static inline __attribute_const__ __u32 ___swahb32(__u32 val)
107 */ 107 */
108#define __swab32(x) \ 108#define __swab32(x) \
109 (__builtin_constant_p((__u32)(x)) ? \ 109 (__builtin_constant_p((__u32)(x)) ? \
110 __const_swab32((x)) : \ 110 ___constant_swab32(x) : \
111 ___swab32((x))) 111 __fswab32(x))
112 112
113/** 113/**
114 * __swab64 - return a byteswapped 64-bit value 114 * __swab64 - return a byteswapped 64-bit value
@@ -116,8 +116,8 @@ static inline __attribute_const__ __u32 ___swahb32(__u32 val)
116 */ 116 */
117#define __swab64(x) \ 117#define __swab64(x) \
118 (__builtin_constant_p((__u64)(x)) ? \ 118 (__builtin_constant_p((__u64)(x)) ? \
119 __const_swab64((x)) : \ 119 ___constant_swab64(x) : \
120 ___swab64((x))) 120 __fswab64(x))
121 121
122/** 122/**
123 * __swahw32 - return a word-swapped 32-bit value 123 * __swahw32 - return a word-swapped 32-bit value
@@ -127,8 +127,8 @@ static inline __attribute_const__ __u32 ___swahb32(__u32 val)
127 */ 127 */
128#define __swahw32(x) \ 128#define __swahw32(x) \
129 (__builtin_constant_p((__u32)(x)) ? \ 129 (__builtin_constant_p((__u32)(x)) ? \
130 __const_swahw32((x)) : \ 130 ___constant_swahw32(x) : \
131 ___swahw32((x))) 131 __fswahw32(x))
132 132
133/** 133/**
134 * __swahb32 - return a high and low byte-swapped 32-bit value 134 * __swahb32 - return a high and low byte-swapped 32-bit value
@@ -138,8 +138,8 @@ static inline __attribute_const__ __u32 ___swahb32(__u32 val)
138 */ 138 */
139#define __swahb32(x) \ 139#define __swahb32(x) \
140 (__builtin_constant_p((__u32)(x)) ? \ 140 (__builtin_constant_p((__u32)(x)) ? \
141 __const_swahb32((x)) : \ 141 ___constant_swahb32(x) : \
142 ___swahb32((x))) 142 __fswahb32(x))
143 143
144/** 144/**
145 * __swab16p - return a byteswapped 16-bit value from a pointer 145 * __swab16p - return a byteswapped 16-bit value from a pointer