blob: 2988d29a0867f4c0ce187040e710e3c87344030d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Ralf Baechle1e32cee2006-02-01 15:29:21 +000011#include <linux/compiler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/types.h>
13
Harvey Harrison255a12f2008-10-29 14:21:32 -070014#if defined(__MIPSEB__)
15# define __BIG_ENDIAN
16#elif defined(__MIPSEL__)
17# define __LITTLE_ENDIAN
18#else
19# error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
20#endif
21
22#define __SWAB_64_THRU_32__
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Ralf Baechle1e32cee2006-02-01 15:29:21 +000024#ifdef CONFIG_CPU_MIPSR2
25
Harvey Harrison255a12f2008-10-29 14:21:32 -070026static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
Ralf Baechle1e32cee2006-02-01 15:29:21 +000027{
28 __asm__(
29 " wsbh %0, %1 \n"
30 : "=r" (x)
31 : "r" (x));
32
33 return x;
34}
Harvey Harrison255a12f2008-10-29 14:21:32 -070035#define __arch_swab16 __arch_swab16
Ralf Baechle1e32cee2006-02-01 15:29:21 +000036
Harvey Harrison255a12f2008-10-29 14:21:32 -070037static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
Ralf Baechle1e32cee2006-02-01 15:29:21 +000038{
39 __asm__(
40 " wsbh %0, %1 \n"
41 " rotr %0, %0, 16 \n"
42 : "=r" (x)
43 : "r" (x));
44
45 return x;
46}
Harvey Harrison255a12f2008-10-29 14:21:32 -070047#define __arch_swab32 __arch_swab32
Ralf Baechle1e32cee2006-02-01 15:29:21 +000048
Ralf Baechlebbad8122006-02-15 13:06:34 +000049#ifdef CONFIG_CPU_MIPS64_R2
Harvey Harrison255a12f2008-10-29 14:21:32 -070050static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
Ralf Baechlebbad8122006-02-15 13:06:34 +000051{
52 __asm__(
53 " dsbh %0, %1 \n"
54 " dshd %0, %0 \n"
55 " drotr %0, %0, 32 \n"
56 : "=r" (x)
57 : "r" (x));
58
59 return x;
60}
Harvey Harrison255a12f2008-10-29 14:21:32 -070061#define __arch_swab64 __arch_swab64
Ralf Baechlebbad8122006-02-15 13:06:34 +000062#endif /* CONFIG_CPU_MIPS64_R2 */
63
Ralf Baechle1e32cee2006-02-01 15:29:21 +000064#endif /* CONFIG_CPU_MIPSR2 */
65
Harvey Harrison255a12f2008-10-29 14:21:32 -070066#include <linux/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#endif /* _ASM_BYTEORDER_H */