• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This header was generated from the Linux kernel headers by update_headers.py,
3  * to provide necessary information from kernel to userspace, such as constants,
4  * structures, and macros, and thus, contains no copyrightable information.
5  */
6 #ifndef _UAPI_LINUX_SWAB_H
7 #define _UAPI_LINUX_SWAB_H
8 #include <linux/types.h>
9 #include <linux/compiler.h>
10 #include <asm/bitsperlong.h>
11 #include <asm/swab.h>
12 #define ___constant_swab16(x) ((__u16)(				\
13 	(((__u16)(x) & (__u16)0x00ffU) << 8) |			\
14 	(((__u16)(x) & (__u16)0xff00U) >> 8)))
15 #define ___constant_swab32(x) ((__u32)(				\
16 	(((__u32)(x) & (__u32)0x000000ffUL) << 24) |		\
17 	(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |		\
18 	(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |		\
19 	(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
20 #define ___constant_swab64(x) ((__u64)(				\
21 	(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) |	\
22 	(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) |	\
23 	(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) |	\
24 	(((__u64)(x) & (__u64)0x00000000ff000000ULL) <<  8) |	\
25 	(((__u64)(x) & (__u64)0x000000ff00000000ULL) >>  8) |	\
26 	(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) |	\
27 	(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) |	\
28 	(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
29 #define ___constant_swahw32(x) ((__u32)(			\
30 	(((__u32)(x) & (__u32)0x0000ffffUL) << 16) |		\
31 	(((__u32)(x) & (__u32)0xffff0000UL) >> 16)))
32 #define ___constant_swahb32(x) ((__u32)(			\
33 	(((__u32)(x) & (__u32)0x00ff00ffUL) << 8) |		\
34 	(((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))
__fswab16(__u16 val)35 static inline __attribute_const__ __u16 __fswab16(__u16 val)
36 {
37 #if defined (__arch_swab16)
38 	return __arch_swab16(val);
39 #else
40 	return ___constant_swab16(val);
41 #endif
42 }
__fswab32(__u32 val)43 static inline __attribute_const__ __u32 __fswab32(__u32 val)
44 {
45 #if defined(__arch_swab32)
46 	return __arch_swab32(val);
47 #else
48 	return ___constant_swab32(val);
49 #endif
50 }
__fswab64(__u64 val)51 static inline __attribute_const__ __u64 __fswab64(__u64 val)
52 {
53 #if defined (__arch_swab64)
54 	return __arch_swab64(val);
55 #elif defined(__SWAB_64_THRU_32__)
56 	__u32 h = val >> 32;
57 	__u32 l = val & ((1ULL << 32) - 1);
58 	return (((__u64)__fswab32(l)) << 32) | ((__u64)(__fswab32(h)));
59 #else
60 	return ___constant_swab64(val);
61 #endif
62 }
__fswahw32(__u32 val)63 static inline __attribute_const__ __u32 __fswahw32(__u32 val)
64 {
65 #ifdef __arch_swahw32
66 	return __arch_swahw32(val);
67 #else
68 	return ___constant_swahw32(val);
69 #endif
70 }
__fswahb32(__u32 val)71 static inline __attribute_const__ __u32 __fswahb32(__u32 val)
72 {
73 #ifdef __arch_swahb32
74 	return __arch_swahb32(val);
75 #else
76 	return ___constant_swahb32(val);
77 #endif
78 }
79 #if 1
80 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
81 #else
82 #define __swab16(x)				\
83 	(__builtin_constant_p((__u16)(x)) ?	\
84 	___constant_swab16(x) :			\
85 	__fswab16(x))
86 #endif
87 #if 1
88 #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
89 #else
90 #define __swab32(x)				\
91 	(__builtin_constant_p((__u32)(x)) ?	\
92 	___constant_swab32(x) :			\
93 	__fswab32(x))
94 #endif
95 #if 1
96 #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
97 #else
98 #define __swab64(x)				\
99 	(__builtin_constant_p((__u64)(x)) ?	\
100 	___constant_swab64(x) :			\
101 	__fswab64(x))
102 #endif
__swab(const unsigned long y)103 static __always_inline unsigned long __swab(const unsigned long y)
104 {
105 #if __BITS_PER_LONG == 64
106 	return __swab64(y);
107 #else
108 	return __swab32(y);
109 #endif
110 }
111 #define __swahw32(x)				\
112 	(__builtin_constant_p((__u32)(x)) ?	\
113 	___constant_swahw32(x) :		\
114 	__fswahw32(x))
115 #define __swahb32(x)				\
116 	(__builtin_constant_p((__u32)(x)) ?	\
117 	___constant_swahb32(x) :		\
118 	__fswahb32(x))
__swab16p(const __u16 * p)119 static __always_inline __u16 __swab16p(const __u16 *p)
120 {
121 #ifdef __arch_swab16p
122 	return __arch_swab16p(p);
123 #else
124 	return __swab16(*p);
125 #endif
126 }
__swab32p(const __u32 * p)127 static __always_inline __u32 __swab32p(const __u32 *p)
128 {
129 #ifdef __arch_swab32p
130 	return __arch_swab32p(p);
131 #else
132 	return __swab32(*p);
133 #endif
134 }
__swab64p(const __u64 * p)135 static __always_inline __u64 __swab64p(const __u64 *p)
136 {
137 #ifdef __arch_swab64p
138 	return __arch_swab64p(p);
139 #else
140 	return __swab64(*p);
141 #endif
142 }
__swahw32p(const __u32 * p)143 static inline __u32 __swahw32p(const __u32 *p)
144 {
145 #ifdef __arch_swahw32p
146 	return __arch_swahw32p(p);
147 #else
148 	return __swahw32(*p);
149 #endif
150 }
__swahb32p(const __u32 * p)151 static inline __u32 __swahb32p(const __u32 *p)
152 {
153 #ifdef __arch_swahb32p
154 	return __arch_swahb32p(p);
155 #else
156 	return __swahb32(*p);
157 #endif
158 }
__swab16s(__u16 * p)159 static inline void __swab16s(__u16 *p)
160 {
161 #ifdef __arch_swab16s
162 	__arch_swab16s(p);
163 #else
164 	*p = __swab16p(p);
165 #endif
166 }
__swab32s(__u32 * p)167 static __always_inline void __swab32s(__u32 *p)
168 {
169 #ifdef __arch_swab32s
170 	__arch_swab32s(p);
171 #else
172 	*p = __swab32p(p);
173 #endif
174 }
__swab64s(__u64 * p)175 static __always_inline void __swab64s(__u64 *p)
176 {
177 #ifdef __arch_swab64s
178 	__arch_swab64s(p);
179 #else
180 	*p = __swab64p(p);
181 #endif
182 }
__swahw32s(__u32 * p)183 static inline void __swahw32s(__u32 *p)
184 {
185 #ifdef __arch_swahw32s
186 	__arch_swahw32s(p);
187 #else
188 	*p = __swahw32p(p);
189 #endif
190 }
__swahb32s(__u32 * p)191 static inline void __swahb32s(__u32 *p)
192 {
193 #ifdef __arch_swahb32s
194 	__arch_swahb32s(p);
195 #else
196 	*p = __swahb32p(p);
197 #endif
198 }
199 #endif
200