blob: 33790b9e0cc0d46ee41f0ec8d3f3dbf181c8a9fc [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 Baechle1e32ceec2006-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 Baechle1e32ceec2006-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 Baechle1e32ceec2006-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 Baechle1e32ceec2006-02-01 15:29:21 +000036
Harvey Harrison255a12f2008-10-29 14:21:32 -070037static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
Ralf Baechle1e32ceec2006-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 Baechle1e32ceec2006-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__(
David Daneyed2b03e2008-12-17 13:28:39 -080053 " dsbh %0, %1\n"
54 " dshd %0, %0"
Ralf Baechlebbad8122006-02-15 13:06:34 +000055 : "=r" (x)
56 : "r" (x));
57
58 return x;
59}
Harvey Harrison255a12f2008-10-29 14:21:32 -070060#define __arch_swab64 __arch_swab64
Ralf Baechlebbad8122006-02-15 13:06:34 +000061#endif /* CONFIG_CPU_MIPS64_R2 */
62
Ralf Baechle1e32ceec2006-02-01 15:29:21 +000063#endif /* CONFIG_CPU_MIPSR2 */
64
Harvey Harrison255a12f2008-10-29 14:21:32 -070065#include <linux/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#endif /* _ASM_BYTEORDER_H */