swab.h
001: #ifndef _LINUX_SWAB_H
002: #define _LINUX_SWAB_H
003:
004: #include <linux/types.h>
005:
006: #include <asm/swab.h>
007:
008:
009:
010:
011:
012: #define ___constant_swab16(x) ((__u16)( \
013: (((__u16)(x) & (__u16)0x00ffU) << 8) | \
014: (((__u16)(x) & (__u16)0xff00U) >> 8)))
015:
016: #define ___constant_swab32(x) ((__u32)( \
017: (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
018: (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
019: (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
020: (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
021:
022: #define ___constant_swab64(x) ((__u64)( \
023: (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
024: (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
025: (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
026: (((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
027: (((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
028: (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
029: (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
030: (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
031:
032: #define ___constant_swahw32(x) ((__u32)( \
033: (((__u32)(x) & (__u32)0x0000ffffUL) << 16) | \
034: (((__u32)(x) & (__u32)0xffff0000UL) >> 16)))
035:
036: #define ___constant_swahb32(x) ((__u32)( \
037: (((__u32)(x) & (__u32)0x00ff00ffUL) << 8) | \
038: (((__u32)(x) & (__u32)0xff00ff00UL) >> 8)))
039:
040:
041:
042:
043:
044:
045:
046: static __inline__ __u16 __fswab16(__u16 val)
047: {
048: #ifdef __arch_swab16
049: return __arch_swab16(val);
050: #else
051: return ___constant_swab16(val);
052: #endif
053: }
054:
055: static __inline__ __u32 __fswab32(__u32 val)
056: {
057: #ifdef __arch_swab32
058: return __arch_swab32(val);
059: #else
060: return ___constant_swab32(val);
061: #endif
062: }
063:
064: static __inline__ __u64 __fswab64(__u64 val)
065: {
066: #ifdef __arch_swab64
067: return __arch_swab64(val);
068: #elif defined(__SWAB_64_THRU_32__)
069: __u32 h = val >> 32;
070: __u32 l = val & ((1ULL << 32) - 1);
071: return (((__u64)__fswab32(l)) << 32) | ((__u64)(__fswab32(h)));
072: #else
073: return ___constant_swab64(val);
074: #endif
075: }
076:
077: static __inline__ __u32 __fswahw32(__u32 val)
078: {
079: #ifdef __arch_swahw32
080: return __arch_swahw32(val);
081: #else
082: return ___constant_swahw32(val);
083: #endif
084: }
085:
086: static __inline__ __u32 __fswahb32(__u32 val)
087: {
088: #ifdef __arch_swahb32
089: return __arch_swahb32(val);
090: #else
091: return ___constant_swahb32(val);
092: #endif
093: }
094:
095:
096:
097: @x
098:
099: #define __swab16(x) \
100: (__builtin_constant_p((__u16)(x)) ? \
101: ___constant_swab16(x) : \
102: __fswab16(x))
103:
104:
105:
106: @x
107:
108: #define __swab32(x) \
109: (__builtin_constant_p((__u32)(x)) ? \
110: ___constant_swab32(x) : \
111: __fswab32(x))
112:
113:
114:
115: @x
116:
117: #define __swab64(x) \
118: (__builtin_constant_p((__u64)(x)) ? \
119: ___constant_swab64(x) : \
120: __fswab64(x))
121:
122:
123:
124: @x
125:
126:
127:
128: #define __swahw32(x) \
129: (__builtin_constant_p((__u32)(x)) ? \
130: ___constant_swahw32(x) : \
131: __fswahw32(x))
132:
133:
134:
135: @x
136:
137:
138:
139: #define __swahb32(x) \
140: (__builtin_constant_p((__u32)(x)) ? \
141: ___constant_swahb32(x) : \
142: __fswahb32(x))
143:
144:
145:
146: @p
147:
148: static __inline__ __u16 __swab16p(const __u16 *p)
149: {
150: #ifdef __arch_swab16p
151: return __arch_swab16p(p);
152: #else
153: return __swab16(*p);
154: #endif
155: }
156:
157:
158:
159: @p
160:
161: static __inline__ __u32 __swab32p(const __u32 *p)
162: {
163: #ifdef __arch_swab32p
164: return __arch_swab32p(p);
165: #else
166: return __swab32(*p);
167: #endif
168: }
169:
170:
171:
172: @p
173:
174: static __inline__ __u64 __swab64p(const __u64 *p)
175: {
176: #ifdef __arch_swab64p
177: return __arch_swab64p(p);
178: #else
179: return __swab64(*p);
180: #endif
181: }
182:
183:
184:
185: @p
186:
187:
188:
189: static __inline__ __u32 __swahw32p(const __u32 *p)
190: {
191: #ifdef __arch_swahw32p
192: return __arch_swahw32p(p);
193: #else
194: return __swahw32(*p);
195: #endif
196: }
197:
198:
199:
200: @p
201:
202:
203:
204: static __inline__ __u32 __swahb32p(const __u32 *p)
205: {
206: #ifdef __arch_swahb32p
207: return __arch_swahb32p(p);
208: #else
209: return __swahb32(*p);
210: #endif
211: }
212:
213:
214:
215: @p
216:
217: static __inline__ void __swab16s(__u16 *p)
218: {
219: #ifdef __arch_swab16s
220: __arch_swab16s(p);
221: #else
222: *p = __swab16p(p);
223: #endif
224: }
225:
226:
227: @p
228:
229: static __inline__ void __swab32s(__u32 *p)
230: {
231: #ifdef __arch_swab32s
232: __arch_swab32s(p);
233: #else
234: *p = __swab32p(p);
235: #endif
236: }
237:
238:
239:
240: @p
241:
242: static __inline__ void __swab64s(__u64 *p)
243: {
244: #ifdef __arch_swab64s
245: __arch_swab64s(p);
246: #else
247: *p = __swab64p(p);
248: #endif
249: }
250:
251:
252:
253: @p
254:
255:
256:
257: static __inline__ void __swahw32s(__u32 *p)
258: {
259: #ifdef __arch_swahw32s
260: __arch_swahw32s(p);
261: #else
262: *p = __swahw32p(p);
263: #endif
264: }
265:
266:
267:
268: @p
269:
270:
271:
272: static __inline__ void __swahb32s(__u32 *p)
273: {
274: #ifdef __arch_swahb32s
275: __arch_swahb32s(p);
276: #else
277: *p = __swahb32p(p);
278: #endif
279: }
280:
281:
282: #endif
283:
© Andrew Scott 2006 -
2025,
All Rights Reserved