~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/uapi/linux/swab.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/uapi/linux/swab.h (Version linux-6.11-rc3) and /include/uapi/linux/swab.h (Version linux-4.9.337)


  1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux << 
  2 #ifndef _UAPI_LINUX_SWAB_H                          1 #ifndef _UAPI_LINUX_SWAB_H
  3 #define _UAPI_LINUX_SWAB_H                          2 #define _UAPI_LINUX_SWAB_H
  4                                                     3 
  5 #include <linux/types.h>                            4 #include <linux/types.h>
  6 #include <linux/stddef.h>                           5 #include <linux/stddef.h>
  7 #include <asm/bitsperlong.h>                        6 #include <asm/bitsperlong.h>
  8 #include <asm/swab.h>                               7 #include <asm/swab.h>
  9                                                     8 
 10 /*                                                  9 /*
 11  * casts are necessary for constants, because      10  * casts are necessary for constants, because we never know how for sure
 12  * how U/UL/ULL map to __u16, __u32, __u64. At     11  * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
 13  */                                                12  */
 14 #define ___constant_swab16(x) ((__u16)(            13 #define ___constant_swab16(x) ((__u16)(                         \
 15         (((__u16)(x) & (__u16)0x00ffU) << 8) |     14         (((__u16)(x) & (__u16)0x00ffU) << 8) |                  \
 16         (((__u16)(x) & (__u16)0xff00U) >> 8)))     15         (((__u16)(x) & (__u16)0xff00U) >> 8)))
 17                                                    16 
 18 #define ___constant_swab32(x) ((__u32)(            17 #define ___constant_swab32(x) ((__u32)(                         \
 19         (((__u32)(x) & (__u32)0x000000ffUL) <<     18         (((__u32)(x) & (__u32)0x000000ffUL) << 24) |            \
 20         (((__u32)(x) & (__u32)0x0000ff00UL) <<     19         (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
 21         (((__u32)(x) & (__u32)0x00ff0000UL) >>     20         (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |            \
 22         (((__u32)(x) & (__u32)0xff000000UL) >>     21         (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
 23                                                    22 
 24 #define ___constant_swab64(x) ((__u64)(            23 #define ___constant_swab64(x) ((__u64)(                         \
 25         (((__u64)(x) & (__u64)0x00000000000000     24         (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) |   \
 26         (((__u64)(x) & (__u64)0x000000000000ff     25         (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) |   \
 27         (((__u64)(x) & (__u64)0x0000000000ff00     26         (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) |   \
 28         (((__u64)(x) & (__u64)0x00000000ff0000     27         (((__u64)(x) & (__u64)0x00000000ff000000ULL) <<  8) |   \
 29         (((__u64)(x) & (__u64)0x000000ff000000     28         (((__u64)(x) & (__u64)0x000000ff00000000ULL) >>  8) |   \
 30         (((__u64)(x) & (__u64)0x0000ff00000000     29         (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) |   \
 31         (((__u64)(x) & (__u64)0x00ff0000000000     30         (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) |   \
 32         (((__u64)(x) & (__u64)0xff000000000000     31         (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
 33                                                    32 
 34 #define ___constant_swahw32(x) ((__u32)(           33 #define ___constant_swahw32(x) ((__u32)(                        \
 35         (((__u32)(x) & (__u32)0x0000ffffUL) <<     34         (((__u32)(x) & (__u32)0x0000ffffUL) << 16) |            \
 36         (((__u32)(x) & (__u32)0xffff0000UL) >>     35         (((__u32)(x) & (__u32)0xffff0000UL) >> 16)))
 37                                                    36 
 38 #define ___constant_swahb32(x) ((__u32)(           37 #define ___constant_swahb32(x) ((__u32)(                        \
 39         (((__u32)(x) & (__u32)0x00ff00ffUL) <<     38         (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) |             \
 40         (((__u32)(x) & (__u32)0xff00ff00UL) >>     39         (((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))
 41                                                    40 
 42 /*                                                 41 /*
 43  * Implement the following as inlines, but def     42  * Implement the following as inlines, but define the interface using
 44  * macros to allow constant folding when possi     43  * macros to allow constant folding when possible:
 45  * ___swab16, ___swab32, ___swab64, ___swahw32     44  * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
 46  */                                                45  */
 47                                                    46 
 48 static inline __attribute_const__ __u16 __fswa     47 static inline __attribute_const__ __u16 __fswab16(__u16 val)
 49 {                                                  48 {
 50 #if defined (__arch_swab16)                        49 #if defined (__arch_swab16)
 51         return __arch_swab16(val);                 50         return __arch_swab16(val);
 52 #else                                              51 #else
 53         return ___constant_swab16(val);            52         return ___constant_swab16(val);
 54 #endif                                             53 #endif
 55 }                                                  54 }
 56                                                    55 
 57 static inline __attribute_const__ __u32 __fswa     56 static inline __attribute_const__ __u32 __fswab32(__u32 val)
 58 {                                                  57 {
 59 #if defined(__arch_swab32)                         58 #if defined(__arch_swab32)
 60         return __arch_swab32(val);                 59         return __arch_swab32(val);
 61 #else                                              60 #else
 62         return ___constant_swab32(val);            61         return ___constant_swab32(val);
 63 #endif                                             62 #endif
 64 }                                                  63 }
 65                                                    64 
 66 static inline __attribute_const__ __u64 __fswa     65 static inline __attribute_const__ __u64 __fswab64(__u64 val)
 67 {                                                  66 {
 68 #if defined (__arch_swab64)                        67 #if defined (__arch_swab64)
 69         return __arch_swab64(val);                 68         return __arch_swab64(val);
 70 #elif defined(__SWAB_64_THRU_32__)                 69 #elif defined(__SWAB_64_THRU_32__)
 71         __u32 h = val >> 32;                       70         __u32 h = val >> 32;
 72         __u32 l = val & ((1ULL << 32) - 1);        71         __u32 l = val & ((1ULL << 32) - 1);
 73         return (((__u64)__fswab32(l)) << 32) |     72         return (((__u64)__fswab32(l)) << 32) | ((__u64)(__fswab32(h)));
 74 #else                                              73 #else
 75         return ___constant_swab64(val);            74         return ___constant_swab64(val);
 76 #endif                                             75 #endif
 77 }                                                  76 }
 78                                                    77 
 79 static inline __attribute_const__ __u32 __fswa     78 static inline __attribute_const__ __u32 __fswahw32(__u32 val)
 80 {                                                  79 {
 81 #ifdef __arch_swahw32                              80 #ifdef __arch_swahw32
 82         return __arch_swahw32(val);                81         return __arch_swahw32(val);
 83 #else                                              82 #else
 84         return ___constant_swahw32(val);           83         return ___constant_swahw32(val);
 85 #endif                                             84 #endif
 86 }                                                  85 }
 87                                                    86 
 88 static inline __attribute_const__ __u32 __fswa     87 static inline __attribute_const__ __u32 __fswahb32(__u32 val)
 89 {                                                  88 {
 90 #ifdef __arch_swahb32                              89 #ifdef __arch_swahb32
 91         return __arch_swahb32(val);                90         return __arch_swahb32(val);
 92 #else                                              91 #else
 93         return ___constant_swahb32(val);           92         return ___constant_swahb32(val);
 94 #endif                                             93 #endif
 95 }                                                  94 }
 96                                                    95 
 97 /**                                                96 /**
 98  * __swab16 - return a byteswapped 16-bit valu     97  * __swab16 - return a byteswapped 16-bit value
 99  * @x: value to byteswap                           98  * @x: value to byteswap
100  */                                                99  */
101 #ifdef __HAVE_BUILTIN_BSWAP16__                   100 #ifdef __HAVE_BUILTIN_BSWAP16__
102 #define __swab16(x) (__u16)__builtin_bswap16((    101 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
103 #else                                             102 #else
104 #define __swab16(x)                               103 #define __swab16(x)                             \
105         (__u16)(__builtin_constant_p(x) ?      !! 104         (__builtin_constant_p((__u16)(x)) ?     \
106         ___constant_swab16(x) :                   105         ___constant_swab16(x) :                 \
107         __fswab16(x))                             106         __fswab16(x))
108 #endif                                            107 #endif
109                                                   108 
110 /**                                               109 /**
111  * __swab32 - return a byteswapped 32-bit valu    110  * __swab32 - return a byteswapped 32-bit value
112  * @x: value to byteswap                          111  * @x: value to byteswap
113  */                                               112  */
114 #ifdef __HAVE_BUILTIN_BSWAP32__                   113 #ifdef __HAVE_BUILTIN_BSWAP32__
115 #define __swab32(x) (__u32)__builtin_bswap32((    114 #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
116 #else                                             115 #else
117 #define __swab32(x)                               116 #define __swab32(x)                             \
118         (__u32)(__builtin_constant_p(x) ?      !! 117         (__builtin_constant_p((__u32)(x)) ?     \
119         ___constant_swab32(x) :                   118         ___constant_swab32(x) :                 \
120         __fswab32(x))                             119         __fswab32(x))
121 #endif                                            120 #endif
122                                                   121 
123 /**                                               122 /**
124  * __swab64 - return a byteswapped 64-bit valu    123  * __swab64 - return a byteswapped 64-bit value
125  * @x: value to byteswap                          124  * @x: value to byteswap
126  */                                               125  */
127 #ifdef __HAVE_BUILTIN_BSWAP64__                   126 #ifdef __HAVE_BUILTIN_BSWAP64__
128 #define __swab64(x) (__u64)__builtin_bswap64((    127 #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
129 #else                                             128 #else
130 #define __swab64(x)                               129 #define __swab64(x)                             \
131         (__u64)(__builtin_constant_p(x) ?      !! 130         (__builtin_constant_p((__u64)(x)) ?     \
132         ___constant_swab64(x) :                   131         ___constant_swab64(x) :                 \
133         __fswab64(x))                             132         __fswab64(x))
134 #endif                                            133 #endif
135                                                   134 
136 static __always_inline unsigned long __swab(co    135 static __always_inline unsigned long __swab(const unsigned long y)
137 {                                                 136 {
138 #if __BITS_PER_LONG == 64                         137 #if __BITS_PER_LONG == 64
139         return __swab64(y);                       138         return __swab64(y);
140 #else /* __BITS_PER_LONG == 32 */                 139 #else /* __BITS_PER_LONG == 32 */
141         return __swab32(y);                       140         return __swab32(y);
142 #endif                                            141 #endif
143 }                                                 142 }
144                                                   143 
145 /**                                               144 /**
146  * __swahw32 - return a word-swapped 32-bit va    145  * __swahw32 - return a word-swapped 32-bit value
147  * @x: value to wordswap                          146  * @x: value to wordswap
148  *                                                147  *
149  * __swahw32(0x12340000) is 0x00001234            148  * __swahw32(0x12340000) is 0x00001234
150  */                                               149  */
151 #define __swahw32(x)                              150 #define __swahw32(x)                            \
152         (__builtin_constant_p((__u32)(x)) ?       151         (__builtin_constant_p((__u32)(x)) ?     \
153         ___constant_swahw32(x) :                  152         ___constant_swahw32(x) :                \
154         __fswahw32(x))                            153         __fswahw32(x))
155                                                   154 
156 /**                                               155 /**
157  * __swahb32 - return a high and low byte-swap    156  * __swahb32 - return a high and low byte-swapped 32-bit value
158  * @x: value to byteswap                          157  * @x: value to byteswap
159  *                                                158  *
160  * __swahb32(0x12345678) is 0x34127856            159  * __swahb32(0x12345678) is 0x34127856
161  */                                               160  */
162 #define __swahb32(x)                              161 #define __swahb32(x)                            \
163         (__builtin_constant_p((__u32)(x)) ?       162         (__builtin_constant_p((__u32)(x)) ?     \
164         ___constant_swahb32(x) :                  163         ___constant_swahb32(x) :                \
165         __fswahb32(x))                            164         __fswahb32(x))
166                                                   165 
167 /**                                               166 /**
168  * __swab16p - return a byteswapped 16-bit val    167  * __swab16p - return a byteswapped 16-bit value from a pointer
169  * @p: pointer to a naturally-aligned 16-bit v    168  * @p: pointer to a naturally-aligned 16-bit value
170  */                                               169  */
171 static __always_inline __u16 __swab16p(const _    170 static __always_inline __u16 __swab16p(const __u16 *p)
172 {                                                 171 {
173 #ifdef __arch_swab16p                             172 #ifdef __arch_swab16p
174         return __arch_swab16p(p);                 173         return __arch_swab16p(p);
175 #else                                             174 #else
176         return __swab16(*p);                      175         return __swab16(*p);
177 #endif                                            176 #endif
178 }                                                 177 }
179                                                   178 
180 /**                                               179 /**
181  * __swab32p - return a byteswapped 32-bit val    180  * __swab32p - return a byteswapped 32-bit value from a pointer
182  * @p: pointer to a naturally-aligned 32-bit v    181  * @p: pointer to a naturally-aligned 32-bit value
183  */                                               182  */
184 static __always_inline __u32 __swab32p(const _    183 static __always_inline __u32 __swab32p(const __u32 *p)
185 {                                                 184 {
186 #ifdef __arch_swab32p                             185 #ifdef __arch_swab32p
187         return __arch_swab32p(p);                 186         return __arch_swab32p(p);
188 #else                                             187 #else
189         return __swab32(*p);                      188         return __swab32(*p);
190 #endif                                            189 #endif
191 }                                                 190 }
192                                                   191 
193 /**                                               192 /**
194  * __swab64p - return a byteswapped 64-bit val    193  * __swab64p - return a byteswapped 64-bit value from a pointer
195  * @p: pointer to a naturally-aligned 64-bit v    194  * @p: pointer to a naturally-aligned 64-bit value
196  */                                               195  */
197 static __always_inline __u64 __swab64p(const _    196 static __always_inline __u64 __swab64p(const __u64 *p)
198 {                                                 197 {
199 #ifdef __arch_swab64p                             198 #ifdef __arch_swab64p
200         return __arch_swab64p(p);                 199         return __arch_swab64p(p);
201 #else                                             200 #else
202         return __swab64(*p);                      201         return __swab64(*p);
203 #endif                                            202 #endif
204 }                                                 203 }
205                                                   204 
206 /**                                               205 /**
207  * __swahw32p - return a wordswapped 32-bit va    206  * __swahw32p - return a wordswapped 32-bit value from a pointer
208  * @p: pointer to a naturally-aligned 32-bit v    207  * @p: pointer to a naturally-aligned 32-bit value
209  *                                                208  *
210  * See __swahw32() for details of wordswapping    209  * See __swahw32() for details of wordswapping.
211  */                                               210  */
212 static inline __u32 __swahw32p(const __u32 *p)    211 static inline __u32 __swahw32p(const __u32 *p)
213 {                                                 212 {
214 #ifdef __arch_swahw32p                            213 #ifdef __arch_swahw32p
215         return __arch_swahw32p(p);                214         return __arch_swahw32p(p);
216 #else                                             215 #else
217         return __swahw32(*p);                     216         return __swahw32(*p);
218 #endif                                            217 #endif
219 }                                                 218 }
220                                                   219 
221 /**                                               220 /**
222  * __swahb32p - return a high and low byteswap    221  * __swahb32p - return a high and low byteswapped 32-bit value from a pointer
223  * @p: pointer to a naturally-aligned 32-bit v    222  * @p: pointer to a naturally-aligned 32-bit value
224  *                                                223  *
225  * See __swahb32() for details of high/low byt    224  * See __swahb32() for details of high/low byteswapping.
226  */                                               225  */
227 static inline __u32 __swahb32p(const __u32 *p)    226 static inline __u32 __swahb32p(const __u32 *p)
228 {                                                 227 {
229 #ifdef __arch_swahb32p                            228 #ifdef __arch_swahb32p
230         return __arch_swahb32p(p);                229         return __arch_swahb32p(p);
231 #else                                             230 #else
232         return __swahb32(*p);                     231         return __swahb32(*p);
233 #endif                                            232 #endif
234 }                                                 233 }
235                                                   234 
236 /**                                               235 /**
237  * __swab16s - byteswap a 16-bit value in-plac    236  * __swab16s - byteswap a 16-bit value in-place
238  * @p: pointer to a naturally-aligned 16-bit v    237  * @p: pointer to a naturally-aligned 16-bit value
239  */                                               238  */
240 static inline void __swab16s(__u16 *p)            239 static inline void __swab16s(__u16 *p)
241 {                                                 240 {
242 #ifdef __arch_swab16s                             241 #ifdef __arch_swab16s
243         __arch_swab16s(p);                        242         __arch_swab16s(p);
244 #else                                             243 #else
245         *p = __swab16p(p);                        244         *p = __swab16p(p);
246 #endif                                            245 #endif
247 }                                                 246 }
248 /**                                               247 /**
249  * __swab32s - byteswap a 32-bit value in-plac    248  * __swab32s - byteswap a 32-bit value in-place
250  * @p: pointer to a naturally-aligned 32-bit v    249  * @p: pointer to a naturally-aligned 32-bit value
251  */                                               250  */
252 static __always_inline void __swab32s(__u32 *p    251 static __always_inline void __swab32s(__u32 *p)
253 {                                                 252 {
254 #ifdef __arch_swab32s                             253 #ifdef __arch_swab32s
255         __arch_swab32s(p);                        254         __arch_swab32s(p);
256 #else                                             255 #else
257         *p = __swab32p(p);                        256         *p = __swab32p(p);
258 #endif                                            257 #endif
259 }                                                 258 }
260                                                   259 
261 /**                                               260 /**
262  * __swab64s - byteswap a 64-bit value in-plac    261  * __swab64s - byteswap a 64-bit value in-place
263  * @p: pointer to a naturally-aligned 64-bit v    262  * @p: pointer to a naturally-aligned 64-bit value
264  */                                               263  */
265 static __always_inline void __swab64s(__u64 *p    264 static __always_inline void __swab64s(__u64 *p)
266 {                                                 265 {
267 #ifdef __arch_swab64s                             266 #ifdef __arch_swab64s
268         __arch_swab64s(p);                        267         __arch_swab64s(p);
269 #else                                             268 #else
270         *p = __swab64p(p);                        269         *p = __swab64p(p);
271 #endif                                            270 #endif
272 }                                                 271 }
273                                                   272 
274 /**                                               273 /**
275  * __swahw32s - wordswap a 32-bit value in-pla    274  * __swahw32s - wordswap a 32-bit value in-place
276  * @p: pointer to a naturally-aligned 32-bit v    275  * @p: pointer to a naturally-aligned 32-bit value
277  *                                                276  *
278  * See __swahw32() for details of wordswapping    277  * See __swahw32() for details of wordswapping
279  */                                               278  */
280 static inline void __swahw32s(__u32 *p)           279 static inline void __swahw32s(__u32 *p)
281 {                                                 280 {
282 #ifdef __arch_swahw32s                            281 #ifdef __arch_swahw32s
283         __arch_swahw32s(p);                       282         __arch_swahw32s(p);
284 #else                                             283 #else
285         *p = __swahw32p(p);                       284         *p = __swahw32p(p);
286 #endif                                            285 #endif
287 }                                                 286 }
288                                                   287 
289 /**                                               288 /**
290  * __swahb32s - high and low byteswap a 32-bit    289  * __swahb32s - high and low byteswap a 32-bit value in-place
291  * @p: pointer to a naturally-aligned 32-bit v    290  * @p: pointer to a naturally-aligned 32-bit value
292  *                                                291  *
293  * See __swahb32() for details of high and low    292  * See __swahb32() for details of high and low byte swapping
294  */                                               293  */
295 static inline void __swahb32s(__u32 *p)           294 static inline void __swahb32s(__u32 *p)
296 {                                                 295 {
297 #ifdef __arch_swahb32s                            296 #ifdef __arch_swahb32s
298         __arch_swahb32s(p);                       297         __arch_swahb32s(p);
299 #else                                             298 #else
300         *p = __swahb32p(p);                       299         *p = __swahb32p(p);
301 #endif                                            300 #endif
302 }                                                 301 }
303                                                   302 
304                                                   303 
305 #endif /* _UAPI_LINUX_SWAB_H */                   304 #endif /* _UAPI_LINUX_SWAB_H */
306                                                   305 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php