4ce5bc37f403b37e7395e3851928e8439a52fdf6
[linux-2.6.git] / include / asm-mips / byteorder.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1996, 99, 2003 by Ralf Baechle
7  */
8 #ifndef _ASM_BYTEORDER_H
9 #define _ASM_BYTEORDER_H
10
11 #include <linux/config.h>
12 #include <linux/compiler.h>
13 #include <asm/types.h>
14
15 #ifdef __GNUC__
16
17 #ifdef CONFIG_CPU_MIPSR2
18
19 static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
20 {
21         __asm__(
22         "       .set    mips32r2                \n"
23         "       wsbh    %0, %1                  \n"
24         "       .set    mips0                   \n"
25         : "=r" (x)
26         : "r" (x));
27
28         return x;
29 }
30 #define __arch__swab16(x)       ___arch__swab16(x)
31
32 static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
33 {
34         __asm__(
35         "       .set    mips32r2                \n"
36         "       wsbh    %0, %1                  \n"
37         "       rotr    %0, %0, 16              \n"
38         "       .set    mips0                   \n"
39         : "=r" (x)
40         : "r" (x));
41
42         return x;
43 }
44 #define __arch__swab32(x)       ___arch__swab32(x)
45
46 #endif /* CONFIG_CPU_MIPSR2 */
47
48 #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
49 #  define __BYTEORDER_HAS_U64__
50 #  define __SWAB_64_THRU_32__
51 #endif
52
53 #endif /* __GNUC__ */
54
55 #if defined (__MIPSEB__)
56 #  include <linux/byteorder/big_endian.h>
57 #elif defined (__MIPSEL__)
58 #  include <linux/byteorder/little_endian.h>
59 #else
60 #  error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
61 #endif
62
63 #endif /* _ASM_BYTEORDER_H */