1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #ifndef _LINUX_BYTEORDER_SWAB_H
21 #define _LINUX_BYTEORDER_SWAB_H
23 #if !defined(CONFIG_PLATFORM_MSTAR)
25 typedef unsigned short __u16;
29 typedef unsigned int __u32;
33 typedef unsigned char __u8;
37 typedef unsigned long long __u64;
41 __inline static __u16 ___swab16(__u16 x)
46 (((__u16)(__x)&(__u16)0x00ffU) << 8) |
47 (((__u16)(__x)&(__u16)0xff00U) >> 8));
51 __inline static __u32 ___swab32(__u32 x)
55 (((__u32)(__x)&(__u32)0x000000ffUL) << 24) |
56 (((__u32)(__x)&(__u32)0x0000ff00UL) << 8) |
57 (((__u32)(__x)&(__u32)0x00ff0000UL) >> 8) |
58 (((__u32)(__x)&(__u32)0xff000000UL) >> 24));
61 __inline static __u64 ___swab64(__u64 x)
67 (__u64)(((__u64)(__x)&(__u64)0x00000000000000ffULL) << 56) | \
68 (__u64)(((__u64)(__x)&(__u64)0x000000000000ff00ULL) << 40) | \
69 (__u64)(((__u64)(__x)&(__u64)0x0000000000ff0000ULL) << 24) | \
70 (__u64)(((__u64)(__x)&(__u64)0x00000000ff000000ULL) << 8) | \
71 (__u64)(((__u64)(__x)&(__u64)0x000000ff00000000ULL) >> 8) | \
72 (__u64)(((__u64)(__x)&(__u64)0x0000ff0000000000ULL) >> 24) | \
73 (__u64)(((__u64)(__x)&(__u64)0x00ff000000000000ULL) >> 40) | \
74 (__u64)(((__u64)(__x)&(__u64)0xff00000000000000ULL) >> 56));
77 #endif /* CONFIG_PLATFORM_MSTAR */
79 #ifndef __arch__swab16
80 __inline static __u16 __arch__swab16(__u16 x)
87 #ifndef __arch__swab32
88 __inline static __u32 __arch__swab32(__u32 x)
91 return ___swab32(__tmp);
95 #ifndef __arch__swab64
97 __inline static __u64 __arch__swab64(__u64 x)
100 return ___swab64(__tmp);
107 #define __swab16(x) __fswab16(x)
108 #define __swab32(x) __fswab32(x)
109 #define __swab64(x) __fswab64(x)
110 #endif /* __swab16 */
112 #ifdef PLATFORM_FREEBSD
113 __inline static __u16 __fswab16(__u16 x)
115 __inline static const __u16 __fswab16(__u16 x)
116 #endif /* PLATFORM_FREEBSD */
118 return __arch__swab16(x);
120 #ifdef PLATFORM_FREEBSD
121 __inline static __u32 __fswab32(__u32 x)
123 __inline static const __u32 __fswab32(__u32 x)
124 #endif /* PLATFORM_FREEBSD */
126 return __arch__swab32(x);
129 #if defined(PLATFORM_LINUX) || defined(PLATFORM_WINDOWS)
130 #define swab16 __swab16
131 #define swab32 __swab32
132 #define swab64 __swab64
133 #define swab16p __swab16p
134 #define swab32p __swab32p
135 #define swab64p __swab64p
136 #define swab16s __swab16s
137 #define swab32s __swab32s
138 #define swab64s __swab64s
141 #endif /* _LINUX_BYTEORDER_SWAB_H */